Skip to content

Commit f7fc6fa

Browse files
committed
Fix classpath when executing with quoted.Expr.run
1 parent 166c49c commit f7fc6fa

File tree

5 files changed

+23
-11
lines changed

5 files changed

+23
-11
lines changed

compiler/src/dotty/tools/dotc/quoted/QuoteDriver.scala

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,11 @@ class QuoteDriver extends Driver {
5050

5151
override def initCtx: Context = {
5252
val ictx = super.initCtx.fresh
53-
// TODO add compiler to java.class.path
54-
val classpath = List(
55-
System.getProperty("java.class.path"),
56-
"../compiler/target/scala-2.12/dotty-compiler_2.12-0.6.0-bin-SNAPSHOT-nonbootstrapped.jar",
57-
"../library/target/scala-2.12/dotty-library_2.12-0.6.0-bin-SNAPSHOT-nonbootstrapped.jar",
58-
"../interfaces/target/dotty-interfaces-0.6.0-bin-SNAPSHOT.jar"
59-
).mkString(":")
60-
ictx.settings.classpath.update(classpath)(ictx)
53+
val compilerClasspath = System.getProperty("dotty.tools.dotc.classpath")
54+
assert(compilerClasspath ne null, "System property `dotty.tools.dotc.classpath` is not set.")
55+
val classpath = System.getProperty("java.class.path")
56+
val scalaLib = classpath.split(":").filter(_.contains("scala-library")).mkString(":")
57+
ictx.settings.classpath.update(compilerClasspath + ":" + scalaLib)(ictx)
6158
ictx
6259
}
6360

compiler/test/dotty/tools/vulpix/ChildJVMMain.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public class ChildJVMMain {
1212
static final String MessageEnd = "##THIS IS THE END FOR ME, GOODBYE##";
1313

1414
private static void runMain(String dir) throws Exception {
15+
System.setProperty("dotty.tools.dotc.classpath", dir);
1516
ArrayList<URL> cp = new ArrayList<>();
1617
for (String path : dir.split(":"))
1718
cp.add(new File(path).toURI().toURL());

dist/bin/dotr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ fi
3030
source "$PROG_HOME/bin/common"
3131

3232
declare -a residual_args
33+
declare -a system_properties
3334
run_repl=false
3435
with_compiler=false
3536
CLASS_PATH=""
@@ -76,6 +77,7 @@ else
7677
fi
7778
if [ $with_compiler == true ]; then
7879
cp_arg+="$PSEP$DOTTY_COMP$PSEP$DOTTY_INTF$PSEP$SCALA_ASM"
80+
system_properties+=("-Ddotty.tools.dotc.classpath=$DOTTY_COMP$PSEP$DOTTY_LIB$PSEP$DOTTY_INTF$PSEP$SCALA_ASM")
7981
fi
80-
eval exec "\"$JAVACMD\"" "$DEBUG" "-classpath \"$cp_arg\"" "${residual_args[@]}"
82+
eval exec "\"$JAVACMD\"" "$DEBUG" "-classpath \"$cp_arg\"" "${system_properties[@]}" "${residual_args[@]}"
8183
fi

project/Build.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,9 +578,9 @@ object Build {
578578
.toList.mkString(":")
579579

580580
val scalaLib = findLib("scala-library")
581+
val dottyLib = packageAll.value("dotty-library")
581582

582583
def run(args: List[String]): Unit = {
583-
val dottyLib = packageAll.value("dotty-library")
584584
val fullArgs = insertClasspathInArgs(args, s".:$dottyLib:$scalaLib")
585585
s"$java ${fullArgs.mkString(" ")}".!
586586
}
@@ -596,7 +596,9 @@ object Build {
596596
val asm = findLib("scala-asm")
597597
val dottyCompiler = packageAll.value("dotty-compiler")
598598
val dottyInterfaces = packageAll.value("dotty-interfaces")
599-
run(insertClasspathInArgs(args1, s"$dottyCompiler:$dottyInterfaces:$asm"))
599+
val deps = s"$dottyCompiler:$dottyInterfaces:$asm"
600+
val args2 = s"-Ddotty.tools.dotc.classpath=$deps:$dottyLib" :: insertClasspathInArgs(args1, deps)
601+
run(args2)
600602
} else run(args)
601603
},
602604
run := dotc.evaluated,

project/scripts/sbtTests

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,13 @@ else
5656
echo "failed output check"
5757
exit -1
5858
fi
59+
60+
echo "testing scala.quoted.Expr.run from sbt dotr"
61+
./project/scripts/sbt ";dotc -classpath compiler/target/scala-2.12/classes tests/run-special/quote-run.scala; dotr -with-compiler Test" > sbtdot5.out
62+
cat sbtdot5.out
63+
if grep -e "val a: Int = 3" sbtdot5.out; then
64+
echo "output ok"
65+
else
66+
echo "failed output check"
67+
exit -1
68+
fi

0 commit comments

Comments
 (0)