From 5d10e310792737569b7e614c50c5c979f545b62d Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Mon, 4 Jul 2022 13:44:10 +0200 Subject: [PATCH 1/3] Compile CLI for a single Scala version --- build.sc | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/build.sc b/build.sc index faa6b51..0ebddb3 100644 --- a/build.sc +++ b/build.sc @@ -20,7 +20,7 @@ def scalaVersions = Seq("2.12.15", "2.13.8") def mainScalaVersion = scalaVersions.last object core extends Cross[Core](scalaVersions: _*) -object cli extends Cross[Cli](scalaVersions: _*) +object cli extends Cli class Core(val crossScalaVersion: String) extends CrossSbtModule with SnailgunPublishModule { object test extends Tests { @@ -36,12 +36,10 @@ class Core(val crossScalaVersion: String) extends CrossSbtModule with SnailgunPu } def ghOrg = "scala-cli" -class Cli(val crossScalaVersion: String) - extends CrossSbtModule - with NativeImage - with SnailgunPublishModule { +trait Cli extends SbtModule with NativeImage with SnailgunPublishModule { + def scalaVersion = mainScalaVersion def moduleDeps = Seq( - core() + core(mainScalaVersion) ) def ivyDeps = super.ivyDeps() ++ Seq( ivy"com.github.alexarchambault::case-app:2.1.0-M14" @@ -197,7 +195,7 @@ private def finalPublishVersion = { } def nativeImage = T { - cli(mainScalaVersion).nativeImage() + cli.nativeImage() } object ci extends Module { @@ -257,7 +255,7 @@ object ci extends Module { } def copyLauncher(directory: String = "artifacts") = T.command { - val nativeLauncher = cli(mainScalaVersion).nativeImage().path + val nativeLauncher = cli.nativeImage().path Upload.copyLauncher( nativeLauncher, directory, @@ -268,7 +266,7 @@ object ci extends Module { def copyJvmLauncher(directory: String = "artifacts") = T.command { val platformExecutableJarExtension = if (Properties.isWin) ".bat" else "" - val launcher = cli(mainScalaVersion).standaloneLauncher().path + val launcher = cli.standaloneLauncher().path os.copy( launcher, os.Path(directory, os.pwd) / s"snailgun$platformExecutableJarExtension", @@ -281,7 +279,7 @@ object ci extends Module { sys.error("UPLOAD_GH_TOKEN not set") } def uploadLaunchers(directory: String = "artifacts") = T.command { - val version = cli(mainScalaVersion).publishVersion() + val version = cli.publishVersion() val path = os.Path(directory, os.pwd) val launchers = os.list(path).filter(os.isFile(_)).map { path => From 9a06c01e9d31932cbe828885a94526adde48e3b3 Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Mon, 4 Jul 2022 13:44:20 +0200 Subject: [PATCH 2/3] NIT --- cli/src/main/scala/snailgun/Cli.scala | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cli/src/main/scala/snailgun/Cli.scala b/cli/src/main/scala/snailgun/Cli.scala index e5522a9..a3177e1 100644 --- a/cli/src/main/scala/snailgun/Cli.scala +++ b/cli/src/main/scala/snailgun/Cli.scala @@ -33,7 +33,6 @@ object Cli extends CaseApp[CliOptions] { .orElse(Defaults.env.get("NAILGUN_PORT").map(_.toInt)) .getOrElse(Defaults.Port) val client = TcpClient(hostServer, portServer) - val noCancel = new AtomicBoolean(false) val logger = new SnailgunLogger("log", out, isVerbose = options.verbose) val code = try @@ -44,7 +43,7 @@ object Cli extends CaseApp[CliOptions] { Defaults.env, streams, logger, - noCancel, + new AtomicBoolean(false), true ) catch { From 4c0e2d0c4d256c5ad2f4aa6c3e393cd838216cc9 Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Mon, 4 Jul 2022 13:50:15 +0200 Subject: [PATCH 3/3] Tweak CLI --- build.sc | 2 +- cli/src/main/scala/snailgun/{Cli.scala => Snailgun.scala} | 4 ++-- .../snailgun/{CliOptions.scala => SnailgunOptions.scala} | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) rename cli/src/main/scala/snailgun/{Cli.scala => Snailgun.scala} (93%) rename cli/src/main/scala/snailgun/{CliOptions.scala => SnailgunOptions.scala} (77%) diff --git a/build.sc b/build.sc index 0ebddb3..50e185f 100644 --- a/build.sc +++ b/build.sc @@ -44,7 +44,7 @@ trait Cli extends SbtModule with NativeImage with SnailgunPublishModule { def ivyDeps = super.ivyDeps() ++ Seq( ivy"com.github.alexarchambault::case-app:2.1.0-M14" ) - def mainClass = Some("snailgun.Cli") + def mainClass = Some("snailgun.Snailgun") def nativeImageClassPath = runClasspath() def nativeImageMainClass = mainClass().getOrElse { diff --git a/cli/src/main/scala/snailgun/Cli.scala b/cli/src/main/scala/snailgun/Snailgun.scala similarity index 93% rename from cli/src/main/scala/snailgun/Cli.scala rename to cli/src/main/scala/snailgun/Snailgun.scala index a3177e1..5e3e733 100644 --- a/cli/src/main/scala/snailgun/Cli.scala +++ b/cli/src/main/scala/snailgun/Snailgun.scala @@ -9,9 +9,9 @@ import java.io.{InputStream, PrintStream} import java.net.ConnectException import java.util.concurrent.atomic.AtomicBoolean -object Cli extends CaseApp[CliOptions] { +object Snailgun extends CaseApp[SnailgunOptions] { override def stopAtFirstUnrecognized = true - def run(options: CliOptions, args: RemainingArgs): Unit = { + def run(options: SnailgunOptions, args: RemainingArgs): Unit = { val inOpt = if (options.hasInput) Some(System.in) else None val out = System.out val err = System.err diff --git a/cli/src/main/scala/snailgun/CliOptions.scala b/cli/src/main/scala/snailgun/SnailgunOptions.scala similarity index 77% rename from cli/src/main/scala/snailgun/CliOptions.scala rename to cli/src/main/scala/snailgun/SnailgunOptions.scala index 1d86db4..e62136b 100644 --- a/cli/src/main/scala/snailgun/CliOptions.scala +++ b/cli/src/main/scala/snailgun/SnailgunOptions.scala @@ -4,7 +4,7 @@ import caseapp._ // format: off @ArgsName("The command and arguments for the Nailgun server") -final case class CliOptions( +final case class SnailgunOptions( @HelpMessage("Specify the host name of the target Nailgun server") nailgunServer: Option[String] = None, @HelpMessage("Specify the port of the target Nailgun server") @@ -18,7 +18,7 @@ final case class CliOptions( ) // format: on -object CliOptions { - implicit lazy val parser: Parser[CliOptions] = Parser.derive - implicit lazy val help: Help[CliOptions] = Help.derive +object SnailgunOptions { + implicit lazy val parser: Parser[SnailgunOptions] = Parser.derive + implicit lazy val help: Help[SnailgunOptions] = Help.derive }