Skip to content

Commit 98ba509

Browse files
committed
Update Mill launch scripts
1 parent 988488f commit 98ba509

File tree

2 files changed

+92
-279
lines changed

2 files changed

+92
-279
lines changed

mill.bat

Lines changed: 37 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,8 @@
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 (https://repo1.maven.org/maven2)
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 %USERPROFILE%\.mill\download
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 (%USERPROFILE%\.mill\download).
24-
rem
25-
rem Mill Project URL: https://github.com/com-lihaoyi/mill
26-
rem Script Version: 1.0.5
27-
rem
28-
rem If you want to improve this script, please also contribute your changes back!
29-
rem This script was generated from: dist/scripts/src/mill.bat
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

37-
if [!DEFAULT_MILL_VERSION!]==[] ( set "DEFAULT_MILL_VERSION=0.12.16" )
5+
if [!DEFAULT_MILL_VERSION!]==[] ( set "DEFAULT_MILL_VERSION=1.0.6" )
386

397
if [!MILL_GITHUB_RELEASE_CDN!]==[] ( set "MILL_GITHUB_RELEASE_CDN=" )
408

@@ -65,9 +33,24 @@ if [!MILL_VERSION!]==[] (
6533
if exist .config\mill-version (
6634
set /p MILL_VERSION=<.config\mill-version
6735
) else (
68-
if not "%MILL_BUILD_SCRIPT%"=="" (
36+
rem Determine which config file to use for version extraction
37+
set "MILL_VERSION_CONFIG_FILE="
38+
set "MILL_VERSION_SEARCH_PATTERN="
39+
40+
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" "%MILL_BUILD_SCRIPT%"') 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,27 +78,23 @@ if [!MILL_VERSION!]==[] (
9578

9679
:version_found
9780
rem no-op
98-
) else (
99-
rem no-op
10081
)
10182
)
10283
)
10384
)
10485

10586
if [!MILL_VERSION!]==[] (
106-
echo No mill version specified. >&2
107-
echo You should provide a version via a '//^| mill-version: ' comment or a '.mill-version' file. >&2
10887
set MILL_VERSION=%DEFAULT_MILL_VERSION%
10988
)
11089

111-
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
11291

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

11594
set "MILL_NATIVE_SUFFIX=-native"
11695
set "MILL_JVM_SUFFIX=-jvm"
117-
set "FULL_MILL_VERSION=%MILL_VERSION%"
118-
set "MILL_EXT=.bat"
96+
set "MILL_FULL_VERSION=%MILL_VERSION%"
97+
set "MILL_DOWNLOAD_EXT=.bat"
11998
set "ARTIFACT_SUFFIX="
12099
REM Check if MILL_VERSION contains MILL_NATIVE_SUFFIX
121100
echo !MILL_VERSION! | findstr /C:"%MILL_NATIVE_SUFFIX%" >nul
@@ -125,7 +104,7 @@ if !errorlevel! equ 0 (
125104
REM https://github.com/oracle/graal/issues/9215
126105
IF /I NOT "%PROCESSOR_ARCHITECTURE%"=="ARM64" (
127106
set "ARTIFACT_SUFFIX=-native-windows-amd64"
128-
set "MILL_EXT=.exe"
107+
set "MILL_DOWNLOAD_EXT=.exe"
129108
) else (
130109
rem no-op
131110
)
@@ -153,15 +132,15 @@ if !errorlevel! equ 0 (
153132
if "!SKIP_VERSION!"=="false" (
154133
IF /I NOT "%PROCESSOR_ARCHITECTURE%"=="ARM64" (
155134
set "ARTIFACT_SUFFIX=-native-windows-amd64"
156-
set "MILL_EXT=.exe"
135+
set "MILL_DOWNLOAD_EXT=.exe"
157136
)
158137
) else (
159138
rem no-op
160139
)
161140
)
162141
)
163142

164-
set MILL=%MILL_DOWNLOAD_PATH%\!FULL_MILL_VERSION!!MILL_EXT!
143+
set MILL=%MILL_FINAL_DOWNLOAD_FOLDER%\!MILL_FULL_VERSION!!MILL_DOWNLOAD_EXT!
165144

166145
set MILL_RESOLVE_DOWNLOAD=
167146

@@ -257,34 +236,26 @@ if [!MILL_RESOLVE_DOWNLOAD!]==[true] (
257236
)
258237

259238
rem there seems to be no way to generate a unique temporary file path (on native Windows)
260-
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+
)
261246

262247
echo Downloading mill !MILL_VERSION! from !MILL_DOWNLOAD_URL! ... 1>&2
263248

264-
if not exist "%MILL_DOWNLOAD_PATH%" mkdir "%MILL_DOWNLOAD_PATH%"
265-
rem curl is bundled with recent Windows 10
266-
rem but I don't think we can expect all the users to have it in 2019
267-
where /Q curl
268-
if !ERRORLEVEL! EQU 0 (
269-
curl -f -L "!MILL_DOWNLOAD_URL!" -o "!MILL_DOWNLOAD_FILE!"
270-
) else (
271-
rem bitsadmin seems to be available on Windows 7
272-
rem without /dynamic, github returns 403
273-
rem bitsadmin is sometimes needlessly slow but it looks better with /priority foreground
274-
bitsadmin /transfer millDownloadJob /dynamic /priority foreground "!MILL_DOWNLOAD_URL!" "!MILL_DOWNLOAD_FILE!"
275-
)
276-
if not exist "!MILL_DOWNLOAD_FILE!" (
277-
echo Could not download mill !MILL_VERSION! 1>&2
278-
exit /b 1
279-
)
249+
curl -f -L "!MILL_DOWNLOAD_URL!" -o "!MILL_TEMP_DOWNLOAD_FILE!"
280250

281-
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%"
282253

283-
set MILL_DOWNLOAD_FILE=
254+
set MILL_TEMP_DOWNLOAD_FILE=
284255
set MILL_DOWNLOAD_SUFFIX=
285256
)
286257

287-
set MILL_DOWNLOAD_PATH=
258+
set MILL_FINAL_DOWNLOAD_FOLDER=
288259
set MILL_VERSION=
289260
set MILL_REPO_URL=
290261

0 commit comments

Comments
 (0)