Skip to content
Merged
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
14 changes: 12 additions & 2 deletions build.mill.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import java.util.Locale
import de.tobiasroeser.mill.vcs.version.VcsVersion
import io.github.alexarchambault.millnativeimage.upload.Upload
import mill._
import mill.api.{BuildCtx, Loose}
import mill.api.{BuildCtx, BuildInfo, Loose}
import scalalib.{publish => _, _}
import mill.contrib.bloop.Bloop
import mill.define.Task.Simple
Expand Down Expand Up @@ -492,7 +492,7 @@ trait Core extends ScalaCliCrossSbtModule
|
| def ammoniteVersion = "${Deps.Versions.ammonite}"
| def ammoniteVersionForScala3Lts = "${Deps.Versions.ammoniteForScala3Lts}"
| def millVersion = "${_root_.mill.main.BuildInfo.millVersion}"
| def millVersion = "${BuildInfo.millVersion}"
| def maxScalaNativeForMillExport = "${Deps.Versions.maxScalaNativeForMillExport}"
|
| def scalafmtOrganization = "${Deps.scalafmtCli.dep.module.organization.value}"
Expand Down Expand Up @@ -841,6 +841,13 @@ trait Cli extends CrossSbtModule with ProtoBuildModule with CliLaunchers
| def defaultGraalVMVersion = "${deps.graalVmVersion}"
| def scalaPyVersion = "${Deps.scalaPy.dep.versionConstraint.asString}"
| def signingCliJvmVersion = ${Deps.Versions.signingCliJvmVersion}
| def defaultMillVersion = "${BuildInfo.millVersion}"
| def mill012Version = "${Deps.Versions.mill012Version}"
| def mill10Version = "${Deps.Versions.mill10Version}"
| def defaultSbtVersion = "${Deps.Versions.sbtVersion}"
| def defaultMavenVersion = "${Deps.Versions.mavenVersion}"
| def defaultMavenScalaCompilerPluginVersion = "${Deps.Versions.mavenScalaCompilerPluginVersion}"
| def defaultMavenExecPluginVersion = "${Deps.Versions.mavenExecPluginVersion}"
|}
|""".stripMargin
if (!os.isFile(dest) || os.read(dest) != code)
Expand Down Expand Up @@ -1089,6 +1096,9 @@ trait CliIntegration extends SbtModule with ScalaCliPublishModule with HasTests
| def jmhOrg = "${Deps.jmhCore.dep.module.organization.value}"
| def jmhCoreModule = "${Deps.jmhCore.dep.module.name.value}"
| def jmhGeneratorBytecodeModule = "${Deps.jmhGeneratorBytecode.dep.module.name.value}"
| def defaultMillVersion = "${BuildInfo.millVersion}"
| def mill012Version = "${Deps.Versions.mill012Version}"
| def mill10Version = "${Deps.Versions.mill10Version}"
|}
|""".stripMargin
if (!os.isFile(dest) || os.read(dest) != code)
Expand Down
47 changes: 31 additions & 16 deletions modules/cli/src/main/scala/scala/cli/commands/export0/Export.scala
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,12 @@ object Export extends ScalaCommand[ExportOptions] {
def millProjectDescriptor(
cache: FileCache[Task],
projectName: Option[String],
millVersion: String,
logger: Logger
): MillProjectDescriptor = {
val launcherArtifacts = Seq(
os.rel / "mill" -> s"https://github.com/com-lihaoyi/mill/raw/${Constants.millVersion}/mill",
os.rel / "mill.bat" -> s"https://github.com/com-lihaoyi/mill/raw/${Constants.millVersion}/mill.bat"
os.rel / "mill" -> s"https://github.com/com-lihaoyi/mill/raw/$millVersion/mill",
os.rel / "mill.bat" -> s"https://github.com/com-lihaoyi/mill/raw/$millVersion/mill.bat"
)
val launcherTasks = launcherArtifacts.map {
case (path, url) =>
Expand All @@ -117,7 +118,12 @@ object Export extends ScalaCommand[ExportOptions] {
}
val launchersTask = cache.logger.using(Task.gather.gather(launcherTasks))
val launchers = launchersTask.unsafeRun()(using cache.ec)
MillProjectDescriptor(Constants.millVersion, projectName, launchers, logger)
MillProjectDescriptor(
millVersion = millVersion,
projectName = projectName,
launchers = launchers,
logger = logger
)
}

def jsonProjectDescriptor(
Expand Down Expand Up @@ -261,21 +267,30 @@ object Export extends ScalaCommand[ExportOptions] {
sbtProjectDescriptor(options.sbtSetting.map(_.trim).filter(_.nonEmpty), sbtVersion, logger)

val projectDescriptor =
if (shouldExportToMill)
millProjectDescriptor(options.shared.coursierCache, options.project, logger)
else if (shouldExportToMaven)
if shouldExportToMill then
millProjectDescriptor(
cache = options.shared.coursierCache,
projectName = options.project,
millVersion = options.millVersion.getOrElse(Constants.millVersion),
logger = logger
)
else if shouldExportToMaven then
mavenProjectDescriptor(
defaultMavenCompilerVersion,
defaultScalaMavenCompilerVersion,
defaultMavenExecPluginVersion,
Nil,
defaultMavenGroupId,
defaultMavenArtifactId,
defaultMavenVersion,
logger
mavenPluginVersion = defaultMavenCompilerVersion,
mavenScalaPluginVersion = defaultScalaMavenCompilerVersion,
mavenExecPluginVersion = defaultMavenExecPluginVersion,
extraSettings = Nil,
mavenGroupId = defaultMavenGroupId,
mavenArtifactId = defaultMavenArtifactId,
mavenVersion = defaultMavenVersion,
logger = logger
)
else if shouldExportToJson then
jsonProjectDescriptor(
projectName = options.project,
workspace = inputs.workspace,
logger = logger
)
else if (shouldExportToJson)
jsonProjectDescriptor(options.project, inputs.workspace, logger)
else // shouldExportToSbt isn't checked, as it's treated as default
sbtProjectDescriptor0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,63 +10,74 @@ import scala.cli.commands.shared.{
MainClassOptions,
SharedOptions
}
import scala.cli.commands.tags
import scala.cli.commands.{Constants, tags}

// format: off
@HelpMessage(ExportOptions.helpMessage, "", ExportOptions.detailedHelpMessage)
final case class ExportOptions(
// FIXME There might be too many options for 'scala-cli export' there
@Recurse
shared: SharedOptions = SharedOptions(),
shared: SharedOptions = SharedOptions(),
@Recurse
mainClass: MainClassOptions = MainClassOptions(),

mainClass: MainClassOptions = MainClassOptions(),
@Group(HelpGroup.BuildToolExport.toString)
@Tag(tags.restricted)
@Tag(tags.inShortHelp)
@HelpMessage("Sets the export format to SBT")
sbt: Option[Boolean] = None,
sbt: Option[Boolean] = None,
@Group(HelpGroup.BuildToolExport.toString)
@Tag(tags.experimental)
@Tag(tags.inShortHelp)
@HelpMessage("Sets the export format to Maven")
@Name("mvn")
maven: Option[Boolean] = None,
maven: Option[Boolean] = None,
@Group(HelpGroup.BuildToolExport.toString)
@Tag(tags.restricted)
@Tag(tags.inShortHelp)
@HelpMessage("Sets the export format to Mill")
mill: Option[Boolean] = None,
mill: Option[Boolean] = None,
@Tag(tags.restricted)
@Tag(tags.inShortHelp)
@Group(HelpGroup.BuildToolExport.toString)
@HelpMessage("Sets the export format to Json")
json: Option[Boolean] = None,

json: Option[Boolean] = None,
@Name("setting")
@Group(HelpGroup.BuildToolExport.toString)
@Tag(tags.restricted)
sbtSetting: List[String] = Nil,
sbtSetting: List[String] = Nil,
@Name("p")
@Group(HelpGroup.BuildToolExport.toString)
@Tag(tags.restricted)
@HelpMessage("Project name to be used on Mill build file")
project: Option[String] = None,
project: Option[String] = None,
@Group(HelpGroup.BuildToolExport.toString)
@Tag(tags.restricted)
@HelpMessage(
s"Version of SBT to be used for the export (${Constants.defaultSbtVersion} by default)"
)
sbtVersion: Option[String] = None,
@Group(HelpGroup.BuildToolExport.toString)
@Tag(tags.restricted)
@HelpMessage("Version of SBT to be used for the export")
sbtVersion: Option[String] = None,
@HelpMessage(
s"Version of Mill to be used for the export (${Constants.defaultMillVersion} by default)"
)
millVersion: Option[String] = None,
@Group(HelpGroup.BuildToolExport.toString)
@Tag(tags.experimental)
@HelpMessage("Version of Maven Compiler Plugin to be used for the export")
mvnVersion: Option[String] = None,
@HelpMessage(
s"Version of Maven Compiler Plugin to be used for the export (${Constants.defaultMavenVersion} by default)"
)
mvnVersion: Option[String] = None,
@Group(HelpGroup.BuildToolExport.toString)
@Tag(tags.experimental)
@HelpMessage("Version of Maven Scala Plugin to be used for the export")
@HelpMessage(
s"Version of Maven Scala Plugin to be used for the export (${Constants.defaultMavenScalaCompilerPluginVersion} by default)"
)
mvnScalaVersion: Option[String] = None,
@Group(HelpGroup.BuildToolExport.toString)
@Tag(tags.experimental)
@HelpMessage("Version of Maven Exec Plugin to be used for the export")
@HelpMessage(
s"Version of Maven Exec Plugin to be used for the export (${Constants.defaultMavenExecPluginVersion} by default)"
)
mvnExecPluginVersion: Option[String] = None,
@Group(HelpGroup.BuildToolExport.toString)
@Tag(tags.experimental)
Expand All @@ -83,9 +94,8 @@ final case class ExportOptions(
@Name("o")
@Group(HelpGroup.BuildToolExport.toString)
@Tag(tags.restricted)
output: Option[String] = None,
output: Option[String] = None
) extends HasSharedOptions
// format: on
object ExportOptions {
implicit lazy val parser: Parser[ExportOptions] = Parser.derive
implicit lazy val help: Help[ExportOptions] = Help.derive
Expand Down
41 changes: 30 additions & 11 deletions modules/cli/src/main/scala/scala/cli/exportCmd/MillProject.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ final case class MillProject(
extraTestDecls: Seq[String] = Nil,
mainClass: Option[String] = None
) extends Project {
private lazy val isMill1OrNewer: Boolean = !millVersion.exists(_.startsWith("0."))

def +(other: MillProject): MillProject =
MillProject.monoid.orElse(this, other)
Expand Down Expand Up @@ -82,24 +83,37 @@ final case class MillProject(
Some(s"""def scalacOptions = super.scalacOptions() ++ Seq($optsString)""")
}
def maybeDeps(deps: Seq[String], isCompileOnly: Boolean = false) = {
val depsDefinition = if (isCompileOnly)
Seq("def compileIvyDeps = super.compileIvyDeps() ++ Seq(")
else Seq("def ivyDeps = super.ivyDeps() ++ Seq(")
if (deps.isEmpty) Seq.empty[String]
val depsDefinition = isCompileOnly -> isMill1OrNewer match {
case (true, true) => Seq("def compileMvnDeps = super.compileMvnDeps() ++ Seq(")
case (true, false) => Seq("def compileIvyDeps = super.compileIvyDeps() ++ Seq(")
case (false, true) => Seq("def mvnDeps = super.mvnDeps() ++ Seq(")
case (false, false) => Seq("def ivyDeps = super.ivyDeps() ++ Seq(")
}
if deps.isEmpty then Seq.empty[String]
else
depsDefinition ++
deps
.map(dep => """ ivy"""" + dep + "\"")
.map {
case dep if isMill1OrNewer => s""" mvn"$dep""""
case dep => s""" ivy"$dep""""
}
.appendOnInit(",") ++
Seq(")")
}

val maybeScalaCompilerPlugins =
if (scalaCompilerPlugins.isEmpty) Seq.empty
if scalaCompilerPlugins.isEmpty then Seq.empty
else
Seq("def scalacPluginIvyDeps = super.scalacPluginIvyDeps() ++ Seq(") ++
Seq(
if isMill1OrNewer
then "def scalacPluginMvnDeps = super.scalacPluginMvnDeps() ++ Seq("
else "def scalacPluginIvyDeps = super.scalacPluginIvyDeps() ++ Seq("
) ++
scalaCompilerPlugins
.map(dep => s" ivy\"$dep\"")
.map {
case dep if isMill1OrNewer => s" mvn\"$dep\""
case dep => s" ivy\"$dep\""
}
.appendOnInit(",")
++ Seq(")")

Expand All @@ -110,7 +124,11 @@ final case class MillProject(
if (resourcesDirs.isEmpty) Nil
else {
val resources =
resourcesDirs.map(p => s"""T.workspace / os.RelPath("${p.relativeTo(dir)}")""")
resourcesDirs.map {
case p if isMill1OrNewer =>
s"""mill.api.BuildCtx.workspaceRoot / os.RelPath("${p.relativeTo(dir)}")"""
case p => s"""T.workspace / os.RelPath("${p.relativeTo(dir)}")"""
}
Seq("def runClasspath = super.runClasspath() ++ Seq(") ++
resources.map(resource => s" $resource").appendOnInit(",") ++
Seq(").map(PathRef(_))")
Expand All @@ -128,7 +146,7 @@ final case class MillProject(
extraTestDecls.map(s => s" $s") ++ Seq(" }")
else Seq.empty

val buildSc: String = {
val buildFileContent: String = {
val parts: Seq[String] = Seq(
"import mill._",
"import mill.scalalib._"
Expand Down Expand Up @@ -158,7 +176,8 @@ final case class MillProject(
os.write(path0, content, createFolders = true)
}

os.write(dir / "build.sc", buildSc.getBytes(charSet))
val outputBuildFile = if isMill1OrNewer then dir / "build.mill.scala" else dir / "build.sc"
os.write(outputBuildFile, buildFileContent.getBytes(charSet))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ final case class MillProjectDescriptor(

val pureJava = ProjectDescriptor.isPureJavaProject(options, sources)

val sv = options.scalaParams.toOption.flatten.map(_.scalaVersion).getOrElse(
ScalaCli.getDefaultScalaVersion
)

if (pureJava)
MillProject()
else
MillProject(scalaVersion = Some(sv))
val sv = options.scalaParams
.toOption
.flatten
.map(_.scalaVersion)
.getOrElse(ScalaCli.getDefaultScalaVersion)

if pureJava then MillProject()
else MillProject(scalaVersion = Some(sv))
}

private def scalaCompilerPlugins(buildOptions: BuildOptions): MillProject =
Expand All @@ -49,9 +49,7 @@ final case class MillProjectDescriptor(
MillProject(scalacOptions = buildOptions.scalaOptions.scalacOptions.toSeq.map(_.value.value))

private def scalaJsSettings(options: ScalaJsOptions): MillProject = {

val scalaJsVersion = Some(options.version.getOrElse(Constants.scalaJsVersion))

val scalaJsVersion = Some(options.version.getOrElse(Constants.scalaJsVersion))
val moduleKindDecls =
if (options.moduleKindStr.isEmpty) Nil
else
Expand Down Expand Up @@ -108,36 +106,31 @@ final case class MillProjectDescriptor(
}

private def customResourcesSettings(options: BuildOptions): MillProject =
MillProject(
resourcesDirs = options.classPathOptions.resourcesDir
)
MillProject(resourcesDirs = options.classPathOptions.resourcesDir)

private def customJarsSettings(options: BuildOptions): MillProject = {

val customCompileOnlyJarsDecls =
if (options.classPathOptions.extraCompileOnlyJars.isEmpty) Nil
if options.classPathOptions.extraCompileOnlyJars.isEmpty then Nil
else {
val jars =
options.classPathOptions.extraCompileOnlyJars.map(p => s"""PathRef(os.Path("$p"))""")
Seq(s"""def compileClasspath = super.compileClasspath() ++ Seq(${jars.mkString(", ")})""")
}

val customJarsDecls =
if (options.classPathOptions.extraClassPath.isEmpty) Nil
if options.classPathOptions.extraClassPath.isEmpty then Nil
else {
val jars = options.classPathOptions.extraClassPath.map(p => s"""PathRef(os.Path("$p"))""")
Seq(
s"""def unmanagedClasspath = super.unmanagedClasspath() ++ Seq(${jars.mkString(", ")})"""
)
}

MillProject(
extraDecls = customCompileOnlyJarsDecls ++ customJarsDecls
)
MillProject(extraDecls = customCompileOnlyJarsDecls ++ customJarsDecls)
}

private def testFrameworkSettings(options: BuildOptions): MillProject = {

val testClassPath: Seq[Path] = options.artifacts(logger, Scope.Test) match {
case Right(artifacts) => artifacts.classPath.map(_.toNIO)
case Left(exception) =>
Expand Down Expand Up @@ -185,9 +178,9 @@ final case class MillProjectDescriptor(
scalaCompilerPlugins(optionsMain),
dependencySettings(optionsMain, optionsTest),
repositorySettings(optionsMain),
if (optionsMain.platform.value == Platform.JS) scalaJsSettings(optionsMain.scalaJsOptions)
if optionsMain.platform.value == Platform.JS then scalaJsSettings(optionsMain.scalaJsOptions)
else MillProject(),
if (optionsMain.platform.value == Platform.Native)
if optionsMain.platform.value == Platform.Native then
scalaNativeSettings(optionsMain.scalaNativeOptions)
else MillProject(),
customResourcesSettings(optionsMain),
Expand Down
Loading