Skip to content

Commit 1d7fa20

Browse files
committed
Add default output directory scalac in dotty project
The previous default output directory when executing `scalac`, `run`, `scala3-bootstrapped/scalac` and `scala3-bootstrapped/run` was the root directory of the project. This could easily pollute the project with `.class`/`.tasty` files. In some situations, these could be mistakenly loaded by some of the projects or scripts. Now when we execute `scalac` with no `-d` option set, we output `./out/default-last-scalac-out.jar`. We also make `scala` and `run` use that JAR by default in the classpath if no `-classpath` option is set.
1 parent 16f1680 commit 1d7fa20

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

project/Build.scala

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,10 @@ object Build {
712712
val externalDeps = externalCompilerClasspathTask.value
713713
val jars = packageAll.value
714714

715+
val argsWithDefaultClasspath: List[String] =
716+
if (args.contains("-classpath")) args
717+
else insertClasspathInArgs(args, (baseDirectory.value / ".." / "out" / "default-last-scalac-out.jar").getPath)
718+
715719
val scalaLib = findArtifactPath(externalDeps, "scala-library")
716720
val dottyLib = jars("scala3-library")
717721

@@ -725,7 +729,7 @@ object Build {
725729
} else if (scalaLib == "") {
726730
println("Couldn't find scala-library on classpath, please run using script in bin dir instead")
727731
} else if (args.contains("-with-compiler")) {
728-
val args1 = args.filter(_ != "-with-compiler")
732+
val args1 = argsWithDefaultClasspath.filter(_ != "-with-compiler")
729733
val asm = findArtifactPath(externalDeps, "scala-asm")
730734
val dottyCompiler = jars("scala3-compiler")
731735
val dottyStaging = jars("scala3-staging")
@@ -734,7 +738,7 @@ object Build {
734738
val tastyCore = jars("tasty-core")
735739
val compilerInterface = findArtifactPath(externalDeps, "compiler-interface")
736740
run(insertClasspathInArgs(args1, List(dottyCompiler, dottyInterfaces, asm, dottyStaging, dottyTastyInspector, tastyCore, compilerInterface).mkString(File.pathSeparator)))
737-
} else run(args)
741+
} else run(argsWithDefaultClasspath)
738742
},
739743

740744
run := scalac.evaluated,
@@ -749,6 +753,9 @@ object Build {
749753
val args0: List[String] = spaceDelimited("<arg>").parsed.toList
750754
val decompile = args0.contains("-decompile")
751755
val printTasty = args0.contains("-print-tasty")
756+
val defaultOutputDirectory =
757+
if (args0.contains("-d")) Nil else List("-d", (baseDirectory.value / ".." / "out" / "default-last-scalac-out.jar").getPath)
758+
println(defaultOutputDirectory)
752759
val debugFromTasty = args0.contains("-Ythrough-tasty")
753760
val args = args0.filter(arg => arg != "-repl" && arg != "-decompile" &&
754761
arg != "-with-compiler" && arg != "-Ythrough-tasty" && arg != "-print-tasty")
@@ -783,7 +790,7 @@ object Build {
783790
extraClasspath ++= Seq(dottyCompiler, dottyInterfaces, asm, dottyStaging, dottyTastyInspector, tastyCore, compilerInterface)
784791
}
785792

786-
val fullArgs = main :: (if (printTasty) args else insertClasspathInArgs(args, extraClasspath.mkString(File.pathSeparator)))
793+
val fullArgs = main :: defaultOutputDirectory ::: (if (printTasty) args else insertClasspathInArgs(args, extraClasspath.mkString(File.pathSeparator)))
787794

788795
(Compile / runMain).toTask(fullArgs.mkString(" ", " ", ""))
789796
}.evaluated,

0 commit comments

Comments
 (0)