Skip to content

Commit 23cff24

Browse files
Update coursier to 2.1.25-M11 and use short paths for GraalVM distributions (new attempt) (#5018)
New attempt at #4917 It seems the too long paths are being an issue as soon as we bump the coursier version ([this job](https://github.com/alexarchambault/mill/actions/runs/14705154651/attempts/1) only bumps the coursier version, and results in issues with too long GraalVM paths). Unlike #4917, this not only uses short paths in examples and integration tests, but also in the Mill build itself. It seems this makes `dist.native.nativeImage` happy.
1 parent 6d3d25b commit 23cff24

File tree

8 files changed

+230
-34
lines changed

8 files changed

+230
-34
lines changed

build.mill

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ object Deps {
127127
val bloopConfig = mvn"ch.epfl.scala::bloop-config:1.5.5".withDottyCompat(scalaVersion)
128128

129129
val classgraph = mvn"io.github.classgraph:classgraph:4.8.179"
130-
val coursierVersion = "2.1.25-M4"
130+
val coursierVersion = "2.1.25-M11"
131131
val coursier = mvn"io.get-coursier::coursier:$coursierVersion".withDottyCompat(scalaVersion)
132132
val coursierInterface = mvn"io.get-coursier:interface:1.0.29-M1"
133133
val coursierJvm =

ci/mill-bootstrap.patch

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
diff --git a/dist/package.mill b/dist/package.mill
2+
index c16347a6a19..f1c2303e45b 100644
3+
--- a/dist/package.mill
4+
+++ b/dist/package.mill
5+
@@ -336,84 +336,6 @@ object `package` extends InstallModule {
6+
7+
object JvmWorkerGraalvm extends JvmWorkerModule {
8+
def jvmId = build.Settings.graalvmJvmId
9+
-
10+
- import coursier.cache.{ArchiveCache, FileCache}
11+
- import coursier.jvm.{JavaHome, JvmCache}
12+
- import coursier.util.{Task => CsTask}
13+
- import mill.api.Result
14+
- import scala.util.Properties.isWin
15+
-
16+
- def javaHome: T[Option[PathRef]] = Task {
17+
- Option(jvmId()).filter(_ != "").map { id =>
18+
- val path = resolveJavaHome(
19+
- id = id,
20+
- coursierCacheCustomizer = coursierCacheCustomizer(),
21+
- ctx = Some(Task.ctx()),
22+
- jvmIndexVersion = jvmIndexVersion(),
23+
- useShortPaths = isWin && (
24+
- jvmId().startsWith("graalvm") || jvmId().startsWith("liberica-nik")
25+
- )
26+
- ).get
27+
- // Java home is externally managed, better revalidate it at least once
28+
- PathRef(path, quick = true).withRevalidateOnce
29+
- }
30+
- }
31+
-
32+
- def resolveJavaHome(
33+
- id: String,
34+
- ctx: Option[mill.define.TaskCtx] = None,
35+
- coursierCacheCustomizer: Option[FileCache[CsTask] => FileCache[CsTask]] = None,
36+
- jvmIndexVersion: String = mill.api.BuildInfo.coursierJvmIndexVersion,
37+
- useShortPaths: Boolean = false
38+
- ): Result[os.Path] = {
39+
- val coursierCache0 =
40+
- FileCache() // .withLogger(new CoursierTickerResolutionLogger(Task.ctx))
41+
- val shortPathDirOpt = Option.when(useShortPaths) {
42+
- if (isWin)
43+
- // On Windows, prefer to use System.getenv over sys.env (or ctx.env for
44+
- // now), as the former respects the case-insensitiveness of env vars on
45+
- // Windows, while the latter doesn't
46+
- os.Path(System.getenv("UserProfile")) / ".mill/cache/jvm"
47+
- else {
48+
- val cacheBase = ctx.map(_.env)
49+
- .getOrElse(sys.env)
50+
- .get("XDG_CACHE_HOME")
51+
- .map(os.Path(_))
52+
- .getOrElse(os.home / ".cache")
53+
- cacheBase / "mill/jvm"
54+
- }
55+
- }
56+
- val jvmCache = JvmCache()
57+
- .withArchiveCache(
58+
- ArchiveCache()
59+
- .withCache(coursierCache0)
60+
- // .withShortPathDirectory(shortPathDirOpt.map(_.toIO))
61+
- )
62+
- .withIndex(Jvm.jvmIndex0(ctx, coursierCacheCustomizer, jvmIndexVersion))
63+
- val javaHome = JavaHome()
64+
- .withCache(jvmCache)
65+
- // when given a version like "17", always pick highest version in the index
66+
- // rather than the highest already on disk
67+
- .withUpdate(true)
68+
- val file = os.Path(javaHome.get(id).unsafeRun()(coursierCache0.ec))
69+
- val finalDir = shortPathDirOpt match {
70+
- case None => file
71+
- case Some(shortPathDir) =>
72+
- val sha1 = {
73+
- import java.math.BigInteger
74+
- import java.security.MessageDigest
75+
- val bytes = MessageDigest.getInstance("SHA-1").digest(file.toString.getBytes)
76+
- val baseSha1 = new BigInteger(1, bytes).toString(16)
77+
- "0" * (40 - baseSha1.length) + baseSha1
78+
- }
79+
- val dir = shortPathDir / sha1.take(8)
80+
- os.copy(file, dir, createFolders = true)
81+
- dir
82+
- }
83+
- Result.Success(finalDir)
84+
-
85+
- }
86+
-
87+
}
88+
}
89+
}

core/util/src/mill/util/Jvm.scala

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -614,12 +614,30 @@ object Jvm {
614614
id: String,
615615
ctx: Option[mill.define.TaskCtx] = None,
616616
coursierCacheCustomizer: Option[FileCache[Task] => FileCache[Task]] = None,
617-
jvmIndexVersion: String = mill.api.BuildInfo.coursierJvmIndexVersion
617+
jvmIndexVersion: String = mill.api.BuildInfo.coursierJvmIndexVersion,
618+
useShortPaths: Boolean = false
618619
): Result[os.Path] = {
619620
val coursierCache0 = coursierCache(ctx, coursierCacheCustomizer)
621+
val shortPathDirOpt = Option.when(useShortPaths) {
622+
if (isWin)
623+
// On Windows, prefer to use System.getenv over sys.env (or ctx.env for
624+
// now), as the former respects the case-insensitiveness of env vars on
625+
// Windows, while the latter doesn't
626+
os.Path(System.getenv("UserProfile")) / ".mill/cache/jvm"
627+
else {
628+
val cacheBase = ctx.map(_.env)
629+
.getOrElse(sys.env)
630+
.get("XDG_CACHE_HOME")
631+
.map(os.Path(_))
632+
.getOrElse(os.home / ".cache")
633+
cacheBase / "mill/jvm"
634+
}
635+
}
620636
val jvmCache = JvmCache()
621637
.withArchiveCache(
622-
ArchiveCache().withCache(coursierCache0)
638+
ArchiveCache()
639+
.withCache(coursierCache0)
640+
.withShortPathDirectory(shortPathDirOpt.map(_.toIO))
623641
)
624642
.withIndex(jvmIndex0(ctx, coursierCacheCustomizer, jvmIndexVersion))
625643
val javaHome = JavaHome()

dist/package.mill

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,84 @@ object `package` extends InstallModule {
336336

337337
object JvmWorkerGraalvm extends JvmWorkerModule {
338338
def jvmId = build.Settings.graalvmJvmId
339+
340+
import coursier.cache.{ArchiveCache, FileCache}
341+
import coursier.jvm.{JavaHome, JvmCache}
342+
import coursier.util.{Task => CsTask}
343+
import mill.api.Result
344+
import scala.util.Properties.isWin
345+
346+
def javaHome: T[Option[PathRef]] = Task {
347+
Option(jvmId()).filter(_ != "").map { id =>
348+
val path = resolveJavaHome(
349+
id = id,
350+
coursierCacheCustomizer = coursierCacheCustomizer(),
351+
ctx = Some(Task.ctx()),
352+
jvmIndexVersion = jvmIndexVersion(),
353+
useShortPaths = isWin && (
354+
jvmId().startsWith("graalvm") || jvmId().startsWith("liberica-nik")
355+
)
356+
).get
357+
// Java home is externally managed, better revalidate it at least once
358+
PathRef(path, quick = true).withRevalidateOnce
359+
}
360+
}
361+
362+
def resolveJavaHome(
363+
id: String,
364+
ctx: Option[mill.define.TaskCtx] = None,
365+
coursierCacheCustomizer: Option[FileCache[CsTask] => FileCache[CsTask]] = None,
366+
jvmIndexVersion: String = mill.api.BuildInfo.coursierJvmIndexVersion,
367+
useShortPaths: Boolean = false
368+
): Result[os.Path] = {
369+
val coursierCache0 =
370+
FileCache() // .withLogger(new CoursierTickerResolutionLogger(Task.ctx))
371+
val shortPathDirOpt = Option.when(useShortPaths) {
372+
if (isWin)
373+
// On Windows, prefer to use System.getenv over sys.env (or ctx.env for
374+
// now), as the former respects the case-insensitiveness of env vars on
375+
// Windows, while the latter doesn't
376+
os.Path(System.getenv("UserProfile")) / ".mill/cache/jvm"
377+
else {
378+
val cacheBase = ctx.map(_.env)
379+
.getOrElse(sys.env)
380+
.get("XDG_CACHE_HOME")
381+
.map(os.Path(_))
382+
.getOrElse(os.home / ".cache")
383+
cacheBase / "mill/jvm"
384+
}
385+
}
386+
val jvmCache = JvmCache()
387+
.withArchiveCache(
388+
ArchiveCache()
389+
.withCache(coursierCache0)
390+
// .withShortPathDirectory(shortPathDirOpt.map(_.toIO))
391+
)
392+
.withIndex(Jvm.jvmIndex0(ctx, coursierCacheCustomizer, jvmIndexVersion))
393+
val javaHome = JavaHome()
394+
.withCache(jvmCache)
395+
// when given a version like "17", always pick highest version in the index
396+
// rather than the highest already on disk
397+
.withUpdate(true)
398+
val file = os.Path(javaHome.get(id).unsafeRun()(coursierCache0.ec))
399+
val finalDir = shortPathDirOpt match {
400+
case None => file
401+
case Some(shortPathDir) =>
402+
val sha1 = {
403+
import java.math.BigInteger
404+
import java.security.MessageDigest
405+
val bytes = MessageDigest.getInstance("SHA-1").digest(file.toString.getBytes)
406+
val baseSha1 = new BigInteger(1, bytes).toString(16)
407+
"0" * (40 - baseSha1.length) + baseSha1
408+
}
409+
val dir = shortPathDir / sha1.take(8)
410+
os.copy(file, dir, createFolders = true)
411+
dir
412+
}
413+
Result.Success(finalDir)
414+
415+
}
416+
339417
}
340418
}
341419
}

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,21 @@
1515
<orderEntry type="library" name="asm-9.6.jar" level="project"/>
1616
<orderEntry type="library" name="asm-commons-9.6.jar" level="project"/>
1717
<orderEntry type="library" name="asm-tree-9.6.jar" level="project"/>
18-
<orderEntry type="library" name="cache-util-2.1.25-M4.jar" level="project"/>
18+
<orderEntry type="library" name="cache-util-2.1.25-M11.jar" level="project"/>
1919
<orderEntry type="library" name="commons-codec-1.17.0.jar" level="project"/>
2020
<orderEntry type="library" name="commons-compress-1.26.2.jar" level="project"/>
2121
<orderEntry type="library" name="commons-io-2.18.0.jar" level="project"/>
2222
<orderEntry type="library" name="commons-lang3-3.16.0.jar" level="project"/>
2323
<orderEntry type="library" name="concurrent-reference-hash-map-1.1.0.jar" level="project"/>
2424
<orderEntry type="library" name="config_2.13-1.1.3.jar" level="project"/>
25-
<orderEntry type="library" name="coursier-cache_2.13-2.1.25-M4.jar" level="project"/>
26-
<orderEntry type="library" name="coursier-core_2.13-2.1.25-M4.jar" level="project"/>
27-
<orderEntry type="library" name="coursier-env_2.13-2.1.25-M4.jar" level="project"/>
28-
<orderEntry type="library" name="coursier-jvm_2.13-2.1.25-M4.jar" level="project"/>
29-
<orderEntry type="library" name="coursier-proxy-setup-2.1.25-M4.jar" level="project"/>
30-
<orderEntry type="library" name="coursier-util_2.13-2.1.25-M4.jar" level="project"/>
31-
<orderEntry type="library" name="coursier_2.13-2.1.25-M4.jar" level="project"/>
25+
<orderEntry type="library" name="coursier-cache_2.13-2.1.25-M11.jar" level="project"/>
26+
<orderEntry type="library" name="coursier-core_2.13-2.1.25-M11.jar" level="project"/>
27+
<orderEntry type="library" name="coursier-env_2.13-2.1.25-M11.jar" level="project"/>
28+
<orderEntry type="library" name="coursier-exec-2.1.25-M11.jar" level="project"/>
29+
<orderEntry type="library" name="coursier-jvm_2.13-2.1.25-M11.jar" level="project"/>
30+
<orderEntry type="library" name="coursier-proxy-setup-2.1.25-M11.jar" level="project"/>
31+
<orderEntry type="library" name="coursier-util_2.13-2.1.25-M11.jar" level="project"/>
32+
<orderEntry type="library" name="coursier_2.13-2.1.25-M11.jar" level="project"/>
3233
<orderEntry type="library" name="dependency_2.13-0.3.2.jar" level="project"/>
3334
<orderEntry type="library" name="fansi_3-0.5.0.jar" level="project"/>
3435
<orderEntry type="library" name="fastparse_3-3.1.1.jar" level="project"/>
@@ -49,7 +50,7 @@
4950
<orderEntry type="library" name="jline-native-3.29.0.jar" level="project"/>
5051
<orderEntry type="library" name="jna-5.17.0.jar" level="project"/>
5152
<orderEntry type="library" name="jna-platform-5.16.0.jar" level="project"/>
52-
<orderEntry type="library" name="jsoniter-scala-core_2.13-2.13.5.2.jar" level="project"/>
53+
<orderEntry type="library" name="jsoniter-scala-core_2.13-2.13.39.jar" level="project"/>
5354
<orderEntry type="library" name="jsr305-3.0.2.jar" level="project"/>
5455
<orderEntry type="library" name="jul-to-slf4j-1.7.30.jar" level="project"/>
5556
<orderEntry type="library" name="junit-4.13.2.jar" level="project"/>
@@ -118,6 +119,6 @@
118119
<orderEntry type="library" name="windows-jni-utils-0.3.3.jar" level="project"/>
119120
<orderEntry type="library" name="xbean-reflect-3.7.jar" level="project"/>
120121
<orderEntry type="library" scope="RUNTIME" name="xz-1.9.jar" level="project"/>
121-
<orderEntry type="library" scope="RUNTIME" name="zstd-jni-1.5.6-3.jar" level="project"/>
122+
<orderEntry type="library" name="zstd-jni-1.5.7-2.jar" level="project"/>
122123
</component>
123124
</module>

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,21 @@
1717
<orderEntry type="library" name="asm-9.8.jar" level="project"/>
1818
<orderEntry type="library" name="asm-commons-9.6.jar" level="project"/>
1919
<orderEntry type="library" name="asm-tree-9.8.jar" level="project"/>
20-
<orderEntry type="library" name="cache-util-2.1.25-M4.jar" level="project"/>
20+
<orderEntry type="library" name="cache-util-2.1.25-M11.jar" level="project"/>
2121
<orderEntry type="library" name="commons-codec-1.17.0.jar" level="project"/>
2222
<orderEntry type="library" name="commons-compress-1.26.2.jar" level="project"/>
2323
<orderEntry type="library" name="commons-io-2.18.0.jar" level="project"/>
2424
<orderEntry type="library" name="commons-lang3-3.16.0.jar" level="project"/>
2525
<orderEntry type="library" name="concurrent-reference-hash-map-1.1.0.jar" level="project"/>
2626
<orderEntry type="library" name="config_2.13-1.1.3.jar" level="project"/>
27-
<orderEntry type="library" name="coursier-cache_2.13-2.1.25-M4.jar" level="project"/>
28-
<orderEntry type="library" name="coursier-core_2.13-2.1.25-M4.jar" level="project"/>
29-
<orderEntry type="library" name="coursier-env_2.13-2.1.25-M4.jar" level="project"/>
30-
<orderEntry type="library" name="coursier-jvm_2.13-2.1.25-M4.jar" level="project"/>
31-
<orderEntry type="library" name="coursier-proxy-setup-2.1.25-M4.jar" level="project"/>
32-
<orderEntry type="library" name="coursier-util_2.13-2.1.25-M4.jar" level="project"/>
33-
<orderEntry type="library" name="coursier_2.13-2.1.25-M4.jar" level="project"/>
27+
<orderEntry type="library" name="coursier-cache_2.13-2.1.25-M11.jar" level="project"/>
28+
<orderEntry type="library" name="coursier-core_2.13-2.1.25-M11.jar" level="project"/>
29+
<orderEntry type="library" name="coursier-env_2.13-2.1.25-M11.jar" level="project"/>
30+
<orderEntry type="library" name="coursier-exec-2.1.25-M11.jar" level="project"/>
31+
<orderEntry type="library" name="coursier-jvm_2.13-2.1.25-M11.jar" level="project"/>
32+
<orderEntry type="library" name="coursier-proxy-setup-2.1.25-M11.jar" level="project"/>
33+
<orderEntry type="library" name="coursier-util_2.13-2.1.25-M11.jar" level="project"/>
34+
<orderEntry type="library" name="coursier_2.13-2.1.25-M11.jar" level="project"/>
3435
<orderEntry type="library" name="dependency_2.13-0.3.2.jar" level="project"/>
3536
<orderEntry type="library" name="fansi_3-0.5.0.jar" level="project"/>
3637
<orderEntry type="library" name="fastparse_3-3.1.1.jar" level="project"/>
@@ -50,7 +51,7 @@
5051
<orderEntry type="library" name="jline-native-3.29.0.jar" level="project"/>
5152
<orderEntry type="library" name="jna-5.17.0.jar" level="project"/>
5253
<orderEntry type="library" name="jna-platform-5.16.0.jar" level="project"/>
53-
<orderEntry type="library" name="jsoniter-scala-core_2.13-2.13.5.2.jar" level="project"/>
54+
<orderEntry type="library" name="jsoniter-scala-core_2.13-2.13.39.jar" level="project"/>
5455
<orderEntry type="library" name="jsr305-3.0.2.jar" level="project"/>
5556
<orderEntry type="library" name="jul-to-slf4j-1.7.30.jar" level="project"/>
5657
<orderEntry type="library" name="logback-classic-1.5.17.jar" level="project"/>
@@ -119,6 +120,6 @@
119120
<orderEntry type="library" name="windows-jni-utils-0.3.3.jar" level="project"/>
120121
<orderEntry type="library" name="xbean-reflect-3.7.jar" level="project"/>
121122
<orderEntry type="library" scope="RUNTIME" name="xz-1.9.jar" level="project"/>
122-
<orderEntry type="library" scope="RUNTIME" name="zstd-jni-1.5.6-3.jar" level="project"/>
123+
<orderEntry type="library" name="zstd-jni-1.5.7-2.jar" level="project"/>
123124
</component>
124125
</module>

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,21 @@
1515
<orderEntry type="library" name="asm-9.6.jar" level="project"/>
1616
<orderEntry type="library" name="asm-commons-9.6.jar" level="project"/>
1717
<orderEntry type="library" name="asm-tree-9.6.jar" level="project"/>
18-
<orderEntry type="library" name="cache-util-2.1.25-M4.jar" level="project"/>
18+
<orderEntry type="library" name="cache-util-2.1.25-M11.jar" level="project"/>
1919
<orderEntry type="library" name="commons-codec-1.17.0.jar" level="project"/>
2020
<orderEntry type="library" name="commons-compress-1.26.2.jar" level="project"/>
2121
<orderEntry type="library" name="commons-io-2.18.0.jar" level="project"/>
2222
<orderEntry type="library" name="commons-lang3-3.16.0.jar" level="project"/>
2323
<orderEntry type="library" name="concurrent-reference-hash-map-1.1.0.jar" level="project"/>
2424
<orderEntry type="library" name="config_2.13-1.1.3.jar" level="project"/>
25-
<orderEntry type="library" name="coursier-cache_2.13-2.1.25-M4.jar" level="project"/>
26-
<orderEntry type="library" name="coursier-core_2.13-2.1.25-M4.jar" level="project"/>
27-
<orderEntry type="library" name="coursier-env_2.13-2.1.25-M4.jar" level="project"/>
28-
<orderEntry type="library" name="coursier-jvm_2.13-2.1.25-M4.jar" level="project"/>
29-
<orderEntry type="library" name="coursier-proxy-setup-2.1.25-M4.jar" level="project"/>
30-
<orderEntry type="library" name="coursier-util_2.13-2.1.25-M4.jar" level="project"/>
31-
<orderEntry type="library" name="coursier_2.13-2.1.25-M4.jar" level="project"/>
25+
<orderEntry type="library" name="coursier-cache_2.13-2.1.25-M11.jar" level="project"/>
26+
<orderEntry type="library" name="coursier-core_2.13-2.1.25-M11.jar" level="project"/>
27+
<orderEntry type="library" name="coursier-env_2.13-2.1.25-M11.jar" level="project"/>
28+
<orderEntry type="library" name="coursier-exec-2.1.25-M11.jar" level="project"/>
29+
<orderEntry type="library" name="coursier-jvm_2.13-2.1.25-M11.jar" level="project"/>
30+
<orderEntry type="library" name="coursier-proxy-setup-2.1.25-M11.jar" level="project"/>
31+
<orderEntry type="library" name="coursier-util_2.13-2.1.25-M11.jar" level="project"/>
32+
<orderEntry type="library" name="coursier_2.13-2.1.25-M11.jar" level="project"/>
3233
<orderEntry type="library" name="dependency_2.13-0.3.2.jar" level="project"/>
3334
<orderEntry type="library" name="fansi_3-0.5.0.jar" level="project"/>
3435
<orderEntry type="library" name="fastparse_3-3.1.1.jar" level="project"/>
@@ -48,7 +49,7 @@
4849
<orderEntry type="library" name="jline-native-3.29.0.jar" level="project"/>
4950
<orderEntry type="library" name="jna-5.17.0.jar" level="project"/>
5051
<orderEntry type="library" name="jna-platform-5.16.0.jar" level="project"/>
51-
<orderEntry type="library" name="jsoniter-scala-core_2.13-2.13.5.2.jar" level="project"/>
52+
<orderEntry type="library" name="jsoniter-scala-core_2.13-2.13.39.jar" level="project"/>
5253
<orderEntry type="library" name="jsr305-3.0.2.jar" level="project"/>
5354
<orderEntry type="library" name="jul-to-slf4j-1.7.30.jar" level="project"/>
5455
<orderEntry type="library" name="logback-classic-1.5.17.jar" level="project"/>
@@ -114,6 +115,6 @@
114115
<orderEntry type="library" name="windows-jni-utils-0.3.3.jar" level="project"/>
115116
<orderEntry type="library" name="xbean-reflect-3.7.jar" level="project"/>
116117
<orderEntry type="library" scope="RUNTIME" name="xz-1.9.jar" level="project"/>
117-
<orderEntry type="library" scope="RUNTIME" name="zstd-jni-1.5.6-3.jar" level="project"/>
118+
<orderEntry type="library" name="zstd-jni-1.5.7-2.jar" level="project"/>
118119
</component>
119120
</module>

0 commit comments

Comments
 (0)