Skip to content

Commit 6254a72

Browse files
(Backport) Update mill and mill.bat to download 0.12.12 and above from the .exe URL (#5123)
Backport of #5124, and pulls in all the other changes in the `mill` and `mill.bat` file from the `main` branch --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent e6d7a94 commit 6254a72

File tree

3 files changed

+310
-184
lines changed

3 files changed

+310
-184
lines changed

build.mill

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ object MillPublishJavaModule {
448448
}
449449

450450
}
451+
451452
/**
452453
* Some custom scala settings and test convenience
453454
*/

mill

Lines changed: 124 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,39 @@
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-49-ac90e3
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

1433
set -e
1534

1635
if [ -z "${DEFAULT_MILL_VERSION}" ] ; then
17-
DEFAULT_MILL_VERSION="0.11.4"
36+
DEFAULT_MILL_VERSION="0.12.10"
1837
fi
1938

2039

@@ -31,16 +50,17 @@ fi
3150

3251
# Explicit commandline argument takes precedence over all other methods
3352
if [ "$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
53+
echo "The --mill-version option is no longer supported." 1>&2
54+
fi
55+
56+
MILL_BUILD_SCRIPT=""
57+
58+
if [ -f "build.mill" ] ; then
59+
MILL_BUILD_SCRIPT="build.mill"
60+
elif [ -f "build.mill.scala" ] ; then
61+
MILL_BUILD_SCRIPT="build.mill.scala"
62+
elif [ -f "build.sc" ] ; then
63+
MILL_BUILD_SCRIPT="build.sc"
4464
fi
4565

4666
# Please note, that if a MILL_VERSION is already set in the environment,
@@ -52,6 +72,8 @@ if [ -z "${MILL_VERSION}" ] ; then
5272
MILL_VERSION="$(tr '\r' '\n' < .mill-version | head -n 1 2> /dev/null)"
5373
elif [ -f ".config/mill-version" ] ; then
5474
MILL_VERSION="$(tr '\r' '\n' < .config/mill-version | head -n 1 2> /dev/null)"
75+
elif [ -n "${MILL_BUILD_SCRIPT}" ] ; then
76+
MILL_VERSION="$(cat ${MILL_BUILD_SCRIPT} | grep '//[|] *mill-version: *' | sed 's;//| *mill-version: *;;')"
5577
fi
5678
fi
5779

@@ -65,7 +87,7 @@ fi
6587
if [ -z "${MILL_VERSION}" ] ; then
6688
# TODO: try to load latest version from release page
6789
echo "No mill version specified." 1>&2
68-
echo "You should provide a version via '.mill-version' file or --mill-version option." 1>&2
90+
echo "You should provide a version via a '//| mill-version: ' comment or a '.mill-version' file." 1>&2
6991

7092
mkdir -p "${MILL_DOWNLOAD_PATH}"
7193
LANG=C touch -d '1 hour ago' "${MILL_DOWNLOAD_PATH}/.expire_latest" 2>/dev/null || (
@@ -102,11 +124,10 @@ if [ -z "${MILL_VERSION}" ] ; then
102124
fi
103125

104126
MILL_NATIVE_SUFFIX="-native"
127+
MILL_JVM_SUFFIX="-jvm"
105128
FULL_MILL_VERSION=$MILL_VERSION
106129
ARTIFACT_SUFFIX=""
107-
case "$MILL_VERSION" in
108-
*"$MILL_NATIVE_SUFFIX")
109-
MILL_VERSION=${MILL_VERSION%"$MILL_NATIVE_SUFFIX"}
130+
set_artifact_suffix(){
110131
if [ "$(expr substr $(uname -s) 1 5 2>/dev/null)" = "Linux" ]; then
111132
if [ "$(uname -m)" = "aarch64" ]; then
112133
ARTIFACT_SUFFIX="-native-linux-aarch64"
@@ -123,9 +144,39 @@ case "$MILL_VERSION" in
123144
echo "This native mill launcher supports only Linux and macOS." 1>&2
124145
exit 1
125146
fi
147+
}
148+
149+
case "$MILL_VERSION" in
150+
*"$MILL_NATIVE_SUFFIX")
151+
MILL_VERSION=${MILL_VERSION%"$MILL_NATIVE_SUFFIX"}
152+
set_artifact_suffix
153+
;;
154+
155+
*"$MILL_JVM_SUFFIX")
156+
MILL_VERSION=${MILL_VERSION%"$MILL_JVM_SUFFIX"}
157+
;;
158+
159+
*)
160+
case "$MILL_VERSION" in
161+
0.1.*) ;;
162+
0.2.*) ;;
163+
0.3.*) ;;
164+
0.4.*) ;;
165+
0.5.*) ;;
166+
0.6.*) ;;
167+
0.7.*) ;;
168+
0.8.*) ;;
169+
0.9.*) ;;
170+
0.10.*) ;;
171+
0.11.*) ;;
172+
0.12.*) ;;
173+
*)
174+
set_artifact_suffix
175+
esac
176+
;;
126177
esac
127178

128-
MILL="${MILL_DOWNLOAD_PATH}/${FULL_MILL_VERSION}"
179+
MILL="${MILL_DOWNLOAD_PATH}/$MILL_VERSION$ARTIFACT_SUFFIX"
129180

130181
try_to_use_system_mill() {
131182
if [ "$(uname)" != "Linux" ]; then
@@ -198,49 +249,59 @@ EOF
198249
try_to_use_system_mill
199250

200251
# If not already downloaded, download it
201-
if [ ! -s "${MILL}" ] ; then
202-
203-
# support old non-XDG download dir
204-
MILL_OLD_DOWNLOAD_PATH="${HOME}/.mill/download"
205-
OLD_MILL="${MILL_OLD_DOWNLOAD_PATH}/${MILL_VERSION}"
206-
if [ -x "${OLD_MILL}" ] ; then
207-
MILL="${OLD_MILL}"
252+
if [ ! -s "${MILL}" ] || [ "$MILL_TEST_DRY_RUN_LAUNCHER_SCRIPT" = "1" ] ; then
253+
case $MILL_VERSION in
254+
0.0.* | 0.1.* | 0.2.* | 0.3.* | 0.4.* )
255+
DOWNLOAD_SUFFIX=""
256+
DOWNLOAD_FROM_MAVEN=0
257+
;;
258+
0.5.* | 0.6.* | 0.7.* | 0.8.* | 0.9.* | 0.10.* | 0.11.0-M* )
259+
DOWNLOAD_SUFFIX="-assembly"
260+
DOWNLOAD_FROM_MAVEN=0
261+
;;
262+
*)
263+
DOWNLOAD_SUFFIX="-assembly"
264+
DOWNLOAD_FROM_MAVEN=1
265+
;;
266+
esac
267+
case $MILL_VERSION in
268+
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 )
269+
DOWNLOAD_EXT="jar"
270+
;;
271+
0.12.* )
272+
DOWNLOAD_EXT="exe"
273+
;;
274+
0.* )
275+
DOWNLOAD_EXT="jar"
276+
;;
277+
*)
278+
DOWNLOAD_EXT="exe"
279+
;;
280+
esac
281+
282+
DOWNLOAD_FILE=$(mktemp mill.XXXXXX)
283+
if [ "$DOWNLOAD_FROM_MAVEN" = "1" ] ; then
284+
DOWNLOAD_URL="https://repo1.maven.org/maven2/com/lihaoyi/mill-dist${ARTIFACT_SUFFIX}/${MILL_VERSION}/mill-dist${ARTIFACT_SUFFIX}-${MILL_VERSION}.${DOWNLOAD_EXT}"
208285
else
209-
case $MILL_VERSION in
210-
0.0.* | 0.1.* | 0.2.* | 0.3.* | 0.4.* )
211-
DOWNLOAD_SUFFIX=""
212-
DOWNLOAD_FROM_MAVEN=0
213-
;;
214-
0.5.* | 0.6.* | 0.7.* | 0.8.* | 0.9.* | 0.10.* | 0.11.0-M* )
215-
DOWNLOAD_SUFFIX="-assembly"
216-
DOWNLOAD_FROM_MAVEN=0
217-
;;
218-
*)
219-
DOWNLOAD_SUFFIX="-assembly"
220-
DOWNLOAD_FROM_MAVEN=1
221-
;;
222-
esac
223-
224-
DOWNLOAD_FILE=$(mktemp mill.XXXXXX)
225-
226-
if [ "$DOWNLOAD_FROM_MAVEN" = "1" ] ; then
227-
DOWNLOAD_URL="https://repo1.maven.org/maven2/com/lihaoyi/mill-dist${ARTIFACT_SUFFIX}/${MILL_VERSION}/mill-dist${ARTIFACT_SUFFIX}-${MILL_VERSION}.jar"
228-
else
229-
MILL_VERSION_TAG=$(echo "$MILL_VERSION" | sed -E 's/([^-]+)(-M[0-9]+)?(-.*)?/\1\2/')
230-
DOWNLOAD_URL="${GITHUB_RELEASE_CDN}${MILL_REPO_URL}/releases/download/${MILL_VERSION_TAG}/${MILL_VERSION}${DOWNLOAD_SUFFIX}"
231-
unset MILL_VERSION_TAG
232-
fi
233-
234-
# TODO: handle command not found
235-
echo "Downloading mill ${MILL_VERSION} from ${DOWNLOAD_URL} ..." 1>&2
236-
${CURL_CMD} -f -L -o "${DOWNLOAD_FILE}" "${DOWNLOAD_URL}"
237-
chmod +x "${DOWNLOAD_FILE}"
238-
mkdir -p "${MILL_DOWNLOAD_PATH}"
239-
mv "${DOWNLOAD_FILE}" "${MILL}"
286+
MILL_VERSION_TAG=$(echo "$MILL_VERSION" | sed -E 's/([^-]+)(-M[0-9]+)?(-.*)?/\1\2/')
287+
DOWNLOAD_URL="${GITHUB_RELEASE_CDN}${MILL_REPO_URL}/releases/download/${MILL_VERSION_TAG}/${MILL_VERSION}${DOWNLOAD_SUFFIX}"
288+
unset MILL_VERSION_TAG
289+
fi
240290

241-
unset DOWNLOAD_FILE
242-
unset DOWNLOAD_SUFFIX
291+
if [ "$MILL_TEST_DRY_RUN_LAUNCHER_SCRIPT" = "1" ] ; then
292+
echo $DOWNLOAD_URL
293+
echo $MILL
294+
exit 0
243295
fi
296+
# TODO: handle command not found
297+
echo "Downloading mill ${MILL_VERSION} from ${DOWNLOAD_URL} ..." 1>&2
298+
${CURL_CMD} -f -L -o "${DOWNLOAD_FILE}" "${DOWNLOAD_URL}"
299+
chmod +x "${DOWNLOAD_FILE}"
300+
mkdir -p "${MILL_DOWNLOAD_PATH}"
301+
mv "${DOWNLOAD_FILE}" "${MILL}"
302+
303+
unset DOWNLOAD_FILE
304+
unset DOWNLOAD_SUFFIX
244305
fi
245306

246307
if [ -z "$MILL_MAIN_CLI" ] ; then
@@ -260,6 +321,7 @@ unset OLD_MILL
260321
unset MILL_VERSION
261322
unset MILL_REPO_URL
262323

324+
# -D mill.main.cli is for compatibility with Mill 0.10.9 - 0.13.0-M2
263325
# We don't quote MILL_FIRST_ARG on purpose, so we can expand the empty value without quotes
264326
# shellcheck disable=SC2086
265-
exec "${MILL}" $MILL_FIRST_ARG -D "mill.main.cli=${MILL_MAIN_CLI}" "$@"
327+
exec "${MILL}" $MILL_FIRST_ARG -D "mill.main.cli=${MILL_MAIN_CLI}" "$@"

0 commit comments

Comments
 (0)