Skip to content

Commit 8f8d978

Browse files
authored
More Script Polish (#6029)
TODO: - [x] Example of script depending on programmatic module - [x] Packaging scripts into assemblies and Graal native images - [x] More details on how testing works, and list of supported classes - [x] Fix tab completion to work for script files as well as module selectors - [x] Script REPL and Console instructions - [ ] Script autoformatting - [x] Script pinned java version - [x] Error message tests - [x] Fleshed out use cases for scripts
1 parent e72f1d1 commit 8f8d978

File tree

142 files changed

+1587
-285
lines changed

Some content is hidden

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

142 files changed

+1587
-285
lines changed

.github/actions/post-build-selective/action.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ inputs:
44
default: ''
55
type: string
66

7+
extra:
8+
default: ''
9+
type: string
10+
711
shell:
812
required: true
913
type: string
@@ -43,7 +47,7 @@ runs:
4347
#- run: ./mill -i -k selective.resolveChanged ${{ inputs.millargs }}
4448
# shell: ${{ inputs.shell }}
4549

46-
- run: ./mill -i -k selective.run ${{ inputs.millargs }}
50+
- run: ./mill -i -k ${{ inputs.extra }} selective.run ${{ inputs.millargs }}
4751
shell: ${{ inputs.shell }}
4852

4953
- name: Clean-up Test Reports

.github/workflows/post-build-selective.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ on:
1616
os:
1717
default: 'ubuntu-latest'
1818
type: string
19+
extra:
20+
default: ''
21+
type: string
1922
timeout-minutes:
2023
default: 60
2124
type: number
@@ -63,4 +66,5 @@ jobs:
6366

6467
with:
6568
millargs: ${{ inputs.millargs }}
66-
shell: ${{ inputs.shell }}
69+
shell: ${{ inputs.shell }}
70+
extra: ${{ inputs.extra }}

.github/workflows/run-tests.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,9 @@ jobs:
204204
millargs: "'integration.invalidation.__.packaged.daemon'"
205205

206206
- java-version: 11
207+
# turn of parallelism since it sometimes causes issues with concurrent migrations
207208
millargs: '"example.migrating.javalib.__.packaged.daemon"'
208-
209+
extra: "--jobs=1"
209210
- java-version: 11
210211
millargs: '"libs.{util,javalib,androidlib,graphviz}.__.test"'
211212

@@ -223,6 +224,7 @@ jobs:
223224
os: windows-latest
224225
java-version: ${{ matrix.java-version }}
225226
millargs: ${{ matrix.millargs }}
227+
extra: ${{ matrix.extra || '' }}
226228
shell: powershell
227229

228230
itest:

core/api/daemon/src/mill/api/daemon/ExecResult.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ object ExecResult {
130130
catch {
131131
case e: InvocationTargetException =>
132132
Result.Failure(makeResultException(e.getCause, new java.lang.Exception()).left.get)
133-
case e: Exception =>
133+
case e: java.lang.Exception =>
134134
Result.Failure(makeResultException(e, new java.lang.Exception()).left.get)
135135
}
136136
}

core/api/daemon/src/mill/api/daemon/Result.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import scala.util.boundary
66
/**
77
* Represents a computation that either succeeds with a value [[T]] or
88
* fails. Basically equivalent to `Either[String, T]`, with converters
9-
* back and forther via [[Result.toEither]] or [[Result.fromEither]]
9+
* back and forth via [[Result.toEither]] or [[Result.fromEither]]
1010
*/
1111
sealed trait Result[+T] {
1212
def map[V](f: T => V): Result[V]

core/api/src/mill/api/Discover.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import scala.collection.mutable
1616
* can then be used later to look up the `MainData` for any module.
1717
*/
1818
final class Discover(val classInfo: Map[Class[?], Discover.ClassInfo]) {
19+
private[mill] val allTaskNames = classInfo.values.flatMap(_.declaredTaskNameSet).toSet
1920
private[mill] def resolveEntrypoint(cls: Class[?], name: String) = {
2021
val res = for {
2122
(cls2, node) <- classInfo

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

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,29 @@ trait GroupExecution {
111111
case ujson.Obj(kvs) => ujson.Obj.from(kvs.map((k, v) => (k, rec(v))))
112112
case v => v
113113
}
114-
val (resultData, serializedPaths) = PathRef.withSerializedPaths {
115-
PathRef.currentOverrideModulePath.withValue(labelled.ctx.millSourcePath) {
116-
upickle.read[Any](rec(jsonData))(
117-
using labelled.readWriterOpt.get.asInstanceOf[upickle.Reader[Any]]
118-
)
114+
115+
val (execRes, serializedPaths) =
116+
try {
117+
val (resultData, serializedPaths) = PathRef.withSerializedPaths {
118+
PathRef.currentOverrideModulePath.withValue(labelled.ctx.millSourcePath) {
119+
upickle.read[Any](rec(jsonData))(
120+
using labelled.readWriterOpt.get.asInstanceOf[upickle.Reader[Any]]
121+
)
122+
}
123+
}
124+
(ExecResult.Success(Val(resultData), resultData.##), serializedPaths)
125+
} catch {
126+
case e: upickle.core.TraceVisitor.TraceException =>
127+
(
128+
ExecResult.Failure(
129+
s"Failed de-serializing config override: ${e.getCause.getMessage}"
130+
),
131+
Nil
132+
)
119133
}
120-
}
134+
121135
GroupExecution.Results(
122-
Map(labelled -> ExecResult.Success(Val(resultData), resultData.##)),
136+
Map(labelled -> execRes),
123137
Nil,
124138
cached = true,
125139
inputsHash,

core/resolve/src/mill/resolve/Resolve.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ private[mill] object Resolve {
193193
)
194194
.head
195195

196-
ResolveCore.catchWrapException(
196+
mill.api.ExecResult.catchWrapException(
197197
definition.invoke(p).asInstanceOf[Task.Named[?]]
198198
)
199199
}
@@ -206,7 +206,7 @@ private[mill] object Resolve {
206206
nullCommandDefaults: Boolean,
207207
allowPositionalCommandArgs: Boolean
208208
) = {
209-
ResolveCore.catchWrapException {
209+
mill.api.ExecResult.catchWrapException {
210210
val invoked = invokeCommand0(
211211
p,
212212
r.segments.last.value,

core/resolve/src/mill/resolve/ResolveCore.scala

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package mill.resolve
33
import mill.api.*
44
import mill.api.internal.{Reflect, Resolved, RootModule0}
55

6-
import java.lang.reflect.InvocationTargetException
76
import java.lang.reflect.Method
87

98
/**
@@ -79,16 +78,6 @@ private object ResolveCore {
7978
}
8079
}
8180

82-
def catchWrapException[T](t: => T): mill.api.Result[T] = {
83-
try mill.api.Result.Success(t)
84-
catch {
85-
case e: InvocationTargetException =>
86-
mill.api.Result.Failure(makeResultException(e.getCause, new java.lang.Exception()).left.get)
87-
case e: Exception =>
88-
mill.api.Result.Failure(makeResultException(e, new java.lang.Exception()).left.get)
89-
}
90-
}
91-
9281
def makeResultException(e: Throwable, base: Exception): Left[String, Nothing] =
9382
mill.api.ExecResult.makeResultException(e, base)
9483

@@ -231,7 +220,7 @@ private object ResolveCore {
231220
if (classOf[Cross[?]].isAssignableFrom(m.cls)) {
232221
instantiateModule(rootModule, current.segments, cache).flatMap {
233222
case c: Cross[_] =>
234-
catchWrapException(
223+
mill.api.ExecResult.catchWrapException(
235224
if (cross == Seq("__")) for ((_, v) <- c.valuesToModules.toSeq) yield v
236225
else if (cross.contains("_")) {
237226
for {
@@ -291,7 +280,7 @@ private object ResolveCore {
291280
case (mill.api.Result.Success(current), Segment.Cross(vs)) =>
292281
assert(!vs.contains("_"), vs)
293282

294-
catchWrapException(
283+
mill.api.ExecResult.catchWrapException(
295284
current
296285
.asInstanceOf[Cross[?]]
297286
.segmentsToModules(vs.toList)
@@ -445,7 +434,8 @@ private object ResolveCore {
445434
.collect {
446435
case (name, memberCls, getter) =>
447436
val resolved = Resolved.Module(Segments.labels(cache.decode(name)), memberCls)
448-
val getter2 = Some((mod: Module) => catchWrapException(getter(mod)))
437+
val getter2 =
438+
Some((mod: Module) => mill.api.ExecResult.catchWrapException(getter(mod)))
449439
(resolved, getter2)
450440
}
451441
.toSeq

example/javalib/basic/1-script/build.mill

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//// SNIPPET:FILE
22
/** See Also: Foo.java */
3+
//// SNIPPET:END
4+
//// SNIPPET:CMD
35
/** Usage
46
> ./mill Foo.java --text hello
57
compiling 1 Java source to...

0 commit comments

Comments
 (0)