From d0c28f5360b2b268c1eb30efad2f3b4a91915e22 Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Wed, 7 Jun 2023 13:45:20 -0700 Subject: [PATCH] Bump Mill to 0.11.0 (#171) --- .mill-version | 3 +- build.sc | 178 ++++++++++++++------------------------------- mill | 22 +++++- os/src/Model.scala | 3 + 4 files changed, 77 insertions(+), 129 deletions(-) diff --git a/.mill-version b/.mill-version index 51114462..edda4c06 100644 --- a/.mill-version +++ b/.mill-version @@ -1 +1,2 @@ -0.10.12 \ No newline at end of file +0.11.0 + diff --git a/build.sc b/build.sc index 8a91b81b..4b7e81a2 100644 --- a/build.sc +++ b/build.sc @@ -1,18 +1,11 @@ // plugins -import $ivy.`de.tototec::de.tobiasroeser.mill.vcs.version::0.3.1` -import $ivy.`com.github.lolgab::mill-mima::0.0.22` +import $ivy.`de.tototec::de.tobiasroeser.mill.vcs.version::0.4.0` +import $ivy.`com.github.lolgab::mill-mima::0.0.23` // imports -import mill._ -import mill.define.{Task, Target} -import mill.scalalib._ -import mill.scalanativelib._ -import mill.scalalib.publish._ +import mill._, scalalib._, scalanativelib._, publish._ import mill.scalalib.api.ZincWorkerUtil -// avoid name collisions -import _root_.{os => oslib} import com.github.lolgab.mill.mima.Mima - import de.tobiasroeser.mill.vcs.version.VcsVersion val communityBuildDottyVersion = sys.props.get("dottyVersion").toList @@ -26,10 +19,6 @@ val scalaVersions = Seq( "2.11.12" ) ++ communityBuildDottyVersion -val scalaNativeVersions = scalaVersions.map((_, "0.4.5")) - -val backwardCompatibleVersions: Seq[String] = Seq("0.9.0", "0.9.1") - object Deps { val acyclic = ivy"com.lihaoyi:::acyclic:0.3.8" val jna = ivy"net.java.dev.jna:jna:5.13.0" @@ -39,92 +28,40 @@ object Deps { def scalaLibrary(version: String) = ivy"org.scala-lang:scala-library:${version}" } -object os extends Module { - - object jvm extends Cross[OsJvmModule](scalaVersions: _*) - class OsJvmModule(val crossScalaVersion: String) extends OsModule with MiMaChecks { - def platformSegment = "jvm" - object test extends Tests with OsLibTestModule { - def platformSegment = "jvm" - } - } - - object native extends Cross[OsNativeModule](scalaNativeVersions: _*) - class OsNativeModule( - val crossScalaVersion: String, - crossScalaNativeVersion: String - ) extends OsModule - with ScalaNativeModule { - def platformSegment = "native" - override def millSourcePath = super.millSourcePath / oslib.up - def scalaNativeVersion = crossScalaNativeVersion - object test extends Tests with OsLibTestModule { - def platformSegment = "native" - override def nativeLinkStubs = true - } - } - - object watch extends Module { - - object jvm extends Cross[WatchJvmModule](scalaVersions: _*) - class WatchJvmModule(val crossScalaVersion: String) extends WatchModule { - def platformSegment = "jvm" - override def moduleDeps = super.moduleDeps :+ os.jvm() - override def ivyDeps = Agg( - Deps.jna - ) - object test extends Tests with OsLibTestModule { - def platformSegment = "jvm" - override def moduleDeps = super.moduleDeps :+ os.jvm().test - } - } - - /* - object native extends Cross[WatchNativeModule](scalaNativeVersions:_*) - class WatchNativeModule(val crossScalaVersion: String, crossScalaNativeVersion: String) extends WatchModule with ScalaNativeModule { - def platformSegment = "native" - def millSourcePath = super.millSourcePath / ammonite.ops.up - def scalaNativeVersion = crossScalaNativeVersion - def moduleDeps = super.moduleDeps :+ os.native() - object test extends Tests with OsLibTestModule { - def platformSegment = "native" - def moduleDeps = super.moduleDeps :+ os.native().test - def nativeLinkStubs = true - } - } - */ - } -} - trait AcyclicModule extends ScalaModule { def acyclicDep: T[Agg[Dep]] = T { - if (!ZincWorkerUtil.isScala3(scalaVersion())) Agg(Deps.acyclic) - else Agg.empty[Dep] + Agg.from(Option.when(!ZincWorkerUtil.isScala3(scalaVersion()))(Deps.acyclic)) } def acyclicOptions: T[Seq[String]] = T { - if (!ZincWorkerUtil.isScala3(scalaVersion())) Seq("-P:acyclic:force") - else Seq.empty - } - override def compileIvyDeps = acyclicDep - override def scalacPluginIvyDeps = acyclicDep - override def scalacOptions = T { - super.scalacOptions() ++ acyclicOptions() + Option.when(!ZincWorkerUtil.isScala3(scalaVersion()))("-P:acyclic:force").toSeq } + def compileIvyDeps = acyclicDep + def scalacPluginIvyDeps = acyclicDep + def scalacOptions = super.scalacOptions() ++ acyclicOptions() } trait SafeDeps extends ScalaModule { - override def mapDependencies: Task[coursier.Dependency => coursier.Dependency] = T.task { + def mapDependencies: Task[coursier.Dependency => coursier.Dependency] = T.task { val sd = Deps.scalaLibrary(scala213Version) super.mapDependencies().andThen { d => // enforce up-to-date Scala 2.13.x version - if (d.module == sd.dep.module && d.version.startsWith("2.13.")) { - sd.dep - } else d + if (d.module == sd.dep.module && d.version.startsWith("2.13.")) sd.dep + else d } } } -trait OsLibModule extends CrossScalaModule with PublishModule with AcyclicModule with SafeDeps { +trait MiMaChecks extends Mima { + def mimaPreviousVersions = Seq("0.9.0", "0.9.1") +} + +trait OsLibModule + extends CrossScalaModule + with PublishModule + with AcyclicModule + with SafeDeps + with PlatformScalaModule { outer => + def publishVersion = VcsVersion.vcsState().format() def pomSettings = PomSettings( description = artifactName(), @@ -139,53 +76,44 @@ trait OsLibModule extends CrossScalaModule with PublishModule with AcyclicModule Developer("lihaoyi", "Li Haoyi", "https://github.com/lihaoyi") ) ) - def platformSegment: String - override def millSourcePath = super.millSourcePath / oslib.up - override def sources = T.sources( - millSourcePath / "src", - millSourcePath / s"src-$platformSegment" - ) -} -trait OsLibTestModule extends ScalaModule with TestModule.Utest with SafeDeps { - override def ivyDeps = Agg( - Deps.utest, - Deps.sourcecode - ) - def platformSegment: String - override def sources = T.sources( - millSourcePath / "src", - millSourcePath / s"src-$platformSegment" - ) + trait OsLibTestModule extends ScalaModule with TestModule.Utest with SafeDeps { + def ivyDeps = Agg(Deps.utest, Deps.sourcecode) - // we check the textual output of system commands and expect it in english - override def forkEnv: Target[Map[String, String]] = T { - super.forkEnv() ++ Map("LC_ALL" -> "C") + // we check the textual output of system commands and expect it in english + def forkEnv = super.forkEnv() ++ Map("LC_ALL" -> "C") } } -trait OsModule extends OsLibModule { - override def artifactName = "os-lib" - override def ivyDeps = Agg( - Deps.geny - ) -} +trait OsModule extends OsLibModule { outer => + def ivyDeps = Agg(Deps.geny) -trait WatchModule extends OsLibModule { - override def artifactName = "os-lib-watch" + def artifactName = "os-lib" } -trait MiMaChecks extends Mima { - override def mimaPreviousVersions = backwardCompatibleVersions - override def mimaPreviousArtifacts: Target[Agg[Dep]] = T { - val versions = mimaPreviousVersions().distinct - val info = artifactMetadata() - if (versions.isEmpty) - T.log.error("No binary compatible versions configured!") - Agg.from( - versions.map(version => - ivy"${info.group}:${info.id}:${version}" - ) - ) +object os extends Module { + + object jvm extends Cross[OsJvmModule](scalaVersions) + trait OsJvmModule extends OsModule with MiMaChecks { + object test extends ScalaTests with OsLibTestModule + } + + object native extends Cross[OsNativeModule](scalaVersions) + trait OsNativeModule extends OsModule with ScalaNativeModule{ + def scalaNativeVersion = "0.4.5" + object test extends ScalaNativeTests with OsLibTestModule { + def nativeLinkStubs = true + } + } + + object watch extends Module { + object jvm extends Cross[WatchJvmModule](scalaVersions) + trait WatchJvmModule extends OsLibModule { + def moduleDeps = super.moduleDeps ++ Seq(os.jvm()) + def ivyDeps = Agg(Deps.jna) + object test extends ScalaTests with OsLibTestModule { + def moduleDeps = super.moduleDeps ++ Seq(os.jvm().test) + } + } } } diff --git a/mill b/mill index e616548f..cb1ee32f 100755 --- a/mill +++ b/mill @@ -3,13 +3,18 @@ # This is a wrapper script, that automatically download mill from GitHub release pages # You can give the required mill version with MILL_VERSION env variable # If no version is given, it falls back to the value of DEFAULT_MILL_VERSION -DEFAULT_MILL_VERSION=0.10.5 set -e +if [ -z "${DEFAULT_MILL_VERSION}" ] ; then + DEFAULT_MILL_VERSION=0.11.0 +fi + if [ -z "$MILL_VERSION" ] ; then if [ -f ".mill-version" ] ; then MILL_VERSION="$(head -n 1 .mill-version 2> /dev/null)" + elif [ -f ".config/mill-version" ] ; then + MILL_VERSION="$(head -n 1 .config/mill-version 2> /dev/null)" elif [ -f "mill" ] && [ "$0" != "mill" ] ; then MILL_VERSION=$(grep -F "DEFAULT_MILL_VERSION=" "mill" | head -n 1 | cut -d= -f2) else @@ -35,7 +40,7 @@ if [ ! -s "$MILL_EXEC_PATH" ] ; then fi DOWNLOAD_FILE=$MILL_EXEC_PATH-tmp-download MILL_VERSION_TAG=$(echo $MILL_VERSION | sed -E 's/([^-]+)(-M[0-9]+)?(-.*)?/\1\2/') - MILL_DOWNLOAD_URL="https://github.com/lihaoyi/mill/releases/download/${MILL_VERSION_TAG}/$MILL_VERSION${ASSEMBLY}" + MILL_DOWNLOAD_URL="https://repo1.maven.org/maven2/com/lihaoyi/mill-dist/$MILL_VERSION/mill-dist-$MILL_VERSION.jar" curl --fail -L -o "$DOWNLOAD_FILE" "$MILL_DOWNLOAD_URL" chmod +x "$DOWNLOAD_FILE" mv "$DOWNLOAD_FILE" "$MILL_EXEC_PATH" @@ -43,7 +48,18 @@ if [ ! -s "$MILL_EXEC_PATH" ] ; then unset MILL_DOWNLOAD_URL fi +if [ -z "$MILL_MAIN_CLI" ] ; then + MILL_MAIN_CLI="${0}" +fi + +MILL_FIRST_ARG="" +if [ "$1" = "--bsp" ] || [ "$1" = "-i" ] || [ "$1" = "--interactive" ] || [ "$1" = "--no-server" ] || [ "$1" = "--repl" ] || [ "$1" = "--help" ] ; then + # Need to preserve the first position of those listed options + MILL_FIRST_ARG=$1 + shift +fi + unset MILL_DOWNLOAD_PATH unset MILL_VERSION -exec $MILL_EXEC_PATH "$@" +exec $MILL_EXEC_PATH $MILL_FIRST_ARG -D "mill.main.cli=${MILL_MAIN_CLI}" "$@" diff --git a/os/src/Model.scala b/os/src/Model.scala index 136e0df9..2d9fb45e 100644 --- a/os/src/Model.scala +++ b/os/src/Model.scala @@ -224,6 +224,9 @@ object Shellable { implicit def RelPathShellable(s: RelPath): Shellable = Shellable(Seq(s.toString)) implicit def NumericShellable[T: Numeric](s: T): Shellable = Shellable(Seq(s.toString)) + implicit def OptionShellable[T](s: Option[T])(implicit f: T => Shellable): Shellable = + Shellable(s.toSeq.flatMap(f(_).value)) + implicit def IterableShellable[T](s: Iterable[T])(implicit f: T => Shellable): Shellable = Shellable(s.toSeq.flatMap(f(_).value))