Skip to content

Only allow jar and tasty as input for -from-tasty #10003

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions compiler/src/dotty/tools/dotc/Driver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -90,23 +90,23 @@ class Driver {
// Resolve classpath and class names of tasty files
val (classPaths, classNames) = fileNames0.flatMap { name =>
val path = Paths.get(name)
if !name.endsWith(".jar") && !name.endsWith(".tasty") then // is class name
("", name) :: Nil // TODO remove this case. We cannot rely on an expected tasty file beeing loaded.
else if !Files.exists(path) then
if !Files.exists(path) then
report.error(s"File does not exist: $name")
Nil
else if name.endsWith(".jar") then
new dotty.tools.io.Jar(File(name)).toList.collect {
case e if e.getName.endsWith(".tasty") && !fromTastyIgnoreList(e.getName) =>
(name, e.getName.stripSuffix(".tasty").replace("/", "."))
}
else
assert(name.endsWith(".tasty"))
else if name.endsWith(".tasty") then
TastyFileUtil.getClassName(path) match
case Some(res) => res :: Nil
case _ =>
report.error(s"Could not load classname from: $name")
Nil
else
report.error(s"File extension is not `tasty` or `jar`: $name")
Nil
}.unzip
val ctx1 = ctx0.fresh
val classPaths1 = classPaths.distinct.filter(_ != "")
Expand Down
2 changes: 1 addition & 1 deletion project/scripts/bootstrapCmdTests
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ clear_out "$OUT"
# check that `scalac -from-tasty` compiles and `scala` runs it
echo "testing ./bin/scalac -from-tasty and scala -classpath"
clear_out "$OUT1"
./bin/scalac -from-tasty -classpath "$OUT" -d "$OUT1" "$MAIN"
./bin/scalac -from-tasty -d "$OUT1" "$OUT/$TASTY"
./bin/scala -classpath "$OUT1" "$MAIN" > "$tmp"
test "$EXPECTED_OUTPUT" = "$(cat "$tmp")"

Expand Down
10 changes: 3 additions & 7 deletions project/scripts/cmdTests
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ grep -qe "$EXPECTED_OUTPUT" "$tmp"
# check that `sbt scalac` compiles and `sbt scala` runs it
echo "testing sbt scalac -from-tasty and scala -classpath"
clear_out "$OUT"
"$SBT" ";scalac $SOURCE -d $OUT ;scalac -from-tasty -classpath $OUT -d $OUT1 $MAIN ;scala -classpath $OUT1 $MAIN" > "$tmp"
"$SBT" ";scalac $SOURCE -d $OUT ;scalac -from-tasty -d $OUT1 $OUT/$TASTY ;scala -classpath $OUT1 $MAIN" > "$tmp"
grep -qe "$EXPECTED_OUTPUT" "$tmp"

echo "testing sbt scalac -from-tasty from a jar and scala -classpath"
Expand All @@ -19,12 +19,8 @@ clear_out "$OUT"
grep -qe "$EXPECTED_OUTPUT" "$tmp"

# check that `sbt scalac -decompile` runs
echo "testing sbt scalac -decompile"
"$SBT" ";scalac -decompile -color:never -classpath $OUT $MAIN" > "$tmp"
grep -qe "def main(args: scala.Array\[scala.Predef.String\]): scala.Unit =" "$tmp"

echo "testing sbt scalac -decompile from file"
"$SBT" ";scalac -decompile -color:never -classpath $OUT $OUT/$TASTY" > "$tmp"
"$SBT" ";scalac -decompile -color:never $OUT/$TASTY" > "$tmp"
grep -qe "def main(args: scala.Array\[scala.Predef.String\]): scala.Unit =" "$tmp"

echo "testing sbt scala with no -classpath"
Expand All @@ -34,7 +30,7 @@ grep -qe "$EXPECTED_OUTPUT" "$tmp"

echo "testing loading tasty from .tasty file in jar"
clear_out "$OUT"
"$SBT" ";scalac -d $OUT/out.jar $SOURCE; scalac -decompile -classpath $OUT/out.jar -color:never $MAIN" > "$tmp"
"$SBT" ";scalac -d $OUT/out.jar $SOURCE; scalac -decompile -color:never $OUT/out.jar" > "$tmp"
grep -qe "def main(args: scala.Array\[scala.Predef.String\]): scala.Unit =" "$tmp"

echo "testing sbt scalac with suspension"
Expand Down