Skip to content

Commit 675d3d7

Browse files
committed
fix #1274: test for dotty bootstrap based on tasty
1 parent 0e8f05d commit 675d3d7

File tree

4 files changed

+43
-13
lines changed

4 files changed

+43
-13
lines changed

src/dotty/tools/dotc/config/PathResolver.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ class PathResolver(implicit ctx: Context) {
180180
case "extdirs" => settings.extdirs.value
181181
case "classpath" | "cp" => settings.classpath.value
182182
case "sourcepath" => settings.sourcepath.value
183+
case "priorityclasspath" => settings.priorityclasspath.value
183184
}
184185

185186
/** Calculated values based on any given command line options, falling back on
@@ -193,6 +194,7 @@ class PathResolver(implicit ctx: Context) {
193194
def javaUserClassPath = if (useJavaClassPath) Defaults.javaUserClassPath else ""
194195
def scalaBootClassPath = cmdLineOrElse("bootclasspath", Defaults.scalaBootClassPath)
195196
def scalaExtDirs = cmdLineOrElse("extdirs", Defaults.scalaExtDirs)
197+
def priorityClassPath = cmdLineOrElse("prioritypath", "")
196198
/** Scaladoc doesn't need any bootstrapping, otherwise will create errors such as:
197199
* [scaladoc] ../scala-trunk/src/reflect/scala/reflect/macros/Reifiers.scala:89: error: object api is not a member of package reflect
198200
* [scaladoc] case class ReificationException(val pos: reflect.api.PositionApi, val msg: String) extends Throwable(msg)
@@ -220,7 +222,9 @@ class PathResolver(implicit ctx: Context) {
220222
import context._
221223

222224
// Assemble the elements!
225+
// priority class path takes precedence
223226
def basis = List[Traversable[ClassPath]](
227+
classesInExpandedPath(priorityClassPath), // 0. The priority class path (for testing).
224228
classesInPath(javaBootClassPath), // 1. The Java bootstrap class path.
225229
contentsOfDirsInPath(javaExtDirs), // 2. The Java extension class path.
226230
classesInExpandedPath(javaUserClassPath), // 3. The Java application class path.
@@ -235,6 +239,7 @@ class PathResolver(implicit ctx: Context) {
235239
override def toString = """
236240
|object Calculated {
237241
| scalaHome = %s
242+
| priorityClassPath = %s
238243
| javaBootClassPath = %s
239244
| javaExtDirs = %s
240245
| javaUserClassPath = %s
@@ -244,7 +249,7 @@ class PathResolver(implicit ctx: Context) {
244249
| userClassPath = %s
245250
| sourcePath = %s
246251
|}""".trim.stripMargin.format(
247-
scalaHome,
252+
scalaHome, ppcp(priorityClassPath),
248253
ppcp(javaBootClassPath), ppcp(javaExtDirs), ppcp(javaUserClassPath),
249254
useJavaClassPath,
250255
ppcp(scalaBootClassPath), ppcp(scalaExtDirs), ppcp(userClassPath),

src/dotty/tools/dotc/config/ScalaSettings.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ class ScalaSettings extends Settings.SettingGroup {
1515
val javabootclasspath = PathSetting("-javabootclasspath", "Override java boot classpath.", Defaults.javaBootClassPath)
1616
val javaextdirs = PathSetting("-javaextdirs", "Override java extdirs classpath.", Defaults.javaExtDirs)
1717
val sourcepath = PathSetting("-sourcepath", "Specify location(s) of source files.", "") // Defaults.scalaSourcePath
18+
val argfiles = BooleanSetting("@<file>", "A text file containing compiler arguments (options and source files)")
19+
val classpath = PathSetting("-classpath", "Specify where to find user class files.", defaultClasspath) withAbbreviation "-cp"
20+
val d = StringSetting("-d", "directory|jar", "destination for generated classfiles.", ".")
21+
val priorityclasspath = PathSetting("-priorityclasspath", "class path that takes precedence over all other paths (or testing only)", "")
1822

1923
/** Other settings.
2024
*/
@@ -45,9 +49,6 @@ class ScalaSettings extends Settings.SettingGroup {
4549
val nobootcp = BooleanSetting("-nobootcp", "Do not use the boot classpath for the scala jars.")
4650
val strict = BooleanSetting("-strict", "Use strict type rules, which means some formerly legal code does not typecheck anymore.")
4751

48-
val argfiles = BooleanSetting("@<file>", "A text file containing compiler arguments (options and source files)")
49-
val classpath = PathSetting("-classpath", "Specify where to find user class files.", defaultClasspath) withAbbreviation "-cp"
50-
val d = StringSetting("-d", "directory|jar", "destination for generated classfiles.", ".")
5152
val nospecialization = BooleanSetting("-no-specialization", "Ignore @specialize annotations.")
5253
val language = MultiStringSetting("-language", "feature", "Enable one or more language features.")
5354
val rewrite = OptionSetting[Rewrites]("-rewrite", "When used in conjunction with -language:Scala2 rewrites sources to migrate to new syntax")

src/dotty/tools/dotc/core/Contexts.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ object Contexts {
131131
def compilationUnit: CompilationUnit = _compilationUnit
132132

133133
/** The current tree */
134-
private[this] var _tree: Tree[_ >: Untyped] = _
134+
private[this] var _tree: Tree[_ >: Untyped]= _
135135
protected def tree_=(tree: Tree[_ >: Untyped]) = _tree = tree
136136
def tree: Tree[_ >: Untyped] = _tree
137137

test/dotc/tests.scala

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,29 @@
11
package dotc
22

33
import test._
4-
import dotty.partest._
5-
import org.junit.Test
6-
import org.junit.experimental.categories._
4+
import org.junit.{Before, Test}
75

6+
import scala.reflect.io.Directory
87
import scala.io.Source
98

109
// tests that match regex '(pos|dotc|run|java|compileStdLib)\.*' would be executed as benchmarks.
1110
class tests extends CompilerTest {
1211

1312
def isRunByJenkins: Boolean = sys.props.isDefinedAt("dotty.jenkins.build")
1413

14+
val defaultOutputDir = "./out/"
15+
1516
val noCheckOptions = List(
1617
// "-verbose",
1718
// "-Ylog:frontend",
1819
// "-Xprompt",
1920
// "-explaintypes",
2021
// "-Yshow-suppressed-errors",
22+
"-d", defaultOutputDir,
2123
"-pagewidth", "160")
2224

23-
val defaultOutputDir = "./out/"
24-
25-
implicit val defaultOptions = noCheckOptions ++ List(
26-
"-Yno-deep-subtypes", "-Yno-double-bindings", "-Yforce-sbt-phases",
27-
"-d", defaultOutputDir) ++ {
25+
implicit val defaultOptions = noCheckOptions ++
26+
List("-Yno-deep-subtypes", "-Yno-double-bindings", "-Yforce-sbt-phases") ++ {
2827
if (isRunByJenkins) List("-Ycheck:tailrec,resolveSuper,mixin,restoreScopes,labelDef") // should be Ycheck:all, but #725
2928
else List("-Ycheck:tailrec,resolveSuper,mixin,restoreScopes,labelDef")
3029
}
@@ -57,6 +56,12 @@ class tests extends CompilerTest {
5756
val dottyReplDir = dotcDir + "repl/"
5857
val typerDir = dotcDir + "typer/"
5958

59+
@Before def cleanup(): Unit = {
60+
// remove class files from stdlib and tests compilation
61+
Directory(defaultOutputDir + "scala").deleteRecursively()
62+
Directory(defaultOutputDir + "java").deleteRecursively()
63+
}
64+
6065
@Test def pickle_pickleOK = compileDir(testsDir, "pickling", testPickling)
6166
// This directory doesn't exist anymore
6267
// @Test def pickle_pickling = compileDir(coreDir, "pickling", testPickling)
@@ -295,4 +300,23 @@ class tests extends CompilerTest {
295300
@Test def tasty_dotc_util = compileDir(dotcDir, "util", testPickling)
296301
@Test def tasty_tools_io = compileDir(toolsDir, "io", testPickling)
297302
@Test def tasty_tests = compileDir(testsDir, "tasty", testPickling)
303+
304+
@Test def tasty_bootstrap = {
305+
val opt = List("-priorityclasspath", defaultOutputDir, "-Ylog-classpath")
306+
// first compile dotty
307+
compileDir(dottyDir, ".", List("-deep", "-Ycheck-reentrant", "-strict"))(allowDeepSubtypes)
308+
309+
compileDir(dottyDir, "tools", opt)
310+
compileDir(toolsDir, "dotc", opt)
311+
compileDir(dotcDir, "ast", opt)
312+
compileDir(dotcDir, "config", opt)
313+
compileDir(dotcDir, "parsing", opt)
314+
compileDir(dotcDir, "printing", opt)
315+
compileDir(dotcDir, "repl", opt)
316+
compileDir(dotcDir, "reporting", opt)
317+
compileDir(dotcDir, "rewrite", opt)
318+
compileDir(dotcDir, "transform", opt)
319+
compileDir(dotcDir, "typer", opt)
320+
compileDir(dotcDir, "util", opt)
321+
}
298322
}

0 commit comments

Comments
 (0)