Skip to content

Commit 26f3447

Browse files
committed
Merge branch 'main' into tr-path-mapping-optional
2 parents 2d6d576 + 17f4854 commit 26f3447

File tree

52 files changed

+792
-224
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+792
-224
lines changed

build.mill

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//| mill-version: 1.0.6-88-54d201
1+
//| mill-version: 1.0.6-95-b08901
22
//| mill-jvm-opts: ["-XX:NonProfiledCodeHeapSize=250m", "-XX:ReservedCodeCacheSize=500m"]
33
//| mill-opts: ["--jobs=0.5C"]
44

core/api/daemon/src/mill/api/daemon/internal/bsp/BspModuleApi.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ trait BspModuleApi extends ModuleApi {
66
private[mill] def bspBuildTargetData: TaskApi[Option[(String, AnyRef)]]
77
private[mill] def bspBuildTarget: BspBuildTarget
88
private[mill] def bspDisplayName: String
9+
10+
/**
11+
* Set this to false to make the Mill BSP server hide / ignore that module
12+
*
13+
* Beware that if a module depends via `moduleDeps` or `compileModuleDeps` on modules
14+
* that have `enableBsp` set to false, it will be ignored by the Mill BSP server too
15+
*/
16+
def enableBsp: Boolean = true
917
}
1018

1119
object BspModuleApi {

core/api/src/mill/api/Task.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,9 @@ object Task {
504504
ctx0,
505505
upickle.readwriter[Seq[PathRef]],
506506
isPrivate
507-
) {}
507+
) {
508+
override def readWriterOpt = Some(upickle.readwriter[Seq[PathRef]])
509+
}
508510

509511
class Source(
510512
evaluate0: (Seq[Any], mill.api.TaskCtx) => Result[PathRef],
@@ -515,7 +517,9 @@ object Task {
515517
ctx0,
516518
upickle.readwriter[PathRef],
517519
isPrivate
518-
) {}
520+
) {
521+
override def readWriterOpt = Some(upickle.readwriter[PathRef])
522+
}
519523

520524
private object Macros {
521525
def appImpl[M[_]: Type, T: Type](using

core/exec/src/mill/exec/GroupExecution.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ trait GroupExecution {
123123
val (execRes, serializedPaths) =
124124
try {
125125
val (resultData, serializedPaths) = PathRef.withSerializedPaths {
126-
PathRef.currentOverrideModulePath.withValue(labelled.ctx.millSourcePath) {
126+
PathRef.currentOverrideModulePath.withValue(
127+
labelled.ctx.enclosingModule.moduleCtx.millSourcePath
128+
) {
127129
upickle.read[Any](interpolateEnvVarsInJson(jsonData))(
128130
using labelled.readWriterOpt.get.asInstanceOf[upickle.Reader[Any]]
129131
)

dist/package.mill

Lines changed: 90 additions & 24 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,38 +75,61 @@ 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) =
38-
Task.Command {
39-
PathRef(installLocalTask(Task.Anon(binFile), ivyRepo)())
79+
def installLocal(binFile: String = localBinName) = {
80+
val binFile0 = os.Path(binFile, BuildCtx.workspaceRoot)
81+
Task.Command[Unit] {
82+
installIvyLocalTask(Task.Anon(binFile0))()
4083
}
84+
}
4185

4286
val batExt = if (scala.util.Properties.isWin) ".bat" else ""
4387

44-
def installLocalCachePath(suffixTask: Task[String]) = Task.Anon {
45-
(os.home / ".cache/mill/download" / (build.millVersion() + suffixTask() + batExt)).toString()
46-
}
88+
def installLocalCache() = {
4789

48-
def installLocalCache() = Task.Command {
49-
val path = installLocalTask(installLocalCachePath(build.dist.cacheBinarySuffix))()
50-
val path2 = installLocalTask(installLocalCachePath(build.dist.native.cacheBinarySuffix))()
90+
def launcherPathTask(suffix: Task[String]) =
91+
Task.Anon {
92+
os.home / ".cache/mill/download" / (build.millVersion() + suffix() + batExt)
93+
}
5194

52-
Task.log.streams.out.println(path.toString())
53-
PathRef(path)
54-
}
95+
val jarLauncherPathTask = launcherPathTask(build.dist.cacheBinarySuffix)
96+
val nativeLauncherPathTask = launcherPathTask(build.dist.native.cacheBinarySuffix)
5597

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
98+
Task.Command {
99+
val Seq(jarLauncherPath, _*) =
100+
installIvyLocalTask(jarLauncherPathTask, nativeLauncherPathTask)()
101+
Task.log.streams.out.println(jarLauncherPath.path.toString())
102+
jarLauncherPath
103+
}
65104
}
66105

106+
def installLocalTask(binFile: Task[String]): Task[os.Path] =
107+
Task.Anon {
108+
val targetFile = os.Path(binFile(), BuildCtx.workspaceRoot)
109+
if (os.exists(targetFile))
110+
Task.log.info(s"Overwriting existing local Mill binary at ${targetFile}")
111+
os.copy.over(executable().path, targetFile, createFolders = true)
112+
Task.log.info(
113+
s"Published ${build.dist.allPublishModules.size} modules under Mill sources local repo ${localRepo().path} and installed ${targetFile}"
114+
)
115+
targetFile
116+
}
117+
118+
def installIvyLocalTask(targetFiles: Task[os.Path]*) =
119+
Task.Anon[Seq[PathRef]] {
120+
Task.traverse(allPublishModules)(m => m.publishLocal(doc = false))()
121+
val targetFiles0 = Task.sequence(targetFiles)()
122+
for (targetFile <- targetFiles0) {
123+
if (os.exists(targetFile))
124+
Task.log.info(s"Overwriting existing local Mill binary at $targetFile")
125+
os.copy.over(executableRaw().path, targetFile, createFolders = true)
126+
}
127+
Task.log.info(
128+
s"Published ${build.dist.allPublishModules.size} modules under ~/.ivy2/local and installed ${targetFiles0.mkString(", ")}"
129+
)
130+
targetFiles0.map(PathRef(_))
131+
}
132+
67133
def artifactName: T[String]
68134
def artifact = Task { Artifact(Settings.pomOrg, artifactName(), build.millVersion()) }
69135
def pomSettings = Task { MillPublishJavaModule.commonPomSettings(artifactName()) }
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//| mill-jvm-index-version: 0.0.4-88-f9ba3d
2+
//| mill-jvm-version: temurin:11
3+
//
4+
// Mill uses the https://github.com/coursier/jvm-index[Coursier JVM Index] to resolve JVM
5+
// versions to their download location, as well as partially-qualified versions such as
6+
// `temurin:11` to the specific point version such as `temurin:11.0.28`. The version of
7+
// the JVM index is set by the version of Mill you are using, but you can override it
8+
// to use a newer JVM index (e.g. if you want to use a newly-released JVM not yet included
9+
// in Mill's jvm index version) or an older JVM index.
10+
//
11+
// The list of JVM index versions can be seen here:
12+
//
13+
// - https://repo1.maven.org/maven2/io/get-coursier/jvm/indices/[JVM Indices on Maven Central]
14+
//
15+
package build
16+
17+
import mill._
18+
19+
def printJavaVersion() = Task.Command {
20+
println("Java version: " + System.getProperty("java.version"))
21+
}
22+
23+
// This example uses an older `mill-jvm-index-version` to ensure the resolved version
24+
// of `temurin:11` gets appropriately downgraded from `11.0.28` (the most recent `11.x` version)
25+
// to `11.0.26` (the version of `11.x` available when the JVM index `0.0.4-88-f9ba3d` was released)
26+
/** Usage
27+
28+
> ./mill printJavaVersion
29+
Java version: 11.0.26
30+
31+
*/
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//| resources: ["./resources"]
2+
package foo;
3+
4+
public class Foo {
5+
public static void main(String[] args) throws Exception {
6+
try (var inputStream = Foo.class.getClassLoader().getResourceAsStream("file.txt")) {
7+
System.out.println(new String(inputStream.readAllBytes()));
8+
}
9+
}
10+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//// SNIPPET:ALL
2+
3+
/** See Also: Foo.java */
4+
5+
/** Usage
6+
> ./mill Foo.java
7+
Hello World Resource File
8+
*/
9+
10+
//// SNIPPET:END
11+
//// SNIPPET:ALL2
12+
13+
/** Usage
14+
15+
> ./mill show Foo.java:assembly
16+
".../out/Foo.java/assembly.dest/out.jar"
17+
18+
> out/Foo.java/assembly.dest/out.jar
19+
Hello World Resource File
20+
21+
*/
22+
23+
//// SNIPPET:END
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello World Resource File
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
package foo
22

33
object Foo {
4-
// Read `file.txt` from classpath
5-
fun classpathResourceText(): String {
6-
// Get the resource as an InputStream
7-
return Foo::class.java.classLoader.getResourceAsStream("file.txt").use {
8-
it.readAllBytes().toString(Charsets.UTF_8)
9-
}
4+
fun classpathResourceText(): String = Foo::class.java.classLoader.getResourceAsStream("file.txt").use {
5+
it.readAllBytes().toString(Charsets.UTF_8)
106
}
117
}

0 commit comments

Comments
 (0)