Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BACKPORT] Allow Task.Source/Task.Sources to be constructed directly from subpath string literals #4487

Merged
merged 4 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ object Deps {
val junitInterface = ivy"com.github.sbt:junit-interface:0.13.3"
val commonsIo = ivy"commons-io:commons-io:2.18.0"
val log4j2Core = ivy"org.apache.logging.log4j:log4j-core:2.24.3"
val osLib = ivy"com.lihaoyi::os-lib:0.11.4-M5"
val osLib = ivy"com.lihaoyi::os-lib:0.11.4-M6"
val pprint = ivy"com.lihaoyi::pprint:0.9.0"
val mainargs = ivy"com.lihaoyi::mainargs:0.7.6"
val millModuledefsVersion = "0.11.2"
Expand Down Expand Up @@ -381,7 +381,7 @@ trait MillJavaModule extends JavaModule {

def writeLocalTestOverrides = Task.Anon {
for ((k, v) <- testTransitiveDeps()) {
os.write(Task.dest / "mill" / "local-test-overrides" / k, v, createFolders = true)
os.write(Task.dest / "mill/local-test-overrides" / k, v, createFolders = true)
}
Seq(PathRef(Task.dest))
}
Expand Down
2 changes: 1 addition & 1 deletion changelog.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ or `;exclude=org:*` or `;exclude=*:name` {link-pr}/3492[#3492]

* Update to https://github.com/com-lihaoyi/os-lib?tab=readme-ov-file#0-10-7[OS-Lib 0.10.7] to
allow concise multi-segment sub-paths; you can now write `os.pwd / "foo/bar/qux"` rather than
`os.pwd / "foo" / "bar" / "qux"`
`os.pwd / "foo/bar/qux"`

* Add `JavaModule.mandatoryJavacOptions`. Those are not propagated to the inner test
traits intentionally, since those options are typically configured by other means,
Expand Down
4 changes: 2 additions & 2 deletions contrib/playlib/src/mill/playlib/Layout.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import mill.scalalib._

private[playlib] trait Layout extends JavaModule {

def conf = Task.Sources { millSourcePath / "conf" }
def app = Task.Sources { millSourcePath / "app" }
def conf = Task.Sources { "conf" }
def app = Task.Sources { "app" }

override def sources = Task { app() }
override def resources = Task { conf() }
Expand Down
2 changes: 1 addition & 1 deletion contrib/playlib/src/mill/playlib/RouterModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import mill.{Agg, T, Task}

trait RouterModule extends ScalaModule with Version {

def routes: T[Seq[PathRef]] = Task.Sources { millSourcePath / "routes" }
def routes: T[Seq[PathRef]] = Task.Sources { "routes" }

def routeFiles = Task {
val paths = routes().flatMap(file => os.walk(file.path))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import mill._
trait VersionFileModule extends Module {

/** The file containing the current version. */
def versionFile: T[PathRef] = Task.Source(millSourcePath / "version")
def versionFile: T[PathRef] = Task.Source("version")

/** The current version. */
def currentVersion: T[Version] = Task { Version.of(os.read(versionFile().path).trim) }
Expand Down
2 changes: 1 addition & 1 deletion dist/package.mill
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ trait InstallModule extends build.MillPublishJavaModule {
def installLocalCache() = Task.Command {
val path = installLocalTask(
Task.Anon(
(os.home / ".cache" / "mill" / "download" / (build.millVersion() + batExt)).toString()
(os.home / ".cache/mill/download" / (build.millVersion() + batExt)).toString()
)
)()
Task.log.outputStream.println(path.toString())
Expand Down
10 changes: 5 additions & 5 deletions docs/modules/ROOT/pages/comparisons/maven.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ import $ivy.`ant:ant-optional:1.5.3-1`

object common extends NettyModule{
...
def script = Task.Source(millSourcePath / "src" / "main" / "script")
def script = Task.Source("src/main/script")
def generatedSources0 = Task {
val shell = new groovy.lang.GroovyShell()
val context = new java.util.HashMap[String, Object]
Expand Down Expand Up @@ -520,8 +520,8 @@ with the `make` command essentially being a bash script wrapped in layers of XML
In contrast, the Mill configuration for this logic is as follows:

```scala
def makefile = Task.Source(millSourcePath / "Makefile")
def cSources = Task.Source(millSourcePath / "src" / "main" / "c")
def makefile = Task.Source("Makefile")
def cSources = Task.Source("src/main/c")
def cHeaders = Task {
for(p <- os.walk(cSources().path) if p.ext == "h"){
os.copy(p, Task.dest / p.relativeTo(cSources().path), createFolders = true)
Expand All @@ -531,14 +531,14 @@ def cHeaders = Task {

def make = Task {
os.copy(makefile().path, Task.dest / "Makefile")
os.copy(cSources().path, Task.dest / "src" / "main" / "c", createFolders = true)
os.copy(cSources().path, Task.dest / "src/main/c", createFolders = true)

val Seq(sourceJar) = resolveDeps(
deps = Task.Anon(Agg(ivy"io.netty:netty-jni-util:0.0.9.Final").map(bindDependency())),
sources = true
)().toSeq

os.proc("jar", "xf", sourceJar.path).call(cwd = Task.dest / "src" / "main" / "c")
os.proc("jar", "xf", sourceJar.path).call(cwd = Task.dest / "src/main/c")

os.proc("make").call(
cwd = Task.dest,
Expand Down
4 changes: 2 additions & 2 deletions docs/modules/ROOT/pages/comparisons/unique.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ them into classfiles, and then the `jar` executable to package them together int
```scala
def mainClass: T[Option[String]] = Some("foo.Foo")

def sources = Task.Source(millSourcePath / "src")
def resources = Task.Source(millSourcePath / "resources")
def sources = Task.Source("src")
def resources = Task.Source("resources")

def compile = Task {
val allSources = os.walk(sources().path)
Expand Down
10 changes: 5 additions & 5 deletions docs/package.mill
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@ object `package` extends RootModule {
envArgs = Map("CI" -> "true"),
workingDir = workDir
)
PathRef(workDir / "build" / "site")
PathRef(workDir / "build/site")
}

def source0 = Task.Source(millSourcePath)
def projectChangelog = Task.Source(Task.workspace / "changelog.adoc")
def source = Task {
os.copy(source0().path, Task.dest, mergeFolders = true)

val pagesWd = Task.dest / "modules" / "ROOT" / "pages"
val partialsWd = Task.dest / "modules" / "ROOT" / "partials"
val pagesWd = Task.dest / "modules/ROOT/pages"
val partialsWd = Task.dest / "modules/ROOT/partials"

os.copy(projectChangelog().path, partialsWd / "project-changelog.adoc", createFolders = true)

Expand Down Expand Up @@ -284,7 +284,7 @@ object `package` extends RootModule {
val checkout = Task.dest / displayVersion
os.proc("git", "clone", Task.workspace / ".git", checkout).call(stdout = os.Inherit)
os.proc("git", "checkout", millLastTag).call(cwd = checkout, stdout = os.Inherit)
val outputFolder = checkout / "out" / "docs" / "source.dest"
val outputFolder = checkout / "out/docs/source.dest"
os.proc("./mill", "-i", "docs.source").call(cwd = checkout, stdout = os.Inherit)
expandDiagramsInDirectoryAdocFile(
outputFolder,
Expand Down Expand Up @@ -360,7 +360,7 @@ object `package` extends RootModule {
// only copy the "api" sub-dir; api docs contains a top-level index.html with we don't want
val unidocSrc = if (authorMode) site.unidocLocal().path else site.unidocSite().path
Task.log.errorStream.println(s"Copying API docs from ${unidocSrc} ...")
os.copy(unidocSrc, siteDir / "api" / "latest", createFolders = true)
os.copy(unidocSrc, siteDir / "api/latest", createFolders = true)

PathRef(siteDir)
}
Expand Down
2 changes: 1 addition & 1 deletion example/extending/jvmcode/1-subprocess/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ object foo extends JavaModule {
defaultResolver().resolveDeps(Agg(ivy"org.codehaus.groovy:groovy:3.0.9"))
}

def groovyScript = Task.Source(millSourcePath / "generate.groovy")
def groovyScript = Task.Source("generate.groovy")

def groovyGeneratedResources = Task {
Jvm.runSubprocess(
Expand Down
2 changes: 1 addition & 1 deletion example/extending/jvmcode/2-classloader/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ object foo extends JavaModule {
defaultResolver().resolveDeps(Agg(ivy"org.codehaus.groovy:groovy:3.0.9"))
}

def groovyScript = Task.Source(millSourcePath / "generate.groovy")
def groovyScript = Task.Source("generate.groovy")

def groovyGeneratedResources = Task {
Jvm.runClassloader(classPath = groovyClasspath().map(_.path)) { classLoader =>
Expand Down
2 changes: 1 addition & 1 deletion example/extending/jvmcode/3-worker/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def groovyWorker: Worker[java.net.URLClassLoader] = Task.Worker {
}

trait GroovyGenerateJavaModule extends JavaModule {
def groovyScript = Task.Source(millSourcePath / "generate.groovy")
def groovyScript = Task.Source("generate.groovy")

def groovyGeneratedResources = Task {
mill.api.ClassLoader.withContextClassLoader(groovyWorker()) {
Expand Down
4 changes: 2 additions & 2 deletions example/extending/python/1-hello-python/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import mill._
def pythonExe: T[PathRef] = Task {

os.call(("python3", "-m", "venv", Task.dest / "venv"))
val python = Task.dest / "venv" / "bin" / "python3"
val python = Task.dest / "venv/bin/python3"
os.call((python, "-m", "pip", "install", "mypy==1.13.0"))

PathRef(python)
Expand All @@ -19,7 +19,7 @@ def pythonExe: T[PathRef] = Task {

// The `sources` task specifies the directory for Python source files (`src` folder).

def sources: T[PathRef] = Task.Source(millSourcePath / "src")
def sources: T[PathRef] = Task.Source("src")

// === Type Checking

Expand Down
4 changes: 2 additions & 2 deletions example/extending/python/2-python-modules/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import mill._

trait PythonModule extends Module {

def sources: T[PathRef] = Task.Source(millSourcePath / "src")
def sources: T[PathRef] = Task.Source("src")
def mainFileName: T[String] = Task { "main.py" }

def pythonExe: T[PathRef] = Task {

os.call(("python3", "-m", "venv", Task.dest / "venv"))
val python = Task.dest / "venv" / "bin" / "python3"
val python = Task.dest / "venv/bin/python3"
os.call((python, "-m", "pip", "install", "mypy==1.13.0"))

PathRef(python)
Expand Down
4 changes: 2 additions & 2 deletions example/extending/python/3-python-module-deps/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ trait PythonModule extends Module {
// List of module dependencies required by this module.
def moduleDeps: Seq[PythonModule] = Nil

def sources: T[PathRef] = Task.Source(millSourcePath / "src")
def sources: T[PathRef] = Task.Source("src")
def mainFileName: T[String] = Task { "main.py" }

def pythonExe: T[PathRef] = Task {

os.call(("python3", "-m", "venv", Task.dest / "venv"))
val python = Task.dest / "venv" / "bin" / "python3"
val python = Task.dest / "venv/bin/python3"
os.call((python, "-m", "pip", "install", "mypy==1.13.0"))

PathRef(python)
Expand Down
4 changes: 2 additions & 2 deletions example/extending/python/4-python-libs-bundle/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import mill._
trait PythonModule extends Module {
def moduleDeps: Seq[PythonModule] = Nil
def mainFileName: T[String] = Task { "main.py" }
def sources: T[PathRef] = Task.Source(millSourcePath / "src")
def sources: T[PathRef] = Task.Source("src")

def pythonDeps: T[Seq[String]] = Task { Seq.empty[String] }

Expand All @@ -22,7 +22,7 @@ trait PythonModule extends Module {

def pythonExe: T[PathRef] = Task {
os.call(("python3", "-m", "venv", Task.dest / "venv"))
val python = Task.dest / "venv" / "bin" / "python3"
val python = Task.dest / "venv/bin/python3"
os.call((python, "-m", "pip", "install", "mypy==1.13.0", "pex==2.24.1", transitivePythonDeps()))

PathRef(python)
Expand Down
2 changes: 1 addition & 1 deletion example/extending/typescript/1-hello-typescript/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def npmInstall = Task {
// e.g. someone can later easily override `allSources` to add additional filtering
// on exactly which files within the source root they wish to pick up.

def sources = Task.Source(millSourcePath / "src")
def sources = Task.Source("src")
def allSources = Task {
os.walk(sources().path).filter(_.ext == "ts").map(PathRef(_))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ trait TypeScriptModule extends Module {
PathRef(Task.dest)
}

def sources = Task.Source(millSourcePath / "src")
def sources = Task.Source("src")
def allSources = Task {
os.walk(sources().path).filter(_.ext == "ts").map(PathRef(_))
}
Expand Down
2 changes: 1 addition & 1 deletion example/extending/typescript/3-module-deps/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ trait TypeScriptModule extends Module {
PathRef(Task.dest)
}

def sources = Task.Source(millSourcePath / "src")
def sources = Task.Source("src")
def allSources = Task { os.walk(sources().path).filter(_.ext == "ts").map(PathRef(_)) }

def compile: T[(PathRef, PathRef)] = Task {
Expand Down
2 changes: 1 addition & 1 deletion example/extending/typescript/4-npm-deps-bundle/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ trait TypeScriptModule extends Module {
PathRef(Task.dest)
}

def sources = Task.Source(millSourcePath / "src")
def sources = Task.Source("src")
def allSources = Task { os.walk(sources().path).filter(_.ext == "ts").map(PathRef(_)) }

def compile: T[(PathRef, PathRef)] = Task {
Expand Down
6 changes: 3 additions & 3 deletions example/fundamentals/modules/6-modules/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ object foo2 extends FooModule {
// module expects its input files to be on disk.

trait MyModule extends Module {
def sources = Task.Source(millSourcePath / "sources")
def sources = Task.Source("sources")
def task = Task { "hello " + os.list(sources().path).map(os.read(_)).mkString(" ") }
}

Expand Down Expand Up @@ -238,7 +238,7 @@ object outer2 extends MyModule {
//

trait Foo extends Module {
def sourceRoots = Task.Sources(millSourcePath / "src")
def sourceRoots = Task.Sources("src")
def sourceContents = Task {
sourceRoots()
.flatMap(pref => os.walk(pref.path))
Expand All @@ -249,7 +249,7 @@ trait Foo extends Module {
}

trait Bar extends Foo {
def additionalSources = Task.Sources(millSourcePath / "src2")
def additionalSources = Task.Sources("src2")
def sourceRoots = Task { super.sourceRoots() ++ additionalSources() }
}

Expand Down
2 changes: 1 addition & 1 deletion example/fundamentals/modules/8-diy-java-modules/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ trait DiyJavaModule extends Module {
def mainClass: T[Option[String]] = None

def upstream: T[Seq[PathRef]] = Task { Task.traverse(moduleDeps)(_.classPath)().flatten }
def sources = Task.Source(millSourcePath / "src")
def sources = Task.Source("src")

def compile = Task {
val allSources = os.walk(sources().path)
Expand Down
4 changes: 2 additions & 2 deletions example/fundamentals/tasks/1-task-graph/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import mill._

def mainClass: T[Option[String]] = Some("foo.Foo")

def sources = Task.Source(millSourcePath / "src")
def resources = Task.Source(millSourcePath / "resources")
def sources = Task.Source("src")
def resources = Task.Source("resources")

def compile = Task {
val allSources = os.walk(sources().path)
Expand Down
4 changes: 2 additions & 2 deletions example/fundamentals/tasks/2-primary-tasks/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ package build

import mill.{Module, T, _}

def sources = Task.Source { millSourcePath / "src" }
def resources = Task.Source { millSourcePath / "resources" }
def sources = Task.Source { "src" }
def resources = Task.Source { "resources" }

// ``Source``s are defined using `Task.Source{...}` taking one `os.Path`, or `Task.Sources{...}`,
// taking multiple ``os.Path``s as arguments. A ``Source``'s:
Expand Down
2 changes: 1 addition & 1 deletion example/fundamentals/tasks/3-anonymous-tasks/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package build
import mill._, define.Task

def data = Task.Source(millSourcePath / "data")
def data = Task.Source("data")

def anonTask(fileName: String): Task[String] = Task.Anon {
os.read(data().path / fileName)
Expand Down
2 changes: 1 addition & 1 deletion example/fundamentals/tasks/5-persistent-tasks/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import java.util.Arrays
import java.io.ByteArrayOutputStream
import java.util.zip.GZIPOutputStream

def data = Task.Source(millSourcePath / "data")
def data = Task.Source("data")

def compressedData = Task(persistent = true) {
println("Evaluating compressedData")
Expand Down
2 changes: 1 addition & 1 deletion example/fundamentals/tasks/6-workers/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import java.util.Arrays
import java.io.ByteArrayOutputStream
import java.util.zip.GZIPOutputStream

def data = Task.Source(millSourcePath / "data")
def data = Task.Source("data")

def compressWorker = Task.Worker { new CompressWorker(Task.dest) }

Expand Down
2 changes: 1 addition & 1 deletion example/javalib/module/15-jni/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import mill._, javalib._, util.Jvm

object `package` extends RootModule with JavaModule {
// Additional source folder to put C sources
def nativeSources = Task.Sources(millSourcePath / "native-src")
def nativeSources = Task.Sources("native-src")

// Auto-generate JNI `.h` files from Java classes using Javac
def nativeHeaders = Task {
Expand Down
2 changes: 1 addition & 1 deletion example/javalib/module/7-resources/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import mill._, javalib._

object foo extends JavaModule {
object test extends JavaTests with TestModule.Junit4 {
def otherFiles = Task.Source(millSourcePath / "other-files")
def otherFiles = Task.Source("other-files")

def forkEnv = super.forkEnv() ++ Map(
"OTHER_FILES_DIR" -> otherFiles().path.toString
Expand Down
2 changes: 1 addition & 1 deletion example/javalib/publishing/3-revapi/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ object bar extends JavaModule with RevapiModule {

override def revapiConfigFiles: T[Seq[PathRef]] =
// add Revapi config JSON file(s)
Task.Sources(millSourcePath / "conf/revapi.json")
Task.Sources("conf/revapi.json")

override def revapiClasspath: T[Agg[PathRef]] = Task {
// add folder containing logback.xml
Expand Down
Loading
Loading