Skip to content

Commit 95030c2

Browse files
committed
Accept jars as input with -from-tasty
Recompile all classes in the given jar.
1 parent c770869 commit 95030c2

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

compiler/src/dotty/tools/dotc/Driver.scala

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import core.Comments.{ContextDoc, ContextDocstrings}
88
import core.Contexts.{Context, ContextBase}
99
import core.{MacroClassLoader, Mode, TypeError}
1010
import dotty.tools.dotc.ast.Positioned
11+
import dotty.tools.io.File
1112
import reporting._
1213

1314
import scala.util.control.NonFatal
@@ -70,19 +71,25 @@ class Driver {
7071
protected def fromTastySetup(fileNames0: List[String], ctx0: Context): (List[String], Context) = {
7172
if (ctx0.settings.fromTasty.value(ctx0)) {
7273
// Resolve classpath and class names of tasty files
73-
val (classPaths, classNames) = fileNames0.map { name =>
74+
val (classPaths, classNames) = fileNames0.flatMap { name =>
7475
val path = Paths.get(name)
75-
if (!name.endsWith(".tasty")) ("", name)
76+
if (name.endsWith(".jar")) {
77+
new dotty.tools.io.Jar(File(name)).iterator.collect {
78+
case e if e.getName.endsWith(".tasty") =>
79+
(name, e.getName.stripSuffix(".tasty").replace("/", "."))
80+
}.toList
81+
}
82+
else if (!name.endsWith(".tasty")) ("", name) :: Nil
7683
else if (Files.exists(path)) {
7784
TastyFileUtil.getClassName(path) match {
78-
case Some(res) => res
85+
case Some(res) => res:: Nil
7986
case _ =>
8087
ctx0.error(s"Could not load classname from $name.")
81-
("", name)
88+
("", name) :: Nil
8289
}
8390
} else {
8491
ctx0.error(s"File $name does not exist.")
85-
("", name)
92+
("", name):: Nil
8693
}
8794
}.unzip
8895
val ctx1 = ctx0.fresh

project/scripts/cmdTests

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ clear_out "$OUT"
1313
"$SBT" ";dotc $SOURCE -d $OUT ;dotc -from-tasty -classpath $OUT -d $OUT1 $MAIN ;dotr -classpath $OUT1 $MAIN" > "$tmp"
1414
grep -qe "$EXPECTED_OUTPUT" "$tmp"
1515

16+
echo "testing sbt dotc -from-tasty from a jar and dotr -classpath"
17+
clear_out "$OUT"
18+
"$SBT" ";dotc -d $OUT/out.jar $SOURCE ;dotc -from-tasty -d $OUT1 $OUT/out.jar ;dotr -classpath $OUT1 $MAIN" > "$tmp"
19+
grep -qe "$EXPECTED_OUTPUT" "$tmp"
20+
1621
# check that `sbt dotc -decompile` runs
1722
echo "testing sbt dotc -decompile"
1823
"$SBT" ";dotc -decompile -color:never -classpath $OUT $MAIN" > "$tmp"

0 commit comments

Comments
 (0)