Skip to content

Commit 2beb6c1

Browse files
Run examples with local repo under out/ rather than ~/.ivy2/local (#5949)
This changes how Mill is run in integration tests and examples. This makes it stop publishing things under `~/.ivy2/local`, and use something like `out/dist/localRepo.dest` instead, which is the `Task.dest` of the new `dist.localRepo` task. That new repository is a local Maven repositiory rather than an Ivy one, which has a slightly different file structure, the same as Maven Central. For that new repository to be taken into account, the Mill launcher used in examples and ITs is now a script (bat under Windows, bash everywhere else) that sets the `COURSIER_REPOSITORIES` env var, so that the new local repo is added to it, and gets automatically used when running examples and ITs. The second commit of this PR mainly updates the file names of the locally published Mill artifacts, because of the switch from an Ivy repository to a Maven one. That's been useful to me when using a locally published Mill version, to develop on Mill or other projects. Running examples or ITs erases it, which is annoying, but also somewhat unexpected (running tests shouldn't erase things in the local repository, at least not things put there manually on purpose). This PR fixes that.
1 parent f219fbe commit 2beb6c1

File tree

7 files changed

+204
-142
lines changed

7 files changed

+204
-142
lines changed

dist/package.mill

Lines changed: 73 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import mill.util.Jvm
99
import millbuild.*
1010
import mill.api.BuildCtx
1111
import scala.util.Using
12+
import scala.util.Properties
13+
import java.nio.file.Files
14+
import java.nio.file.attribute.PosixFilePermission
1215

1316
trait DistModule extends Module {
1417
// All modules that we want to aggregate as part of this `dev` assembly.
@@ -19,9 +22,49 @@ trait DistModule extends Module {
1922

2023
def executableRaw: T[PathRef]
2124

25+
def localRepo: T[PathRef] = Task {
26+
val dest = Task.dest
27+
val repos = Task.traverse(allPublishModules)(m => m.publishLocalTestRepo)().map(_.path)
28+
for (repo <- repos; elem <- os.list(repo))
29+
os.copy.into(elem, dest, mergeFolders = true)
30+
PathRef(dest)
31+
}
32+
2233
def executable = Task {
23-
Task.traverse(allPublishModules)(m => m.publishLocal(doc = false))()
24-
executableRaw()
34+
val rawExecutable = executableRaw()
35+
if (Properties.isWin) {
36+
val launcher = Task.dest / "mill.bat"
37+
val launcherContent =
38+
s"""@echo off
39+
|set "NEW_COURSIER_REPOSITORIES=${localRepo().path.toNIO.toUri.toASCIIString}|ivy2Local|central"
40+
|if defined COURSIER_REPOSITORIES (
41+
| set "NEW_COURSIER_REPOSITORIES=%NEW_COURSIER_REPOSITORIES%|%COURSIER_REPOSITORIES%"
42+
|) else (
43+
| set "NEW_COURSIER_REPOSITORIES=%NEW_COURSIER_REPOSITORIES%|ivy2Local|central"
44+
|)
45+
|set "COURSIER_REPOSITORIES=%NEW_COURSIER_REPOSITORIES%"
46+
|set NEW_COURSIER_REPOSITORIES=
47+
|"${rawExecutable.path.toString.replace("\"", "\\\"")}" %*
48+
|if errorlevel 1 exit /b %errorlevel%
49+
|""".stripMargin
50+
os.write(launcher, launcherContent)
51+
PathRef(launcher)
52+
} else {
53+
val launcher = Task.dest / "mill"
54+
val launcherContent =
55+
s"""#!/usr/bin/env bash
56+
|set -e
57+
|export COURSIER_REPOSITORIES="${localRepo().path.toNIO.toUri.toASCIIString}|$${COURSIER_REPOSITORIES:-ivy2Local|central}"
58+
|exec '${rawExecutable.path.toString.replace("'", "\\'")}' "$$@"
59+
|""".stripMargin
60+
os.write(launcher, launcherContent)
61+
val perms = Files.getPosixFilePermissions(launcher.toNIO)
62+
perms.add(PosixFilePermission.OWNER_EXECUTE)
63+
perms.add(PosixFilePermission.GROUP_EXECUTE)
64+
perms.add(PosixFilePermission.OTHERS_EXECUTE)
65+
Files.setPosixFilePermissions(launcher.toNIO, perms)
66+
PathRef(launcher)
67+
}
2568
}
2669

2770
def localBinName: String
@@ -32,12 +75,15 @@ trait DistModule extends Module {
3275
* Build and install Mill locally.
3376
*
3477
* @param binFile The location where the Mill binary should be installed
35-
* @param ivyRepo The local Ivy repository where Mill modules should be published to
3678
*/
37-
def installLocal(binFile: String = localBinName, ivyRepo: String = null) =
79+
def installLocal(binFile: String = localBinName) = {
80+
val binFile0 = os.Path(binFile, BuildCtx.workspaceRoot)
81+
val task = installIvyLocalTask(binFile0)
3882
Task.Command {
39-
PathRef(installLocalTask(Task.Anon(binFile), ivyRepo)())
83+
task()
84+
PathRef(binFile0)
4085
}
86+
}
4187

4288
val batExt = if (scala.util.Properties.isWin) ".bat" else ""
4389

@@ -53,16 +99,28 @@ trait DistModule extends Module {
5399
PathRef(path)
54100
}
55101

56-
def installLocalTask(binFile: Task[String], ivyRepo: String = null): Task[os.Path] = Task.Anon {
57-
val targetFile = os.Path(binFile(), BuildCtx.workspaceRoot)
58-
if (os.exists(targetFile))
59-
Task.log.info(s"Overwriting existing local Mill binary at ${targetFile}")
60-
os.copy.over(executable().path, targetFile, createFolders = true)
61-
Task.log.info(
62-
s"Published ${build.dist.allPublishModules.size} modules and installed ${targetFile}"
63-
)
64-
targetFile
65-
}
102+
def installLocalTask(binFile: Task[String]): Task[os.Path] =
103+
Task.Anon {
104+
val targetFile = os.Path(binFile(), BuildCtx.workspaceRoot)
105+
if (os.exists(targetFile))
106+
Task.log.info(s"Overwriting existing local Mill binary at ${targetFile}")
107+
os.copy.over(executable().path, targetFile, createFolders = true)
108+
Task.log.info(
109+
s"Published ${build.dist.allPublishModules.size} modules under Mill sources local repo ${localRepo().path} and installed ${targetFile}"
110+
)
111+
targetFile
112+
}
113+
114+
def installIvyLocalTask(targetFile: os.Path): Task[Unit] =
115+
Task.Anon {
116+
if (os.exists(targetFile))
117+
Task.log.info(s"Overwriting existing local Mill binary at ${targetFile}")
118+
Task.traverse(allPublishModules)(m => m.publishLocal(doc = false))()
119+
os.copy.over(executableRaw().path, targetFile, createFolders = true)
120+
Task.log.info(
121+
s"Published ${build.dist.allPublishModules.size} modules under ~/.ivy2/local and installed ${targetFile}"
122+
)
123+
}
66124

67125
def artifactName: T[String]
68126
def artifact = Task { Artifact(Settings.pomOrg, artifactName(), build.millVersion()) }

integration/ide/bsp-server/resources/snapshots/build-targets-jvm-test-environments.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"file:///workspace/app/test/compile-resources",
1919
"file:///workspace/app/test/resources",
2020
"file:///workspace/out/mill-bsp-out/app/test/compile.dest/classes",
21-
"file:///user-home/.ivy2/local/com.lihaoyi/mill-libs-javalib-testrunner-entrypoint/SNAPSHOT/jars/mill-libs-javalib-testrunner-entrypoint.jar",
21+
"file:///mill-workspace/out/dist/localRepo.dest/com/lihaoyi/mill-libs-javalib-testrunner-entrypoint/SNAPSHOT/mill-libs-javalib-testrunner-entrypoint-SNAPSHOT.jar",
2222
"file:///coursier-cache/https/repo1.maven.org/maven2/org/scala-sbt/test-interface/1.0/test-interface-1.0.jar"
2323
],
2424
"jvmOptions": [],
@@ -52,7 +52,7 @@
5252
"file:///workspace/hello-java/test/compile-resources",
5353
"file:///workspace/hello-java/test/resources",
5454
"file:///workspace/out/mill-bsp-out/hello-java/test/compile.dest/classes",
55-
"file:///user-home/.ivy2/local/com.lihaoyi/mill-libs-javalib-testrunner-entrypoint/SNAPSHOT/jars/mill-libs-javalib-testrunner-entrypoint.jar",
55+
"file:///mill-workspace/out/dist/localRepo.dest/com/lihaoyi/mill-libs-javalib-testrunner-entrypoint/SNAPSHOT/mill-libs-javalib-testrunner-entrypoint-SNAPSHOT.jar",
5656
"file:///coursier-cache/https/repo1.maven.org/maven2/org/scala-sbt/test-interface/1.0/test-interface-1.0.jar"
5757
],
5858
"jvmOptions": [],
@@ -87,7 +87,7 @@
8787
"file:///workspace/hello-scala/test/compile-resources",
8888
"file:///workspace/hello-scala/test/resources",
8989
"file:///workspace/out/mill-bsp-out/hello-scala/test/compile.dest/classes",
90-
"file:///user-home/.ivy2/local/com.lihaoyi/mill-libs-javalib-testrunner-entrypoint/SNAPSHOT/jars/mill-libs-javalib-testrunner-entrypoint.jar",
90+
"file:///mill-workspace/out/dist/localRepo.dest/com/lihaoyi/mill-libs-javalib-testrunner-entrypoint/SNAPSHOT/mill-libs-javalib-testrunner-entrypoint-SNAPSHOT.jar",
9191
"file:///coursier-cache/https/repo1.maven.org/maven2/org/scala-sbt/test-interface/1.0/test-interface-1.0.jar"
9292
],
9393
"jvmOptions": [],

integration/ide/build-classpath-contents/src/BuildClasspathContentsTests.scala

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,37 +18,38 @@ object BuildClasspathContentsTests extends UtestIntegrationTestSuite {
1818
.filter(_.startsWith(BuildCtx.workspaceRoot))
1919
.map(_.subRelativeTo(BuildCtx.workspaceRoot))
2020
.filter(!_.startsWith("out/integration"))
21+
.filter(!_.startsWith("out/dist/localRepo.dest"))
2122
.map(_.toString)
2223
.sorted
2324
if (sys.env("MILL_INTEGRATION_IS_PACKAGED_LAUNCHER") == "true") {
2425
assertGoldenLiteral(
2526
millPublishedJars,
2627
List(
27-
"mill-core-api-daemon_3.jar",
28-
"mill-core-api_3.jar",
29-
"mill-core-constants.jar",
30-
"mill-libs-androidlib-databinding_3.jar",
31-
"mill-libs-androidlib_3.jar",
32-
"mill-libs-daemon-client.jar",
33-
"mill-libs-daemon-server_3.jar",
34-
"mill-libs-javalib-api_3.jar",
35-
"mill-libs-javalib-testrunner-entrypoint.jar",
36-
"mill-libs-javalib-testrunner_3.jar",
37-
"mill-libs-javalib_3.jar",
38-
"mill-libs-javascriptlib_3.jar",
39-
"mill-libs-kotlinlib-api_3.jar",
40-
"mill-libs-kotlinlib-ksp2-api_3.jar",
41-
"mill-libs-kotlinlib_3.jar",
42-
"mill-libs-pythonlib_3.jar",
43-
"mill-libs-rpc_3.jar",
44-
"mill-libs-scalajslib-api_3.jar",
45-
"mill-libs-scalajslib_3.jar",
46-
"mill-libs-scalalib_3.jar",
47-
"mill-libs-scalanativelib-api_3.jar",
48-
"mill-libs-scalanativelib_3.jar",
49-
"mill-libs-script_3.jar",
50-
"mill-libs-util_3.jar",
51-
"mill-libs_3.jar",
28+
"mill-core-api-daemon_3-SNAPSHOT.jar",
29+
"mill-core-api_3-SNAPSHOT.jar",
30+
"mill-core-constants-SNAPSHOT.jar",
31+
"mill-libs-androidlib-databinding_3-SNAPSHOT.jar",
32+
"mill-libs-androidlib_3-SNAPSHOT.jar",
33+
"mill-libs-daemon-client-SNAPSHOT.jar",
34+
"mill-libs-daemon-server_3-SNAPSHOT.jar",
35+
"mill-libs-javalib-api_3-SNAPSHOT.jar",
36+
"mill-libs-javalib-testrunner-entrypoint-SNAPSHOT.jar",
37+
"mill-libs-javalib-testrunner_3-SNAPSHOT.jar",
38+
"mill-libs-javalib_3-SNAPSHOT.jar",
39+
"mill-libs-javascriptlib_3-SNAPSHOT.jar",
40+
"mill-libs-kotlinlib-api_3-SNAPSHOT.jar",
41+
"mill-libs-kotlinlib-ksp2-api_3-SNAPSHOT.jar",
42+
"mill-libs-kotlinlib_3-SNAPSHOT.jar",
43+
"mill-libs-pythonlib_3-SNAPSHOT.jar",
44+
"mill-libs-rpc_3-SNAPSHOT.jar",
45+
"mill-libs-scalajslib-api_3-SNAPSHOT.jar",
46+
"mill-libs-scalajslib_3-SNAPSHOT.jar",
47+
"mill-libs-scalalib_3-SNAPSHOT.jar",
48+
"mill-libs-scalanativelib-api_3-SNAPSHOT.jar",
49+
"mill-libs-scalanativelib_3-SNAPSHOT.jar",
50+
"mill-libs-script_3-SNAPSHOT.jar",
51+
"mill-libs-util_3-SNAPSHOT.jar",
52+
"mill-libs_3-SNAPSHOT.jar",
5253
"mill-moduledefs_3-0.11.10.jar"
5354
)
5455
)

integration/ide/gen-idea/resources/extended/idea/mill_modules/mill-build.iml

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -53,38 +53,38 @@
5353
<orderEntry type="library" scope="RUNTIME" name="logback-classic-1.5.18.jar" level="project"/>
5454
<orderEntry type="library" scope="RUNTIME" name="logback-core-1.5.18.jar" level="project"/>
5555
<orderEntry type="library" name="mainargs_3-0.7.7.jar" level="project"/>
56-
<orderEntry type="library" name="mill-core-api-daemon_3.jar" level="project"/>
57-
<orderEntry type="library" name="mill-core-api_3.jar" level="project"/>
58-
<orderEntry type="library" name="mill-core-constants.jar" level="project"/>
59-
<orderEntry type="library" scope="RUNTIME" name="mill-core-eval_3.jar" level="project"/>
60-
<orderEntry type="library" scope="RUNTIME" name="mill-core-exec_3.jar" level="project"/>
61-
<orderEntry type="library" scope="RUNTIME" name="mill-core-internal-cli_3.jar" level="project"/>
62-
<orderEntry type="library" scope="RUNTIME" name="mill-core-internal_3.jar" level="project"/>
63-
<orderEntry type="library" scope="RUNTIME" name="mill-core-resolve_3.jar" level="project"/>
64-
<orderEntry type="library" name="mill-libs-androidlib-databinding_3.jar" level="project"/>
65-
<orderEntry type="library" name="mill-libs-androidlib_3.jar" level="project"/>
66-
<orderEntry type="library" name="mill-libs-daemon-client.jar" level="project"/>
67-
<orderEntry type="library" name="mill-libs-daemon-server_3.jar" level="project"/>
68-
<orderEntry type="library" scope="RUNTIME" name="mill-libs-init_3.jar" level="project"/>
69-
<orderEntry type="library" name="mill-libs-javalib-api_3.jar" level="project"/>
70-
<orderEntry type="library" name="mill-libs-javalib-testrunner-entrypoint.jar" level="project"/>
71-
<orderEntry type="library" name="mill-libs-javalib-testrunner_3.jar" level="project"/>
72-
<orderEntry type="library" name="mill-libs-javalib_3.jar" level="project"/>
73-
<orderEntry type="library" name="mill-libs-javascriptlib_3.jar" level="project"/>
74-
<orderEntry type="library" name="mill-libs-kotlinlib-api_3.jar" level="project"/>
75-
<orderEntry type="library" name="mill-libs-kotlinlib-ksp2-api_3.jar" level="project"/>
76-
<orderEntry type="library" name="mill-libs-kotlinlib_3.jar" level="project"/>
77-
<orderEntry type="library" name="mill-libs-pythonlib_3.jar" level="project"/>
78-
<orderEntry type="library" name="mill-libs-rpc_3.jar" level="project"/>
79-
<orderEntry type="library" name="mill-libs-scalajslib-api_3.jar" level="project"/>
80-
<orderEntry type="library" name="mill-libs-scalajslib_3.jar" level="project"/>
81-
<orderEntry type="library" name="mill-libs-scalalib_3.jar" level="project"/>
82-
<orderEntry type="library" name="mill-libs-scalanativelib-api_3.jar" level="project"/>
83-
<orderEntry type="library" name="mill-libs-scalanativelib_3.jar" level="project"/>
84-
<orderEntry type="library" name="mill-libs-script_3.jar" level="project"/>
85-
<orderEntry type="library" scope="RUNTIME" name="mill-libs-tabcomplete_3.jar" level="project"/>
86-
<orderEntry type="library" name="mill-libs-util_3.jar" level="project"/>
87-
<orderEntry type="library" name="mill-libs_3.jar" level="project"/>
56+
<orderEntry type="library" name="mill-core-api-daemon_3-SNAPSHOT.jar" level="project"/>
57+
<orderEntry type="library" name="mill-core-api_3-SNAPSHOT.jar" level="project"/>
58+
<orderEntry type="library" name="mill-core-constants-SNAPSHOT.jar" level="project"/>
59+
<orderEntry type="library" scope="RUNTIME" name="mill-core-eval_3-SNAPSHOT.jar" level="project"/>
60+
<orderEntry type="library" scope="RUNTIME" name="mill-core-exec_3-SNAPSHOT.jar" level="project"/>
61+
<orderEntry type="library" scope="RUNTIME" name="mill-core-internal-cli_3-SNAPSHOT.jar" level="project"/>
62+
<orderEntry type="library" scope="RUNTIME" name="mill-core-internal_3-SNAPSHOT.jar" level="project"/>
63+
<orderEntry type="library" scope="RUNTIME" name="mill-core-resolve_3-SNAPSHOT.jar" level="project"/>
64+
<orderEntry type="library" name="mill-libs-androidlib-databinding_3-SNAPSHOT.jar" level="project"/>
65+
<orderEntry type="library" name="mill-libs-androidlib_3-SNAPSHOT.jar" level="project"/>
66+
<orderEntry type="library" name="mill-libs-daemon-client-SNAPSHOT.jar" level="project"/>
67+
<orderEntry type="library" name="mill-libs-daemon-server_3-SNAPSHOT.jar" level="project"/>
68+
<orderEntry type="library" scope="RUNTIME" name="mill-libs-init_3-SNAPSHOT.jar" level="project"/>
69+
<orderEntry type="library" name="mill-libs-javalib-api_3-SNAPSHOT.jar" level="project"/>
70+
<orderEntry type="library" name="mill-libs-javalib-testrunner-entrypoint-SNAPSHOT.jar" level="project"/>
71+
<orderEntry type="library" name="mill-libs-javalib-testrunner_3-SNAPSHOT.jar" level="project"/>
72+
<orderEntry type="library" name="mill-libs-javalib_3-SNAPSHOT.jar" level="project"/>
73+
<orderEntry type="library" name="mill-libs-javascriptlib_3-SNAPSHOT.jar" level="project"/>
74+
<orderEntry type="library" name="mill-libs-kotlinlib-api_3-SNAPSHOT.jar" level="project"/>
75+
<orderEntry type="library" name="mill-libs-kotlinlib-ksp2-api_3-SNAPSHOT.jar" level="project"/>
76+
<orderEntry type="library" name="mill-libs-kotlinlib_3-SNAPSHOT.jar" level="project"/>
77+
<orderEntry type="library" name="mill-libs-pythonlib_3-SNAPSHOT.jar" level="project"/>
78+
<orderEntry type="library" name="mill-libs-rpc_3-SNAPSHOT.jar" level="project"/>
79+
<orderEntry type="library" name="mill-libs-scalajslib-api_3-SNAPSHOT.jar" level="project"/>
80+
<orderEntry type="library" name="mill-libs-scalajslib_3-SNAPSHOT.jar" level="project"/>
81+
<orderEntry type="library" name="mill-libs-scalalib_3-SNAPSHOT.jar" level="project"/>
82+
<orderEntry type="library" name="mill-libs-scalanativelib-api_3-SNAPSHOT.jar" level="project"/>
83+
<orderEntry type="library" name="mill-libs-scalanativelib_3-SNAPSHOT.jar" level="project"/>
84+
<orderEntry type="library" name="mill-libs-script_3-SNAPSHOT.jar" level="project"/>
85+
<orderEntry type="library" scope="RUNTIME" name="mill-libs-tabcomplete_3-SNAPSHOT.jar" level="project"/>
86+
<orderEntry type="library" name="mill-libs-util_3-SNAPSHOT.jar" level="project"/>
87+
<orderEntry type="library" name="mill-libs_3-SNAPSHOT.jar" level="project"/>
8888
<orderEntry type="library" name="mill-moduledefs_3-0.11.10.jar" level="project"/>
8989
<orderEntry type="library" name="munit_3-0.7.29.jar" level="project"/>
9090
<orderEntry type="library" scope="RUNTIME" name="native-terminal-no-ffm-0.0.9.1.jar" level="project"/>

0 commit comments

Comments
 (0)