Skip to content
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

Log scala-cli version when --log-cli-version is enabled #3614

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,7 @@ trait CliIntegration extends SbtModule with ScalaCliPublishModule with HasTests
|
|/** Build-time constants. Generated by mill. */
|object Constants {
| def scalaCliVersion = "${publishVersion()}"
| def allJavaVersions = Seq(${Java.allJavaVersions.sorted.mkString(", ")})
| def bspVersion = "${Deps.bsp4j.dep.version}"
| def bloopMinimumJvmVersion = ${Java.minimumBloopJava}
Expand Down
7 changes: 6 additions & 1 deletion modules/build/src/main/scala/scala/build/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1090,13 +1090,18 @@ object Build {
)
else
options

val params = value(options0.scalaParams)

val scopeParams =
if (scope == Scope.Main) Nil
else Seq(scope.name)

buildClient.setProjectParams(scopeParams ++ value(options0.projectParams))
val scalaCliVersionLog =
if options0.internal.logCliVersion then Seq(s"scala-cli ${Constants.version}") else Nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't use scala-cli here, as contextually it may be just scala. What you actually need is scala.cli.ScalaCli.fullRunnerName... which is unfortunate, since you log it in the build module.
You could maybe pass it via scala.build.input.ScalaCliInvokeData... See how it's passed around in the code elsewhere. I wonder if scala.build.input.ScalaCliInvokeData.progName would be enough...

I'm thinking this would look awkward:

Compiling project (Scala 3.7.0 JVM (17), scala 1.7.1)

We should have the full runner name, so:

Compiling project (Scala 3.7.0 JVM (17), Scala code runner  1.7.1)

buildClient.setProjectParams(
scopeParams ++ value(options0.projectParams) ++ scalaCliVersionLog
)

val classesDir0 = classesDir(inputs.workspace, inputs.projectName, scope)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ final case class LoggingOptions(
@Group(HelpGroup.Logging.toString)
@Tag(tags.implementation)
@HelpMessage("Use progress bars")
progress: Option[Boolean] = None
progress: Option[Boolean] = None,
@Group(HelpGroup.Logging.toString)
@Tag(tags.implementation)
@HelpMessage("Logs scala-cli version on project build")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@HelpMessage("Logs scala-cli version on project build")
@HelpMessage(s"Logs ${scala.cli.ScalaCli.fullRunnerName} version alongside JVM and Scala versions when the project gets recompiled by the server.")

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it still feels hyper-granular to have a command line option just for that... wouldn't it be better to print this when verbosity is set to +1? (as in, just a single -v)
If we can live without this command line option, I guess I'd rather not have it.
tagging @tgodzik for second opinion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, probably too less info for a separate flag. I think it is alos fine with -v. Additionally, it might be good if the scala-cli version is also added to buildinfo, so that in cases such as mine, I can explicitly log this info using the buildinfo.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, adding it to BuildInfo is a good idea, I think.
Feel free to do it in a separate PR (or make a new issue).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me see if I can create a separate PR with adding this info in the buildinfo. Reg -v, let me know. It would still be nice to see this info without making any code change in the scripts.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Gedochao I created a new PR
#3617

logCliVersion: Boolean = false
) {
// format: on

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,8 @@ final case class SharedOptions(
strictBloopJsonCheck = strictBloopJsonCheck,
interactive = Some(() => interactive),
exclude = exclude.map(Positioned.commandLine),
offline = coursier.getOffline()
offline = coursier.getOffline(),
logCliVersion = logging.logCliVersion
),
notForBloopOptions = bo.PostBuildOptions(
scalaJsLinkerOptions = linkerOptions(js),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,33 @@ abstract class CompileTestDefinitions
}
}

test("logs the scala-cli version when the --log-cli-version option is used") {
val filename = "Main.scala"
val inputs = TestInputs(
os.rel / filename ->
"""|object Main extends App {
| val msg: String = "1"
|}
|""".stripMargin
)
inputs.fromRoot { root =>
val result = os.proc(TestUtil.cli, "compile", ".", "--log-cli-version", extraOptions).call(
cwd = root,
check = false,
mergeErrIntoOut = true
)

assertEquals(
TestUtil.fullStableOutput(result),
s"""|Compiling project (Scala $actualScalaVersion, JVM (${Constants
.defaultGraalVMJavaVersion}), scala-cli ${Constants.scalaCliVersion})
|Compiled project (Scala $actualScalaVersion, JVM (${Constants
.defaultGraalVMJavaVersion}), scala-cli ${Constants.scalaCliVersion})""".stripMargin
)

}
}

test("i3389") {
val filename = "Main.scala"
val inputs = TestInputs(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ final case class InternalOptions(
keepResolution: Boolean = false,
extraSourceFiles: Seq[Positioned[os.Path]] = Nil,
exclude: Seq[Positioned[String]] = Nil,
offline: Option[Boolean] = None
offline: Option[Boolean] = None,
logCliVersion: Boolean = false
) {
def verbosityOrDefault: Int = verbosity.getOrElse(0)
def strictBloopJsonCheckOrDefault: Boolean =
Expand Down
4 changes: 4 additions & 0 deletions website/docs/reference/cli-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,10 @@ Decrease logging verbosity

Use progress bars

### `--log-cli-version`

Logs scala-cli version on project build

## Main class options

Available in commands:
Expand Down
6 changes: 6 additions & 0 deletions website/docs/reference/scala-command/cli-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,12 @@ Decrease logging verbosity

Use progress bars

### `--log-cli-version`

`IMPLEMENTATION specific` per Scala Runner specification

Logs scala-cli version on project build

## Main class options

Available in commands:
Expand Down
72 changes: 72 additions & 0 deletions website/docs/reference/scala-command/runner-specification.md
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,10 @@ Aliases: `-q`

Use progress bars

**--log-cli-version**

Logs scala-cli version on project build

**--js-no-opt**

Disable optimalisation for Scala.js, overrides `--js-mode`
Expand Down Expand Up @@ -787,6 +791,10 @@ Aliases: `-q`

Use progress bars

**--log-cli-version**

Logs scala-cli version on project build

**--suppress-experimental-feature-warning**

Suppress warnings about using experimental features
Expand Down Expand Up @@ -1176,6 +1184,10 @@ Aliases: `-q`

Use progress bars

**--log-cli-version**

Logs scala-cli version on project build

**--js-no-opt**

Disable optimalisation for Scala.js, overrides `--js-mode`
Expand Down Expand Up @@ -1777,6 +1789,10 @@ Aliases: `-q`

Use progress bars

**--log-cli-version**

Logs scala-cli version on project build

**--js-no-opt**

Disable optimalisation for Scala.js, overrides `--js-mode`
Expand Down Expand Up @@ -2408,6 +2424,10 @@ Aliases: `-q`

Use progress bars

**--log-cli-version**

Logs scala-cli version on project build

**--js-no-opt**

Disable optimalisation for Scala.js, overrides `--js-mode`
Expand Down Expand Up @@ -3048,6 +3068,10 @@ Aliases: `-q`

Use progress bars

**--log-cli-version**

Logs scala-cli version on project build

**--js-no-opt**

Disable optimalisation for Scala.js, overrides `--js-mode`
Expand Down Expand Up @@ -3640,6 +3664,10 @@ Aliases: `-q`

Use progress bars

**--log-cli-version**

Logs scala-cli version on project build

**--js-no-opt**

Disable optimalisation for Scala.js, overrides `--js-mode`
Expand Down Expand Up @@ -4307,6 +4335,10 @@ Aliases: `-q`

Use progress bars

**--log-cli-version**

Logs scala-cli version on project build

**--js-no-opt**

Disable optimalisation for Scala.js, overrides `--js-mode`
Expand Down Expand Up @@ -4632,6 +4664,10 @@ Aliases: `-q`

Use progress bars

**--log-cli-version**

Logs scala-cli version on project build

**--suppress-experimental-feature-warning**

Suppress warnings about using experimental features
Expand Down Expand Up @@ -4987,6 +5023,10 @@ Aliases: `-q`

Use progress bars

**--log-cli-version**

Logs scala-cli version on project build

**--js-no-opt**

Disable optimalisation for Scala.js, overrides `--js-mode`
Expand Down Expand Up @@ -5316,6 +5356,10 @@ Aliases: `-q`

Use progress bars

**--log-cli-version**

Logs scala-cli version on project build

**--suppress-experimental-feature-warning**

Suppress warnings about using experimental features
Expand Down Expand Up @@ -5407,6 +5451,10 @@ Aliases: `-q`

Use progress bars

**--log-cli-version**

Logs scala-cli version on project build

**--suppress-experimental-feature-warning**

Suppress warnings about using experimental features
Expand Down Expand Up @@ -5486,6 +5534,10 @@ Aliases: `-q`

Use progress bars

**--log-cli-version**

Logs scala-cli version on project build

**--suppress-experimental-feature-warning**

Suppress warnings about using experimental features
Expand Down Expand Up @@ -5589,6 +5641,10 @@ Aliases: `-q`

Use progress bars

**--log-cli-version**

Logs scala-cli version on project build

**--suppress-experimental-feature-warning**

Suppress warnings about using experimental features
Expand Down Expand Up @@ -5950,6 +6006,10 @@ Aliases: `-q`

Use progress bars

**--log-cli-version**

Logs scala-cli version on project build

**--js-no-opt**

Disable optimalisation for Scala.js, overrides `--js-mode`
Expand Down Expand Up @@ -6279,6 +6339,10 @@ Aliases: `-q`

Use progress bars

**--log-cli-version**

Logs scala-cli version on project build

**--suppress-experimental-feature-warning**

Suppress warnings about using experimental features
Expand Down Expand Up @@ -6472,6 +6536,10 @@ Aliases: `-q`

Use progress bars

**--log-cli-version**

Logs scala-cli version on project build

**--suppress-experimental-feature-warning**

Suppress warnings about using experimental features
Expand Down Expand Up @@ -6551,6 +6619,10 @@ Aliases: `-q`

Use progress bars

**--log-cli-version**

Logs scala-cli version on project build

**--suppress-experimental-feature-warning**

Suppress warnings about using experimental features
Expand Down