From 95030c29334e57e50e8c73a91288c9b221889984 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 5 Aug 2019 23:23:01 +0200 Subject: [PATCH 1/2] Accept jars as input with -from-tasty Recompile all classes in the given jar. --- compiler/src/dotty/tools/dotc/Driver.scala | 17 ++++++++++++----- project/scripts/cmdTests | 5 +++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/Driver.scala b/compiler/src/dotty/tools/dotc/Driver.scala index b42d9984d683..4207f1ee61b5 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,25 @@ 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" From f6288a55e2864ee9fdc41f02052762aac9046396 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Tue, 6 Aug 2019 19:20:59 +0200 Subject: [PATCH 2/2] Code format cleanup --- compiler/src/dotty/tools/dotc/Driver.scala | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/Driver.scala b/compiler/src/dotty/tools/dotc/Driver.scala index 4207f1ee61b5..f3ab08a7c0cc 100644 --- a/compiler/src/dotty/tools/dotc/Driver.scala +++ b/compiler/src/dotty/tools/dotc/Driver.scala @@ -79,7 +79,8 @@ class Driver { (name, e.getName.stripSuffix(".tasty").replace("/", ".")) }.toList } - else if (!name.endsWith(".tasty")) ("", name) :: Nil + else if (!name.endsWith(".tasty")) + ("", name) :: Nil else if (Files.exists(path)) { TastyFileUtil.getClassName(path) match { case Some(res) => res:: Nil @@ -89,7 +90,7 @@ class Driver { } } else { ctx0.error(s"File $name does not exist.") - ("", name):: Nil + ("", name) :: Nil } }.unzip val ctx1 = ctx0.fresh