Skip to content

Commit

Permalink
Merge pull request #2834 from alexarchambault/coursier-cli-2.13
Browse files Browse the repository at this point in the history
Cross-compile cli module in 2.13
  • Loading branch information
alexarchambault committed Sep 9, 2023
2 parents be99e4b + 3d013ed commit ef2b102
Show file tree
Hide file tree
Showing 12 changed files with 95 additions and 402 deletions.
2 changes: 1 addition & 1 deletion .github/scripts/generate-os-packages.sh
Expand Up @@ -14,7 +14,7 @@ fi


launcher() {
local launcherMillCommand="cli.nativeImage"
local launcherMillCommand="cliNativeImageLauncher"
local launcherName

if [[ "$OSTYPE" == "msys" ]]; then
Expand Down
6 changes: 3 additions & 3 deletions DEVELOP.md
Expand Up @@ -73,13 +73,13 @@ Run this command again to re-import the project if you change the build configur
### Run the CLI from sources

```text
$ ./mill -i cli.run …args…
$ ./mill -i cli[2.12.18].run …args…
```

### Generate a JVM launcher of the CLI

```text
$ ./mill show cli.standaloneLauncher
$ ./mill show cli[2.12.18].standaloneLauncher
```

This should print the path to the generated launcher, that can be copied, or run on other
Expand All @@ -88,7 +88,7 @@ machines.
### Generate a GraalVM native image of the CLI

```text
$ ./mill -i show cli.nativeImage
$ ./mill -i show cli[2.12.18].nativeImage
```

This should print the path to the generated native image.
Expand Down
149 changes: 51 additions & 98 deletions build.sc
Expand Up @@ -62,11 +62,9 @@ object cache extends Module {
object jvm extends Cross[CacheJvm](ScalaVersions.all: _*)
object js extends Cross[CacheJs](ScalaVersions.all: _*)
}
object launcher extends Cross[Launcher](ScalaVersions.all: _*)
object env extends Cross[Env](ScalaVersions.all: _*)
object `launcher-native_03` extends LauncherNative03
object `launcher-native_040M2` extends LauncherNative040M2
object `launcher-native_04` extends LauncherNative04
object launcher extends Cross[Launcher](ScalaVersions.all: _*)
object env extends Cross[Env](ScalaVersions.all: _*)
object `launcher-native_04` extends Cross[LauncherNative04](ScalaVersions.all: _*)

object coursier extends Module {
object jvm extends Cross[CoursierJvm](ScalaVersions.all: _*)
Expand Down Expand Up @@ -189,8 +187,8 @@ object interop extends Module {
object jvm extends Cross[Jvm](ScalaVersions.all: _*)
object install extends Cross[Install](ScalaVersions.all: _*)

object cli extends Cli
object `cli-tests` extends CliTests
object cli extends Cross[Cli](ScalaVersions.all: _*)
object `cli-tests` extends Cross[CliTests](ScalaVersions.all: _*)

object web extends Web

Expand Down Expand Up @@ -318,33 +316,12 @@ class Env(val crossScalaVersion: String) extends CrossSbtModule with CsModule
}
}

def cliScalaVersion = ScalaVersions.scala212
def launcherModule = launcher
trait LauncherNative03 extends CsModule with CoursierPublishModule {
def artifactName = "coursier-launcher-native_0.3"
def scalaVersion = cliScalaVersion
def compileModuleDeps = Seq(
launcherModule(cliScalaVersion)
)
def ivyDeps = super.ivyDeps() ++ Agg(
Deps.scalaNativeTools03
)
}
trait LauncherNative040M2 extends CsModule with CoursierPublishModule {
def artifactName = "coursier-launcher-native_0.4.0-M2"
def scalaVersion = cliScalaVersion
def compileModuleDeps = Seq(
launcherModule(cliScalaVersion)
)
def ivyDeps = super.ivyDeps() ++ Agg(
Deps.scalaNativeTools040M2
)
}
trait LauncherNative04 extends CsModule with CoursierPublishModule {
def mainCliScalaVersion = ScalaVersions.scala212
def launcherModule = launcher
class LauncherNative04(val crossScalaVersion: String) extends CsCrossJvmJsModule with CoursierPublishModule {
def artifactName = "coursier-launcher-native_0.4"
def scalaVersion = cliScalaVersion
def compileModuleDeps = Seq(
launcherModule(cliScalaVersion)
launcherModule()
)
def ivyDeps = super.ivyDeps() ++ Agg(
Deps.scalaNativeTools040
Expand Down Expand Up @@ -544,25 +521,24 @@ class Jvm(val crossScalaVersion: String) extends CrossSbtModule with CsModule
}
}

trait Cli extends CsModule with CoursierPublishModule with Launchers {
class Cli(val crossScalaVersion: String) extends CsCrossJvmJsModule
with CoursierPublishModule with Launchers {
def artifactName = "coursier-cli"
def scalaVersion = cliScalaVersion
def moduleDeps = super.moduleDeps ++ Seq(
coursier.jvm(cliScalaVersion),
`sbt-maven-repository`.jvm(cliScalaVersion),
install(cliScalaVersion),
jvm(cliScalaVersion),
launcherModule(cliScalaVersion)
coursier.jvm(),
`sbt-maven-repository`.jvm(),
install(),
jvm(),
launcherModule()
)
def ivyDeps = super.ivyDeps() ++ Agg(
Deps.argonautShapeless,
Deps.caseApp,
Deps.catsCore,
Deps.catsFree,
Deps.classPathUtil,
Deps.collectionCompat,
Deps.dataClass,
Deps.monadlessCats,
Deps.monadlessStdlib,
Deps.noCrcZis,
ivy"com.chuusai::shapeless:2.3.10",
Deps.slf4JNop
Expand Down Expand Up @@ -599,10 +575,10 @@ trait Cli extends CsModule with CoursierPublishModule with Launchers {
object test extends Tests with CsTests
}

trait CliTests extends CsModule with CoursierPublishModule { self =>
def scalaVersion = cliScalaVersion
class CliTests(val crossScalaVersion: String) extends CsCrossJvmJsModule
with CoursierPublishModule { self =>
def moduleDeps = super.moduleDeps ++ Seq(
coursier.jvm(cliScalaVersion)
coursier.jvm()
)
def ivyDeps = super.ivyDeps() ++ Agg(
Deps.caseApp,
Expand All @@ -617,8 +593,8 @@ trait CliTests extends CsModule with CoursierPublishModule { self =>
)
object test extends Tests with CsTests {
def forkArgs = {
val launcherTask = cli.launcher.map(_.path)
val assemblyTask = cli.assembly.map(_.path)
val launcherTask = cli().launcher.map(_.path)
val assemblyTask = cli().assembly.map(_.path)
T {
super.forkArgs() ++ sharedTestArgs ++ Seq(
s"-Dcoursier-test-launcher=${launcherTask()}",
Expand Down Expand Up @@ -649,16 +625,16 @@ trait CliTests extends CsModule with CoursierPublishModule { self =>
}
}
object `native-tests` extends NativeTests {
def cliLauncher = cli.nativeImage
def cliLauncher = cli().nativeImage
}
object `native-static-tests` extends NativeTests {
def cliLauncher = cli.`static-image`.nativeImage
def cliLauncher = cli().`static-image`.nativeImage
}
object `native-mostly-static-tests` extends NativeTests {
def cliLauncher = cli.`mostly-static-image`.nativeImage
def cliLauncher = cli().`mostly-static-image`.nativeImage
}
object `native-container-tests` extends NativeTests {
def cliLauncher = cli.containerImage
def cliLauncher = cli().containerImage
}
}

Expand Down Expand Up @@ -698,35 +674,9 @@ object `redirecting-server` extends CsModule {
def mainClass = Some("redirectingserver.RedirectingServer")
}

def simpleNative03CliTest() = T.command {
`launcher-native_03`.publishLocal()()
val launcher = cli.launcher().path
val tmpDir = os.temp.dir(prefix = "coursier-bootstrap-scala-native-test")
def cleanUp(): Unit =
try os.remove.all(tmpDir)
catch {
case _: java.io.IOException =>
System.err.println(s"Error removing $tmpDir, ignoring it")
}
val res =
try {
os.proc(
launcher.toString,
"bootstrap",
"-S",
"-o",
"native-echo",
"io.get-coursier:echo_native0.3_2.11:1.0.1"
).call(cwd = tmpDir) // TODO inherit all
os.proc(tmpDir / "native-echo", "-n", "foo", "a").call()
}
finally cleanUp()
assert(res.out.text == "foo a")
}

def simpleNative04CliTest() = T.command {
`launcher-native_04`.publishLocal()()
val launcher = cli.launcher().path
`launcher-native_04`(mainCliScalaVersion).publishLocal()()
val launcher = cli(mainCliScalaVersion).launcher().path
val tmpDir = os.temp.dir(prefix = "coursier-bootstrap-scala-native-test")
def cleanUp(): Unit =
try os.remove.all(tmpDir)
Expand Down Expand Up @@ -757,17 +707,17 @@ def copyTo(task: mill.main.Tasks[PathRef], dest: os.Path) = T.command {
os.copy.over(ref.path, dest)
}
def copyLauncher(directory: String = "artifacts") = T.command {
val nativeLauncher = cli.nativeImage().path
val nativeLauncher = cli(mainCliScalaVersion).nativeImage().path
ghreleaseassets.copyLauncher(nativeLauncher, os.Path(directory, os.pwd))
}

def copyStaticLauncher(directory: String = "artifacts") = T.command {
val nativeLauncher = cli.`static-image`.nativeImage().path
val nativeLauncher = cli(mainCliScalaVersion).`static-image`.nativeImage().path
ghreleaseassets.copyLauncher(nativeLauncher, os.Path(directory, os.pwd), suffix = "-static")
}

def copyMostlyStaticLauncher(directory: String = "artifacts") = T.command {
val nativeLauncher = cli.`mostly-static-image`.nativeImage().path
val nativeLauncher = cli(mainCliScalaVersion).`mostly-static-image`.nativeImage().path
ghreleaseassets.copyLauncher(
nativeLauncher,
os.Path(directory, os.pwd),
Expand All @@ -776,7 +726,7 @@ def copyMostlyStaticLauncher(directory: String = "artifacts") = T.command {
}

def copyContainerLauncher(directory: String = "artifacts") = T.command {
val nativeLauncher = cli.containerImage().path
val nativeLauncher = cli(mainCliScalaVersion).containerImage().path
ghreleaseassets.copyLauncher(
nativeLauncher,
os.Path(directory, os.pwd),
Expand All @@ -785,7 +735,7 @@ def copyContainerLauncher(directory: String = "artifacts") = T.command {
}

def uploadLaunchers(directory: String = "artifacts") = T.command {
val version = cli.publishVersion()
val version = cli(mainCliScalaVersion).publishVersion()
ghreleaseassets.uploadLaunchers(version, os.Path(directory, os.pwd))
}

Expand All @@ -794,37 +744,37 @@ def bootstrapLauncher(
dest: String = s"coursier$platformBootstrapExtension"
) = T.command {
val extraArgs = if (version.endsWith("SNAPSHOT")) Seq("-r", "sonatype:snapshots") else Nil
cli.run(Seq(
cli(mainCliScalaVersion).run(Seq(
"bootstrap",
"-o",
dest,
"-f",
s"$mavenOrg::coursier-cli:$version",
"--scala",
cliScalaVersion
mainCliScalaVersion
) ++ extraArgs: _*).map { _ =>
os.Path(dest, os.pwd)
}
}

def assemblyLauncher(version: String = buildVersion, dest: String = "coursier.jar") = T.command {
val extraArgs = if (version.endsWith("SNAPSHOT")) Seq("-r", "sonatype:snapshots") else Nil
cli.run(Seq(
cli(mainCliScalaVersion).run(Seq(
"bootstrap",
"--assembly",
"-o",
dest,
"-f",
s"$mavenOrg::coursier-cli:$version",
"--scala",
cliScalaVersion
mainCliScalaVersion
) ++ extraArgs: _*).map { _ =>
os.Path(dest, os.pwd)
}
}

def waitForSync(version: String = buildVersion) = T.command {
val launcher = cli.launcher().path
val launcher = cli(mainCliScalaVersion).launcher().path
val extraArgs = if (version.endsWith("SNAPSHOT")) Seq("-r", "sonatype:snapshots") else Nil
sync.waitForSync(
launcher.toString,
Expand Down Expand Up @@ -946,23 +896,22 @@ def jvmTests(scalaVersion: String = "*") = {

val prerequisites = Seq(
// required for some tests of `cli-tests`
`launcher-native_04`.publishLocal()
`launcher-native_04`(scalaVersion).publishLocal()
)

val nonCrossTests = Seq(
// format: off
`bootstrap-launcher` .test .test(),
`bootstrap-launcher` .it .test(),
cli .test .test(),
`cli-tests` .test .test()
`bootstrap-launcher` .test .test(),
`bootstrap-launcher` .it .test(),
cli(scalaVersion) .test .test(),
`cli-tests`(scalaVersion) .test .test()
// format: on
)

val extraTests =
if (Properties.isWin) Nil
else
Seq(
simpleNative03CliTest(),
simpleNative04CliTest()
)

Expand Down Expand Up @@ -1005,19 +954,23 @@ def jsTests(scalaVersion: String = "*") = {
}

def nativeTests() = T.command {
`cli-tests`.`native-tests`.test()()
`cli-tests`(mainCliScalaVersion).`native-tests`.test()()
}

def nativeStaticTests() = T.command {
`cli-tests`.`native-static-tests`.test()()
`cli-tests`(mainCliScalaVersion).`native-static-tests`.test()()
}

def nativeMostlyStaticTests() = T.command {
`cli-tests`.`native-mostly-static-tests`.test()()
`cli-tests`(mainCliScalaVersion).`native-mostly-static-tests`.test()()
}

def nativeContainerTests() = T.command {
`cli-tests`.`native-container-tests`.test()()
`cli-tests`(mainCliScalaVersion).`native-container-tests`.test()()
}

def cliNativeImageLauncher() = T.command {
cli(mainCliScalaVersion).nativeImage()
}

object ci extends Module {
Expand Down
Expand Up @@ -109,7 +109,7 @@ object Output {
val classpathOrder = params.classpathOrder.getOrElse(false)
Print.dependenciesUnknownConfigs(
if (classpathOrder) res.orderedDependencies else res.minDependencies.toVector,
res.projectCache.mapValues { case (_, p) => p },
res.projectCache.map { case (k, (_, p)) => k -> p },
printExclusions = withExclusions,
reorder = !classpathOrder
)
Expand Down

0 comments on commit ef2b102

Please sign in to comment.