diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2016-02-03 22:06:42 +1000 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2016-02-04 09:19:19 +1000 |
commit | da46355a90442636ee7634c31a69eae8e8b9cd42 (patch) | |
tree | eec9abbf057e3c5fd4566df6628f9693835cc536 /project/ScalaTool.scala | |
parent | 74e53cb4930fc3e02222d8be0f065ce8aaa71230 (diff) | |
parent | cc6fea6d30609b8879db1ecdbc288e4cdaa5b8d4 (diff) | |
download | scala-da46355a90442636ee7634c31a69eae8e8b9cd42.tar.gz scala-da46355a90442636ee7634c31a69eae8e8b9cd42.tar.bz2 scala-da46355a90442636ee7634c31a69eae8e8b9cd42.zip |
Merge commit 'cc6fea6' into merge/2.11.x-to-2.12.x-20160203
Conflicts:
build.sbt
scripts/jobs/integrate/bootstrap
Diffstat (limited to 'project/ScalaTool.scala')
-rw-r--r-- | project/ScalaTool.scala | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/project/ScalaTool.scala b/project/ScalaTool.scala index 559b215c18..e9531f229e 100644 --- a/project/ScalaTool.scala +++ b/project/ScalaTool.scala @@ -1,4 +1,5 @@ import sbt._ +import org.apache.commons.lang3.SystemUtils import org.apache.commons.lang3.StringUtils.replaceEach /** @@ -15,8 +16,15 @@ case class ScalaTool(mainClass: String, // demarcation of any script variables (e.g. `${SCALA_HOME}` or // `%SCALA_HOME%`) can be specified in a platform independent way (e.g. // `@SCALA_HOME@`) and automatically translated for you. - def patchedToolScript(template: String, platform: String) = { + def patchedToolScript(template: String, forWindows: Boolean) = { val varRegex = """@(\w+)@""" // the group should be able to capture each of the keys of the map below + val platformClasspath = + if(forWindows) classpath.mkString(";").replace('/', '\\').replaceAll(varRegex, "%$1%") + else if(SystemUtils.IS_OS_WINDOWS) { + // When building on Windows, use a Windows classpath in the shell script (for MSYS/Cygwin). + // This is only used for "quick", which uses absolute paths, so it is not portable anyway. + classpath.mkString(";").replace("\\", "\\\\").replaceAll(varRegex, """\${$1}""") + } else classpath.mkString(":").replace('\\', '/').replaceAll(varRegex, """\${$1}""") val variables = Map( ("@@" -> "@"), // for backwards compatibility @@ -24,10 +32,7 @@ case class ScalaTool(mainClass: String, ("@properties@" -> (properties map { case (k, v) => s"""-D$k="$v""""} mkString " ")), ("@javaflags@" -> javaOpts), ("@toolflags@" -> toolFlags), - ("@classpath@" -> (platform match { - case "unix" => classpath.mkString(":").replace('\\', '/').replaceAll(varRegex, """\${$1}""") - case "windows" => classpath.mkString(";").replace('/', '\\').replaceAll(varRegex, "%$1%") - })) + ("@classpath@" -> platformClasspath) ) val (from, to) = variables.unzip @@ -35,10 +40,12 @@ case class ScalaTool(mainClass: String, } def writeScript(file: String, platform: String, rootDir: File, outDir: File): File = { + val forWindows = platform match { case "windows" => true case _ => false } val templatePath = s"scala/tools/ant/templates/tool-$platform.tmpl" - val suffix = platform match { case "windows" => ".bat" case _ => "" } + val suffix = if(forWindows) ".bat" else "" val scriptFile = outDir / s"$file$suffix" - IO.write(scriptFile, patchedToolScript(IO.read(rootDir / templatePath), platform)) + val patched = patchedToolScript(IO.read(rootDir / templatePath).replace("\r", ""), forWindows) + IO.write(scriptFile, if(forWindows) patched.replace("\n", "\r\n") else patched) scriptFile } } |