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

Update Mill to 0.11.7 #1431

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion .mill-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.10.15
0.11.7
134 changes: 71 additions & 63 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@ import $ivy.`io.get-coursier::coursier-launcher:2.1.0-RC1`
import $file.ci.upload
// imports
import java.util.concurrent.atomic.AtomicInteger
import scala.concurrent.{Await, ExecutionContext, Future, duration}
import scala.util.chaining.scalaUtilChainingOps
import coursier.mavenRepositoryString
import mill._
import mill.api.Lazy
import mill.api.Result
import mill.contrib.bloop.Bloop
import mill.define.Command
import mill.main.Tasks
import mill.scalalib._
import mill.scalalib.publish._
import mill.scalalib.api.ZincWorkerUtil._
import mill.testrunner.TestRunner
import mill.scalalib.publish._
import mill.testrunner.TestResult
import scala.concurrent.{Await, ExecutionContext, Future, duration}
import scala.util.chaining.scalaUtilChainingOps
import scala.util.control.NonFatal

val ghOrg = "com-lihaoyi"
val ghRepo = "Ammonite"
Expand All @@ -33,15 +35,15 @@ val isPublishableCommit =
publishBranches.exists(suffix => x.endsWith(s"/${suffix}"))
)

val latestTaggedVersion = os.proc("git", "describe", "--abbrev=0", "--tags").call().out.trim
val latestTaggedVersion = os.proc("git", "describe", "--abbrev=0", "--tags").call().out.trim()

val gitHead = os.proc("git", "rev-parse", "HEAD").call().out.trim
val gitHead = os.proc("git", "rev-parse", "HEAD").call().out.trim()

val commitsSinceTaggedVersion = {
os.proc("git", "rev-list", gitHead, "--not", latestTaggedVersion, "--count")
.call()
.out
.trim
.trim()
.toInt
}

Expand All @@ -68,10 +70,10 @@ val (buildVersion, unstable) = scala.util.Try(
os.proc("git", "describe", "--exact-match", "--tags", "--always", gitHead)
.call()
.out
.trim
.trim()
).toOption match {
case None =>
val gitHash = os.proc("git", "rev-parse", "--short", "HEAD").call().out.trim
val gitHash = os.proc("git", "rev-parse", "--short", "HEAD").call().out.trim()
(s"$latestTaggedVersion-$commitsSinceTaggedVersion-$gitHash", true)
case Some(tagName) => (tagName, false)
}
Expand Down Expand Up @@ -166,11 +168,12 @@ trait AmmInternalModule extends CrossSbtModule with Bloop.Module {
ivy"$scalaO:scala-library:$scalaV"
)
}
trait AmmTests extends super.Tests with TestModule.Utest {
trait AmmTests extends CrossSbtModuleTests with TestModule.Utest {
def ivyDeps = super.ivyDeps() ++ Agg(Deps.utest)
def forkArgs = Seq("-Xmx2g", "-Dfile.encoding=UTF8")
}
def allIvyDeps = T { transitiveIvyDeps() ++ scalaLibraryIvyDeps() }
// why is this here?
def allIvyDeps = T { transitiveIvyDeps().map(_.toDep) ++ scalaLibraryIvyDeps() }
def sources = T.sources {
val sv = scalaVersion()
val extraDir =
Expand Down Expand Up @@ -221,11 +224,13 @@ trait AmmInternalModule extends CrossSbtModule with Bloop.Module {
super.sources() ++ extraDir ++ extraDir2 ++ extraDir3 ++ extraDir4 ++ extraDir5
}
def externalSources = T {
resolveDeps(allIvyDeps, sources = true)()
resolveDeps(T.task { allIvyDeps().map(bindDependency()) }, sources = true)()
}
def repositoriesTask = T.task {
super.repositoriesTask() ++ Seq(
mvn"https://scala-ci.typesafe.com/artifactory/scala-integration"
)
}
def repositories = super.repositories ++ Seq(
mvn"https://scala-ci.typesafe.com/artifactory/scala-integration"
)
override implicit def crossSbtModuleResolver: mill.define.Cross.Resolver[CrossModuleBase] =
new mill.define.Cross.Resolver[CrossModuleBase] {
def resolve[V <: CrossModuleBase](c: Cross[V]): V = {
Expand All @@ -237,14 +242,14 @@ trait AmmInternalModule extends CrossSbtModule with Bloop.Module {
}
.flatMap(prefix =>
c.items
.map(_._2)
.map(_.module.value)
.find(_.crossScalaVersion.split('.').startsWith(prefix))
)
.collectFirst { case x => x }
.getOrElse {
throw new Exception(
s"Unable to find compatible cross version between $crossScalaVersion and " +
c.items.map(_._2.crossScalaVersion).mkString(",")
c.items.map(_.module.value.crossScalaVersion).mkString(",")
)
}

Expand Down Expand Up @@ -281,11 +286,11 @@ trait AmmModule extends AmmInternalModule with PublishModule {
trait AmmDependenciesResourceFileModule extends JavaModule {
def dependencyResourceFileName: String
def dependencyFileResources = T {
val deps0 = T.task { compileIvyDeps() ++ transitiveIvyDeps() }()
val (_, res) = mill.modules.Jvm.resolveDependenciesMetadata(
val deps0 = compileIvyDeps().map(bindDependency()) ++ transitiveIvyDeps()
val (_, res) = mill.util.Jvm.resolveDependenciesMetadata(
repositoriesTask(),
deps0.map(resolveCoursierDependency().apply(_)),
deps0.filter(_.force).map(resolveCoursierDependency().apply(_)),
deps0.map(_.dep), // .map(resolveCoursierDependency().apply(_)),
deps0.filter(_.force).map(_.dep), // .map(resolveCoursierDependency().apply(_)),
mapDependencies = Some(mapDependencies())
)

Expand All @@ -300,8 +305,8 @@ trait AmmDependenciesResourceFileModule extends JavaModule {
}
}

object terminal extends Cross[TerminalModule](binCrossScalaVersions: _*)
class TerminalModule(val crossScalaVersion: String) extends AmmModule {
object terminal extends Cross[TerminalModule](binCrossScalaVersions)
trait TerminalModule extends AmmModule {
def ivyDeps = T {
super.ivyDeps() ++ Agg(
Deps.fansi,
Expand All @@ -313,9 +318,9 @@ class TerminalModule(val crossScalaVersion: String) extends AmmModule {
}
}

object amm extends Cross[MainModule](fullCrossScalaVersions: _*) {
object util extends Cross[UtilModule](binCrossScalaVersions: _*)
class UtilModule(val crossScalaVersion: String) extends AmmModule {
object amm extends Cross[MainModule](fullCrossScalaVersions) {
object util extends Cross[UtilModule](binCrossScalaVersions)
trait UtilModule extends AmmModule {
def moduleDeps = Seq()
def ivyDeps = T {
super.ivyDeps() ++ Agg(
Expand All @@ -330,8 +335,8 @@ object amm extends Cross[MainModule](fullCrossScalaVersions: _*) {
(if (isScala3(crossScalaVersion)) Agg.empty[Dep] else Agg(Deps.scalaReflect(scalaVersion())))
}

object runtime extends Cross[RuntimeModule](fullCrossScalaVersions: _*)
class RuntimeModule(val crossScalaVersion: String) extends AmmModule {
object runtime extends Cross[RuntimeModule](fullCrossScalaVersions)
trait RuntimeModule extends AmmModule {
def moduleDeps = Seq(amm.util(), interp.api(), amm.repl.api())
def isCrossFullScalaVersion = true
def ivyDeps = super.ivyDeps() ++ Agg(
Expand All @@ -343,9 +348,9 @@ object amm extends Cross[MainModule](fullCrossScalaVersions: _*) {
)
}

object compiler extends Cross[CompilerModule](fullCrossScalaVersions: _*) {
object interface extends Cross[CompilerInterfaceModule](fullCrossScalaVersions: _*)
class CompilerInterfaceModule(val crossScalaVersion: String) extends AmmModule {
object compiler extends Cross[CompilerModule](fullCrossScalaVersions) {
object interface extends Cross[CompilerInterfaceModule](fullCrossScalaVersions)
trait CompilerInterfaceModule extends AmmModule {
def isCrossFullScalaVersion = true
def moduleDeps = Seq(amm.util())
def exposedClassPath = T {
Expand All @@ -356,7 +361,7 @@ object amm extends Cross[MainModule](fullCrossScalaVersions: _*) {
}
}
}
class CompilerModule(val crossScalaVersion: String) extends AmmModule {
trait CompilerModule extends AmmModule {
def supports3 = true
def moduleDeps = Seq(amm.compiler.interface(), amm.util(), amm.repl.api())
def isCrossFullScalaVersion = true
Expand Down Expand Up @@ -389,9 +394,9 @@ object amm extends Cross[MainModule](fullCrossScalaVersions: _*) {
object test extends AmmTests
}

object interp extends Cross[InterpModule](fullCrossScalaVersions: _*) {
object api extends Cross[InterpApiModule](fullCrossScalaVersions: _*)
class InterpApiModule(val crossScalaVersion: String) extends AmmModule
object interp extends Cross[InterpModule](fullCrossScalaVersions) {
object api extends Cross[InterpApiModule](fullCrossScalaVersions)
trait InterpApiModule extends AmmModule
with AmmDependenciesResourceFileModule {
def moduleDeps = Seq(amm.compiler.interface(), amm.util())
def isCrossFullScalaVersion = true
Expand All @@ -403,7 +408,7 @@ object amm extends Cross[MainModule](fullCrossScalaVersions: _*) {
val outDir = T.ctx().dest
val javadocDir = outDir / "javadoc"
os.makeDir.all(javadocDir)
mill.api.Result.Success(mill.modules.Jvm.createJar(Agg(javadocDir))(outDir))
mill.api.Result.Success(mill.util.Jvm.createJar(Agg(javadocDir))(outDir))
}
else super.docJar
def constantsSourceDir = T {
Expand All @@ -424,7 +429,7 @@ object amm extends Cross[MainModule](fullCrossScalaVersions: _*) {
super.generatedSources() ++ Seq(constantsSourceDir())
}
}
class InterpModule(val crossScalaVersion: String) extends AmmModule {
trait InterpModule extends AmmModule {
def moduleDeps = Seq(amm.util(), amm.runtime(), amm.compiler.interface())
def isCrossFullScalaVersion = true
def ivyDeps = super.ivyDeps() ++ Agg(
Expand All @@ -449,10 +454,10 @@ object amm extends Cross[MainModule](fullCrossScalaVersions: _*) {
// )
// }

object repl extends Cross[ReplModule](fullCrossScalaVersions: _*) {
object repl extends Cross[ReplModule](fullCrossScalaVersions) {

object api extends Cross[ReplApiModule](fullCrossScalaVersions: _*)
class ReplApiModule(val crossScalaVersion: String) extends AmmModule
object api extends Cross[ReplApiModule](fullCrossScalaVersions)
trait ReplApiModule extends AmmModule
with AmmDependenciesResourceFileModule {
def isCrossFullScalaVersion = true
def dependencyResourceFileName = "amm-dependencies.txt"
Expand All @@ -478,7 +483,7 @@ object amm extends Cross[MainModule](fullCrossScalaVersions: _*) {
}

}
class ReplModule(val crossScalaVersion: String) extends AmmModule {
trait ReplModule extends AmmModule {
def isCrossFullScalaVersion = true
def moduleDeps = Seq(
amm.util(),
Expand Down Expand Up @@ -507,7 +512,7 @@ object amm extends Cross[MainModule](fullCrossScalaVersions: _*) {
amm.repl.api().exposedClassPath() ++
amm.compiler().exposedClassPath() ++
Seq(compile().classes) ++
resolveDeps(T.task { compileIvyDeps() ++ transitiveIvyDeps() })()
resolveDeps(T.task { this.compileIvyDeps().map(bindDependency()) ++ transitiveIvyDeps() })()
)
}

Expand All @@ -519,7 +524,7 @@ object amm extends Cross[MainModule](fullCrossScalaVersions: _*) {
(super.resources() ++
ReplModule.this.sources() ++
ReplModule.this.externalSources() ++
resolveDeps(ivyDeps, sources = true)()).distinct
resolveDeps(T.task { ivyDeps().map(bindDependency()) }, sources = true)()).distinct
}
def ivyDeps = super.ivyDeps() ++ amm.compiler().ivyDeps() ++ Agg(
Deps.scalazCore
Expand All @@ -528,7 +533,7 @@ object amm extends Cross[MainModule](fullCrossScalaVersions: _*) {
}
}

class MainModule(val crossScalaVersion: String) extends AmmModule {
trait MainModule extends AmmModule {

def isCrossFullScalaVersion = true

Expand Down Expand Up @@ -560,7 +565,7 @@ class MainModule(val crossScalaVersion: String) extends AmmModule {
externalSources()

def prependShellScript = T {
mill.modules.Jvm.launcherUniversalScript(
mill.util.Jvm.launcherUniversalScript(
mainClass().get,
Agg("$0"),
Agg("%~dpnx0"),
Expand Down Expand Up @@ -624,7 +629,7 @@ class MainModule(val crossScalaVersion: String) extends AmmModule {
amm.repl.api().exposedClassPath() ++
amm.compiler().exposedClassPath() ++
Seq(amm.repl().test.compile().classes, compile().classes) ++
resolveDeps(T.task { compileIvyDeps() ++ transitiveIvyDeps() })()
resolveDeps(T.task { compileIvyDeps().map(bindDependency()) ++ transitiveIvyDeps() })()
)
}

Expand Down Expand Up @@ -653,7 +658,7 @@ def generateApiWhitelist(replApiCp: Seq[PathRef])(implicit ctx: mill.api.Ctx.Des
val thinClasspathEntries = replApiCp.map(_.path).flatMap { cpRoot =>
if (os.isFile(cpRoot) && cpRoot.ext == "jar") {
val zip = new java.util.zip.ZipFile(cpRoot.toIO)
import collection.JavaConverters._
import scala.jdk.CollectionConverters._
for (e <- zip.entries().asScala) yield e.getName
} else if (os.isDir(cpRoot)) {
for (sub <- os.walk(cpRoot)) yield sub.relativeTo(cpRoot).toString
Expand All @@ -672,8 +677,8 @@ def generateApiWhitelist(replApiCp: Seq[PathRef])(implicit ctx: mill.api.Ctx.Des
PathRef(ctx.dest)
}

object integration extends Cross[IntegrationModule](fullCrossScalaVersions: _*)
class IntegrationModule(val crossScalaVersion: String) extends AmmInternalModule {
object integration extends Cross[IntegrationModule](fullCrossScalaVersions)
trait IntegrationModule extends AmmInternalModule {
def moduleDeps = Seq(amm())
def ivyDeps = T {
super.ivyDeps() ++ (
Expand All @@ -696,8 +701,8 @@ class IntegrationModule(val crossScalaVersion: String) extends AmmInternalModule
}
}

object sshd extends Cross[SshdModule](fullCrossScalaVersions: _*)
class SshdModule(val crossScalaVersion: String) extends AmmModule {
object sshd extends Cross[SshdModule](fullCrossScalaVersions)
trait SshdModule extends AmmModule {
def moduleDeps = Seq(amm())
def isCrossFullScalaVersion = true
def ivyDeps = super.ivyDeps() ++ Agg(
Expand All @@ -719,24 +724,27 @@ class SshdModule(val crossScalaVersion: String) extends AmmModule {
* Selects all cross module instances, that match the given predicate.
* In Mill 0.11, this can be hopefully replaced with a simple filter on the `crossValue`.
*/
def selectCrossPrefix[T <: Module, V](
def selectCrossPrefix[T <: Cross.Module[_], V](
crossModule: Cross[T],
predicate: String => Boolean
)(accessor: T => V): Seq[V] =
crossModule.items.collect {
case (List(key: String), mod) if predicate(key) => accessor(mod)
case item if predicate(item.crossSegments.head) => accessor(item.module.value)
// case (List(key: String), mod) if predicate(key) => accessor(mod)
}
.tap { mods =>
if (mods.isEmpty) sys.error(s"No matching cross-instances found in ${crossModule}")
}

def unitTest(scalaBinaryVersion: String = ""): Command[Seq[(String, Seq[TestRunner.Result])]] = {
val pred = (_: String).startsWith(scalaBinaryVersion)
def unitTest(scalaVersion: String = "") = T.command {
val predBinVer = (_: String).startsWith(scalaVersion.split("[.]", 3).take(2).mkString("."))
val predFullVer = (_: String).startsWith(scalaVersion)
val tests = Seq(
selectCrossPrefix(terminal, pred)(_.test),
selectCrossPrefix(amm.repl, pred)(_.test),
selectCrossPrefix(amm, pred)(_.test),
selectCrossPrefix(sshd, pred)(_.test)
selectCrossPrefix(terminal, predBinVer)(_.test),
selectCrossPrefix(amm.compiler, predFullVer)(_.test),
selectCrossPrefix(amm.repl, predFullVer)(_.test),
selectCrossPrefix(amm, predFullVer)(_.test),
selectCrossPrefix(sshd, predFullVer)(_.test)
).flatten

val log = T.task { T.log.outputStream.println(s"Testing modules: ${tests.mkString(", ")}") }
Expand All @@ -762,7 +770,7 @@ def generateConstantsFile(
oldCurlUrls: Seq[(String, String)] = Nil,
oldUnstableCurlUrls: Seq[(String, String)] = Nil,
returnDirectory: Boolean = true
)(implicit ctx: mill.util.Ctx.Dest) = {
)(implicit ctx: mill.api.Ctx.Dest) = {
val versionTxt = s"""
package ammonite
object Constants{
Expand Down Expand Up @@ -790,7 +798,7 @@ def generateConstantsFile(
}

def generateDependenciesFile(fileName: String, deps: Seq[coursier.Dependency])(implicit
ctx: mill.util.Ctx.Dest
ctx: mill.api.Ctx.Dest
) = {

val dir = ctx.dest / "extra-resources"
Expand Down Expand Up @@ -884,7 +892,7 @@ def publishDocs(skipDeploy: Boolean = false): Command[Unit] = {
)
)
} catch {
case e =>
case NonFatal(e) =>
println(e)
e.printStackTrace()
throw e
Expand Down Expand Up @@ -1012,7 +1020,7 @@ def publishSonatype(
),
readTimeout = 600000,
connectTimeout = 600000,
log = T.ctx().log,
log = T.log,
workspace = T.workspace,
env = T.env,
awaitTimeout = 600000,
Expand Down
2 changes: 1 addition & 1 deletion ci/upload.sc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env amm

@main
@mainargs.main
def apply(
uploadedFile: os.Path,
tagName: String,
Expand Down
Loading