Skip to content

Commit e8f1012

Browse files
authored
Cleanup bootstrap scripts (#6117)
* Remove github latest-release downloader, since that's a hermeticity issue that can cause nondeterminism as new github versions are released, or even as time passes and you run the command again * Remove `No mill version specified` warning, since now we recommend people to rely on the `MILL_DEFAULT_VERSION` in the docs * Remove check for system-installed Mill, which adds a bunch of complexity just to save a single download * Remove header comment that is already out of date and impossible to maintain * DRY up the `sed` regexes in `mill.sh` and the `sed`-emulation code in `mill.bat` * Re-arranged the two scripts and standardized variable names so the logic happens in the same order, so they are easier to read through side-by-side and compare * Move mill temp download to `out/mill-bootstrap-download` to fix #5837 * Added a `dist.scripts.test` windows CI job to ensure the windows code paths are covered * Tweaked a few windows cache paths to fix #6109 Covered by unit tests, and tested manually on my macbook pro and windows microsoft surface laptop 7
1 parent 39e353b commit e8f1012

File tree

9 files changed

+269
-650
lines changed

9 files changed

+269
-650
lines changed

.github/workflows/run-tests.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,9 @@ jobs:
216216
- java-version: 17
217217
millargs: '"example.scalalib.{basic,publishing}.__.packaged.daemon"'
218218

219+
- java-version: 17
220+
millargs: '"dist.scripts.test"' # run this on both windows and mac to exercise bootstrap scripts
221+
219222
- java-version: 17
220223
millargs: "'integration.failure.__.packaged.nodaemon'"
221224

dist/scripts/src/mill.bat

Lines changed: 35 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,5 @@
11
@echo off
22

3-
rem This is a wrapper script, that automatically selects or downloads Mill from Maven Central or GitHub release pages.
4-
rem
5-
rem This script determines the Mill version to use by trying these sources
6-
rem - env-variable `MILL_VERSION`
7-
rem - local file `.mill-version`
8-
rem - local file `.config/mill-version`
9-
rem - `mill-version` from YAML frontmatter of current buildfile
10-
rem - if accessible, find the latest stable version available on Maven Central ({{{ mill-maven-url }}})
11-
rem - env-variable `DEFAULT_MILL_VERSION`
12-
rem
13-
rem If a version has the suffix '-native' a native binary will be used.
14-
rem If a version has the suffix '-jvm' an executable jar file will be used, requiring an already installed Java runtime.
15-
rem If no such suffix is found, the script will pick a default based on version and platform.
16-
rem
17-
rem Once a version was determined, it tries to use either
18-
rem - a system-installed mill, if found and it's version matches
19-
rem - an already downloaded version under {{{ mill-download-cache-win }}}
20-
rem
21-
rem If no working mill version was found on the system,
22-
rem this script downloads a binary file from Maven Central or Github Pages (this is version dependent)
23-
rem into a cache location ({{{ mill-download-cache-win }}}).
24-
rem
25-
rem Mill Project URL: {{{ mill-repo-url }}}
26-
rem Script Version: {{{ mill-version }}}
27-
rem
28-
rem If you want to improve this script, please also contribute your changes back!
29-
rem This script was generated from: {{{ template-file }}}
30-
rem
31-
rem Licensed under the Apache License, Version 2.0
32-
33-
rem setlocal seems to be unavailable on Windows 95/98/ME
34-
rem but I don't think we need to support them in 2019
353
setlocal enabledelayedexpansion
364

375
if [!DEFAULT_MILL_VERSION!]==[] ( set "DEFAULT_MILL_VERSION={{{ mill-version }}}" )
@@ -65,9 +33,24 @@ if [!MILL_VERSION!]==[] (
6533
if exist .config\mill-version (
6634
set /p MILL_VERSION=<.config\mill-version
6735
) else (
36+
rem Determine which config file to use for version extraction
37+
set "MILL_VERSION_CONFIG_FILE="
38+
set "MILL_VERSION_SEARCH_PATTERN="
39+
6840
if exist build.mill.yaml (
41+
set "MILL_VERSION_CONFIG_FILE=build.mill.yaml"
42+
set "MILL_VERSION_SEARCH_PATTERN=mill-version:"
43+
) else (
44+
if not "%MILL_BUILD_SCRIPT%"=="" (
45+
set "MILL_VERSION_CONFIG_FILE=%MILL_BUILD_SCRIPT%"
46+
set "MILL_VERSION_SEARCH_PATTERN=//\|.*mill-version"
47+
)
48+
)
49+
50+
rem Process the config file if found
51+
if not "!MILL_VERSION_CONFIG_FILE!"=="" (
6952
rem Find the line and process it
70-
for /f "tokens=*" %%a in ('findstr /R /C:"mill-version:" "build.mill.yaml"') do (
53+
for /f "tokens=*" %%a in ('findstr /R /C:"!MILL_VERSION_SEARCH_PATTERN!" "!MILL_VERSION_CONFIG_FILE!"') do (
7154
set "line=%%a"
7255

7356
rem --- 1. Replicate sed 's/.*://' ---
@@ -85,7 +68,7 @@ if [!MILL_VERSION!]==[] (
8568
set "line=!line:'=!"
8669
set "line=!line:"=!"
8770

88-
rem --- 4. NEW: Replicate sed's trim/space removal ---
71+
rem --- 4. Replicate sed's trim/space removal ---
8972
rem Remove all space characters from the result. This is more robust.
9073
set "MILL_VERSION=!line: =!"
9174

@@ -95,59 +78,23 @@ if [!MILL_VERSION!]==[] (
9578

9679
:version_found
9780
rem no-op
98-
) else (
99-
if not "%MILL_BUILD_SCRIPT%"=="" (
100-
rem Find the line and process it
101-
for /f "tokens=*" %%a in ('findstr /R /C:"//\|.*mill-version" "%MILL_BUILD_SCRIPT%"') do (
102-
set "line=%%a"
103-
104-
rem --- 1. Replicate sed 's/.*://' ---
105-
rem This removes everything up to and including the first colon
106-
set "line=!line:*:=!"
107-
108-
rem --- 2. Replicate sed 's/#.*//' ---
109-
rem Split on '#' and keep the first part
110-
for /f "tokens=1 delims=#" %%b in ("!line!") do (
111-
set "line=%%b"
112-
)
113-
114-
rem --- 3. Replicate sed 's/['"]//g' ---
115-
rem Remove all quotes
116-
set "line=!line:'=!"
117-
set "line=!line:"=!"
118-
119-
rem --- 4. NEW: Replicate sed's trim/space removal ---
120-
rem Remove all space characters from the result. This is more robust.
121-
set "MILL_VERSION=!line: =!"
122-
123-
rem We found the version, so we can exit the loop
124-
goto :version_found
125-
)
126-
127-
:version_found
128-
rem no-op
129-
) else (
130-
rem no-op
131-
)
13281
)
13382
)
13483
)
13584
)
13685

13786
if [!MILL_VERSION!]==[] (
138-
echo No mill version specified. >&2
139-
echo You should provide a version via a '//^| mill-version: ' comment or a '.mill-version' file. >&2
14087
set MILL_VERSION=%DEFAULT_MILL_VERSION%
14188
)
14289

143-
if [!MILL_DOWNLOAD_PATH!]==[] set MILL_DOWNLOAD_PATH=%USERPROFILE%\.mill\download
90+
if [!MILL_FINAL_DOWNLOAD_FOLDER!]==[] set MILL_FINAL_DOWNLOAD_FOLDER=%USERPROFILE%\.cache\mill\download
14491

14592
rem without bat file extension, cmd doesn't seem to be able to run it
14693

14794
set "MILL_NATIVE_SUFFIX=-native"
14895
set "MILL_JVM_SUFFIX=-jvm"
149-
set "FULL_MILL_VERSION=%MILL_VERSION%"
150-
set "MILL_EXT=.bat"
96+
set "MILL_FULL_VERSION=%MILL_VERSION%"
97+
set "MILL_DOWNLOAD_EXT=.bat"
15198
set "ARTIFACT_SUFFIX="
15299
REM Check if MILL_VERSION contains MILL_NATIVE_SUFFIX
153100
echo !MILL_VERSION! | findstr /C:"%MILL_NATIVE_SUFFIX%" >nul
@@ -157,7 +104,7 @@ if !errorlevel! equ 0 (
157104
REM https://github.com/oracle/graal/issues/9215
158105
IF /I NOT "%PROCESSOR_ARCHITECTURE%"=="ARM64" (
159106
set "ARTIFACT_SUFFIX=-native-windows-amd64"
160-
set "MILL_EXT=.exe"
107+
set "MILL_DOWNLOAD_EXT=.exe"
161108
) else (
162109
rem no-op
163110
)
@@ -185,15 +132,15 @@ if !errorlevel! equ 0 (
185132
if "!SKIP_VERSION!"=="false" (
186133
IF /I NOT "%PROCESSOR_ARCHITECTURE%"=="ARM64" (
187134
set "ARTIFACT_SUFFIX=-native-windows-amd64"
188-
set "MILL_EXT=.exe"
135+
set "MILL_DOWNLOAD_EXT=.exe"
189136
)
190137
) else (
191138
rem no-op
192139
)
193140
)
194141
)
195142

196-
set MILL=%MILL_DOWNLOAD_PATH%\!FULL_MILL_VERSION!!MILL_EXT!
143+
set MILL=%MILL_FINAL_DOWNLOAD_FOLDER%\!MILL_FULL_VERSION!!MILL_DOWNLOAD_EXT!
197144

198145
set MILL_RESOLVE_DOWNLOAD=
199146

@@ -289,34 +236,26 @@ if [!MILL_RESOLVE_DOWNLOAD!]==[true] (
289236
)
290237

291238
rem there seems to be no way to generate a unique temporary file path (on native Windows)
292-
set MILL_DOWNLOAD_FILE=%MILL%.tmp
239+
if defined MILL_OUTPUT_DIR (
240+
set MILL_TEMP_DOWNLOAD_FILE=%MILL_OUTPUT_DIR%\mill-temp-download
241+
if not exist "%MILL_OUTPUT_DIR%" mkdir "%MILL_OUTPUT_DIR%"
242+
) else (
243+
set MILL_TEMP_DOWNLOAD_FILE=out\mill-bootstrap-download
244+
if not exist "out" mkdir "out"
245+
)
293246

294247
echo Downloading mill !MILL_VERSION! from !MILL_DOWNLOAD_URL! ... 1>&2
295248

296-
if not exist "%MILL_DOWNLOAD_PATH%" mkdir "%MILL_DOWNLOAD_PATH%"
297-
rem curl is bundled with recent Windows 10
298-
rem but I don't think we can expect all the users to have it in 2019
299-
where /Q curl
300-
if !ERRORLEVEL! EQU 0 (
301-
curl -f -L "!MILL_DOWNLOAD_URL!" -o "!MILL_DOWNLOAD_FILE!"
302-
) else (
303-
rem bitsadmin seems to be available on Windows 7
304-
rem without /dynamic, github returns 403
305-
rem bitsadmin is sometimes needlessly slow but it looks better with /priority foreground
306-
bitsadmin /transfer millDownloadJob /dynamic /priority foreground "!MILL_DOWNLOAD_URL!" "!MILL_DOWNLOAD_FILE!"
307-
)
308-
if not exist "!MILL_DOWNLOAD_FILE!" (
309-
echo Could not download mill !MILL_VERSION! 1>&2
310-
exit /b 1
311-
)
249+
curl -f -L "!MILL_DOWNLOAD_URL!" -o "!MILL_TEMP_DOWNLOAD_FILE!"
312250

313-
move /y "!MILL_DOWNLOAD_FILE!" "%MILL%"
251+
if not exist "%MILL_FINAL_DOWNLOAD_FOLDER%" mkdir "%MILL_FINAL_DOWNLOAD_FOLDER%"
252+
move /y "!MILL_TEMP_DOWNLOAD_FILE!" "%MILL%"
314253

315-
set MILL_DOWNLOAD_FILE=
254+
set MILL_TEMP_DOWNLOAD_FILE=
316255
set MILL_DOWNLOAD_SUFFIX=
317256
)
318257

319-
set MILL_DOWNLOAD_PATH=
258+
set MILL_FINAL_DOWNLOAD_FOLDER=
320259
set MILL_VERSION=
321260
set MILL_REPO_URL=
322261

0 commit comments

Comments
 (0)