Skip to content

Commit

Permalink
Fix MILL_CLASSPATH for Windows (#354)
Browse files Browse the repository at this point in the history
* Use comma as separator in MILL_CLASSPATH

There is no need to use environment-specific separator, especially since

 - other variables are using commas anyway, and
 - it is not sent to any system-level command

* Fix whitespace

* Use MILL_CLASSPATH for Windows

* Use vm options file for client on windows

* Remove overzealous distinct

* Clean up unnecessary ceremony
  • Loading branch information
jkstrauss authored and lihaoyi committed May 31, 2018
1 parent d093b97 commit 5766840
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 18 deletions.
24 changes: 15 additions & 9 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -294,12 +294,18 @@ def launcherScript(shellJvmArgs: Seq[String],
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)).distinct
(
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,
"-DMILL_CLASSPATH=" + runClasspath().map(_.path.toString).mkString(",")
)
).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) = {
Expand Down Expand Up @@ -339,11 +345,11 @@ object dev extends MillModule{

def prependShellScript = T{
val classpath = runClasspath().map(_.path.toString)
val args = forkArgs().distinct
val args = forkArgs()
val (shellArgs, cmdArgs) =
if (!scala.util.Properties.isWin) (
Seq("-DMILL_CLASSPATH=" + classpath.mkString(":")) ++ args,
Seq("-DMILL_CLASSPATH=" + classpath.mkString(";")) ++ args
args,
args
)
else (
Seq("""-XX:VMOptionsFile="$( dirname "$0" )"/mill.vmoptions"""),
Expand Down
29 changes: 20 additions & 9 deletions main/client/src/mill/main/client/MillClientMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,36 @@

public class MillClientMain {
static void initServer(String lockBase, boolean setJnaNoSys) throws IOException,URISyntaxException{
String[] selfJars = System.getProperty("MILL_CLASSPATH").split(File.pathSeparator);
String[] selfJars = System.getProperty("MILL_CLASSPATH").split(",");

ArrayList<String> l = new java.util.ArrayList<String>();
List<String> l = new ArrayList<>();
List<String> vmOptions = new ArrayList<>();
l.add("java");
Properties props = System.getProperties();
Iterator<String> keys = props.stringPropertyNames().iterator();
while(keys.hasNext()){
String k = keys.next();
if (k.startsWith("MILL_")) l.add("-D" + k + "=" + props.getProperty(k));
final Properties props = System.getProperties();
for(final String k: props.stringPropertyNames()){
if (k.startsWith("MILL_") && !"MILL_CLASSPATH".equals(k)) {
vmOptions.add("-D" + k + "=" + props.getProperty(k));
}
}
if (setJnaNoSys) {
l.add("-Djna.nosys=true");
vmOptions.add("-Djna.nosys=true");
}
if(!Util.isWindows){
l.addAll(vmOptions);
} else {
final File vmOptionsFile = new File(lockBase, "vmoptions");
try (PrintWriter out = new PrintWriter(vmOptionsFile)) {
for(String opt: vmOptions)
out.println(opt);
}
l.add("-XX:VMOptionsFile=" + vmOptionsFile.getCanonicalPath());
}
l.add("-cp");
l.add(String.join(File.pathSeparator, selfJars));
l.add("mill.main.MillServerMain");
l.add(lockBase);

new java.lang.ProcessBuilder()
new ProcessBuilder()
.command(l)
.redirectOutput(new java.io.File(lockBase + "/logs"))
.redirectError(new java.io.File(lockBase + "/logs"))
Expand Down

0 comments on commit 5766840

Please sign in to comment.