Skip to content

Commit

Permalink
Remove unnecessary .Sources (#4120)
Browse files Browse the repository at this point in the history
Lots of these can just be normal `Task`s, since they simply rely on
upstream `Task.Sources` but do not add any source paths themselves. And
since 0.11.x they're all the same type anyway so changing back and forth
doesn't break compatibility

This speeds up `selective.prepare` on the com-lihaoyi/mill codebase
considerably, since we need to evaluate all sources (and their
transitive upstream tasks) up-front to decide what sources changed and
determine the downstream tasks to run. Before this PR this ended up
compiling a bunch of Scala code, after this PR it no longer does so
  • Loading branch information
lihaoyi authored Dec 13, 2024
1 parent 18b074a commit 4a0046f
Show file tree
Hide file tree
Showing 11 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ trait BridgeModule extends MillPublishJavaModule with CrossScalaModule {
ivy"org.scala-lang:scala-compiler:${crossScalaVersion}"
)

def resources = Task.Sources {
def resources = Task {
os.copy(generatedSources().head.path / "META-INF", Task.dest / "META-INF")
Seq(PathRef(Task.dest))
}
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 @@ -8,6 +8,6 @@ private[playlib] trait Layout extends JavaModule {
def conf = Task.Sources { millSourcePath / "conf" }
def app = Task.Sources { millSourcePath / "app" }

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

trait Twirl extends TwirlModule with Layout {

override def twirlSources = Task.Sources { app() }
override def twirlSources = Task { app() }

override def twirlImports = Task {
super.twirlImports() ++ Seq(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ object PlayModuleTests extends TestSuite with PlayTestSuite {
app.value.map(_.path.relativeTo(playmulti.millSourcePath).toString()) == Seq(
"core/app"
),
sources == app,
sources.value == app.value,
resources.value.map(_.path.relativeTo(playmulti.millSourcePath).toString()).contains(
"core/conf"
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ object PlaySingleApiModuleTests extends TestSuite with PlayTestSuite {
"conf"
),
app.value.map(_.path.relativeTo(playsingleapi.millSourcePath).toString()) == Seq("app"),
sources == app,
resources == conf,
sources.value == app.value,
resources.value == conf.value,
testSources.value.map(
_.path.relativeTo(playsingleapi.millSourcePath).toString()
) == Seq(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ object PlaySingleModuleTests extends TestSuite with PlayTestSuite {
assert(
conf.value.map(_.path.relativeTo(playsingle.millSourcePath).toString()) == Seq("conf"),
app.value.map(_.path.relativeTo(playsingle.millSourcePath).toString()) == Seq("app"),
sources == app,
sources.value == app.value,
resources.value.map(_.path.relativeTo(playsingle.millSourcePath).toString()).contains(
"conf"
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ trait ScoverageModule extends ScalaModule { outer: ScalaModule =>
override def allSources: T[Seq[PathRef]] = Task { outer.allSources() }
override def moduleDeps: Seq[JavaModule] = outer.moduleDeps
override def compileModuleDeps: Seq[JavaModule] = outer.compileModuleDeps
override def sources: T[Seq[PathRef]] = Task.Sources { outer.sources() }
override def resources: T[Seq[PathRef]] = Task.Sources { outer.resources() }
override def sources: T[Seq[PathRef]] = Task { outer.sources() }
override def resources: T[Seq[PathRef]] = Task { outer.resources() }
override def scalaVersion = Task { outer.scalaVersion() }
override def repositoriesTask: Task[Seq[Repository]] = Task.Anon { outer.repositoriesTask() }
override def compileIvyDeps: T[Agg[Dep]] = Task { outer.compileIvyDeps() }
Expand Down
2 changes: 1 addition & 1 deletion example/extending/metabuild/4-meta-build/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ object `package` extends RootModule with ScalaModule {
)

def htmlSnippet = Task { h1("hello").toString }
def resources = Task.Sources {
def resources = Task {
os.write(Task.dest / "snippet.txt", htmlSnippet())
super.resources() ++ Seq(PathRef(Task.dest))
}
Expand Down
8 changes: 4 additions & 4 deletions example/pythonlib/module/3-override-tasks/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package build
import mill._, pythonlib._

object foo extends PythonModule {
def sources = Task.Sources {
def sources = Task {
val destPath = Task.dest / "src"
os.makeDir.all(destPath)

Expand All @@ -20,7 +20,7 @@ object foo extends PythonModule {
Seq(PathRef(destPath))
}

def mainScript = Task.Source { sources().head.path / "foo.py" }
def mainScript = Task { PathRef(sources().head.path / "foo.py") }

def typeCheck = Task {
println("Type Checking...")
Expand Down Expand Up @@ -53,7 +53,7 @@ object foo2 extends PythonModule {
Seq(PathRef(destPath))
}

def mainScript = Task.Source { generatedSources().head.path / "foo.py" }
def mainScript = Task { PathRef(generatedSources().head.path / "foo.py") }

}

Expand All @@ -64,7 +64,7 @@ object foo3 extends PythonModule {
os.write(destPath / "foo.py", """...""")
super.sources() ++ Seq(PathRef(destPath))
}
def mainScript = Task.Source { sources().head.path / "foo.py" }
def mainScript = Task { PathRef(sources().head.path / "foo.py") }

}

Expand Down
2 changes: 1 addition & 1 deletion scalalib/src/mill/scalalib/JavaModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,7 @@ trait JavaModule
* Typically, includes the source files to generate documentation from.
* @see [[docResources]]
*/
def docSources: T[Seq[PathRef]] = Task.Sources(allSources())
def docSources: T[Seq[PathRef]] = Task { allSources() }

/**
* Extra directories to be copied into the documentation.
Expand Down
2 changes: 1 addition & 1 deletion scalalib/src/mill/scalalib/ScalaModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ trait ScalaModule extends JavaModule with TestModule.ScalaModuleBase { outer =>
}
}

override def docSources: T[Seq[PathRef]] = Task.Sources {
override def docSources: T[Seq[PathRef]] = Task {
if (
ZincWorkerUtil.isScala3(scalaVersion()) && !ZincWorkerUtil.isScala3Milestone(scalaVersion())
) Seq(compile().classes)
Expand Down

0 comments on commit 4a0046f

Please sign in to comment.