summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Zeiger <szeiger@novocode.com>2016-01-25 18:33:07 +0100
committerStefan Zeiger <szeiger@novocode.com>2016-01-25 18:33:07 +0100
commit05ec8ac76dbed2c8a9781c9a4366fc01fc4e3aa3 (patch)
tree522786cebc2001c2d44aa8adea0e42ddedc36886
parentbdd3abc1b96e4d2e658fb4fdf2bb8fd09d686a70 (diff)
downloadscala-05ec8ac76dbed2c8a9781c9a4366fc01fc4e3aa3.tar.gz
scala-05ec8ac76dbed2c8a9781c9a4366fc01fc4e3aa3.tar.bz2
scala-05ec8ac76dbed2c8a9781c9a4366fc01fc4e3aa3.zip
Improved EOL handling for scripts generated by the sbt build
We now normalize EOLs in `ScalaTool` to LF when reading the templates, and write them as CRLF or LF depending on the target platform. This allows the script templates to be stored locally with either LF or CRLF line endings (which can both happen, depending on the platform and git configuration).
-rw-r--r--project/ScalaTool.scala19
1 files changed, 10 insertions, 9 deletions
diff --git a/project/ScalaTool.scala b/project/ScalaTool.scala
index a30f5f0a73..e9531f229e 100644
--- a/project/ScalaTool.scala
+++ b/project/ScalaTool.scala
@@ -16,16 +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 = platform match {
- case "unix" =>
+ 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.
- if(SystemUtils.IS_OS_WINDOWS) classpath.mkString(";").replace("\\", "\\\\").replaceAll(varRegex, """\${$1}""")
- else classpath.mkString(":").replace('\\', '/').replaceAll(varRegex, """\${$1}""")
- case "windows" => classpath.mkString(";").replace('/', '\\').replaceAll(varRegex, "%$1%")
- }
+ classpath.mkString(";").replace("\\", "\\\\").replaceAll(varRegex, """\${$1}""")
+ } else classpath.mkString(":").replace('\\', '/').replaceAll(varRegex, """\${$1}""")
val variables = Map(
("@@" -> "@"), // for backwards compatibility
@@ -41,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
}
}