Skip to content

Commit

Permalink
Merge branch 'lihaoyi-patch-13' of github.com:com-lihaoyi/mill
Browse files Browse the repository at this point in the history
  • Loading branch information
lihaoyi committed Oct 9, 2024
2 parents 5db7ed3 + d46b512 commit 9b84ae4
Show file tree
Hide file tree
Showing 23 changed files with 196 additions and 179 deletions.
2 changes: 1 addition & 1 deletion .config/mill-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.12.0-RC3-23-4db51d
0.12.0-RC3-26-d3afbf
5 changes: 2 additions & 3 deletions docs/modules/ROOT/pages/comparisons/maven.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -569,16 +569,15 @@ def make = Task {
}
```

[graphviz]
....
```graphviz
digraph G {
rankdir=LR
node [shape=box width=0 height=0 style=filled fillcolor=white]
makefile -> make
cSources -> make
cSources -> cHeaders
}
....
```

In Mill, we define the `makefile`, `cSources`, `cHeaders`, and `make` tasks. The bulk
of the logic is in `def make`, which prepares the `makefile` and C sources,
Expand Down
10 changes: 4 additions & 6 deletions docs/modules/ROOT/pages/depth/design-principles.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,7 @@ build-related questions listed above.

=== The Object Hierarchy

[graphviz]
....
```graphviz
digraph G {
node [shape=box width=0 height=0 style=filled fillcolor=white]
bgcolor=transparent
Expand All @@ -213,7 +212,7 @@ digraph G {
foo2 -> "foo2.qux" [style=dashed]
foo2 -> "foo2.baz" [style=dashed]
}
....
```

The module hierarchy is the graph of objects, starting from the root of the
`build.mill` file, that extend `mill.Module`. At the leaves of the hierarchy are
Expand All @@ -239,8 +238,7 @@ are sure that it will never clash with any other ``Task``s data.

=== The Call Graph

[graphviz]
....
```graphviz
digraph G {
rankdir=LR
node [shape=box width=0 height=0 style=filled fillcolor=white]
Expand Down Expand Up @@ -275,7 +273,7 @@ digraph G {
"qux.sources" -> "qux.compile" -> "qux.classPath" -> "qux.assembly"
}
}
....
```

The Scala call graph of "which task references which other task" is core to
how Mill operates. This graph is reified via the `T {...}` macro to make it
Expand Down
5 changes: 2 additions & 3 deletions docs/modules/ROOT/partials/Intro_to_Mill_Header.adoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[graphviz]
....
```graphviz
digraph G {
rankdir=LR
node [shape=box width=0 height=0 style=filled fillcolor=white]
Expand All @@ -24,7 +23,7 @@ digraph G {
"bar.mainClass" -> "bar.assembly"
}
}
....
```

{mill-github-url}[Mill] is a fast multi-language JVM build tool that supports {language}, making your
common development workflows xref:comparisons/maven.adoc[5-10x faster to Maven], or
Expand Down
47 changes: 42 additions & 5 deletions docs/package.mill
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package build.docs
import mill.util.Jvm
import mill._, scalalib._
import build.contrib
import de.tobiasroeser.mill.vcs.version.VcsVersion
import guru.nidi.graphviz.engine.AbstractJsGraphvizEngine
import guru.nidi.graphviz.engine.{Format, Graphviz}

/** Generates the mill documentation with Antora. */
object `package` extends RootModule {
Expand Down Expand Up @@ -32,7 +33,6 @@ object `package` extends RootModule {
"@antora/[email protected]",
"gitlab:antora/xref-validator",
"@antora/[email protected]",
"[email protected]"
),
envArgs = Map(),
workingDir = npmDir
Expand Down Expand Up @@ -90,6 +90,46 @@ object `package` extends RootModule {
createFolders = true
)

Graphviz.useEngine(new AbstractJsGraphvizEngine(true, () => new mill.main.graphviz.V8JavascriptEngine()) {})

def walkAllFiles(inputs: Map[(os.Path, Int), String]): Map[(os.Path, Int), String] = {
val output = collection.mutable.Map.empty[(os.Path, Int), String]
for (p <- os.walk(T.dest) if p.ext == "adoc"){
val outputLines = collection.mutable.ArrayDeque.empty[String]
val graphvizLines = collection.mutable.ArrayDeque.empty[String]
var isGraphViz = false

for((line, i) <- os.read.lines(p).zipWithIndex){
line match{
case "```graphviz" => isGraphViz = true
case "```" if isGraphViz =>
isGraphViz = false
if (inputs.isEmpty) output((p, i)) = graphvizLines.mkString("\n")
else {
outputLines.append("++++")
outputLines.append(inputs((p, i)))
outputLines.append("++++")
}

graphvizLines.clear()
case _ =>
if (isGraphViz) graphvizLines.append(line)
else outputLines.append(line)
}
}
if (inputs.nonEmpty) os.write.over(p, outputLines.mkString("\n"))
}
output.toMap
}

val diagrams = walkAllFiles(Map())
// Batch the rendering so later it can be done in one call to a single subprocess,
// minimizing per-subprocess overhead needed to spawn them over and over
val renderedDiagrams = diagrams
.map{case (k, s) => (k, Graphviz.fromString(s).render(Format.SVG).toString)}

walkAllFiles(renderedDiagrams)

PathRef(T.dest)
}

Expand Down Expand Up @@ -167,9 +207,6 @@ object `package` extends RootModule {
| utest-github-url: https://github.com/com-lihaoyi/utest
| upickle-github-url: https://github.com/com-lihaoyi/upickle
| mill-scip-version: ${build.Deps.DocDeps.millScip.dep.version}
| kroki-fetch-diagram: true
| extensions:
| - asciidoctor-kroki
|antora:
| extensions:
| - require: '@antora/lunr-extension'
Expand Down
6 changes: 2 additions & 4 deletions example/fundamentals/cross/1-simple/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ trait FooModule extends Cross.Module[String] {
def sources = Task.Sources(millSourcePath)
}

// [graphviz]
// ....
// ```graphviz
// digraph G {
// rankdir=LR
// node [shape=box width=0 height=0 style=filled fillcolor=white]

// subgraph cluster_2 {
// label="foo[2.12]"
// style=dashed
Expand All @@ -34,7 +32,7 @@ trait FooModule extends Cross.Module[String] {
// "foo[2.10].sources"
// }
// }
// ....
// ```

// Cross modules defined using the `Cross[T]` class allow you to define
// multiple copies of the same module, differing only in some input key. This
Expand Down
5 changes: 2 additions & 3 deletions example/fundamentals/cross/10-static-blog/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ def dist = Task {
// All caching, incremental re-computation, and parallelism is done using the
// Mill task graph. For this simple example, the graph is as follows
//
// [graphviz]
// ....
// ```graphviz
// digraph G {
// node [shape=box width=0 height=0]
// "1 - Foo.md" -> "post[1]\nrender"
Expand All @@ -133,7 +132,7 @@ def dist = Task {
// "index" -> "dist"
//
// }
// ....
// ```
//
// This example use case is taken from the following blog post, which contains
// some extensions and fun exercises to further familiarize yourself with Mill
Expand Down
5 changes: 2 additions & 3 deletions example/fundamentals/cross/3-outside-dependency/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ def bar = Task { s"hello ${foo("2.10").suffix()}" }

def qux = Task { s"hello ${foo("2.10").suffix()} world ${foo("2.12").suffix()}" }

// [graphviz]
// ....
// ```graphviz
// digraph G {
// rankdir=LR
// node [shape=box width=0 height=0 style=filled fillcolor=white]
Expand All @@ -36,7 +35,7 @@ def qux = Task { s"hello ${foo("2.10").suffix()} world ${foo("2.12").suffix()}"
// "foo[2.10].suffix" -> "qux"
// "foo[2.10].suffix" -> "bar"
// }
// ....
// ```


// Here, `def bar` uses `foo("2.10")` to reference the `"2.10"` instance of
Expand Down
5 changes: 2 additions & 3 deletions example/fundamentals/cross/4-cross-dependencies/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ trait BarModule extends Cross.Module[String] {
def bigSuffix = Task { "[[[" + foo(crossValue).suffix() + "]]]" }
}

// [graphviz]
// ....
// ```graphviz
// digraph G {
// rankdir=LR
// node [shape=box width=0 height=0 style=filled fillcolor=white]
Expand Down Expand Up @@ -52,7 +51,7 @@ trait BarModule extends Cross.Module[String] {
// "foo[2.11].suffix" -> "bar[2.11].bigSuffix"
// "foo[2.12].suffix" -> "bar[2.12].bigSuffix"
// }
// ....
// ```

// Rather than pssing in a literal `"2.10"` to the `foo` cross module, we pass
// in the `crossValue` property that is available within every `Cross.Module`.
Expand Down
5 changes: 2 additions & 3 deletions example/fundamentals/cross/5-multiple-cross-axes/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ trait FooModule extends Cross.Module2[String, String] {

def bar = Task { s"hello ${foo("2.10", "jvm").suffix()}" }

// [graphviz]
// ....
// ```graphviz
// digraph G {
// rankdir=LR
// node [shape=box width=0 height=0 style=filled fillcolor=white]
Expand Down Expand Up @@ -65,7 +64,7 @@ def bar = Task { s"hello ${foo("2.10", "jvm").suffix()}" }
//
// "foo[2.10,jvm].suffix" -> bar
// }
// ....
// ```
//
// This example shows off using a for-loop to generate a list of
// cross-key-tuples, as a `Seq[(String, String)]` that we then pass it into the
Expand Down
5 changes: 2 additions & 3 deletions example/fundamentals/cross/7-inner-cross-module/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ trait FooModule extends Cross.Module[String] {

def baz = Task { s"hello ${foo("a").bar.param()}" }

// [graphviz]
// ....
// ```graphviz
// digraph G {
// node [shape=box width=0 height=0 style=filled fillcolor=white]
// "root-module" [style=dashed]
Expand All @@ -45,7 +44,7 @@ def baz = Task { s"hello ${foo("a").bar.param()}" }
// "..." [color=white]
// "foo[a].bar.name" -> "foo[a].bar.param" [constraint=false]
// }
// ....
// ```
//
// You can use the `CrossValue` trait within any `Cross.Module` to
// propagate the `crossValue` defined by an enclosing `Cross.Module` to some
Expand Down
16 changes: 7 additions & 9 deletions example/fundamentals/modules/7-modules/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ object foo extends Module {
}
}

// [graphviz]
// ....
// ```graphviz
// digraph G {
// node [shape=box width=0 height=0 style=filled fillcolor=white]
// "root-module" [style=dashed]
Expand All @@ -24,7 +23,8 @@ object foo extends Module {
// "root-module" -> foo -> "foo.qux" -> "foo.qux.baz" [style=dashed]
// foo -> "foo.bar" [style=dashed]
// }
// ....
// ```
//
// You would be able to run the two tasks via `mill foo.bar` or `mill
// foo.qux.baz`. You can use `mill show foo.bar` or `mill show foo.baz.qux` to
// make Mill echo out the string value being returned by each Task. The two
Expand Down Expand Up @@ -76,8 +76,7 @@ object foo2 extends FooModule {
// arrows representing the module tree, and the solid boxes and arrows representing
// the task graph

// [graphviz]
// ....
// ```graphviz
// digraph G {
// node [shape=box width=0 height=0 style=filled fillcolor=white]
// bgcolor=transparent
Expand All @@ -93,7 +92,7 @@ object foo2 extends FooModule {
// "foo1.bar" -> "foo1.qux.super" -> "foo1.qux" [constraint=false]
// "foo2.bar" -> "foo2.qux" -> "foo2.baz" [constraint=false]
// }
// ....
// ```

// Note that the `override` keyword is optional in mill, as is `T{...}` wrapper.

Expand Down Expand Up @@ -139,8 +138,7 @@ object outer extends MyModule {
object inner extends MyModule
}

// [graphviz]
// ....
// ```graphviz
// digraph G {
// node [shape=box width=0 height=0 style=filled fillcolor=white]
// "root-module" [style=dashed]
Expand All @@ -155,7 +153,7 @@ object outer extends MyModule {
// outer -> "outer.sources" [style=dashed]
// outer -> "outer.task" [style=dashed]
// }
// ....
// ```

// * The `outer` module has a `millSourcePath` of `outer/`, and thus a
// `outer.sources` referencing `outer/sources/`
Expand Down
10 changes: 4 additions & 6 deletions example/fundamentals/modules/8-diy-java-modules/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ trait DiyJavaModule extends Module{
// edges (dashed) are not connected; that is because `DiyJavaModule` is abstract, and
// needs to be inherited by a concrete `object` before it can be used.

// [graphviz]
// ....
// ```graphviz
// digraph G {
// rankdir=LR
// node [shape=box width=0 height=0 style=filled fillcolor=white]
Expand All @@ -51,7 +50,7 @@ trait DiyJavaModule extends Module{
// "sources" -> "compile" -> "classPath" -> "assembly"
// }
// }
// ....
// ```
//
// Some notable things to call out:
//
Expand Down Expand Up @@ -87,8 +86,7 @@ object qux extends DiyJavaModule {
// duplicated three times - once per module - with the tasks wired up between the modules
// according to our overrides for `moduleDeps`

// [graphviz]
// ....
// ```graphviz
// digraph G {
// rankdir=LR
// node [shape=box width=0 height=0 style=filled fillcolor=white]
Expand Down Expand Up @@ -123,7 +121,7 @@ object qux extends DiyJavaModule {
// "qux.sources" -> "qux.compile" -> "qux.classPath" -> "qux.assembly"
// }
// }
// ....
// ```
//
// This simple set of `DiyJavaModule` can be used as follows:

Expand Down
Loading

0 comments on commit 9b84ae4

Please sign in to comment.