Skip to content

Commit ac00443

Browse files
authored
Allow Task.Source/Task.Sources to be constructed directly from subpath string literals (#4486)
First step in #4447, by providing an alternative to the previous `os.Path` APIs. Effectively this allows us to replace ```scala def mainScript = Task.Source { millSourcePath / "src/foo.py" } ``` with ```scala def mainScript = Task.Source { "src/foo.py" } ``` Pulls in com-lihaoyi/os-lib#353 from upstream to make constructing `os.SubPath`s more ergonomic by eliding the lead `os.sub /` prefix in the case of literal strings while still maintaining a degree of safety: * "outer" paths starting with `..`s and absolute paths starting with `/` are rejected at compile time * Only literal strings are converted implicitly, anything non-literal needs to be an explicit `os.SubPath` For now we provide this as an alternative to passing in an absolute `os.Path`, but probably 99% of scenarios should be using this sub-path API rather than absolute paths since (a) it's more concise and (b) your sources should be within your `millSourcePath` anyway. I'm not sure we can get rid of the `os.Path`-taking API entirely, but we can definitely de-prioritize it and call it `SourcesUnsafe` or something so that anyone who needs it can use it but most people won't use it accidentally
1 parent cdf6055 commit ac00443

File tree

85 files changed

+203
-139
lines changed

Some content is hidden

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

85 files changed

+203
-139
lines changed

build.mill

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ object Deps {
158158
val junitInterface = ivy"com.github.sbt:junit-interface:0.13.3"
159159
val commonsIo = ivy"commons-io:commons-io:2.18.0"
160160
val log4j2Core = ivy"org.apache.logging.log4j:log4j-core:2.24.3"
161-
val osLib = ivy"com.lihaoyi::os-lib:0.11.4-M5"
161+
val osLib = ivy"com.lihaoyi::os-lib:0.11.4-M6"
162162
val pprint = ivy"com.lihaoyi::pprint:0.9.0"
163163
val mainargs = ivy"com.lihaoyi::mainargs:0.7.6"
164164
val millModuledefsVersion = "0.11.3-M3"
@@ -398,7 +398,7 @@ trait MillJavaModule extends JavaModule {
398398

399399
def writeLocalTestOverrides = Task.Anon {
400400
for ((k, v) <- testTransitiveDeps()) {
401-
os.write(Task.dest / "mill" / "local-test-overrides" / k, v, createFolders = true)
401+
os.write(Task.dest / "mill/local-test-overrides" / k, v, createFolders = true)
402402
}
403403
Seq(PathRef(Task.dest))
404404
}

contrib/playlib/src/mill/playlib/Layout.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import mill.scalalib._
55

66
private[playlib] trait Layout extends JavaModule {
77

8-
def conf = Task.Sources { millSourcePath / "conf" }
9-
def app = Task.Sources { millSourcePath / "app" }
8+
def conf = Task.Sources { "conf" }
9+
def app = Task.Sources { "app" }
1010

1111
override def sources = Task { app() }
1212
override def resources = Task { conf() }

contrib/playlib/src/mill/playlib/RouterModule.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import mill.{Agg, T, Task}
99

1010
trait RouterModule extends ScalaModule with Version {
1111

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

1414
def routeFiles = Task {
1515
val paths = routes().flatMap(file => os.walk(file.path))

contrib/playlib/src/mill/playlib/Static.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ trait Static extends ScalaModule {
2525
/**
2626
* Directories to include assets from
2727
*/
28-
def assetSources = Task.Sources { millSourcePath / assetsPath() }
28+
def assetSources = Task.Sources { os.sub / assetsPath() }
2929

3030
/*
3131
Collected static assets for the project

contrib/versionfile/src/mill/contrib/versionfile/VersionFileModule.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import mill._
55
trait VersionFileModule extends Module {
66

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

1010
/** The current version. */
1111
def currentVersion: T[Version] = Task { Version.of(os.read(versionFile().path).trim) }

dist/package.mill

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ trait InstallModule extends build.MillPublishJavaModule {
4141
def installLocalCache() = Task.Command {
4242
val path = installLocalTask(
4343
Task.Anon(
44-
(os.home / ".cache" / "mill" / "download" / (build.millVersion() + batExt)).toString()
44+
(os.home / ".cache/mill/download" / (build.millVersion() + batExt)).toString()
4545
)
4646
)()
4747
Task.log.outputStream.println(path.toString())

docs/modules/ROOT/pages/comparisons/maven.adoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ import $ivy.`ant:ant-optional:1.5.3-1`
391391

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

522522
```scala
523-
def makefile = Task.Source(millSourcePath / "Makefile")
524-
def cSources = Task.Source(millSourcePath / "src" / "main" / "c")
523+
def makefile = Task.Source("Makefile")
524+
def cSources = Task.Source("src" / "main" / "c")
525525
def cHeaders = Task {
526526
for(p <- os.walk(cSources().path) if p.ext == "h"){
527527
os.copy(p, Task.dest / p.relativeTo(cSources().path), createFolders = true)

docs/modules/ROOT/pages/comparisons/unique.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,8 @@ them into classfiles, and then the `jar` executable to package them together int
176176
```scala
177177
def mainClass: T[Option[String]] = Some("foo.Foo")
178178

179-
def sources = Task.Source(millSourcePath / "src")
180-
def resources = Task.Source(millSourcePath / "resources")
179+
def sources = Task.Source("src")
180+
def resources = Task.Source("resources")
181181

182182
def compile = Task {
183183
val allSources = os.walk(sources().path)

docs/package.mill

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,16 @@ object `package` extends RootModule {
6868
envArgs = Map("CI" -> "true"),
6969
workingDir = workDir
7070
)
71-
PathRef(workDir / "build" / "site")
71+
PathRef(workDir / "build/site")
7272
}
7373

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

79-
val pagesWd = Task.dest / "modules" / "ROOT" / "pages"
80-
val partialsWd = Task.dest / "modules" / "ROOT" / "partials"
79+
val pagesWd = Task.dest / "modules/ROOT/pages"
80+
val partialsWd = Task.dest / "modules/ROOT/partials"
8181

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

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

372372
PathRef(siteDir)
373373
}

example/extending/jvmcode/1-subprocess/build.mill

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ object foo extends JavaModule {
2222
defaultResolver().resolveDeps(Agg(ivy"org.codehaus.groovy:groovy:3.0.9"))
2323
}
2424

25-
def groovyScript = Task.Source(millSourcePath / "generate.groovy")
25+
def groovyScript = Task.Source("generate.groovy")
2626

2727
def groovyGeneratedResources = Task {
2828
Jvm.runSubprocess(

0 commit comments

Comments
 (0)