summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbuild.sc105
-rw-r--r--main/src/mill/Main.scala6
-rw-r--r--main/src/mill/modules/Jvm.scala31
-rw-r--r--scalalib/src/mill/scalalib/ScalaModule.scala4
4 files changed, 109 insertions, 37 deletions
diff --git a/build.sc b/build.sc
index d47aba4b..1542dfd2 100755
--- a/build.sc
+++ b/build.sc
@@ -208,21 +208,39 @@ object integration extends MillModule{
def forkArgs = testArgs()
}
-def launcherScript(jvmArgs: Seq[String],
+def launcherScript(isWin: Boolean,
+ jvmArgs: Seq[String],
classPath: Agg[String]) = {
val jvmArgsStr = jvmArgs.mkString(" ")
- val classPathStr = classPath.mkString(":")
- s"""#!/usr/bin/env sh
- |
- |case "$$1" in
- | -i | --interactive )
- | shift;
- | exec java $jvmArgsStr $$JAVA_OPTS -cp "$classPathStr" mill.Main "$$@"
- | ;;
- | *)
- | exec java $jvmArgsStr $$JAVA_OPTS -cp "$classPathStr" mill.clientserver.Client "$$@"
- | ;;
- |esac
+ val classPathStr = if (isWin) classPath.mkString(";") else classPath.mkString(":")
+ if (isWin)
+ s"""::#!
+ |@echo off
+ |if "%1" == "-i" set _I_=true
+ |if "%1" == "--interactive" set _I_=true
+ |if defined _I_ (
+ | if "%2" == "" (
+ | echo mill repl is currently only available on a sh environment
+ | exit /B 1
+ | ) else (
+ | java $jvmArgsStr %JAVA_OPTS% -cp "$classPathStr" mill.Main %*
+ | )
+ |) else (
+ | java $jvmArgsStr %JAVA_OPTS% -cp "$classPathStr" mill.clientserver.Client %*
+ |)
+ |EXIT /B %errorlevel%
+ """.stripMargin.split('\n').mkString("\r\n")
+ else
+ s"""#!/usr/bin/env sh
+ |
+ |case "$$1" in
+ | -i | --interactive )
+ | exec java $jvmArgsStr $$JAVA_OPTS -cp "$classPathStr" mill.Main "$$@"
+ | ;;
+ | *)
+ | exec java $jvmArgsStr $$JAVA_OPTS -cp "$classPathStr" mill.clientserver.Client "$$@"
+ | ;;
+ |esac
""".stripMargin
}
@@ -232,11 +250,12 @@ object dev extends MillModule{
scalalib.testArgs() ++ scalajslib.testArgs() ++ scalaworker.testArgs()
}
def launcher = T{
- val outputPath = T.ctx().dest / "run"
+ val isWin = scala.util.Properties.isWin
+ val outputPath = T.ctx().dest / (if (isWin) "run.bat" else "run")
write(outputPath, prependShellScript())
- if (!scala.util.Properties.isWin) {
+ if (!isWin) {
val perms = java.nio.file.Files.getPosixFilePermissions(outputPath.toNIO)
perms.add(PosixFilePermission.GROUP_EXECUTE)
perms.add(PosixFilePermission.OWNER_EXECUTE)
@@ -247,11 +266,12 @@ object dev extends MillModule{
}
def assembly = T{
- mv(super.assembly().path, T.ctx().dest / 'mill)
- PathRef(T.ctx().dest / 'mill)
+ val filename = if (scala.util.Properties.isWin) "mill.bat" else "mill"
+ mv(super.assembly().path, T.ctx().dest / filename)
+ PathRef(T.ctx().dest / filename)
}
- def prependShellScript = launcherScript(forkArgs(), runClasspath().map(_.path.toString))
+ def prependShellScript = launcherScript(scala.util.Properties.isWin, forkArgs(), runClasspath().map(_.path.toString))
def run(args: String*) = T.command{
args match{
@@ -271,18 +291,50 @@ object dev extends MillModule{
}
-def release = T{
+private def releaseHelper(dest: Path,
+ cp: Agg[Path],
+ ver: String,
+ isWin: Boolean)
+ (implicit ctx: mill.util.Ctx.Dest): PathRef = {
+ val (filename, arg) =
+ if (isWin) ("mill.bat", "%~dp0%~nx0")
+ else ("mill", "$0")
mv(
createAssembly(
- dev.runClasspath().map(_.path),
+ cp,
prependShellScript = launcherScript(
- Seq("-DMILL_VERSION=" + publishVersion()._2),
- Agg("$0")
+ isWin,
+ Seq("-DMILL_VERSION=" + ver),
+ Agg(arg)
)
).path,
- T.ctx().dest / 'mill
+ dest / filename
)
- PathRef(T.ctx().dest / 'mill)
+ PathRef(dest / filename)
+}
+
+def release = T{
+ releaseHelper(
+ T.ctx().dest,
+ dev.runClasspath().map(_.path),
+ publishVersion()._2,
+ false)
+}
+
+def releaseBatch = T{
+ releaseHelper(
+ T.ctx().dest,
+ dev.runClasspath().map(_.path),
+ publishVersion()._2,
+ true)
+}
+
+def releaseAll = T{
+ val dest = T.ctx().dest
+ val cp = dev.runClasspath().map(_.path)
+ val ver = publishVersion()._2
+ for (isWin <- Seq(false, true))
+ yield (isWin, releaseHelper(dest, cp, ver, isWin))
}
val isMasterCommit = {
@@ -333,5 +385,8 @@ def uploadToGithub(authKey: String) = T.command{
.asString
}
- upload.apply(release().path, releaseTag, label, authKey)
+ for ((isWin, pr) <- releaseAll())
+ upload.apply(pr.path, releaseTag,
+ if (isWin) s"mill-$label.bat" // so browser downloads it as mill-<version>.bat (?)
+ else label, authKey)
}
diff --git a/main/src/mill/Main.scala b/main/src/mill/Main.scala
index a899c8c6..0844e485 100644
--- a/main/src/mill/Main.scala
+++ b/main/src/mill/Main.scala
@@ -27,8 +27,12 @@ object ServerMain extends mill.clientserver.ServerMain[Evaluator.State]{
object Main {
def main(args: Array[String]): Unit = {
+ val as = args match {
+ case Array(s, _*) if s == "-i" || s == "--interactive" => args.tail
+ case _ => args
+ }
val (result, _) = main0(
- args,
+ as,
None,
ammonite.Main.isInteractive(),
System.in,
diff --git a/main/src/mill/modules/Jvm.scala b/main/src/mill/modules/Jvm.scala
index 2ded95db..9c63d108 100644
--- a/main/src/mill/modules/Jvm.scala
+++ b/main/src/mill/modules/Jvm.scala
@@ -238,7 +238,8 @@ object Jvm {
def createAssembly(inputPaths: Agg[Path],
mainClass: Option[String] = None,
prependShellScript: String = "",
- base: Option[Path] = None)
+ base: Option[Path] = None,
+ isWin: Boolean = scala.util.Properties.isWin)
(implicit ctx: Ctx.Dest) = {
val tmp = ctx.dest / "out-tmp.jar"
@@ -279,8 +280,9 @@ object Jvm {
// Prepend shell script and make it executable
if (prependShellScript.isEmpty) mv(tmp, output)
else{
+ val lineSep = if (isWin) "\r\n" else "\n"
val outputStream = newOutputStream(output.toNIO)
- IO.stream(new ByteArrayInputStream((prependShellScript + "\n").getBytes()), outputStream)
+ IO.stream(new ByteArrayInputStream((prependShellScript + lineSep).getBytes()), outputStream)
IO.stream(read.getInputStream(tmp), outputStream)
outputStream.close()
@@ -320,23 +322,32 @@ object Jvm {
}
- def launcherShellScript(mainClass: String,
+ def launcherShellScript(isWin: Boolean,
+ mainClass: String,
classPath: Agg[String],
jvmArgs: Seq[String]) = {
- s"""#!/usr/bin/env sh
- |
- |exec java ${jvmArgs.mkString(" ")} $$JAVA_OPTS -cp "${classPath.mkString(":")}" $mainClass "$$@"
- """.stripMargin
+ val cp = classPath.mkString(File.pathSeparator)
+ if (isWin)
+ s"""@echo off
+ |
+ |java ${jvmArgs.mkString(" ")} %JAVA_OPTS% -cp "$cp" $mainClass %*
+ """.stripMargin.split('\n').mkString("\r\n")
+ else
+ s"""#!/usr/bin/env sh
+ |
+ |exec java ${jvmArgs.mkString(" ")} $$JAVA_OPTS -cp "$cp" $mainClass "$$@"
+ """.stripMargin
}
def createLauncher(mainClass: String,
classPath: Agg[Path],
jvmArgs: Seq[String])
(implicit ctx: Ctx.Dest)= {
- val outputPath = ctx.dest / "run"
+ val isWin = scala.util.Properties.isWin
+ val outputPath = ctx.dest / (if (isWin) "run.bat" else "run")
- write(outputPath, launcherShellScript(mainClass, classPath.map(_.toString), jvmArgs))
+ write(outputPath, launcherShellScript(isWin, mainClass, classPath.map(_.toString), jvmArgs))
- if (!scala.util.Properties.isWin) {
+ if (!isWin) {
val perms = Files.getPosixFilePermissions(outputPath.toNIO)
perms.add(PosixFilePermission.GROUP_EXECUTE)
perms.add(PosixFilePermission.OWNER_EXECUTE)
diff --git a/scalalib/src/mill/scalalib/ScalaModule.scala b/scalalib/src/mill/scalalib/ScalaModule.scala
index bf68218c..0fe7e3dc 100644
--- a/scalalib/src/mill/scalalib/ScalaModule.scala
+++ b/scalalib/src/mill/scalalib/ScalaModule.scala
@@ -126,9 +126,11 @@ trait ScalaModule extends mill.Module with TaskModule { outer =>
mainClass() match{
case None => ""
case Some(cls) =>
+ val isWin = scala.util.Properties.isWin
mill.modules.Jvm.launcherShellScript(
+ isWin,
cls,
- Agg("$0"),
+ Agg(if (isWin) "%~dp0%~nx0" else "$0"),
forkArgs()
)
}