Skip to content

use cross platform path separatator in build #5085

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
Sep 10, 2018
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
2 changes: 1 addition & 1 deletion bench/src/main/scala/Benchmarks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/quoted/QuoteDriver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions compiler/test/dotty/tools/dotc/CompilationTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)

Expand Down
5 changes: 3 additions & 2 deletions compiler/test/dotty/tools/vulpix/ChildJVMMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<URL> 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()]));
Expand Down
16 changes: 8 additions & 8 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand All @@ -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)
}

Expand Down Expand Up @@ -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)
Expand Down