From 0b0c7635af969bcacd95cf42a4d78d1b77cf55ff Mon Sep 17 00:00:00 2001 From: Martijn Hoekstra Date: Thu, 6 Sep 2018 18:19:47 +0200 Subject: [PATCH] use cross platform path separatator in build --- bench/src/main/scala/Benchmarks.scala | 2 +- .../dotc/core/classfile/ClassfileParser.scala | 2 +- .../dotty/tools/dotc/quoted/QuoteDriver.scala | 2 +- .../dotty/tools/dotc/transform/ReifyQuotes.scala | 2 +- .../test/dotty/tools/dotc/CompilationTests.scala | 10 ++++++---- .../test/dotty/tools/vulpix/ChildJVMMain.java | 5 +++-- project/Build.scala | 16 ++++++++-------- 7 files changed, 21 insertions(+), 18 deletions(-) diff --git a/bench/src/main/scala/Benchmarks.scala b/bench/src/main/scala/Benchmarks.scala index b4c1a369aa33..ec152b5336fa 100644 --- a/bench/src/main/scala/Benchmarks.scala +++ b/bench/src/main/scala/Benchmarks.scala @@ -63,7 +63,7 @@ object Bench { var cpIndex = argsNorm.indexOf("-classpath") if (cpIndex == -1) cpIndex = argsNorm.indexOf("-cp") - if (cpIndex != -1) argsNorm(cpIndex + 1) = argsNorm(cpIndex + 1) + ":" + libs + if (cpIndex != -1) argsNorm(cpIndex + 1) = argsNorm(cpIndex + 1) + java.io.File.pathSeparator + libs else argsNorm = argsNorm :+ "-classpath" :+ libs val file = new File(COMPILE_OPTS_FILE) diff --git a/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala b/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala index f6313f462ada..4c908c712941 100644 --- a/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala +++ b/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala @@ -763,7 +763,7 @@ class ClassfileParser( if (allowed != "always") { failUnless(allowed != "never") - val allowedList = allowed.split(":").toList + val allowedList = allowed.split(java.io.File.pathSeparator).toList val file = classRoot.symbol.associatedFile // Using `.toString.contains` isn't great, but it's good enough for a debug flag. failUnless(file == null || allowedList.exists(path => file.toString.contains(path))) diff --git a/compiler/src/dotty/tools/dotc/quoted/QuoteDriver.scala b/compiler/src/dotty/tools/dotc/quoted/QuoteDriver.scala index d6f77ccc6063..38aa8942bce8 100644 --- a/compiler/src/dotty/tools/dotc/quoted/QuoteDriver.scala +++ b/compiler/src/dotty/tools/dotc/quoted/QuoteDriver.scala @@ -81,7 +81,7 @@ class QuoteDriver extends Driver { // Loads the classes loaded by this class loader // When executing `run` or `test` in sbt the classpath is not in the property java.class.path val newClasspath = cl.getURLs.map(_.getFile()) - classpath = newClasspath.mkString("", ":", if (classpath == "") "" else ":" + classpath) + classpath = newClasspath.mkString("", java.io.File.pathSeparator, if (classpath == "") "" else java.io.File.pathSeparator + classpath) case _ => } ictx.settings.classpath.update(classpath)(ictx) diff --git a/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala b/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala index e7622d6d0af7..a47bf26231e3 100644 --- a/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala +++ b/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala @@ -66,7 +66,7 @@ class ReifyQuotes extends MacroTransformWithImplicits { private[this] var myMacroClassLoader: java.lang.ClassLoader = _ private def macroClassLoader(implicit ctx: Context): ClassLoader = { if (myMacroClassLoader == null) { - val urls = ctx.settings.classpath.value.split(':').map(cp => java.nio.file.Paths.get(cp).toUri.toURL) + val urls = ctx.settings.classpath.value.split(java.io.File.pathSeparatorChar).map(cp => java.nio.file.Paths.get(cp).toUri.toURL) myMacroClassLoader = new java.net.URLClassLoader(urls, getClass.getClassLoader) } myMacroClassLoader diff --git a/compiler/test/dotty/tools/dotc/CompilationTests.scala b/compiler/test/dotty/tools/dotc/CompilationTests.scala index 5fcca127e27f..a172a61f69b3 100644 --- a/compiler/test/dotty/tools/dotc/CompilationTests.scala +++ b/compiler/test/dotty/tools/dotc/CompilationTests.scala @@ -200,14 +200,16 @@ class CompilationTests extends ParallelTesting { // Make sure that the directory is clean dotty.tools.io.Directory(defaultOutputDir + "tastyBootstrap").deleteRecursively() + val sep = java.io.File.pathSeparator + val opt = TestFlags( // compile with bootstrapped library on cp: - defaultOutputDir + libGroup + "/src/:" + + defaultOutputDir + libGroup + "/src/" + sep + // as well as bootstrapped compiler: - defaultOutputDir + dotty1Group + "/dotty/:" + + defaultOutputDir + dotty1Group + "/dotty/" + sep + // and the other compiler dependenies: - Properties.compilerInterface + ":" + Properties.scalaLibrary + ":" + Properties.scalaAsm + ":" + - Properties.dottyInterfaces + ":" + Properties.jlineTerminal + ":" + Properties.jlineReader, + Properties.compilerInterface + sep + Properties.scalaLibrary + sep + Properties.scalaAsm + sep + + Properties.dottyInterfaces + sep + Properties.jlineTerminal + sep + Properties.jlineReader, Array("-Ycheck-reentrant", "-Yemit-tasty-in-class") ) diff --git a/compiler/test/dotty/tools/vulpix/ChildJVMMain.java b/compiler/test/dotty/tools/vulpix/ChildJVMMain.java index 9cc14d473262..7dd7fc49a920 100644 --- a/compiler/test/dotty/tools/vulpix/ChildJVMMain.java +++ b/compiler/test/dotty/tools/vulpix/ChildJVMMain.java @@ -14,10 +14,11 @@ public class ChildJVMMain { private static void runMain(String dir) throws Exception { String jcp = System.getProperty("java.class.path"); - System.setProperty("java.class.path", jcp == null ? dir : dir + ":" + jcp); + String sep = File.pathSeparator; + System.setProperty("java.class.path", jcp == null ? dir : dir + sep + jcp); ArrayList cp = new ArrayList<>(); - for (String path : dir.split(":")) + for (String path : dir.split(sep)) cp.add(new File(path).toURI().toURL()); URLClassLoader ucl = new URLClassLoader(cp.toArray(new URL[cp.size()])); diff --git a/project/Build.scala b/project/Build.scala index 6e9deefbb3d0..08813d6c670f 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -318,8 +318,8 @@ object Build { lazy val commonBenchmarkSettings = Seq( outputStrategy := Some(StdoutOutput), mainClass in (Jmh, run) := Some("dotty.tools.benchmarks.Bench"), // custom main for jmh:run - javaOptions += "-DBENCH_COMPILER_CLASS_PATH=" + Attributed.data((fullClasspath in (`dotty-bootstrapped`, Compile)).value).mkString("", ":", ""), - javaOptions += "-DBENCH_CLASS_PATH=" + Attributed.data((fullClasspath in (`dotty-library-bootstrapped`, Compile)).value).mkString("", ":", "") + javaOptions += "-DBENCH_COMPILER_CLASS_PATH=" + Attributed.data((fullClasspath in (`dotty-bootstrapped`, Compile)).value).mkString("", File.pathSeparator, ""), + javaOptions += "-DBENCH_CLASS_PATH=" + Attributed.data((fullClasspath in (`dotty-library-bootstrapped`, Compile)).value).mkString("", File.pathSeparator, "") ) // sbt >= 0.13.12 will automatically rewrite transitive dependencies on @@ -453,7 +453,7 @@ object Build { def findLib(attList: Seq[Attributed[File]], name: String) = attList .map(_.data.getAbsolutePath) .find(_.contains(name)) - .toList.mkString(":") + .toList.mkString(File.pathSeparator) // Settings shared between dotty-compiler and dotty-compiler-bootstrapped lazy val commonDottyCompilerSettings = Seq( @@ -682,13 +682,13 @@ object Build { else if (debugFromTasty) "dotty.tools.dotc.fromtasty.Debug" else "dotty.tools.dotc.Main" - var extraClasspath = s"$scalaLib:$dottyLib" - if ((decompile || printTasty) && !args.contains("-classpath")) extraClasspath += ":." + var extraClasspath = s"$scalaLib${File.pathSeparator}$dottyLib" + if ((decompile || printTasty) && !args.contains("-classpath")) extraClasspath += s"${File.pathSeparator}." if (args0.contains("-with-compiler")) { if (!isDotty.value) { throw new MessageOnlyException("-with-compiler can only be used with a bootstrapped compiler") } - extraClasspath += s":$dottyCompiler" + extraClasspath += s"${File.pathSeparator}$dottyCompiler" } val fullArgs = main :: insertClasspathInArgs(args, extraClasspath) @@ -698,7 +698,7 @@ object Build { def insertClasspathInArgs(args: List[String], cp: String): List[String] = { val (beforeCp, fromCp) = args.span(_ != "-classpath") - val classpath = fromCp.drop(1).headOption.fold(cp)(_ + ":" + cp) + val classpath = fromCp.drop(1).headOption.fold(cp)(_ + File.pathSeparator + cp) "-classpath" :: classpath :: beforeCp ::: fromCp.drop(2) } @@ -1102,7 +1102,7 @@ object Build { // Discover classpaths def cpToString(cp: Seq[File]) = - cp.map(_.getAbsolutePath).mkString(java.io.File.pathSeparator) + cp.map(_.getAbsolutePath).mkString(File.pathSeparator) val compilerCp = Attributed.data((fullClasspath in (`dotty-compiler`, Compile)).value) val cpStr = cpToString(classpath ++ compilerCp)