summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLi Haoyi <haoyi.sg@gmail.com>2019-07-01 06:22:59 -0700
committerLi Haoyi <haoyi.sg@gmail.com>2019-07-01 06:22:59 -0700
commit78e71785bd5112eec6a66d983717ffde798f438e (patch)
tree217d562cdafd84e955f864f3231c61d910d90eb9
parentd2af62e6c35583fafa2f39e9c204fad6a21b38ab (diff)
downloadmill-78e71785bd5112eec6a66d983717ffde798f438e.tar.gz
mill-78e71785bd5112eec6a66d983717ffde798f438e.tar.bz2
mill-78e71785bd5112eec6a66d983717ffde798f438e.zip
scrape ./mill wrapper script for mill version, instead of exec-ing it
-rwxr-xr-xbuild.sc40
-rwxr-xr-xmain/mill-template31
-rwxr-xr-xmill1
3 files changed, 62 insertions, 10 deletions
diff --git a/build.sc b/build.sc
index dce241b9..dc95e851 100755
--- a/build.sc
+++ b/build.sc
@@ -61,6 +61,7 @@ trait MillModule extends MillApiModule{ outer =>
object main extends MillModule {
def moduleDeps = Seq(core, client)
+ def millBootstrap = T.sources(os.pwd / "mill-template")
def compileIvyDeps = Agg(
ivy"org.scala-lang:scala-reflect:${scalaVersion()}"
@@ -437,19 +438,19 @@ object integration extends MillModule{
def launcherScript(shellJvmArgs: Seq[String],
cmdJvmArgs: Seq[String],
shellClassPath: Agg[String],
- cmdClassPath: Agg[String]) = {
+ cmdClassPath: Agg[String],
+ millBootstrapStringValue: String) = {
mill.modules.Jvm.universalScript(
shellCommands = {
val jvmArgsStr = shellJvmArgs.mkString(" ")
def java(mainClass: String) =
s"""exec $$JAVACMD $jvmArgsStr $$JAVA_OPTS -cp "${shellClassPath.mkString(":")}" $mainClass "$$@""""
- // Delegate to the `./mill` wrapper script if one exists, and we are being
- // called manually (i.e. the MILL_EXEC_PATH that the wrapper script normally
- // sets is not present in the environment)
- s"""if [ -f "$$(dirname "$$BASH_SOURCE")/mill" ] ; then
- | if [ ! -z "$$MILL_EXEC_PATH" ] ; then
- | exec "$$(dirname "$$BASH_SOURCE")/mill"
+ val cutCount = millBootstrapGrepPrefix.length + 1
+ s"""if [ -f "$$PWD/mill" ] ; then
+ | if [ -z "$$MILL_EXEC_PATH" ] ; then
+ | MILL_VERSION=$$(grep -F "$millBootstrapGrepPrefix" "$$PWD/mill" | cut -c $cutCount-)
+ | ${millBootstrapStringValue.replace("\n", "\n ")}
| fi
|fi
|
@@ -485,9 +486,17 @@ def launcherScript(shellJvmArgs: Seq[String],
)
}
+val millBootstrapGrepPrefix = "DEFAULT_MILL_VERSION="
+
+def millBootstrapString = T{
+ os.read(main.millBootstrap().head.path)
+ .replace(millBootstrapGrepPrefix, millBootstrapGrepPrefix + publishVersion())
+}
+
object dev extends MillModule{
def moduleDeps = Seq(scalalib, scalajslib, scalanativelib, contrib.scalapblib, contrib.tut, contrib.scoverage)
+
def forkArgs =
(
scalalib.testArgs() ++
@@ -553,7 +562,13 @@ object dev extends MillModule{
Seq("""-XX:VMOptionsFile="$( dirname "$0" )"/mill.vmoptions"""),
Seq("""-XX:VMOptionsFile=%~dp0\mill.vmoptions""")
)
- launcherScript(shellArgs, cmdArgs, classpath, classpath)
+ launcherScript(
+ shellArgs,
+ cmdArgs,
+ classpath,
+ classpath,
+ millBootstrapString()
+ )
}
def run(args: String*) = T.command{
@@ -591,7 +606,8 @@ def release = T{
shellArgs,
cmdArgs,
Agg("$0"),
- Agg("%~dpnx0")
+ Agg("%~dpnx0"),
+ millBootstrapString()
)
).path,
dest / filename
@@ -652,4 +668,10 @@ def uploadToGithub(authKey: String) = T.command{
}
upload.apply(release().path, releaseTag, label, authKey)
+
+ val bootstrapScript = T.ctx().dest / "mill-bootstrap"
+
+ os.write(bootstrapScript, millBootstrapString)
+
+ upload.apply(bootstrapScript, releaseTag, label + "-bootstrap", authKey)
}
diff --git a/main/mill-template b/main/mill-template
new file mode 100755
index 00000000..084f5e99
--- /dev/null
+++ b/main/mill-template
@@ -0,0 +1,31 @@
+#!/usr/bin/env sh
+
+# This is a wrapper script, that automatically download mill from GitHub release pages
+# You can give the required mill version with MILL_VERSION env variable
+# If no version is given, it falls back to the value of DEFAULT_MILL_VERSION
+DEFAULT_MILL_VERSION=
+
+set -e
+
+if [ -z "$MILL_VERSION" ] ; then
+ MILL_VERSION=$DEFAULT_MILL_VERSION
+fi
+
+MILL_DOWNLOAD_PATH="$HOME/.mill/download"
+MILL_EXEC_PATH="${MILL_DOWNLOAD_PATH}/$MILL_VERSION"
+
+if [ ! -x "$MILL_EXEC_PATH" ] ; then
+ mkdir -p $MILL_DOWNLOAD_PATH
+ DOWNLOAD_FILE=$MILL_EXEC_PATH-tmp-download
+ MILL_DOWNLOAD_URL="https://github.com/lihaoyi/mill/releases/download/${MILL_VERSION%%-*}/$MILL_VERSION"
+ curl --fail -L -o "$DOWNLOAD_FILE" "$MILL_DOWNLOAD_URL"
+ chmod +x "$DOWNLOAD_FILE"
+ mv "$DOWNLOAD_FILE" "$MILL_EXEC_PATH"
+ unset DOWNLOAD_FILE
+ unset MILL_DOWNLOAD_URL
+fi
+
+unset MILL_DOWNLOAD_PATH
+unset MILL_VERSION
+
+exec $MILL_EXEC_PATH "$@" \ No newline at end of file
diff --git a/mill b/mill
index 74f1d62f..abd5a6bf 100755
--- a/mill
+++ b/mill
@@ -20,7 +20,6 @@ if [ ! -x "$MILL_EXEC_PATH" ] ; then
MILL_DOWNLOAD_URL="https://github.com/lihaoyi/mill/releases/download/${MILL_VERSION%%-*}/$MILL_VERSION"
curl --fail -L -o "$DOWNLOAD_FILE" "$MILL_DOWNLOAD_URL"
chmod +x "$DOWNLOAD_FILE"
- mkdir -p "$MILL_DOWNLOAD_PATH"
mv "$DOWNLOAD_FILE" "$MILL_EXEC_PATH"
unset DOWNLOAD_FILE
unset MILL_DOWNLOAD_URL