diff --git a/compiler/src/dotty/tools/dotc/Driver.scala b/compiler/src/dotty/tools/dotc/Driver.scala index b42d9984d683..f3ab08a7c0cc 100644 --- a/compiler/src/dotty/tools/dotc/Driver.scala +++ b/compiler/src/dotty/tools/dotc/Driver.scala @@ -8,6 +8,7 @@ import core.Comments.{ContextDoc, ContextDocstrings} import core.Contexts.{Context, ContextBase} import core.{MacroClassLoader, Mode, TypeError} import dotty.tools.dotc.ast.Positioned +import dotty.tools.io.File import reporting._ import scala.util.control.NonFatal @@ -70,19 +71,26 @@ class Driver { protected def fromTastySetup(fileNames0: List[String], ctx0: Context): (List[String], Context) = { if (ctx0.settings.fromTasty.value(ctx0)) { // Resolve classpath and class names of tasty files - val (classPaths, classNames) = fileNames0.map { name => + val (classPaths, classNames) = fileNames0.flatMap { name => val path = Paths.get(name) - if (!name.endsWith(".tasty")) ("", name) + if (name.endsWith(".jar")) { + new dotty.tools.io.Jar(File(name)).iterator.collect { + case e if e.getName.endsWith(".tasty") => + (name, e.getName.stripSuffix(".tasty").replace("/", ".")) + }.toList + } + else if (!name.endsWith(".tasty")) + ("", name) :: Nil else if (Files.exists(path)) { TastyFileUtil.getClassName(path) match { - case Some(res) => res + case Some(res) => res:: Nil case _ => ctx0.error(s"Could not load classname from $name.") - ("", name) + ("", name) :: Nil } } else { ctx0.error(s"File $name does not exist.") - ("", name) + ("", name) :: Nil } }.unzip val ctx1 = ctx0.fresh diff --git a/project/scripts/cmdTests b/project/scripts/cmdTests index 93384739a345..79aa4a14ceeb 100755 --- a/project/scripts/cmdTests +++ b/project/scripts/cmdTests @@ -13,6 +13,11 @@ clear_out "$OUT" "$SBT" ";dotc $SOURCE -d $OUT ;dotc -from-tasty -classpath $OUT -d $OUT1 $MAIN ;dotr -classpath $OUT1 $MAIN" > "$tmp" grep -qe "$EXPECTED_OUTPUT" "$tmp" +echo "testing sbt dotc -from-tasty from a jar and dotr -classpath" +clear_out "$OUT" +"$SBT" ";dotc -d $OUT/out.jar $SOURCE ;dotc -from-tasty -d $OUT1 $OUT/out.jar ;dotr -classpath $OUT1 $MAIN" > "$tmp" +grep -qe "$EXPECTED_OUTPUT" "$tmp" + # check that `sbt dotc -decompile` runs echo "testing sbt dotc -decompile" "$SBT" ";dotc -decompile -color:never -classpath $OUT $MAIN" > "$tmp"