Skip to content

Commit bfc1b2c

Browse files
Merge pull request #694 from alexarchambault/mill-0.10.0
Update Mill to 0.10.0 and mill-native-image to 0.1.19
2 parents 85604ae + ceb2b20 commit bfc1b2c

File tree

9 files changed

+280
-90
lines changed

9 files changed

+280
-90
lines changed

.github/scripts/generate-native-image.sh

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,25 @@ if [[ "$OSTYPE" == "msys" ]]; then
1111
export GRAALVM_HOME="$JAVA_HOME"
1212
export PATH="$(pwd)/bin:$PATH"
1313
echo "PATH=$PATH"
14-
./mill.bat -i "$COMMAND" generate-native-image.bat
15-
# Ideally, the generated script should create that directory itself
16-
mkdir -p out/cli/base-image/nativeImage/dest
14+
./mill.bat -i "$COMMAND" generate-native-image.bat ""
1715
./generate-native-image.bat
18-
# Ideally, the generated script should write the generated launcher there
19-
cp out/cli/base-image/nativeImageScript/dest/scala-cli.exe out/cli/base-image/nativeImage/dest/scala-cli.exe
2016
else
2117
if [ $# == "0" ]; then
2218
if [[ "$OSTYPE" == "linux-gnu" ]]; then
2319
COMMAND="cli.linux-docker-image.writeNativeImageScript"
2420
CLEANUP=("sudo" "rm" "-rf" "out/cli/linux-docker-image/nativeImageDockerWorkingDir")
25-
# Ideally, the generated script should create that directory itself
26-
mkdir -p out/cli/linux-docker-image/nativeImage/dest/
2721
else
2822
CLEANUP=("true")
29-
# Ideally, the generated script should create that directory itself
30-
mkdir -p out/cli/base-image/nativeImage/dest
3123
fi
3224
else
3325
case "$1" in
3426
"static")
3527
COMMAND="cli.static-image.writeNativeImageScript"
3628
CLEANUP=("sudo" "rm" "-rf" "out/cli/static-image/nativeImageDockerWorkingDir")
37-
# Ideally, the generated script should create that directory itself
38-
mkdir -p out/cli/static-image/nativeImage/dest
3929
;;
4030
"mostly-static")
4131
COMMAND="cli.mostly-static-image.writeNativeImageScript"
4232
CLEANUP=("sudo" "rm" "-rf" "out/cli/mostly-static-image/nativeImageDockerWorkingDir")
43-
# Ideally, the generated script should create that directory itself
44-
mkdir -p out/cli/mostly-static-image/nativeImage/dest
4533
;;
4634
*)
4735
echo "Invalid image name: $1" 1>&2
@@ -50,9 +38,7 @@ else
5038
esac
5139
fi
5240

53-
./mill -i "$COMMAND" generate-native-image-0.sh
54-
# Small mill-native-image issue
55-
sed 's/nativeImageScript/nativeImage/g' < generate-native-image-0.sh > generate-native-image.sh
41+
./mill -i "$COMMAND" generate-native-image.sh ""
5642
bash ./generate-native-image.sh
5743
"${CLEANUP[@]}"
5844
fi

.github/scripts/get-latest-cs.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
CS_VERSION="2.1.0-M5-5-g2cb552ea9"
5+
6+
DIR="$(cs get --archive "https://github.com/coursier/coursier/releases/download/v$CS_VERSION/cs-x86_64-pc-win32.zip")"
7+
8+
cp "$DIR/"*.exe cs.exe

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ jobs:
6262
- uses: coursier/[email protected]
6363
with:
6464
jvm: "temurin:17"
65+
- name: Get latest coursier launcher
66+
run: .github/scripts/get-latest-cs.sh
67+
shell: bash
68+
if: runner.os == 'Windows'
6569
- name: Generate native launcher
6670
run: .github/scripts/generate-native-image.sh
6771
shell: bash

.mill-cs-opts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Java 17 required for domain socket stuff
2+
--jvm
3+
temurin:17
4+
# fixes some issues when fetching snapshot artifacts
5+
io.get-coursier::coursier:2.1.0-M2
6+
--scala
7+
2.13.8

.mill-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.9.12
1+
0.10.0

build.sc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import $ivy.`com.lihaoyi::mill-contrib-bloop:$MILL_VERSION`
22
import $ivy.`io.get-coursier::coursier-launcher:2.1.0-M2`
3-
import $ivy.`io.github.alexarchambault.mill::mill-native-image-upload:0.1.16`
3+
import $ivy.`io.github.alexarchambault.mill::mill-native-image-upload:0.1.19`
44
import $file.project.deps, deps.{Deps, Docker, InternalDeps, Scala, TestDeps}
55
import $file.project.publish, publish.{ghOrg, ghName, ScalaCliPublishModule}
66
import $file.project.settings, settings.{

mill

Lines changed: 187 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,197 @@
11
#!/usr/bin/env bash
2+
3+
# This is a wrapper script, that automatically download mill via coursier
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
6+
#
7+
# Project page: https://github.com/coursier/millw
8+
# Original project page: https://github.com/lefou/millw
9+
# Script Version: 0.4.0-cs
10+
#
11+
# If you want to improve this script, please also contribute your changes back!
12+
#
13+
# Licensed under the Apache License, Version 2.0
14+
15+
16+
DEFAULT_MILL_VERSION=0.9.10
17+
218
set -e
319

4-
# This script ensures:
5-
# - that we're using the right JVM (currently, temurin:17)
6-
# - that we run the mill launcher script with bash rather than sh,
7-
# as the latter has issues with '+' characters, that can appear
8-
# in the JVM entry put in PATH by 'cs'.
20+
MILL_REPO_URL="https://github.com/com-lihaoyi/mill"
21+
22+
if [ "x${CURL_CMD}" = "x" ] ; then
23+
CURL_CMD=curl
24+
fi
25+
26+
# Explicit commandline argument takes precedence over all other methods
27+
if [ "x$1" = "x--mill-version" ] ; then
28+
shift
29+
if [ "x$1" != "x" ] ; then
30+
MILL_VERSION="$1"
31+
shift
32+
else
33+
echo "You specified --mill-version without a version." 1>&2
34+
echo "Please provide a version that matches one provided on" 1>&2
35+
echo "${MILL_REPO_URL}/releases" 1>&2
36+
false
37+
fi
38+
fi
39+
40+
# Please note, that if a MILL_VERSION is already set in the environment,
41+
# We reuse it's value and skip searching for a value.
42+
43+
# If not already set, read .mill-version file
44+
if [ "x${MILL_VERSION}" = "x" ] ; then
45+
if [ -f ".mill-version" ] ; then
46+
MILL_VERSION="$(head -n 1 .mill-version 2> /dev/null)"
47+
fi
48+
fi
49+
50+
if [ "x${XDG_CACHE_HOME}" != "x" ] ; then
51+
MILL_DOWNLOAD_PATH="${XDG_CACHE_HOME}/mill/download"
52+
else
53+
MILL_DOWNLOAD_PATH="${HOME}/.cache/mill/download"
54+
fi
55+
56+
# If not already set, try to fetch newest from Github
57+
if [ "x${MILL_VERSION}" = "x" ] ; then
58+
# TODO: try to load latest version from release page
59+
echo "No mill version specified." 1>&2
60+
echo "You should provide a version via '.mill-version' file or --mill-version option." 1>&2
61+
62+
mkdir -p "${MILL_DOWNLOAD_PATH}"
63+
LANG=C touch -d '1 hour ago' "${MILL_DOWNLOAD_PATH}/.expire_latest" 2>/dev/null || (
64+
# we might be on OSX or BSD which don't have -d option for touch
65+
# but probably a -A [-][[hh]mm]SS
66+
touch "${MILL_DOWNLOAD_PATH}/.expire_latest"; touch -A -010000 "${MILL_DOWNLOAD_PATH}/.expire_latest"
67+
) || (
68+
# in case we still failed, we retry the first touch command with the intention
69+
# to show the (previously suppressed) error message
70+
LANG=C touch -d '1 hour ago' "${MILL_DOWNLOAD_PATH}/.expire_latest"
71+
)
72+
73+
if [ "${MILL_DOWNLOAD_PATH}/.latest" -nt "${MILL_DOWNLOAD_PATH}/.expire_latest" ] ; then
74+
# we know a current latest version
75+
MILL_VERSION="$(head -n 1 ${MILL_DOWNLOAD_PATH}/.latest 2> /dev/null)"
76+
fi
77+
78+
if [ "x${MILL_VERSION}" = "x" ] ; then
79+
# we don't know a current latest version
80+
echo "Retrieving latest mill version ..." 1>&2
81+
LANG=C ${CURL_CMD} -s -i -f -I ${MILL_REPO_URL}/releases/latest 2> /dev/null | grep --ignore-case Location: | sed s'/^.*tag\///' | tr -d '\r\n' > "${MILL_DOWNLOAD_PATH}/.latest"
82+
MILL_VERSION="$(head -n 1 ${MILL_DOWNLOAD_PATH}/.latest 2> /dev/null)"
83+
fi
84+
85+
if [ "x${MILL_VERSION}" = "x" ] ; then
86+
# Last resort
87+
MILL_VERSION="${DEFAULT_MILL_VERSION}"
88+
echo "Falling back to hardcoded mill version ${MILL_VERSION}" 1>&2
89+
else
90+
echo "Using mill version ${MILL_VERSION}" 1>&2
91+
fi
92+
fi
93+
94+
unset MILL_DOWNLOAD_PATH
95+
unset MILL_OLD_DOWNLOAD_PATH
96+
unset OLD_MILL
97+
unset MILL_VERSION_TAG
98+
unset MILL_REPO_URL
99+
100+
if [ "x$1" == "x-i" -o "x$1" == "x--interactive" ]; then
101+
MILL_APP_NAME="mill-interactive"
102+
else
103+
MILL_APP_NAME="mill"
104+
fi
105+
106+
mill_cs_opts=()
107+
108+
# Adapted from Mill 0.10.0-M5 assembly
109+
init_mill_jvm_opts() {
110+
if [ -z $MILL_JVM_OPTS_PATH ] ; then
111+
mill_jvm_opts_file=".mill-jvm-opts"
112+
else
113+
mill_jvm_opts_file=$MILL_JVM_OPTS_PATH
114+
fi
115+
116+
if [ -f "$mill_jvm_opts_file" ] ; then
117+
while IFS= read line
118+
do
119+
case $line in
120+
"-X"*) mill_cs_opts=("${mill_cs_opts[@]}" "--java-opt" "$line")
121+
esac
122+
done <"$mill_jvm_opts_file"
123+
fi
124+
}
125+
126+
init_mill_cs_opts() {
127+
if [ -z $MILL_CS_OPTS_PATH ] ; then
128+
mill_cs_opts_file=".mill-cs-opts"
129+
else
130+
mill_cs_opts_file=$MILL_CS_OPTS_PATH
131+
fi
132+
133+
if [ -f "$mill_cs_opts_file" ] ; then
134+
while IFS= read line
135+
do
136+
case $line in
137+
"#"*) ;;
138+
*) mill_cs_opts=("${mill_cs_opts[@]}" "$line") ;;
139+
esac
140+
done <"$mill_cs_opts_file"
141+
fi
142+
}
9143

10-
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)"
11144

12-
if ! command -v cs >/dev/null; then
13-
cat 1>&2 << EOF
14-
cs command not found.
145+
# Adapted from
15146

16-
Please download a cs launcher from
17-
https://github.com/coursier/coursier/releases/tag/v2.1.0-M2
18-
and install it as 'cs' in your PATH.
19-
EOF
20-
exit 1
147+
coursier_version="2.1.0-M2"
148+
149+
# https://stackoverflow.com/questions/3466166/how-to-check-if-running-in-cygwin-mac-or-linux/17072017#17072017
150+
if [ "$(expr substr $(uname -s) 1 5 2>/dev/null)" == "Linux" ]; then
151+
cs_url="https://github.com/coursier/coursier/releases/download/v$coursier_version/cs-x86_64-pc-linux.gz"
152+
cache_base="$HOME/.cache/coursier/v1"
153+
elif [ "$(uname)" == "Darwin" ]; then
154+
cs_url="https://github.com/coursier/coursier/releases/download/v$coursier_version/cs-x86_64-apple-darwin.gz"
155+
cache_base="$HOME/Library/Caches/Coursier/v1"
156+
else
157+
# assuming Windows…
158+
cs_url="https://github.com/coursier/coursier/releases/download/v$coursier_version/cs-x86_64-pc-win32.zip"
159+
cache_base="$LOCALAPPDATA/Coursier/v1" # TODO Check that
160+
ext=".exe"
161+
do_chmod="0"
162+
fi
163+
164+
cache_dest="$cache_base/$(echo "$cs_url" | sed 's@://@/@')"
165+
166+
if [ ! -f "$cache_dest" ]; then
167+
mkdir -p "$(dirname "$cache_dest")"
168+
tmp_dest="$cache_dest.tmp-setup"
169+
echo "Downloading $cs_url"
170+
curl -fLo "$tmp_dest" "$cs_url"
171+
mv "$tmp_dest" "$cache_dest"
172+
fi
173+
174+
if [[ "$cache_dest" == *.gz ]]; then
175+
cs="$(dirname "$cache_dest")/$(basename "$cache_dest" .gz)"
176+
if [ ! -f "$cs" ]; then
177+
gzip -d < "$cache_dest" > "$cs"
178+
fi
179+
if [ ! -x "$cs" ]; then
180+
chmod +x "$cs"
181+
fi
182+
elif [[ "$cache_dest" == *.zip ]]; then
183+
cs="$(dirname "$cache_dest")/$(basename "$cache_dest" .zip).exe"
184+
if [ ! -f "$cs" ]; then
185+
unzip -p "$cache_dest" "$(basename "$cache_dest" .zip).exe" > "$cs"
186+
fi
21187
fi
22188

23189
eval "$(cs java --env --jvm temurin:17 || cs java --env --jvm openjdk:1.17.0)"
190+
export PATH=".:$PATH"
191+
192+
193+
194+
init_mill_jvm_opts
195+
init_mill_cs_opts
24196

25-
exec /usr/bin/env bash "$DIR/millw" "$@"
197+
exec "$cs" launch "$MILL_APP_NAME:$MILL_VERSION" "${mill_cs_opts[@]}" -- "$@"

0 commit comments

Comments
 (0)