11#! /usr/bin/env sh
22
3- # This is a wrapper script, that automatically download mill from GitHub release pages
4- # You can give the required mill version with --mill-version parameter
5- # If no version is given, it falls back to the value of DEFAULT_MILL_VERSION
3+ # This is a wrapper script, that automatically selects or downloads Mill from Maven Central or GitHub release pages.
64#
7- # Original Project page: https://github.com/lefou/millw
8- # Script Version: 0.4.12
5+ # This script determines the Mill version to use by trying these sources
6+ # - env-variable `MILL_VERSION`
7+ # - local file `.mill-version`
8+ # - local file `.config/mill-version`
9+ # - `mill-version` from YAML fronmatter of current buildfile
10+ # - if accessible, find the latest stable version available on Maven Central (https://repo1.maven.org/maven2)
11+ # - env-variable `DEFAULT_MILL_VERSION`
12+ #
13+ # If a version has the suffix '-native' a native binary will be used.
14+ # If a version has the suffix '-jvm' an executable jar file will be used, requiring an already installed Java runtime.
15+ # If no such suffix is found, the script will pick a default based on version and platform.
16+ #
17+ # Once a version was determined, it tries to use either
18+ # - a system-installed mill, if found and it's version matches
19+ # - an already downloaded version under ~/.cache/mill/download
20+ #
21+ # If no working mill version was found on the system,
22+ # this script downloads a binary file from Maven Central or Github Pages (this is version dependent)
23+ # into a cache location (~/.cache/mill/download).
24+ #
25+ # Mill Project URL: https://github.com/com-lihaoyi/mill
26+ # Script Version: 1.0.0-M1-21-7b6fae-DIRTY892b63e8
927#
1028# If you want to improve this script, please also contribute your changes back!
29+ # This script was generated from: dist/scripts/src/mill.sh
1130#
1231# Licensed under the Apache License, Version 2.0
1332
1433set -e
1534
35+ if [ " $1 " = " --setup-completions" ] ; then
36+ # Need to preserve the first position of those listed options
37+ MILL_FIRST_ARG=$1
38+ shift
39+ fi
40+
1641if [ -z " ${DEFAULT_MILL_VERSION} " ] ; then
17- DEFAULT_MILL_VERSION=0.12.5
42+ DEFAULT_MILL_VERSION=1.0.3
1843fi
1944
2045
3156
3257# Explicit commandline argument takes precedence over all other methods
3358if [ " $1 " = " --mill-version" ] ; then
34- shift
35- if [ " x$1 " != " x" ] ; then
36- MILL_VERSION=" $1 "
37- shift
38- else
39- echo " You specified --mill-version without a version." 1>&2
40- echo " Please provide a version that matches one provided on" 1>&2
41- echo " ${MILL_REPO_URL} /releases" 1>&2
42- false
43- fi
59+ echo " The --mill-version option is no longer supported." 1>&2
60+ fi
61+
62+ MILL_BUILD_SCRIPT=" "
63+
64+ if [ -f " build.mill" ] ; then
65+ MILL_BUILD_SCRIPT=" build.mill"
66+ elif [ -f " build.mill.scala" ] ; then
67+ MILL_BUILD_SCRIPT=" build.mill.scala"
68+ elif [ -f " build.sc" ] ; then
69+ MILL_BUILD_SCRIPT=" build.sc"
4470fi
4571
4672# Please note, that if a MILL_VERSION is already set in the environment,
@@ -52,6 +78,8 @@ if [ -z "${MILL_VERSION}" ] ; then
5278 MILL_VERSION=" $( tr ' \r' ' \n' < .mill-version | head -n 1 2> /dev/null) "
5379 elif [ -f " .config/mill-version" ] ; then
5480 MILL_VERSION=" $( tr ' \r' ' \n' < .config/mill-version | head -n 1 2> /dev/null) "
81+ elif [ -n " ${MILL_BUILD_SCRIPT} " ] ; then
82+ MILL_VERSION=" $( cat ${MILL_BUILD_SCRIPT} | grep ' //[|] *mill-version: *' | sed ' s;//| *mill-version: *;;' ) "
5583 fi
5684fi
5785
6593if [ -z " ${MILL_VERSION} " ] ; then
6694 # TODO: try to load latest version from release page
6795 echo " No mill version specified." 1>&2
68- echo " You should provide a version via '. mill-version' file or -- mill-version option ." 1>&2
96+ echo " You should provide a version via a '//| mill-version: ' comment or a '. mill-version' file ." 1>&2
6997
7098 mkdir -p " ${MILL_DOWNLOAD_PATH} "
7199 LANG=C touch -d ' 1 hour ago' " ${MILL_DOWNLOAD_PATH} /.expire_latest" 2> /dev/null || (
@@ -101,7 +129,60 @@ if [ -z "${MILL_VERSION}" ] ; then
101129 fi
102130fi
103131
104- MILL=" ${MILL_DOWNLOAD_PATH} /${MILL_VERSION} "
132+ MILL_NATIVE_SUFFIX=" -native"
133+ MILL_JVM_SUFFIX=" -jvm"
134+ FULL_MILL_VERSION=$MILL_VERSION
135+ ARTIFACT_SUFFIX=" "
136+ set_artifact_suffix (){
137+ if [ " $( expr substr $( uname -s) 1 5 2> /dev/null) " = " Linux" ]; then
138+ if [ " $( uname -m) " = " aarch64" ]; then
139+ ARTIFACT_SUFFIX=" -native-linux-aarch64"
140+ else
141+ ARTIFACT_SUFFIX=" -native-linux-amd64"
142+ fi
143+ elif [ " $( uname) " = " Darwin" ]; then
144+ if [ " $( uname -m) " = " arm64" ]; then
145+ ARTIFACT_SUFFIX=" -native-mac-aarch64"
146+ else
147+ ARTIFACT_SUFFIX=" -native-mac-amd64"
148+ fi
149+ else
150+ echo " This native mill launcher supports only Linux and macOS." 1>&2
151+ exit 1
152+ fi
153+ }
154+
155+ case " $MILL_VERSION " in
156+ * " $MILL_NATIVE_SUFFIX " )
157+ MILL_VERSION=${MILL_VERSION% " $MILL_NATIVE_SUFFIX " }
158+ set_artifact_suffix
159+ ;;
160+
161+ * " $MILL_JVM_SUFFIX " )
162+ MILL_VERSION=${MILL_VERSION% " $MILL_JVM_SUFFIX " }
163+ ;;
164+
165+ * )
166+ case " $MILL_VERSION " in
167+ 0.1.* ) ;;
168+ 0.2.* ) ;;
169+ 0.3.* ) ;;
170+ 0.4.* ) ;;
171+ 0.5.* ) ;;
172+ 0.6.* ) ;;
173+ 0.7.* ) ;;
174+ 0.8.* ) ;;
175+ 0.9.* ) ;;
176+ 0.10.* ) ;;
177+ 0.11.* ) ;;
178+ 0.12.* ) ;;
179+ * )
180+ set_artifact_suffix
181+ esac
182+ ;;
183+ esac
184+
185+ MILL=" ${MILL_DOWNLOAD_PATH} /$MILL_VERSION$ARTIFACT_SUFFIX "
105186
106187try_to_use_system_mill () {
107188 if [ " $( uname) " != " Linux" ]; then
@@ -174,57 +255,67 @@ EOF
174255try_to_use_system_mill
175256
176257# If not already downloaded, download it
177- if [ ! -s " ${MILL} " ] ; then
178-
179- # support old non-XDG download dir
180- MILL_OLD_DOWNLOAD_PATH=" ${HOME} /.mill/download"
181- OLD_MILL=" ${MILL_OLD_DOWNLOAD_PATH} /${MILL_VERSION} "
182- if [ -x " ${OLD_MILL} " ] ; then
183- MILL=" ${OLD_MILL} "
258+ if [ ! -s " ${MILL} " ] || [ " $MILL_TEST_DRY_RUN_LAUNCHER_SCRIPT " = " 1" ] ; then
259+ case $MILL_VERSION in
260+ 0.0.* | 0.1.* | 0.2.* | 0.3.* | 0.4.* )
261+ DOWNLOAD_SUFFIX=" "
262+ DOWNLOAD_FROM_MAVEN=0
263+ ;;
264+ 0.5.* | 0.6.* | 0.7.* | 0.8.* | 0.9.* | 0.10.* | 0.11.0-M* )
265+ DOWNLOAD_SUFFIX=" -assembly"
266+ DOWNLOAD_FROM_MAVEN=0
267+ ;;
268+ * )
269+ DOWNLOAD_SUFFIX=" -assembly"
270+ DOWNLOAD_FROM_MAVEN=1
271+ ;;
272+ esac
273+ case $MILL_VERSION in
274+ 0.12.0 | 0.12.1 | 0.12.2 | 0.12.3 | 0.12.4 | 0.12.5 | 0.12.6 | 0.12.7 | 0.12.8 | 0.12.9 | 0.12.10 | 0.12.11 )
275+ DOWNLOAD_EXT=" jar"
276+ ;;
277+ 0.12.* )
278+ DOWNLOAD_EXT=" exe"
279+ ;;
280+ 0.* )
281+ DOWNLOAD_EXT=" jar"
282+ ;;
283+ * )
284+ DOWNLOAD_EXT=" exe"
285+ ;;
286+ esac
287+
288+ DOWNLOAD_FILE=$( mktemp mill.XXXXXX)
289+ if [ " $DOWNLOAD_FROM_MAVEN " = " 1" ] ; then
290+ DOWNLOAD_URL=" https://repo1.maven.org/maven2/com/lihaoyi/mill-dist${ARTIFACT_SUFFIX} /${MILL_VERSION} /mill-dist${ARTIFACT_SUFFIX} -${MILL_VERSION} .${DOWNLOAD_EXT} "
184291 else
185- case $MILL_VERSION in
186- 0.0.* | 0.1.* | 0.2.* | 0.3.* | 0.4.* )
187- DOWNLOAD_SUFFIX=" "
188- DOWNLOAD_FROM_MAVEN=0
189- ;;
190- 0.5.* | 0.6.* | 0.7.* | 0.8.* | 0.9.* | 0.10.* | 0.11.0-M* )
191- DOWNLOAD_SUFFIX=" -assembly"
192- DOWNLOAD_FROM_MAVEN=0
193- ;;
194- * )
195- DOWNLOAD_SUFFIX=" -assembly"
196- DOWNLOAD_FROM_MAVEN=1
197- ;;
198- esac
199-
200- DOWNLOAD_FILE=$( mktemp mill.XXXXXX)
201-
202- if [ " $DOWNLOAD_FROM_MAVEN " = " 1" ] ; then
203- DOWNLOAD_URL=" https://repo1.maven.org/maven2/com/lihaoyi/mill-dist/${MILL_VERSION} /mill-dist-${MILL_VERSION} .jar"
204- else
205- MILL_VERSION_TAG=$( echo " $MILL_VERSION " | sed -E ' s/([^-]+)(-M[0-9]+)?(-.*)?/\1\2/' )
206- DOWNLOAD_URL=" ${GITHUB_RELEASE_CDN}${MILL_REPO_URL} /releases/download/${MILL_VERSION_TAG} /${MILL_VERSION}${DOWNLOAD_SUFFIX} "
207- unset MILL_VERSION_TAG
208- fi
209-
210- # TODO: handle command not found
211- echo " Downloading mill ${MILL_VERSION} from ${DOWNLOAD_URL} ..." 1>&2
212- ${CURL_CMD} -f -L -o " ${DOWNLOAD_FILE} " " ${DOWNLOAD_URL} "
213- chmod +x " ${DOWNLOAD_FILE} "
214- mkdir -p " ${MILL_DOWNLOAD_PATH} "
215- mv " ${DOWNLOAD_FILE} " " ${MILL} "
292+ MILL_VERSION_TAG=$( echo " $MILL_VERSION " | sed -E ' s/([^-]+)(-M[0-9]+)?(-.*)?/\1\2/' )
293+ DOWNLOAD_URL=" ${GITHUB_RELEASE_CDN}${MILL_REPO_URL} /releases/download/${MILL_VERSION_TAG} /${MILL_VERSION}${DOWNLOAD_SUFFIX} "
294+ unset MILL_VERSION_TAG
295+ fi
216296
217- unset DOWNLOAD_FILE
218- unset DOWNLOAD_SUFFIX
297+ if [ " $MILL_TEST_DRY_RUN_LAUNCHER_SCRIPT " = " 1" ] ; then
298+ echo $DOWNLOAD_URL
299+ echo $MILL
300+ exit 0
219301 fi
302+ # TODO: handle command not found
303+ echo " Downloading mill ${MILL_VERSION} from ${DOWNLOAD_URL} ..." 1>&2
304+ ${CURL_CMD} -f -L -o " ${DOWNLOAD_FILE} " " ${DOWNLOAD_URL} "
305+ chmod +x " ${DOWNLOAD_FILE} "
306+ mkdir -p " ${MILL_DOWNLOAD_PATH} "
307+ mv " ${DOWNLOAD_FILE} " " ${MILL} "
308+
309+ unset DOWNLOAD_FILE
310+ unset DOWNLOAD_SUFFIX
220311fi
221312
222313if [ -z " $MILL_MAIN_CLI " ] ; then
223314 MILL_MAIN_CLI=" ${0} "
224315fi
225316
226317MILL_FIRST_ARG=" "
227- if [ " $1 " = " --bsp" ] || [ " $1 " = " -i " ] || [ " $1 " = " --interactive" ] || [ " $1 " = " --no-server" ] || [ " $1 " = " --repl" ] || [ " $1 " = " --help" ] ; then
318+ if [ " $1 " = " --bsp" ] || [ " ${1 # " -i " } " ! = " $1 " ] || [ " $1 " = " --interactive" ] || [ " $1 " = " --no-server" ] || [ " $1 " = " --no-daemon " ] || [ " $1 " = " --repl" ] || [ " $1 " = " --help" ] ; then
228319 # Need to preserve the first position of those listed options
229320 MILL_FIRST_ARG=$1
230321 shift
@@ -236,6 +327,7 @@ unset OLD_MILL
236327unset MILL_VERSION
237328unset MILL_REPO_URL
238329
330+ # -D mill.main.cli is for compatibility with Mill 0.10.9 - 0.13.0-M2
239331# We don't quote MILL_FIRST_ARG on purpose, so we can expand the empty value without quotes
240332# shellcheck disable=SC2086
241- exec " ${MILL} " $MILL_FIRST_ARG -D " mill.main.cli=${MILL_MAIN_CLI} " " $@ "
333+ exec " ${MILL} " $MILL_FIRST_ARG -D " mill.main.cli=${MILL_MAIN_CLI} " " $@ "
0 commit comments