summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Rytz <lukas.rytz@typesafe.com>2016-01-26 06:54:26 +0100
committerLukas Rytz <lukas.rytz@typesafe.com>2016-01-26 06:54:26 +0100
commit47b89108cf0f33c70c9958ffd182762243afdbbf (patch)
tree6f09761820b044d7c38d88f80e73ba6e903e3092
parent7604ccbf12f52a4091a98ba74040cf11e476053e (diff)
parent05ec8ac76dbed2c8a9781c9a4366fc01fc4e3aa3 (diff)
downloadscala-47b89108cf0f33c70c9958ffd182762243afdbbf.tar.gz
scala-47b89108cf0f33c70c9958ffd182762243afdbbf.tar.bz2
scala-47b89108cf0f33c70c9958ffd182762243afdbbf.zip
Merge pull request #4913 from szeiger/wip/sbt-windows-fixes
Some fixes for the sbt build on Windows
-rw-r--r--build.sbt7
-rw-r--r--project/JarJar.scala4
-rw-r--r--project/ScalaTool.scala21
3 files changed, 20 insertions, 12 deletions
diff --git a/build.sbt b/build.sbt
index 6f82d78413..ad9d5c8866 100644
--- a/build.sbt
+++ b/build.sbt
@@ -767,9 +767,10 @@ lazy val mkBinImpl: Def.Initialize[Task[Seq[File]]] = Def.task {
scalaTool.writeScript(file, "windows", rootDir, outDir)
)
res.foreach { f =>
- //TODO 2.12: Use Files.setPosixFilePermissions() (Java 7+) instead of calling out to chmod
- if(Process(List("chmod", "ugo+rx", f.getAbsolutePath())).! > 0)
- throw new IOException("chmod failed")
+ if(!f.getAbsoluteFile.setExecutable(true, /* ownerOnly: */ false))
+ throw new IOException("setExecutable failed")
+ if(!f.getAbsoluteFile.setReadable(true, /* ownerOnly: */ false))
+ throw new IOException("setReadable failed")
}
res
}
diff --git a/project/JarJar.scala b/project/JarJar.scala
index 2eec0e9033..918060c9ee 100644
--- a/project/JarJar.scala
+++ b/project/JarJar.scala
@@ -35,12 +35,12 @@ object JarJar {
}
case class JarEntryInput(jarFile: JarFile, entry: JarEntry) extends Entry {
- def name = entry.getName
+ def name = entry.getName.replace('\\', '/')
def time = entry.getTime
def data = sbt.IO.readBytes(jarFile.getInputStream(entry))
}
case class FileInput(base: File, file: File) extends Entry {
- def name = file.relativeTo(base).get.getPath
+ def name = file.relativeTo(base).get.getPath.replace('\\', '/')
def time = file.lastModified
def data = sbt.IO.readBytes(file)
}
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
}
}