Skip to content

Commit e22ed0b

Browse files
Merge pull request #6993 from dotty-staging/from-tasty-jar
Accept jars as input with -from-tasty
2 parents b3b2fd6 + f6288a5 commit e22ed0b

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

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

Lines changed: 13 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,26 @@ 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"))
83+
("", name) :: Nil
7684
else if (Files.exists(path)) {
7785
TastyFileUtil.getClassName(path) match {
78-
case Some(res) => res
86+
case Some(res) => res:: Nil
7987
case _ =>
8088
ctx0.error(s"Could not load classname from $name.")
81-
("", name)
89+
("", name) :: Nil
8290
}
8391
} else {
8492
ctx0.error(s"File $name does not exist.")
85-
("", name)
93+
("", name) :: Nil
8694
}
8795
}.unzip
8896
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)