Skip to content

Add scala-cli version to the BuildInfo #3617

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

Merged
merged 12 commits into from
Apr 10, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ class SourceGeneratorTests extends TestUtil.ScalaCliBuildSuite {
.replaceAll(
"ivy:file:[^\"]*\\.ivy2/local[^\"]*",
"ivy:file:.../.ivy2/local/"
).linesWithSeparators
)
.replaceAll(
"val scalaCliVersion = Some\\(\"[^\"]*\"\\)",
"val scalaCliVersion = Some\\(\"1.1.1-SNAPSHOT\"\\)"
)
.linesWithSeparators
.filterNot(_.stripLeading().startsWith("/**"))
.mkString

Expand Down Expand Up @@ -126,6 +131,7 @@ class SourceGeneratorTests extends TestUtil.ScalaCliBuildSuite {
| val scalaNativeVersion = None
| val mainClass = Some("Main")
| val projectVersion = Some("1.0.0")
| val scalaCliVersion = Some("1.1.1-SNAPSHOT")
|
| object Main {
| val sources = Seq("${root / "main.scala"}")
Expand Down Expand Up @@ -204,6 +210,7 @@ class SourceGeneratorTests extends TestUtil.ScalaCliBuildSuite {
| val scalaNativeVersion = Some("0.4.6")
| val mainClass = Some("Main")
| val projectVersion = None
| val scalaCliVersion = Some("1.1.1-SNAPSHOT")
|
| object Main {
| val sources = Seq("${root / "main.scala"}")
Expand Down Expand Up @@ -281,6 +288,7 @@ class SourceGeneratorTests extends TestUtil.ScalaCliBuildSuite {
| val scalaNativeVersion = None
| val mainClass = Some("Main")
| val projectVersion = None
| val scalaCliVersion = Some("1.1.1-SNAPSHOT")
|
| object Main {
| val sources = Seq("${root / "main.scala"}")
Expand Down Expand Up @@ -355,6 +363,7 @@ class SourceGeneratorTests extends TestUtil.ScalaCliBuildSuite {
| val scalaNativeVersion = None
| val mainClass = Some("Main")
| val projectVersion = None
| val scalaCliVersion = Some("1.1.1-SNAPSHOT")
|
| object Main {
| val sources = Seq("${root / "main.scala"}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,8 @@ object GenerateReferenceDoc extends CaseApp[InternalDocOptions] {
jsEsVersion = None,
scalaNativeVersion = None,
mainClass = Some("Main"),
projectVersion = None
projectVersion = None,
scalaCliVersion = Some("1.7.0")
)
.withScope("main", mainScopedBuildInfo)
.withScope("test", testScopedBuildInfo)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ abstract class ExportJsonTestDefinitions extends ScalaCliSuite with TestScalaVer
"ivy:file:[^\"]*\\.ivy2/local[^\"]*",
"ivy:file:.../.ivy2/local/"
)
.replaceAll(
"\"scalaCliVersion\":(\"[^\"]*\")",
"\"scalaCliVersion\":\"1.1.1-SNAPSHOT\""
)

private def withEscapedBackslashes(s: os.Path): String =
s.toString.replaceAll("\\\\", "\\\\\\\\")
Expand Down Expand Up @@ -71,6 +75,7 @@ abstract class ExportJsonTestDefinitions extends ScalaCliSuite with TestScalaVer
| ]
| }
|]]
|,"scalaCliVersion":"1.1.1-SNAPSHOT"
|}
|""".replaceAll("\\s|\\|", ""))
}
Expand Down Expand Up @@ -172,6 +177,7 @@ abstract class ExportJsonTestDefinitions extends ScalaCliSuite with TestScalaVer
| "customJarsDecls":["${withEscapedBackslashes(root / "TEST.jar")}"]
| }
|]]
|,"scalaCliVersion":"1.1.1-SNAPSHOT"
|}
|""".replaceAll("\\s|\\|", ""))
}
Expand Down Expand Up @@ -248,7 +254,7 @@ abstract class ExportJsonTestDefinitions extends ScalaCliSuite with TestScalaVer
| "ivy:file:.../.ivy2/local/"
| ]
| }
|]]
|]],"scalaCliVersion":"1.1.1-SNAPSHOT"
|}
|""".replaceAll("\\s|\\|", ""))

Expand Down
15 changes: 12 additions & 3 deletions modules/options/src/main/scala/scala/build/info/BuildInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ final case class BuildInfo(
jsEsVersion: Option[String] = None,
scalaNativeVersion: Option[String] = None,
mainClass: Option[String] = None,
scopes: Map[String, ScopedBuildInfo] = Map.empty
scopes: Map[String, ScopedBuildInfo] = Map.empty,
scalaCliVersion: Option[String] = None
) {
def +(other: BuildInfo): BuildInfo =
BuildInfo.monoid.orElse(this, other)
Expand Down Expand Up @@ -64,7 +65,11 @@ final case class BuildInfo(
Seq(
"/** Project version */",
"val projectVersion ="
) -> projectVersion
) -> projectVersion,
Seq(
"/** Scala CLI version used for the compilation */",
"val scalaCliVersion ="
) -> scalaCliVersion
).flatMap { case (Seq(scaladoc, prefix), opt) =>
Seq(
scaladoc,
Expand Down Expand Up @@ -113,7 +118,8 @@ object BuildInfo {
)
),
scalaVersionSettings(options),
platformSettings(options)
platformSettings(options),
scalaCliSettings(options)
)
.reduceLeft(_ + _)
}.left.map {
Expand Down Expand Up @@ -158,6 +164,9 @@ object BuildInfo {
.orElse(Some(options.javaHome().value.version.toString))
)

private def scalaCliSettings(options: BuildOptions): BuildInfo =
BuildInfo(scalaCliVersion = Some(Constants.version))

private def platformSettings(options: BuildOptions): BuildInfo =
options.scalaOptions.platform.map(_.value) match {
case Some(Platform.JS) =>
Expand Down
2 changes: 2 additions & 0 deletions website/docs/reference/build-info.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ object BuildInfo {
val mainClass = Some("Main")
/** Project version */
val projectVersion = None
/** Scala CLI version used for the compilation */
val scalaCliVersion = Some("1.7.0")

/** Information about the Main scope */
object Main {
Expand Down