Skip to content

Commit f164139

Browse files
authored
Use newly-built version of Mill scripts for dist rather than Mill's current ./mill bootstrap script (#5801)
Previously we used the `./mill` in the Mill repo that can potentially be stale and out of date, e.g. the current one was last updated in `1.0.0-M1-21-7b6fae-DIRTY892b63e8`, with an old `DEFAULT_MILL_VERSION`. This PR makes us always use the most recently built script so the `DEFAULT_MILL_VERSION` is up to date With the `DEFAULT_MILL_VERSION` fixed, we now have the freedom to not need a `//| mill-version:` by default, since the bootstrap script comes with one. The user can still customize the `//| mill-version` or `.mill-version` later if they want, but this should remove one manual step from getting started. We can also recommend people update Mill by always downloading new bootstrap scripts via `curl`, which removes yet another degree of freedom and avoids the failure mode we have hit in the past where people bump `//| mill-version`, but don't download the new bootstrap script necessary for using the newer version, resulting in the Mill upgrade failing
1 parent 4e9e840 commit f164139

File tree

3 files changed

+11
-35
lines changed

3 files changed

+11
-35
lines changed

dist/package.mill

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -190,36 +190,12 @@ object `package` extends MillJavaModule with DistModule {
190190
}
191191
}
192192

193-
def millBootstrap = Task.Source(BuildCtx.workspaceRoot / "mill")
194-
def millBootstrapBat = Task.Source(BuildCtx.workspaceRoot / "mill.bat")
195-
196-
def prepareBootstrapLauncher(
197-
bootstrap: os.Path,
198-
dest: os.Path,
199-
buildVersion: String,
200-
fileName: String
201-
) = {
202-
val outputPath = dest / fileName
203-
val millBootstrapGrepPrefix = "(\n *DEFAULT_MILL_VERSION=)"
204-
205-
os.write(
206-
outputPath,
207-
os.read(bootstrap)
208-
.replaceAll(
209-
millBootstrapGrepPrefix + "[^\\n]+",
210-
"$1" + buildVersion
211-
)
212-
)
213-
214-
if (!scala.util.Properties.isWin) os.perms.set(outputPath, "rwxrwxrwx")
215-
216-
PathRef(outputPath)
217-
}
218193
def bootstrapLauncher = Task {
219-
prepareBootstrapLauncher(millBootstrap().path, Task.dest, build.millVersion(), "mill")
194+
build.dist.scripts.millSh.compile0()
220195
}
196+
221197
def bootstrapLauncherBat = Task {
222-
prepareBootstrapLauncher(millBootstrapBat().path, Task.dest, build.millVersion(), "mill.bat")
198+
build.dist.scripts.millBat.compile0()
223199
}
224200

225201
def examplePaths: Task[Seq[os.Path]] = Task.Input {
@@ -245,10 +221,6 @@ object `package` extends MillJavaModule with DistModule {
245221
val ignoreErrorsOnCI = Task.dest / exampleStr / "ignoreErrorsOnCI"
246222
if (os.exists(ignoreErrorsOnCI)) os.remove(ignoreErrorsOnCI)
247223
val buildMill = Task.dest / exampleStr / "build.mill"
248-
os.write.over(
249-
buildMill,
250-
s"//| mill-version: ${build.millVersion()}\n" + os.read(buildMill)
251-
)
252224
os.copy(bootstrapLauncher().path, Task.dest / exampleStr / "mill")
253225
os.copy(bootstrapLauncherBat().path, Task.dest / exampleStr / "mill.bat")
254226
val zip = Task.dest / s"$exampleStr.zip"

website/docs/modules/ROOT/pages/cli/build-header.adoc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ package build
2828

2929
Mill's build headers can contain the following keys:
3030

31-
1. xref:cli/installation-ide.adoc[mill-version]: this must be unquoted in the first line
32-
of the build header, and specifies the version of Mill used in this project.
31+
1. xref:cli/installation-ide.adoc[mill-version]: if provided, this must be unquoted in
32+
the first line of the build header, and specifies the version of Mill used in this
33+
project. If not provided, Mill will launch using the version of your `./mill` or
34+
`./mill.bat` bootstrap script.
3335
3436
2. xref:#_mill_opts[]: flags to pass to Mill by default, useful for flags that you want
3537
everyone to use so they don't need to always remember to type them at the command line

website/docs/modules/ROOT/pages/cli/installation-ide.adoc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ bootstrap script, included. You can also download the bootstrap script manually:
2222
----
2323
> curl -L {mill-download-url}/mill-dist-{mill-version}-mill.sh -o mill
2424
> chmod +x mill
25-
> echo "//| mill-version: {mill-version}" > build.mill
2625
> ./mill version
2726
{mill-version}
2827
----
@@ -31,7 +30,6 @@ bootstrap script, included. You can also download the bootstrap script manually:
3130
[source,console,subs="verbatim,attributes"]
3231
----
3332
> curl.exe -L {mill-download-url}/mill-dist-{mill-version}-mill.bat -o mill.bat
34-
> echo "//| mill-version: {mill-version}" > build.mill
3533
> ./mill version
3634
{mill-version}
3735
----
@@ -63,6 +61,10 @@ In-project bootstrap scripts are also useful for running Mill in CI/CD, ensuring
6361
that your build server like Jenkins or Github Actions has the correct version of Mill
6462
present to build, compile or test your code.
6563

64+
You can also configure a `//| mill-version` in your xref:cli/build-header.adoc[build header]
65+
if you want to try a different version, but the best practice when upgrading is to just
66+
update your bootstrap scripts which ensures the script version and Mill version are compatible.
67+
6668
If you are starting a new project using a Mill bootstrap script, you can use the
6769
xref:cli/builtin-commands.adoc#_init[mill init] to initialize the project
6870
folder with one of the Mill example projects. There are a wide range of example projects,

0 commit comments

Comments
 (0)