Skip to content

Tasty Inspector does not work when classpath is specified in a jar MANIFEST.MF #22911

Open
@msigmond

Description

@msigmond

I ran into this weird situation, and I would like to ask your advice.

I have the following code in a file named MyInspector.scala:

import scala.quoted.*
import scala.tasty.inspector.*

object Algo:
   def sayHello: String = "hello"

class MyInspector extends Inspector:
   def inspect(using Quotes)(tastys: List[Tasty[quotes.type]]): Unit =
      import quotes.reflect.*
      for tasty <- tastys do
         val tree = tasty.ast
         println(s"tree = $tree")

object Test:
   def main(args: Array[String]): Unit =
      println("Hello World!")
      val tastyFiles = List("Algo.tasty")
      TastyInspector.inspectTastyFiles(tastyFiles)(new MyInspector)

I put the following jars into a local lib folder:

$ find lib/
lib/
lib/scala-library-2.13.15.jar
lib/tasty-core_3-3.6.4.jar
lib/compiler-interface-1.10.4.jar
lib/scala3-interfaces-3.6.4.jar
lib/scala3-library_3-3.6.4.jar
lib/scala3-compiler_3-3.6.4.jar
lib/scala3-tasty-inspector_3-3.6.4.jar

I compiled and created a jar as follows:

$ SCALAC_CLASSPATH=$(find lib/ -name "*jar" | sed -z 's/\n/:/g')
$ scalac -classpath $SCALAC_CLASSPATH MyInspector.scala
$ jar cf ./my.jar ./*.class

I can then run the code successfully as follows:

$ CLASSPATH=$(find . -name "*jar" | sed -z 's/\n/:/g')
$ java -cp $CLASSPATH Test
Hello World!
tree = EmptyTree

However, if I wanted to specify the classpath in a manifest inside a jar, I get an error:

$ echo 'Class-Path: ./my.jar' > MANIFEST.MF
$ find lib/ -name "*jar" -exec echo "  " {} \; >> MANIFEST.MF
$ jar cfm mani.jar MANIFEST.MF 
$ java -cp mani.jar Test
Hello World!
Could not find package scala from compiler core libraries.
Make sure the compiler core libraries are on the classpath.

Please could you advise if this is expected?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions