diff options
author | Robby <robby@santoslab.org> | 2018-05-16 07:21:16 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-16 07:21:16 -0500 |
commit | 3e4ed381c6750b798eaaef27567c6636ab4c835c (patch) | |
tree | 07b4ca653c286bcc4f2a5e7536d43f8fbf5c8221 /build.sc | |
parent | 730a40d0324c14adfeb3837604c4a65c8e1941b2 (diff) | |
download | mill-3e4ed381c6750b798eaaef27567c6636ab4c835c.tar.gz mill-3e4ed381c6750b798eaaef27567c6636ab4c835c.tar.bz2 mill-3e4ed381c6750b798eaaef27567c6636ab4c835c.zip |
Fixed dev.{assembly, launcher} reaching max CLI arguments in Windows by generating/using mill.vmoptions file. (#326)
Diffstat (limited to 'build.sc')
-rwxr-xr-x | build.sc | 74 |
1 files changed, 46 insertions, 28 deletions
@@ -250,12 +250,13 @@ private def universalScript(shellCommands: String, ).filterNot(_.isEmpty).mkString("\n") } -def launcherScript(jvmArgs: Seq[String], +def launcherScript(shellJvmArgs: Seq[String], + cmdJvmArgs: Seq[String], shellClassPath: Agg[String], cmdClassPath: Agg[String]) = { - val jvmArgsStr = jvmArgs.mkString(" ") universalScript( shellCommands = { + val jvmArgsStr = shellJvmArgs.mkString(" ") def java(mainClass: String) = s"""exec java $jvmArgsStr $$JAVA_OPTS -cp "${shellClassPath.mkString(":")}" $mainClass "$$@"""" @@ -269,6 +270,7 @@ def launcherScript(jvmArgs: Seq[String], |esac""".stripMargin }, cmdCommands = { + val jvmArgsStr = cmdJvmArgs.mkString(" ") def java(mainClass: String) = s"""java $jvmArgsStr %JAVA_OPTS% -cp "${cmdClassPath.mkString(";")}" $mainClass %*""" @@ -283,30 +285,35 @@ def launcherScript(jvmArgs: Seq[String], ) } -val isBatch = - scala.util.Properties.isWin && - !(org.jline.utils.OSUtils.IS_CYGWIN - || org.jline.utils.OSUtils.IS_MINGW - || "MSYS" == System.getProperty("MSYSTEM")) - - object dev extends MillModule{ def moduleDeps = Seq(scalalib, scalajslib) def forkArgs = - scalalib.testArgs() ++ - scalajslib.testArgs() ++ - scalalib.worker.testArgs() ++ - // Workaround for Zinc/JNA bug - // https://github.com/sbt/sbt/blame/6718803ee6023ab041b045a6988fafcfae9d15b5/main/src/main/scala/sbt/Main.scala#L130 - Seq("-Djna.nosys=true", "-DMILL_VERSION=" + build.publishVersion()._2) + (scalalib.testArgs() ++ + scalajslib.testArgs() ++ + scalalib.worker.testArgs() ++ + // Workaround for Zinc/JNA bug + // https://github.com/sbt/sbt/blame/6718803ee6023ab041b045a6988fafcfae9d15b5/main/src/main/scala/sbt/Main.scala#L130 + Seq("-Djna.nosys=true", "-DMILL_VERSION=" + build.publishVersion()._2)).distinct + + // Pass dev.assembly VM options via file in Window due to small max args limit + def windowsVmOptions(taskName: String, batch: Path, args: Seq[String])(implicit ctx: mill.util.Ctx) = { + if (System.getProperty("java.specification.version").startsWith("1.")) { + throw new Error(s"$taskName in Windows is only supported using Java 9 or above") + } + val vmOptionsFile = T.ctx().dest / "mill.vmoptions" + T.ctx().log.info(s"Generated $vmOptionsFile; it should be kept in the same directory as $taskName's ${batch.last}") + write(vmOptionsFile, args.mkString("\r\n")) + } def launcher = T{ val isWin = scala.util.Properties.isWin - val outputPath = T.ctx().dest / (if (isBatch) "run.bat" else "run") + val outputPath = T.ctx().dest / (if (isWin) "run.bat" else "run") write(outputPath, prependShellScript()) - if (!isWin) { + if (isWin) { + windowsVmOptions("dev.launcher", outputPath, forkArgs()) + } else { val perms = java.nio.file.Files.getPosixFilePermissions(outputPath.toNIO) perms.add(PosixFilePermission.GROUP_EXECUTE) perms.add(PosixFilePermission.OWNER_EXECUTE) @@ -317,14 +324,23 @@ object dev extends MillModule{ } def assembly = T{ - val filename = if (isBatch) "mill.bat" else "mill" - mv(super.assembly().path, T.ctx().dest / filename) - PathRef(T.ctx().dest / filename) + val isWin = scala.util.Properties.isWin + val millPath = T.ctx().dest / (if (isWin) "mill.bat" else "mill") + mv(super.assembly().path, millPath) + if (isWin) windowsVmOptions("dev.launcher", millPath, forkArgs()) + PathRef(millPath) } def prependShellScript = T{ val classpath = runClasspath().map(_.path.toString) - launcherScript(forkArgs(), classpath, classpath) + val args = forkArgs().distinct + val (shellArgs, cmdArgs) = + if (!scala.util.Properties.isWin) (args, args) + else ( + Seq("""-XX:VMOptionsFile="$( dirname "$0" )"/mill.vmoptions"""), + Seq("""-XX:VMOptionsFile=%~dp0\mill.vmoptions""") + ) + launcherScript(shellArgs, cmdArgs, classpath, classpath) } def run(args: String*) = T.command{ @@ -346,17 +362,19 @@ object dev extends MillModule{ def release = T{ val dest = T.ctx().dest - val filename = if (isBatch) "mill.bat" else "mill" + val filename = if (scala.util.Properties.isWin) "mill.bat" else "mill" + val args = Seq( + "-DMILL_VERSION=" + publishVersion()._2, + // Workaround for Zinc/JNA bug + // https://github.com/sbt/sbt/blame/6718803ee6023ab041b045a6988fafcfae9d15b5/main/src/main/scala/sbt/Main.scala#L130 + "-Djna.nosys=true" + ) mv( createAssembly( dev.runClasspath().map(_.path), prependShellScript = launcherScript( - Seq( - "-DMILL_VERSION=" + publishVersion()._2, - // Workaround for Zinc/JNA bug - // https://github.com/sbt/sbt/blame/6718803ee6023ab041b045a6988fafcfae9d15b5/main/src/main/scala/sbt/Main.scala#L130 - "-Djna.nosys=true" - ), + args, + args, Agg("$0"), Agg("%~dpnx0") ) |