Skip to content

Commit d219462

Browse files
authored
More Mill launcher integration work (#4087)
Fixes #2161 - Adds some integration tests for older mill versions - Includes the `mill.ps1` file
1 parent 7f1b618 commit d219462

File tree

5 files changed

+195
-6
lines changed

5 files changed

+195
-6
lines changed

dist/package.mill

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,8 @@ object `package` extends RootModule with build.MillPublishJavaModule {
260260
def millBootstrap = Task.Source(Task.workspace / "mill")
261261
def millBootstrapBat = Task.Source(Task.workspace / "mill.bat")
262262

263-
def prepareBootstrapLauncher(bootstrap: os.Path, dest: os.Path, buildVersion: String) = {
264-
val outputPath = dest / "mill"
263+
def prepareBootstrapLauncher(bootstrap: os.Path, dest: os.Path, buildVersion: String, fileName: String) = {
264+
val outputPath = dest / fileName
265265
val millBootstrapGrepPrefix = "(\n *DEFAULT_MILL_VERSION=)"
266266

267267
os.write(
@@ -272,14 +272,16 @@ object `package` extends RootModule with build.MillPublishJavaModule {
272272
"$1" + buildVersion
273273
)
274274
)
275-
os.perms.set(outputPath, "rwxrwxrwx")
275+
276+
if (!scala.util.Properties.isWin) os.perms.set(outputPath, "rwxrwxrwx")
277+
276278
PathRef(outputPath)
277279
}
278280
def bootstrapLauncher = Task {
279-
prepareBootstrapLauncher(millBootstrap().path, Task.dest, build.millVersion())
281+
prepareBootstrapLauncher(millBootstrap().path, Task.dest, build.millVersion(), "mill")
280282
}
281283
def bootstrapLauncherBat = Task {
282-
prepareBootstrapLauncher(millBootstrapBat().path, Task.dest, build.millVersion())
284+
prepareBootstrapLauncher(millBootstrapBat().path, Task.dest, build.millVersion(), "mill.bat")
283285
}
284286

285287
def examplePathsWithArtifactName:Task[Seq[(os.Path,String)]] = Task.Anon{

integration/feature/launcher-old-versions/resources/build.sc

Whitespace-only changes.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package mill.integration
2+
3+
import mill.testkit.UtestIntegrationTestSuite
4+
5+
import utest._
6+
7+
class LauncherOldVersionsTests(version: String) extends UtestIntegrationTestSuite {
8+
val tests: Tests = Tests {
9+
test - integrationTest { tester =>
10+
val launcherEnv =
11+
if (mill.main.client.Util.isWindows) "MILL_LAUNCHER_BAT"
12+
else "MILL_LAUNCHER"
13+
14+
val workspacePath = tester.workspacePath
15+
16+
val launcherScript = sys.env(launcherEnv)
17+
os.write.over(workspacePath / ".mill-version", version)
18+
19+
// Run Mill once beforehand just to make sure it gets initialized and
20+
// none of the initialization output gets into `outText`
21+
os.call(cmd = (launcherScript, "version"), cwd = workspacePath, stderr = os.Pipe)
22+
23+
val res = os.call(cmd = (launcherScript, "version"), cwd = workspacePath, stderr = os.Pipe)
24+
val outText = res.out.text().trim
25+
assert(outText == version)
26+
}
27+
}
28+
}
29+
30+
// Split these into separate test groups so they can run in parallel
31+
//
32+
// Older versions of Mill do not work on latest macbook pros
33+
//object LauncherVersionTests_0_1 extends LauncherOldVersionsTests("0.1.7")
34+
//object LauncherVersionTests_0_2 extends LauncherOldVersionsTests("0.2.7")
35+
//object LauncherVersionTests_0_3 extends LauncherOldVersionsTests("0.3.6")
36+
//object LauncherVersionTests_0_4 extends LauncherOldVersionsTests("0.4.2")
37+
//object LauncherVersionTests_0_5 extends LauncherOldVersionsTests("0.5.9")
38+
//object LauncherVersionTests_0_6 extends LauncherOldVersionsTests("0.6.3")
39+
//object LauncherVersionTests_0_7 extends LauncherOldVersionsTests("0.7.4")
40+
//object LauncherVersionTests_0_8 extends LauncherOldVersionsTests("0.8.0")
41+
object LauncherVersionTests_0_9 extends LauncherOldVersionsTests("0.9.12")
42+
object LauncherVersionTests_0_10 extends LauncherOldVersionsTests("0.10.15")
43+
object LauncherVersionTests_0_11 extends LauncherOldVersionsTests("0.11.13")

integration/package.mill

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,14 @@ object `package` extends RootModule {
4444
def forkEnv =
4545
super.forkEnv() ++
4646
IntegrationTestModule.this.forkEnv() ++
47-
Map("MILL_INTEGRATION_SERVER_MODE" -> (mode == "local" || mode == "server").toString) ++
47+
Map(
48+
"MILL_INTEGRATION_SERVER_MODE" -> (mode == "local" || mode == "server").toString,
49+
"MILL_LAUNCHER" -> build.dist.bootstrapLauncher().path.toString,
50+
"MILL_LAUNCHER_BAT" -> build.dist.bootstrapLauncherBat().path.toString,
51+
) ++
4852
testReleaseEnv()
4953

54+
5055
def forkArgs = Task { super.forkArgs() ++ build.dist.forkArgs() }
5156

5257
def testReleaseEnv =
@@ -60,6 +65,8 @@ object `package` extends RootModule {
6065

6166
def compile: T[mill.scalalib.api.CompilationResult] =
6267
T { mill.scalalib.api.CompilationResult(null, null) } // binary compatibility stub, not used
68+
69+
def testForkGrouping = discoveredTestClasses().grouped(1).toSeq
6370
}
6471

6572
object local extends ModeModule

mill.ps1

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
# This is a wrapper script, that automatically download mill from GitHub release pages
2+
# You can give the required mill version with --mill-version parameter
3+
# If no version is given, it falls back to the value of DEFAULT_MILL_VERSION
4+
#
5+
# Project page: https://github.com/lefou/millw
6+
# Script Version: 0.4.12
7+
#
8+
# If you want to improve this script, please also contribute your changes back!
9+
#
10+
# Licensed under the Apache License, Version 2.0
11+
12+
[CmdletBinding(PositionalBinding = $false)]
13+
14+
param(
15+
[Parameter(ValueFromRemainingArguments = $true, Position = 0)]
16+
[string[]] $remainingArgs
17+
)
18+
19+
$DEFAULT_MILL_VERSION = $Env:DEFAULT_MILL_VERSION ?? '0.11.6'
20+
21+
$GITHUB_RELEASE_CDN = $Env:GITHUB_RELEASE_CDN ?? ''
22+
23+
$MILL_REPO_URL = 'https://github.com/com-lihaoyi/mill'
24+
25+
$MILL_VERSION = $null
26+
27+
if ($null -ne $remainingArgs) {
28+
if ($remainingArgs[0] -eq '--mill-version') {
29+
$remainingArgs = Select-Object -InputObject $remainingArgs -Skip 1
30+
if ($null -ne $remainingArgs) {
31+
$MILL_VERSION = $remainingArgs[0]
32+
$remainingArgs = Select-Object -InputObject $remainingArgs -Skip 1
33+
}
34+
else {
35+
Write-Error -Message "Please provide a version that matches one provided on $MILL_REPO_URL/releases"
36+
throw [System.ArgumentNullException] '--mill-version'
37+
}
38+
}
39+
}
40+
41+
if ($null -eq $MILL_VERSION) {
42+
if (Test-Path -Path '.mill-version' -PathType Leaf) {
43+
$MILL_VERSION = Get-Content -Path '.mill-version' -TotalCount 1
44+
}
45+
elseif (Test-Path -Path '.config/mill-version' -PathType Leaf) {
46+
$MILL_VERSION = Get-Content -Path '.config/mill-version' -TotalCount 1
47+
}
48+
}
49+
50+
$MILL_USER_CACHE_DIR = Join-Path -Path $Env:LOCALAPPDATA -ChildPath 'mill'
51+
52+
$MILL_DOWNLOAD_PATH = $Env:MILL_DOWNLOAD_PATH ?? @(Join-Path -Path ${MILL_USER_CACHE_DIR} -ChildPath 'download')
53+
54+
if (-not (Test-Path -Path $MILL_DOWNLOAD_PATH)) {
55+
New-Item -Path $MILL_DOWNLOAD_PATH -ItemType Directory | Out-Null
56+
}
57+
58+
if ($null -eq $MILL_VERSION) {
59+
Write-Warning -Message 'No mill version specified.'
60+
Write-Warning -Message "You should provide a version via '.mill-version' file or --mill-version option."
61+
62+
if (-not (Test-Path -Path "$MILL_DOWNLOAD_PATH" -PathType Container)) {
63+
New-Item "$MILL_DOWNLOAD_PATH" -ItemType Directory | Out-Null
64+
}
65+
66+
$MILL_LATEST_PATH = Join-Path -Path $MILL_DOWNLOAD_PATH -ChildPath '.latest'
67+
68+
if (Test-Path -Path $MILL_LATEST_PATH -PathType Leaf) {
69+
if ($(Get-Item -Path $MILL_LATEST_PATH).LastWriteTime -lt $(Get-Date).AddHours(-1)) {
70+
$MILL_VERSION = Get-Content -Path $MILL_LATEST_PATH -TotalCount 1
71+
}
72+
}
73+
74+
if ($null -eq $MILL_VERSION) {
75+
Write-Output 'Retrieving latest mill version ...'
76+
77+
# https://github.com/PowerShell/PowerShell/issues/20964
78+
$targetUrl = try {
79+
Invoke-WebRequest -Uri "$MILL_REPO_URL/releases/latest" -MaximumRedirection 0
80+
}
81+
catch {
82+
$_.Exception.Response.Headers.Location.AbsoluteUri
83+
}
84+
85+
$targetUrl -match "^$MILL_REPO_URL/releases/tag/(.+)$" | Out-Null
86+
87+
$MILL_VERSION = $Matches.1
88+
89+
if ($null -ne $MILL_VERSION) {
90+
Set-Content -Path $MILL_LATEST_PATH -Value $MILL_VERSION
91+
}
92+
}
93+
94+
if ($null -eq $MILL_VERSION) {
95+
$MILL_VERSION = $DEFAULT_MILL_VERSION
96+
Write-Warning "Falling back to hardcoded mill version $MILL_VERSION"
97+
}
98+
else {
99+
Write-Output "Using mill version $MILL_VERSION"
100+
}
101+
}
102+
103+
$MILL = "$MILL_DOWNLOAD_PATH/$MILL_VERSION.bat"
104+
105+
if (-not (Test-Path -Path $MILL -PathType Leaf)) {
106+
$DOWNLOAD_SUFFIX, $DOWNLOAD_FROM_MAVEN = switch -Regex ($MILL_VERSION) {
107+
'^0\.[0-4]\..*$' { '', $false }
108+
'0\.(?:[5-9]\.|10\.|11\.0-M).*' { '-assembly', $false }
109+
Default { '-assembly', $true }
110+
}
111+
112+
if ($DOWNLOAD_FROM_MAVEN) {
113+
$DOWNLOAD_URL = "https://repo1.maven.org/maven2/com/lihaoyi/mill-dist/$MILL_VERSION/mill-dist-$MILL_VERSION.jar"
114+
}
115+
else {
116+
$MILL_VERSION -match '(\d+\.\d+\.\d+(?:-M\d+)?)' | Out-Null
117+
$MILL_VERSION_TAG = $Matches.1
118+
$DOWNLOAD_URL = "$GITHUB_RELEASE_CDN$MILL_REPO_URL/releases/download/$MILL_VERSION_TAG/$MILL_VERSION$DOWNLOAD_SUFFIX"
119+
}
120+
Write-Output "Downloading mill $MILL_VERSION from $DOWNLOAD_URL ..."
121+
122+
Invoke-WebRequest -Uri $DOWNLOAD_URL -OutFile $MILL
123+
}
124+
125+
$MILL_MAIN_CLI = $Env:MILL_MAIN_CLI ?? $PSCommandPath
126+
127+
$MILL_FIRST_ARG = $null
128+
$REMAINING_ARGUMENTS = $remainingArgs
129+
130+
if ($null -ne $remainingArgs) {
131+
if ($remainingArgs[0] -eq '--bsp' -or $remainingArgs -eq '-i' -or $remainingArgs -eq '--interactive' -or $remainingArgs -eq '--no-server') {
132+
$MILL_FIRST_ARG = $remainingArgs[0]
133+
$REMAINING_ARGUMENTS = Select-Object -InputObject $remainingArgs -Skip 1
134+
}
135+
}
136+
137+
& $MILL $MILL_FIRST_ARG -D "mill.main.cli=$MILL_MAIN_CLI" $REMAINING_ARGUMENTS

0 commit comments

Comments
 (0)