Skip to content

Commit 4540af4

Browse files
authored
Improve selective testing precision in Mill's example tests (#5423)
Previously, any change to any example folder would invalidate all of them via ```json { "dist.examplePathsWithArtifactName0": { "dist.examplePathsWithArtifactName": { "libs.init.exampleList": { "libs.init.resources": { "libs.init.localRunClasspath": { "libs.init.localClasspath": { "libs.main.test.transitiveLocalClasspath": { "libs.main.test.runClasspath": { "example.javalib.module[9-docjar].runClasspath": { "example.javalib.module[9-docjar].local.daemon.runClasspath": { "example.javalib.module[9-docjar].local.daemon.testForked": {} } }, ``` This PR splits up `examplePathsWithArtifactNames` into `examplePaths`, `examplePathRefs`, and `exampleArtifactNames`. This allows `libs.init.exampleList` to avoid depending on the contents of the example folders, which should avoid invalidation of all example tests through this dependency path
1 parent e71c712 commit 4540af4

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

dist/package.mill

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -223,30 +223,35 @@ object `package` extends MillJavaModule with DistModule {
223223
prepareBootstrapLauncher(millBootstrapBat().path, Task.dest, build.millVersion(), "mill.bat")
224224
}
225225

226-
def examplePathsWithArtifactName0: Task[Seq[PathRef]] = Task.Input {
227-
for (exampleMod <- build.example.exampleModules) yield PathRef(exampleMod.moduleDir)
226+
def examplePaths: Task[Seq[os.Path]] = Task.Input {
227+
build.example.exampleModules.map(_.moduleDir)
228228
}
229229

230-
def examplePathsWithArtifactName = Task {
231-
for (pr <- examplePathsWithArtifactName0()) yield {
232-
val example = pr.path.subRelativeTo(BuildCtx.workspaceRoot)
230+
def examplePathRefs: Task[Seq[PathRef]] = Task.Sources(
231+
build.example.exampleModules.map(_.moduleDir)*
232+
)
233+
234+
def exampleArtifactNames = Task {
235+
for (path <- examplePaths()) yield {
236+
val example = path.subRelativeTo(BuildCtx.workspaceRoot)
233237
val artifactName = example.segments.mkString("-")
234-
(pr, s"${build.dist.artifactFileNamePrefix()}-$artifactName")
238+
(path, s"${build.dist.artifactFileNamePrefix()}-$artifactName")
235239
}
236240
}
237241

238242
def exampleZips: T[Seq[PathRef]] = Task {
239-
examplePathsWithArtifactName().map { case (examplePath, exampleStr) =>
240-
os.copy(examplePath.path, Task.dest / exampleStr, createFolders = true)
241-
val ignoreErrorsOnCI = Task.dest / exampleStr / "ignoreErrorsOnCI"
242-
if (os.exists(ignoreErrorsOnCI)) os.remove(ignoreErrorsOnCI)
243-
val buildMill = Task.dest / exampleStr / "build.mill"
244-
os.write.over(buildMill, s"//| mill-version: ${build.millVersion()}\n" + os.read(buildMill))
245-
os.copy(bootstrapLauncher().path, Task.dest / exampleStr / "mill")
246-
os.copy(bootstrapLauncherBat().path, Task.dest / exampleStr / "mill.bat")
247-
val zip = Task.dest / s"$exampleStr.zip"
248-
os.proc("zip", "-r", zip, exampleStr).call(cwd = Task.dest)
249-
PathRef(zip)
243+
examplePathRefs().zip(exampleArtifactNames()).map {
244+
case (pr, (examplePath, exampleStr)) =>
245+
os.copy(pr.path, Task.dest / exampleStr, createFolders = true)
246+
val ignoreErrorsOnCI = Task.dest / exampleStr / "ignoreErrorsOnCI"
247+
if (os.exists(ignoreErrorsOnCI)) os.remove(ignoreErrorsOnCI)
248+
val buildMill = Task.dest / exampleStr / "build.mill"
249+
os.write.over(buildMill, s"//| mill-version: ${build.millVersion()}\n" + os.read(buildMill))
250+
os.copy(bootstrapLauncher().path, Task.dest / exampleStr / "mill")
251+
os.copy(bootstrapLauncherBat().path, Task.dest / exampleStr / "mill.bat")
252+
val zip = Task.dest / s"$exampleStr.zip"
253+
os.proc("zip", "-r", zip, exampleStr).call(cwd = Task.dest)
254+
PathRef(zip)
250255
}
251256
}
252257

libs/init/package.mill

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ object `package` extends MillPublishScalaModule {
1818

1919
def exampleList: T[PathRef] = Task {
2020
val data: Seq[(os.SubPath, String)] =
21-
build.dist.examplePathsWithArtifactName().map { case (pathRef, str) =>
21+
build.dist.examplePaths().zip(build.dist.exampleArtifactNames()).map { case (path, str) =>
2222
val downloadUrl =
2323
s"${build.millDownloadUrlCurrent()}/$str.zip"
24-
val subPath = pathRef.path.subRelativeTo(BuildCtx.workspaceRoot / "example")
24+
val subPath = path.subRelativeTo(BuildCtx.workspaceRoot / "example")
2525
(subPath, downloadUrl)
2626
}
2727

0 commit comments

Comments
 (0)