diff --git a/bsp/worker/src/mill/bsp/worker/MillJvmBuildServer.scala b/bsp/worker/src/mill/bsp/worker/MillJvmBuildServer.scala index 925c7f9295d..5accb18cb51 100644 --- a/bsp/worker/src/mill/bsp/worker/MillJvmBuildServer.scala +++ b/bsp/worker/src/mill/bsp/worker/MillJvmBuildServer.scala @@ -53,7 +53,7 @@ private trait MillJvmBuildServer extends JvmBuildServer { this: MillBuildServer m.forkWorkingDir(), m.forkEnv(), m.mainClass(), - m.zincWorker.worker(), + m.zincWorker().worker(), m.compile() ) } diff --git a/bsp/worker/src/mill/bsp/worker/MillScalaBuildServer.scala b/bsp/worker/src/mill/bsp/worker/MillScalaBuildServer.scala index 5eb83900476..84d6da7fb03 100644 --- a/bsp/worker/src/mill/bsp/worker/MillScalaBuildServer.scala +++ b/bsp/worker/src/mill/bsp/worker/MillScalaBuildServer.scala @@ -70,7 +70,7 @@ private trait MillScalaBuildServer extends ScalaBuildServer { this: MillBuildSer hint = "buildTargetScalaMainClasses", targetIds = _ => p.getTargets.asScala.toSeq, tasks = { case m: JavaModule => - T.task((m.zincWorker.worker(), m.compile(), m.forkArgs(), m.forkEnv())) + T.task((m.zincWorker().worker(), m.compile(), m.forkArgs(), m.forkEnv())) } ) { case (state, id, m: JavaModule, (worker, compile, forkArgs, forkEnv)) => diff --git a/build.sc b/build.sc index d5f2755519c..20fe84f7e44 100644 --- a/build.sc +++ b/build.sc @@ -319,7 +319,26 @@ trait MillJavaModule extends JavaModule { ) } -trait MillMimaConfig extends Module { +trait MillMimaConfig extends mima.Mima { + override def mimaPreviousVersions: T[Seq[String]] = Settings.mimaBaseVersions + override def mimaPreviousArtifacts: T[Agg[Dep]] = T { + Agg.from( + Settings.mimaBaseVersions + .filter(v => !skipPreviousVersions().contains(v)) + .map(version => + ivy"${pomSettings().organization}:${artifactId()}:${version}" + ) + ) + } + override def mimaExcludeAnnotations: T[Seq[String]] = Seq( + "mill.api.internal", + "mill.api.experimental" + ) + override def mimaCheckDirection: Target[CheckDirection] = T { CheckDirection.Backward } + override def mimaBinaryIssueFilters: Target[Seq[ProblemFilter]] = T { + issueFilterByModule.getOrElse(this, Seq()) + } + lazy val issueFilterByModule: Map[MillMimaConfig, Seq[ProblemFilter]] = Map() def skipPreviousVersions: T[Seq[String]] = T(Seq.empty[String]) } diff --git a/ci/mill-bootstrap.patch b/ci/mill-bootstrap.patch index e69de29bb2d..f93cf3785a1 100644 --- a/ci/mill-bootstrap.patch +++ b/ci/mill-bootstrap.patch @@ -0,0 +1,235 @@ +diff --git a/build.sc b/build.sc +index 20fe84f7e4..869c3ba31e 100644 +--- a/build.sc ++++ b/build.sc +@@ -2,23 +2,23 @@ + import $file.ci.shared + import $file.ci.upload + import $ivy.`org.scalaj::scalaj-http:2.4.2` +-import $ivy.`de.tototec::de.tobiasroeser.mill.vcs.version::0.3.1-6-e80da7` ++//import $ivy.`de.tototec::de.tobiasroeser.mill.vcs.version::0.3.1-6-e80da7` + +-import $ivy.`com.github.lolgab::mill-mima::0.0.20` ++//import $ivy.`com.github.lolgab::mill-mima::0.0.20` + import $ivy.`net.sourceforge.htmlcleaner:htmlcleaner:2.25` + + // imports +-import com.github.lolgab.mill.mima +-import com.github.lolgab.mill.mima.{ +- CheckDirection, +- DirectMissingMethodProblem, +- IncompatibleMethTypeProblem, +- IncompatibleSignatureProblem, +- ProblemFilter, +- ReversedMissingMethodProblem +-} ++//import com.github.lolgab.mill.mima ++//import com.github.lolgab.mill.mima.{ ++// CheckDirection, ++// DirectMissingMethodProblem, ++// IncompatibleMethTypeProblem, ++// IncompatibleSignatureProblem, ++// ProblemFilter, ++// ReversedMissingMethodProblem ++//} + import coursier.maven.MavenRepository +-import de.tobiasroeser.mill.vcs.version.VcsVersion ++//import de.tobiasroeser.mill.vcs.version.VcsVersion + import mill._ + import mill.eval.Evaluator + import mill.main.MainModule +@@ -167,11 +167,12 @@ object Deps { + val requests = ivy"com.lihaoyi::requests:0.8.0" + } + +-def millVersion: T[String] = T { VcsVersion.vcsState().format() } ++def millVersion: T[String] = T { "dev"/*VcsVersion.vcsState().format()*/ } + def millLastTag: T[String] = T { +- VcsVersion.vcsState().lastTag.getOrElse( +- sys.error("No (last) git tag found. Your git history seems incomplete!") +- ) ++// VcsVersion.vcsState().lastTag.getOrElse( ++// sys.error("No (last) git tag found. Your git history seems incomplete!") ++// ) ++ "dev" + } + def millBinPlatform: T[String] = T { + val tag = millLastTag() +@@ -319,26 +320,26 @@ trait MillJavaModule extends JavaModule { + ) + } + +-trait MillMimaConfig extends mima.Mima { +- override def mimaPreviousVersions: T[Seq[String]] = Settings.mimaBaseVersions +- override def mimaPreviousArtifacts: T[Agg[Dep]] = T { +- Agg.from( +- Settings.mimaBaseVersions +- .filter(v => !skipPreviousVersions().contains(v)) +- .map(version => +- ivy"${pomSettings().organization}:${artifactId()}:${version}" +- ) +- ) +- } +- override def mimaExcludeAnnotations: T[Seq[String]] = Seq( +- "mill.api.internal", +- "mill.api.experimental" +- ) +- override def mimaCheckDirection: Target[CheckDirection] = T { CheckDirection.Backward } +- override def mimaBinaryIssueFilters: Target[Seq[ProblemFilter]] = T { +- issueFilterByModule.getOrElse(this, Seq()) +- } +- lazy val issueFilterByModule: Map[MillMimaConfig, Seq[ProblemFilter]] = Map() ++trait MillMimaConfig extends Module/*mima.Mima*/ { ++// override def mimaPreviousVersions: T[Seq[String]] = Settings.mimaBaseVersions ++// override def mimaPreviousArtifacts: T[Agg[Dep]] = T { ++// Agg.from( ++// Settings.mimaBaseVersions ++// .filter(v => !skipPreviousVersions().contains(v)) ++// .map(version => ++// ivy"${pomSettings().organization}:${artifactId()}:${version}" ++// ) ++// ) ++// } ++// override def mimaExcludeAnnotations: T[Seq[String]] = Seq( ++// "mill.api.internal", ++// "mill.api.experimental" ++// ) ++// override def mimaCheckDirection: Target[CheckDirection] = T { CheckDirection.Backward } ++// override def mimaBinaryIssueFilters: Target[Seq[ProblemFilter]] = T { ++// issueFilterByModule.getOrElse(this, Seq()) ++// } ++// lazy val issueFilterByModule: Map[MillMimaConfig, Seq[ProblemFilter]] = Map() + def skipPreviousVersions: T[Seq[String]] = T(Seq.empty[String]) + } + +@@ -425,10 +426,9 @@ trait BaseMillTestsModule extends TestModule { + + /** A MillScalaModule with default set up test module. */ + trait MillAutoTestSetup extends MillScalaModule { +- // instead of `object test` which can't be overridden, we hand-made a val+class singleton + /** Default tests module. */ +- val test = new Tests(implicitly) +- class Tests(ctx0: mill.define.Ctx) extends mill.Module()(ctx0) with super.MillScalaModuleTests ++ lazy val test: Tests = new Tests {} ++ trait Tests extends super.MillScalaModuleTests + } + + /** Published module which does not contain strictly handled API. */ +@@ -917,8 +917,8 @@ object bsp extends MillModule with BuildInfo { + ) + } + +- override val test = new Test(implicitly) +- class Test(ctx0: mill.define.Ctx) extends Tests(ctx0) { ++ override lazy val test: Test = new Test {} ++ trait Test extends Tests{ + override def forkEnv: Target[Map[String, String]] = T { + // We try to fetch this dependency with coursier in the tests + bsp.worker.publishLocal()() +@@ -1066,7 +1066,7 @@ object example extends MillScalaModule { + val title = + if (seenCode) "" + else { +- val label = VcsVersion.vcsState().format() ++ val label = millVersion() + val exampleDashed = examplePath.segments.mkString("-") + val download = s"{mill-download-url}/$label-$exampleDashed.zip[download]" + val browse = s"{mill-example-url}/$examplePath[browse]" +@@ -1744,7 +1744,7 @@ def exampleZips: Target[Seq[PathRef]] = T { + examplePath = exampleMod.millSourcePath + } yield { + val example = examplePath.subRelativeTo(T.workspace) +- val exampleStr = VcsVersion.vcsState().format() + "-" + example.segments.mkString("-") ++ val exampleStr = millVersion() + "-" + example.segments.mkString("-") + os.copy(examplePath, T.dest / exampleStr, createFolders = true) + os.copy(bootstrapLauncher().path, T.dest / exampleStr / "mill") + val zip = T.dest / s"$exampleStr.zip" +@@ -1754,47 +1754,47 @@ def exampleZips: Target[Seq[PathRef]] = T { + } + + def uploadToGithub(authKey: String) = T.command { +- val vcsState = VcsVersion.vcsState() +- val label = vcsState.format() +- if (label != millVersion()) sys.error("Modified mill version detected, aborting upload") +- val releaseTag = vcsState.lastTag.getOrElse(sys.error( +- "Incomplete git history. No tag found.\nIf on CI, make sure your git checkout job includes enough history." +- )) +- +- if (releaseTag == label) { +- // TODO: check if the tag already exists (e.g. because we created it manually) and do not fail +- scalaj.http.Http( +- s"https://api.github.com/repos/${Settings.githubOrg}/${Settings.githubRepo}/releases" +- ) +- .postData( +- ujson.write( +- ujson.Obj( +- "tag_name" -> releaseTag, +- "name" -> releaseTag +- ) +- ) +- ) +- .header("Authorization", "token " + authKey) +- .asString +- } +- +- val examples = exampleZips().map(z => (z.path, z.path.last)) +- +- val zips = examples ++ Seq( +- (dev.assembly().path, label + "-assembly"), +- (bootstrapLauncher().path, label) +- ) +- +- for ((zip, name) <- zips) { +- upload.apply( +- zip, +- releaseTag, +- name, +- authKey, +- Settings.githubOrg, +- Settings.githubRepo +- ) +- } ++// val vcsState = VcsVersion.vcsState() ++// val label = vcsState.format() ++// if (label != millVersion()) sys.error("Modified mill version detected, aborting upload") ++// val releaseTag = vcsState.lastTag.getOrElse(sys.error( ++// "Incomplete git history. No tag found.\nIf on CI, make sure your git checkout job includes enough history." ++// )) ++// ++// if (releaseTag == label) { ++// // TODO: check if the tag already exists (e.g. because we created it manually) and do not fail ++// scalaj.http.Http( ++// s"https://api.github.com/repos/${Settings.githubOrg}/${Settings.githubRepo}/releases" ++// ) ++// .postData( ++// ujson.write( ++// ujson.Obj( ++// "tag_name" -> releaseTag, ++// "name" -> releaseTag ++// ) ++// ) ++// ) ++// .header("Authorization", "token " + authKey) ++// .asString ++// } ++// ++// val examples = exampleZips().map(z => (z.path, z.path.last)) ++// ++// val zips = examples ++ Seq( ++// (dev.assembly().path, label + "-assembly"), ++// (bootstrapLauncher().path, label) ++// ) ++// ++// for ((zip, name) <- zips) { ++// upload.apply( ++// zip, ++// releaseTag, ++// name, ++// authKey, ++// Settings.githubOrg, ++// Settings.githubRepo ++// ) ++// } + } + + def validate(ev: Evaluator): Command[Unit] = T.command { diff --git a/contrib/scoverage/src/mill/contrib/scoverage/ScoverageModule.scala b/contrib/scoverage/src/mill/contrib/scoverage/ScoverageModule.scala index 730cd6c016d..d2c6df66109 100644 --- a/contrib/scoverage/src/mill/contrib/scoverage/ScoverageModule.scala +++ b/contrib/scoverage/src/mill/contrib/scoverage/ScoverageModule.scala @@ -172,9 +172,9 @@ trait ScoverageModule extends ScalaModule { outer: ScalaModule => ) } - val scoverage: ScoverageData = new ScoverageData(implicitly) + lazy val scoverage = new ScoverageData {} - class ScoverageData(ctx0: mill.define.Ctx) extends Module()(ctx0) with ScalaModule { + trait ScoverageData extends ScalaModule { def doReport(reportType: ReportType): Task[Unit] = T.task { ScoverageReportWorker diff --git a/contrib/twirllib/src/mill/twirllib/TwirlModule.scala b/contrib/twirllib/src/mill/twirllib/TwirlModule.scala index 367cccc5e61..7bd6a46e364 100644 --- a/contrib/twirllib/src/mill/twirllib/TwirlModule.scala +++ b/contrib/twirllib/src/mill/twirllib/TwirlModule.scala @@ -46,8 +46,7 @@ trait TwirlModule extends mill.Module { twirlModule => * Class instead of an object, to allow re-configuration. * @since Mill after 0.10.5 */ - class TwirlResolver()(implicit ctx0: mill.define.Ctx) extends mill.Module()(ctx0) - with CoursierModule { + trait TwirlResolver extends CoursierModule { override def resolveCoursierDependency: Task[Dep => Dependency] = T.task { d: Dep => Lib.depToDependency(d, twirlScalaVersion()) } @@ -61,7 +60,7 @@ trait TwirlModule extends mill.Module { twirlModule => /** * @since Mill after 0.10.5 */ - val twirlCoursierResolver = new TwirlResolver() + lazy val twirlCoursierResolver = new TwirlResolver {} def twirlClasspath: T[Loose.Agg[PathRef]] = T { twirlCoursierResolver.resolveDeps(T.task { diff --git a/example/scalamodule/11-repository-config/build.sc b/example/scalamodule/11-repository-config/build.sc index 84011c2c80a..965582996ba 100644 --- a/example/scalamodule/11-repository-config/build.sc +++ b/example/scalamodule/11-repository-config/build.sc @@ -2,6 +2,7 @@ // your own resolvers by overriding the `repositoriesTask` task in the module: import mill._, scalalib._ +import mill.define.ModuleRef import coursier.maven.MavenRepository val sonatypeReleases = Seq( @@ -26,7 +27,7 @@ object CustomZincWorkerModule extends ZincWorkerModule with CoursierModule { object bar extends ScalaModule { def scalaVersion = "2.13.8" - def zincWorker = CustomZincWorkerModule + def zincWorker = ModuleRef(CustomZincWorkerModule) // ... rest of your build definitions def repositoriesTask = T.task {super.repositoriesTask() ++ sonatypeReleases} diff --git a/main/define/src/mill/define/BaseModule.scala b/main/define/src/mill/define/BaseModule.scala index cf70204fa36..aba9dda0522 100644 --- a/main/define/src/mill/define/BaseModule.scala +++ b/main/define/src/mill/define/BaseModule.scala @@ -11,12 +11,10 @@ abstract class BaseModule( )(implicit millModuleEnclosing0: sourcecode.Enclosing, millModuleLine0: sourcecode.Line, - millName0: sourcecode.Name, millFile0: sourcecode.File, caller: Caller -) extends Module()( +) extends Module.BaseClass()( mill.define.Ctx.make( - implicitly, implicitly, implicitly, Ctx.BasePath(millSourcePath0), @@ -26,7 +24,7 @@ abstract class BaseModule( millFile0, caller ) - ) { + ) with Module { // A BaseModule should provide an empty Segments list to it's children, since // it is the root of the module tree, and thus must not include it's own // sourcecode.Name as part of the list, @@ -40,13 +38,11 @@ abstract class BaseModule( abstract class ExternalModule(implicit millModuleEnclosing0: sourcecode.Enclosing, - millModuleLine0: sourcecode.Line, - millName0: sourcecode.Name + millModuleLine0: sourcecode.Line ) extends BaseModule(os.pwd, external0 = true, foreign0 = None)( implicitly, implicitly, implicitly, - implicitly, Caller(()) ) { diff --git a/main/define/src/mill/define/Cross.scala b/main/define/src/mill/define/Cross.scala index 895d0462569..bdd3aa98a9b 100644 --- a/main/define/src/mill/define/Cross.scala +++ b/main/define/src/mill/define/Cross.scala @@ -277,7 +277,7 @@ object Cross { */ class Cross[M <: Cross.Module[_]](factories: Cross.Factory[M]*)(implicit ctx: mill.define.Ctx -) extends mill.define.Module()(ctx) { +) extends mill.define.Module { trait Item { def crossValues: List[Any] diff --git a/main/define/src/mill/define/Ctx.scala b/main/define/src/mill/define/Ctx.scala index c90fbb30fcf..c6f90d9d3c9 100644 --- a/main/define/src/mill/define/Ctx.scala +++ b/main/define/src/mill/define/Ctx.scala @@ -83,7 +83,6 @@ object Ctx { implicit def make(implicit millModuleEnclosing0: sourcecode.Enclosing, millModuleLine0: sourcecode.Line, - millName0: sourcecode.Name, millModuleBasePath0: BasePath, segments0: Segments, external0: External, @@ -94,7 +93,12 @@ object Ctx { Ctx( millModuleEnclosing0.value, millModuleLine0.value, - Segment.Label(millName0.value), + Segment.Label( + // Manually break apart `sourcecode.Enclosing` instead of using + // `sourcecode.Name` to work around bug with anonymous classes + // returning `$anon` names + millModuleEnclosing0.value.split("\\.|#| ").filter(!_.startsWith("$anon")).last + ), millModuleBasePath0.value, segments0, external0.value, diff --git a/main/define/src/mill/define/Module.scala b/main/define/src/mill/define/Module.scala index 9f802756f7d..b97c7482b86 100644 --- a/main/define/src/mill/define/Module.scala +++ b/main/define/src/mill/define/Module.scala @@ -14,8 +14,7 @@ import scala.reflect.ClassTag * instantiation site so they can capture the enclosing/line information of * the concrete instance. */ -class Module(implicit outerCtx0: mill.define.Ctx) extends mill.moduledefs.Cacher with Module.Trait { - outer => +trait Module extends Module.BaseClass { /** * Miscellaneous machinery around traversing & querying the build hierarchy, @@ -24,26 +23,41 @@ class Module(implicit outerCtx0: mill.define.Ctx) extends mill.moduledefs.Cacher object millInternal extends Module.Internal(this) def millModuleDirectChildren: Seq[Module] = millModuleDirectChildrenImpl + // We keep a private `lazy val` and a public `def` so // subclasses can call `super.millModuleDirectChildren` private lazy val millModuleDirectChildrenImpl: Seq[Module] = millInternal.reflectNestedObjects[Module]().toSeq - def millOuterCtx: Ctx = outerCtx0 + + def millOuterCtx: Ctx + def millSourcePath: os.Path = millOuterCtx.millSourcePath / (millOuterCtx.segment match { case Segment.Label(s) => Seq(s) case Segment.Cross(_) => Seq.empty[String] // drop cross segments }) + implicit def millModuleExternal: Ctx.External = Ctx.External(millOuterCtx.external) implicit def millModuleShared: Ctx.Foreign = Ctx.Foreign(millOuterCtx.foreign) implicit def millModuleBasePath: Ctx.BasePath = Ctx.BasePath(millSourcePath) implicit def millModuleSegments: Segments = { millOuterCtx.segments ++ Seq(millOuterCtx.segment) } + override def toString = millModuleSegments.render } object Module { - trait Trait + + /** + * Base class of the [[Module]] trait, allowing us to take implicit arguments + * (traits cannot). Cannot be used directly, because traits inheriting from + * classes results in the class being invisible to java reflection, which + * messes up the module discovery process + */ + class BaseClass(implicit outerCtx0: mill.define.Ctx) extends mill.moduledefs.Cacher { + def millOuterCtx = outerCtx0 + } + @internal class Internal(outer: Module) { def traverse[T](f: Module => Seq[T]): Seq[T] = { diff --git a/main/define/src/mill/define/ModuleRef.scala b/main/define/src/mill/define/ModuleRef.scala new file mode 100644 index 00000000000..a3a6c87c26f --- /dev/null +++ b/main/define/src/mill/define/ModuleRef.scala @@ -0,0 +1,9 @@ +package mill.define + +/** + * Used to refer to a module from another module without including the target + * module as a child-module of the first. + */ +case class ModuleRef[+T <: mill.define.Module](t: T) { + def apply(): T = t +} diff --git a/main/define/src/mill/define/Reflect.scala b/main/define/src/mill/define/Reflect.scala index 8a3060e13bd..0549c7476c0 100644 --- a/main/define/src/mill/define/Reflect.scala +++ b/main/define/src/mill/define/Reflect.scala @@ -36,12 +36,19 @@ private[mill] object Reflect { if (outer.toString.contains("BarModule")) pprint.log(inner) if (outer.toString.contains("BarModule")) pprint.log(res) // There can be multiple methods of the same name on a class if a sub-class - // overrides a super-class method and narrows the return type. Make sure we - // sort the methods by their declaring class from lowest to highest in the - // the type hierarchy, and use `distinctBy` to only keep the lowest - // version, before we finally sort them by name + // overrides a super-class method and narrows the return type. + // + // 1. Make sure we sort the methods by their declaring class from lowest to + // highest in the the type hierarchy, and use `distinctBy` to only keep + // the lowest version, before we finally sort them by name + // + // 2. Sometimes traits also generate synthetic forwarders for overrides, + // which messes up the the comparison since all forwarders will have the + // same `getDeclaringClass`. To handle these scenarios, also sort by + // return type, so we can identify the most specific override res .sortWith((m1, m2) => m1.getDeclaringClass.isAssignableFrom(m2.getDeclaringClass)) + .sortWith((m1, m2) => m1.getReturnType.isAssignableFrom(m2.getReturnType)) .reverse .distinctBy(_.getName) .sortBy(_.getName) diff --git a/main/src/mill/main/RootModule.scala b/main/src/mill/main/RootModule.scala index 3ba1bfe54ab..6d5c81f5d95 100644 --- a/main/src/mill/main/RootModule.scala +++ b/main/src/mill/main/RootModule.scala @@ -20,12 +20,10 @@ abstract class RootModule()(implicit baseModuleInfo: RootModule.Info, millModuleEnclosing0: sourcecode.Enclosing, millModuleLine0: sourcecode.Line, - millName0: sourcecode.Name, millFile0: sourcecode.File ) extends mill.define.BaseModule(baseModuleInfo.millSourcePath0)( millModuleEnclosing0, millModuleLine0, - millName0, millFile0, Caller(()) ) with mill.main.MainModule { @@ -47,12 +45,10 @@ object RootModule { baseModuleInfo: RootModule.Info, millModuleEnclosing0: sourcecode.Enclosing, millModuleLine0: sourcecode.Line, - millName0: sourcecode.Name, millFile0: sourcecode.File ) extends mill.define.BaseModule(baseModuleInfo.millSourcePath0, foreign0 = foreign0)( millModuleEnclosing0, millModuleLine0, - millName0, millFile0, Caller(()) ) with mill.main.MainModule { diff --git a/main/test/src/mill/util/TestGraphs.scala b/main/test/src/mill/util/TestGraphs.scala index dcfafb29e10..23ab08f8d9c 100644 --- a/main/test/src/mill/util/TestGraphs.scala +++ b/main/test/src/mill/util/TestGraphs.scala @@ -1,7 +1,6 @@ package mill.util import TestUtil.test -import mill.api.SystemStreams -import mill.define.{Command, Cross, Discover, TaskModule} +import mill.define.{ModuleRef, Command, Cross, Discover, TaskModule} import mill.{Module, T} /** @@ -218,14 +217,16 @@ class TestGraphs() { object overrideModule extends TestUtil.BaseModule { trait Base extends Module { - val inner: BaseInnerModule = new BaseInnerModule()(implicitly) - class BaseInnerModule()(implicit ctx: mill.define.Ctx) extends mill.define.Module { + lazy val inner: BaseInnerModule = new BaseInnerModule {} + lazy val ignored: ModuleRef[BaseInnerModule] = ModuleRef(new BaseInnerModule {}) + trait BaseInnerModule extends mill.define.Module { def baseTarget = T { 1 } } } object sub extends Base { - override val inner: SubInnerModule = new SubInnerModule()(implicitly) - class SubInnerModule()(implicit ctx: mill.define.Ctx) extends BaseInnerModule() { + override lazy val inner: SubInnerModule = new SubInnerModule {} + override lazy val ignored: ModuleRef[SubInnerModule] = ModuleRef(new SubInnerModule {}) + trait SubInnerModule extends BaseInnerModule { def subTarget = T { 2 } } } diff --git a/main/testkit/src/mill/testkit/MillTestkit.scala b/main/testkit/src/mill/testkit/MillTestkit.scala index 8d776dca8a4..6e9605f4d13 100644 --- a/main/testkit/src/mill/testkit/MillTestkit.scala +++ b/main/testkit/src/mill/testkit/MillTestkit.scala @@ -43,13 +43,11 @@ trait MillTestKit { class BaseModule(implicit millModuleEnclosing0: sourcecode.Enclosing, - millModuleLine0: sourcecode.Line, - millName0: sourcecode.Name + millModuleLine0: sourcecode.Line ) extends mill.define.BaseModule(getSrcPathBase() / millModuleEnclosing0.value.split("\\.| |#"))( implicitly, implicitly, implicitly, - implicitly, implicitly ) { lazy val millDiscover: Discover[this.type] = Discover[this.type] diff --git a/scalalib/src/mill/scalalib/JavaModule.scala b/scalalib/src/mill/scalalib/JavaModule.scala index 2b17513b3c9..4410465cd3c 100644 --- a/scalalib/src/mill/scalalib/JavaModule.scala +++ b/scalalib/src/mill/scalalib/JavaModule.scala @@ -10,9 +10,9 @@ import coursier.parse.ModuleParser import coursier.util.ModuleMatcher import mainargs.Flag import mill.api.Loose.Agg +import mill.define.ModuleRef import mill.api.{JarManifest, PathRef, Result, internal} import mill.util.Jvm -import mill.scalalib.Assembly import mill.scalalib.api.CompilationResult import mill.scalalib.bsp.{BspBuildTarget, BspModule} import mill.scalalib.publish.Artifact @@ -30,7 +30,7 @@ trait JavaModule with BspModule with SemanticDbJavaModule { outer => - def zincWorker: ZincWorkerModule = mill.scalalib.ZincWorkerModule + def zincWorker: ModuleRef[ZincWorkerModule] = ModuleRef(mill.scalalib.ZincWorkerModule) trait JavaModuleTests extends TestModule { override def moduleDeps: Seq[JavaModule] = Seq(outer) @@ -38,7 +38,7 @@ trait JavaModule override def resolutionCustomizer: Task[Option[coursier.Resolution => coursier.Resolution]] = outer.resolutionCustomizer override def javacOptions: Target[Seq[String]] = T { outer.javacOptions() } - override def zincWorker: ZincWorkerModule = outer.zincWorker + override def zincWorker: ModuleRef[ZincWorkerModule] = outer.zincWorker override def skipIdea: Boolean = outer.skipIdea override def runUseArgsFile: Target[Boolean] = T { outer.runUseArgsFile() } override def sources = T.sources { @@ -66,7 +66,7 @@ trait JavaModule mainClass() match { case Some(m) => Right(m) case None => - zincWorker.worker().discoverMainClasses(compile()) match { + zincWorker().worker().discoverMainClasses(compile()) match { case Seq() => Left("No main class specified or found") case Seq(main) => Right(main) case mains => @@ -323,7 +323,7 @@ trait JavaModule */ // Keep in sync with [[bspCompileClassesPath]] def compile: T[mill.scalalib.api.CompilationResult] = T.persistent { - zincWorker + zincWorker() .worker() .compileJava( upstreamCompileOutput = upstreamCompileOutput(), @@ -790,7 +790,7 @@ trait JavaModule try Result.Success( Jvm.runSubprocess( "mill.scalalib.backgroundwrapper.BackgroundWrapper", - (runClasspath() ++ zincWorker.backgroundWrapperClasspath()).map(_.path), + (runClasspath() ++ zincWorker().backgroundWrapperClasspath()).map(_.path), forkArgs(), forkEnv(), Seq(procId.toString, procTombstone.toString, token, finalMainClass()) ++ args, @@ -814,7 +814,7 @@ trait JavaModule try Result.Success( Jvm.runSubprocess( "mill.scalalib.backgroundwrapper.BackgroundWrapper", - (runClasspath() ++ zincWorker.backgroundWrapperClasspath()) + (runClasspath() ++ zincWorker().backgroundWrapperClasspath()) .map(_.path), forkArgs(), forkEnv(), @@ -912,7 +912,7 @@ trait JavaModule T.command { super.prepareOffline(all)() resolvedIvyDeps() - zincWorker.prepareOffline(all)() + zincWorker().prepareOffline(all)() resolvedRunIvyDeps() T.sequence(tasks)() () diff --git a/scalalib/src/mill/scalalib/PlatformScalaModule.scala b/scalalib/src/mill/scalalib/PlatformScalaModule.scala index 3af42e6a579..f78278084f2 100644 --- a/scalalib/src/mill/scalalib/PlatformScalaModule.scala +++ b/scalalib/src/mill/scalalib/PlatformScalaModule.scala @@ -19,7 +19,7 @@ trait PlatformScalaModule extends ScalaModule { * The platform suffix of this [[PlatformScalaModule]]. Useful if you want to * further customize the source paths or artifact names. */ - def platformScalaSuffix = millModuleSegments + def platformScalaSuffix: String = millModuleSegments .value .collect { case l: mill.define.Segment.Label => l.value } .last diff --git a/scalalib/src/mill/scalalib/ScalaModule.scala b/scalalib/src/mill/scalalib/ScalaModule.scala index ad2561b1eab..fadbc00a1cf 100644 --- a/scalalib/src/mill/scalalib/ScalaModule.scala +++ b/scalalib/src/mill/scalalib/ScalaModule.scala @@ -216,7 +216,7 @@ trait ScalaModule extends JavaModule { outer => |You may want to select another version. Upgrading to a more recent Scala version is recommended. |For details, see: https://github.com/sbt/zinc/issues/1010""".stripMargin ) - zincWorker + zincWorker() .worker() .compileMixed( upstreamCompileOutput = upstreamCompileOutput(), @@ -272,7 +272,7 @@ trait ScalaModule extends JavaModule { outer => def packageWithZinc(options: Seq[String], files: Seq[os.Path], javadocDir: os.Path) = { if (files.isEmpty) Result.Success(createJar(Agg(javadocDir))(T.dest)) else { - zincWorker + zincWorker() .worker() .docJar( scalaVersion(), @@ -482,7 +482,11 @@ trait ScalaModule extends JavaModule { outer => if (all.value) Seq( resolvedAmmoniteReplIvyDeps, T.task { - zincWorker.scalaCompilerBridgeJar(scalaVersion(), scalaOrganization(), repositoriesTask()) + zincWorker().scalaCompilerBridgeJar( + scalaVersion(), + scalaOrganization(), + repositoriesTask() + ) } ) else Seq() diff --git a/scalalib/src/mill/scalalib/SemanticDbJavaModule.scala b/scalalib/src/mill/scalalib/SemanticDbJavaModule.scala index 82fe5d512c6..9e73f271d45 100644 --- a/scalalib/src/mill/scalalib/SemanticDbJavaModule.scala +++ b/scalalib/src/mill/scalalib/SemanticDbJavaModule.scala @@ -188,7 +188,7 @@ trait SemanticDbJavaModule extends CoursierModule { hostModule: JavaModule => T.log.debug(s"effective scalac options: ${scalacOptions}") T.log.debug(s"effective javac options: ${javacOpts}") - zincWorker.worker() + zincWorker().worker() .compileMixed( upstreamCompileOutput = upstreamCompileOutput(), sources = m.allSourceFiles().map(_.path), @@ -213,7 +213,7 @@ trait SemanticDbJavaModule extends CoursierModule { hostModule: JavaModule => T.log.debug(s"effective javac options: ${javacOpts}") - zincWorker.worker() + zincWorker().worker() .compileJava( upstreamCompileOutput = upstreamCompileOutput(), sources = allSourceFiles().map(_.path), diff --git a/scalalib/src/mill/scalalib/TestModule.scala b/scalalib/src/mill/scalalib/TestModule.scala index c8ca1ca443a..329b7c38970 100644 --- a/scalalib/src/mill/scalalib/TestModule.scala +++ b/scalalib/src/mill/scalalib/TestModule.scala @@ -115,7 +115,7 @@ trait TestModule extends JavaModule with TaskModule { Jvm.runSubprocess( mainClass = "mill.testrunner.TestRunner", - classPath = zincWorker.scalalibClasspath().map(_.path), + classPath = zincWorker().scalalibClasspath().map(_.path), jvmArgs = jvmArgs, envArgs = forkEnv(), mainArgs = mainArgs, diff --git a/scalalib/src/mill/scalalib/UnidocModule.scala b/scalalib/src/mill/scalalib/UnidocModule.scala index 5b76fda9948..e615fa4c725 100644 --- a/scalalib/src/mill/scalalib/UnidocModule.scala +++ b/scalalib/src/mill/scalalib/UnidocModule.scala @@ -34,7 +34,7 @@ trait UnidocModule extends ScalaModule { unidocVersion().toSeq.flatMap(Seq("-doc-version", _)) ++ unidocSourceUrl().toSeq.flatMap(_ => Seq("-doc-source-url", "file://€{FILE_PATH}.scala")) - zincWorker.worker().docJar( + zincWorker().worker().docJar( scalaVersion(), scalaOrganization(), scalaDocClasspath(),