Skip to content

Commit efac997

Browse files
committed
Log cross builds information when --cross is not enabled (and some other things, too)
1 parent 65bfd6b commit efac997

File tree

5 files changed

+177
-111
lines changed

5 files changed

+177
-111
lines changed

modules/build/src/main/scala/scala/build/Build.scala

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -447,8 +447,19 @@ object Build {
447447
extraBuilds.flatMap(_.testDocOpt)
448448
)
449449
}
450-
else
450+
else {
451+
if crossOptions.nonEmpty then {
452+
val crossBuildParams: Seq[CrossBuildParams] = crossOptions.map(CrossBuildParams(_))
453+
logger.message(
454+
s"""Cross-building is disabled, ignoring ${crossOptions.length} builds:
455+
| ${crossBuildParams.map(_.asString).mkString("\n ")}
456+
|Cross builds are only available when the --cross option is passed.
457+
|Defaulting to ${CrossBuildParams(options).asString}
458+
|""".stripMargin
459+
)
460+
}
451461
(Nil, Nil, Nil, Nil)
462+
}
452463

453464
Builds(
454465
builds = Seq(nonCrossBuilds.main) ++ nonCrossBuilds.testOpt.toSeq,
@@ -610,7 +621,7 @@ object Build {
610621
actionableDiagnostics: Option[Boolean]
611622
)(using ScalaCliInvokeData): Either[BuildException, Builds] = either {
612623
val buildClient = BloopBuildClient.create(
613-
logger,
624+
logger = logger,
614625
keepDiagnostics = options.internal.keepDiagnostics
615626
)
616627
val classesDir0 = classesRootDir(inputs.workspace, inputs.projectName)
@@ -628,14 +639,15 @@ object Build {
628639
)
629640
value {
630641
compilerMaker.withCompiler(
631-
inputs0.workspace / Constants.workspaceDirName,
632-
classesDir0,
633-
buildClient,
634-
logger,
635-
buildOptions
642+
workspace = inputs0.workspace / Constants.workspaceDirName,
643+
classesDir = classesDir0,
644+
buildClient = buildClient,
645+
logger = logger,
646+
buildOptions = buildOptions
636647
) { compiler =>
637648
docCompilerMakerOpt match {
638649
case None =>
650+
logger.debug("No doc compiler provided, skipping")
639651
build(
640652
inputs = inputs0,
641653
crossSources = crossSources,
@@ -651,11 +663,11 @@ object Build {
651663
)
652664
case Some(docCompilerMaker) =>
653665
docCompilerMaker.withCompiler(
654-
inputs0.workspace / Constants.workspaceDirName,
655-
classesDir0, // ???
656-
buildClient,
657-
logger,
658-
buildOptions
666+
workspace = inputs0.workspace / Constants.workspaceDirName,
667+
classesDir = classesDir0, // ???
668+
buildClient = buildClient,
669+
logger = logger,
670+
buildOptions = buildOptions
659671
) { docCompiler =>
660672
build(
661673
inputs = inputs0,
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package scala.build
2+
3+
import scala.build.internal.Constants
4+
import scala.build.options.BuildOptions
5+
6+
case class CrossBuildParams(scalaVersion: String, platform: String) {
7+
def asString: String = s"Scala $scalaVersion, $platform"
8+
}
9+
10+
object CrossBuildParams {
11+
def apply(buildOptions: BuildOptions) = new CrossBuildParams(
12+
scalaVersion = buildOptions.scalaOptions.scalaVersion
13+
.map(_.asString)
14+
.getOrElse(Constants.defaultScalaVersion),
15+
platform = buildOptions.platform.value.repr
16+
)
17+
}

modules/cli/src/main/scala/scala/cli/commands/run/Run.scala

Lines changed: 91 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,11 @@ object Run extends ScalaCommand[RunOptions] with BuildCommandHelpers {
8484
jvmIdOpt = baseOptions.javaOptions.jvmIdOpt.orElse {
8585
runMode(options) match {
8686
case _: RunMode.Spark | RunMode.HadoopJar =>
87-
Some(Positioned.none("8"))
87+
val sparkOrHadoopDefaultJvm = "8"
88+
logger.message(
89+
s"Defaulting the JVM to $sparkOrHadoopDefaultJvm for Spark/Hadoop runs."
90+
)
91+
Some(Positioned.none(sparkOrHadoopDefaultJvm))
8892
case RunMode.Default => None
8993
}
9094
}
@@ -122,11 +126,14 @@ object Run extends ScalaCommand[RunOptions] with BuildCommandHelpers {
122126
val shouldDefaultServerFalse =
123127
inputArgs.isEmpty && options0.shared.compilationServer.server.isEmpty &&
124128
!options0.shared.hasSnippets
125-
val options = if (shouldDefaultServerFalse) options0.copy(shared =
126-
options0.shared.copy(compilationServer =
127-
options0.shared.compilationServer.copy(server = Some(false))
129+
val options = if (shouldDefaultServerFalse) {
130+
logger.debug("No inputs provided, skipping the build server.")
131+
options0.copy(shared =
132+
options0.shared.copy(compilationServer =
133+
options0.shared.compilationServer.copy(server = Some(false))
134+
)
128135
)
129-
)
136+
}
130137
else options0
131138
val initialBuildOptions = {
132139
val buildOptions = buildOptionsOrExit(options)
@@ -170,15 +177,15 @@ object Run extends ScalaCommand[RunOptions] with BuildCommandHelpers {
170177
else {
171178
val processOrCommand: Either[Seq[Seq[String]], Seq[(Process, Option[() => Unit])]] = value {
172179
maybeRunOnce(
173-
builds,
174-
programArgs,
175-
logger,
180+
builds = builds,
181+
args = programArgs,
182+
logger = logger,
176183
allowExecve = allowTerminate,
177184
jvmRunner = builds.exists(_.artifacts.hasJvmRunner),
178-
potentialMainClasses,
179-
runMode,
180-
showCommand,
181-
scratchDirOpt,
185+
potentialMainClasses = potentialMainClasses,
186+
runMode = runMode,
187+
showCommand = showCommand,
188+
scratchDirOpt = scratchDirOpt,
182189
asJar = options.shared.asJar
183190
)
184191
}
@@ -219,13 +226,17 @@ object Run extends ScalaCommand[RunOptions] with BuildCommandHelpers {
219226
}
220227

221228
val cross = options.sharedRun.compileCross.cross.getOrElse(false)
229+
if cross then
230+
logger.log(
231+
"Cross builds enabled, preparing all builds for all Scala versions and platforms..."
232+
)
222233
SetupIde.runSafe(
223-
options.shared,
224-
inputs,
225-
logger,
226-
initialBuildOptions,
227-
Some(name),
228-
inputArgs
234+
options = options.shared,
235+
inputs = inputs,
236+
logger = logger,
237+
buildOptions = initialBuildOptions,
238+
previousCommandName = Some(name),
239+
args = inputArgs
229240
)
230241
if CommandUtils.shouldCheckUpdate then Update.checkUpdateSafe(logger)
231242

@@ -236,6 +247,8 @@ object Run extends ScalaCommand[RunOptions] with BuildCommandHelpers {
236247
)
237248

238249
val shouldBuildTestScope = options.shared.scope.test.getOrElse(false)
250+
if shouldBuildTestScope then
251+
logger.log("Test scope enabled, including test scope inputs on the classpath...")
239252
if options.sharedRun.watch.watchMode then {
240253

241254
/** A handle to the Runner processes, used to kill the process if it's still alive when a
@@ -403,11 +416,13 @@ object Run extends ScalaCommand[RunOptions] with BuildCommandHelpers {
403416
.orElse(retainedMainClassesByScope.get(Scope.Test))
404417
.get
405418
}
419+
logger.debug(s"Retained main class: $mainClass")
406420
val verbosity = builds.head.options.internal.verbosity.getOrElse(0).toString
407421

408422
val (finalMainClass, finalArgs) =
409423
if (jvmRunner) (Constants.runnerMainClass, mainClass +: verbosity +: args)
410424
else (mainClass, args)
425+
logger.debug(s"Final main class: $finalMainClass")
411426
val res = runOnce(
412427
builds,
413428
finalMainClass,
@@ -424,8 +439,7 @@ object Run extends ScalaCommand[RunOptions] with BuildCommandHelpers {
424439

425440
def pythonPathEnv(dirs: os.Path*): Map[String, String] = {
426441
val onlySafePaths = sys.env.exists {
427-
case (k, v) =>
428-
k.toLowerCase(Locale.ROOT) == "pythonsafepath" && v.nonEmpty
442+
case (k, v) => k.toLowerCase(Locale.ROOT) == "pythonsafepath" && v.nonEmpty
429443
}
430444
// Don't add unsafe directories to PYTHONPATH if PYTHONSAFEPATH is set,
431445
// see https://docs.python.org/3/using/cmdline.html#envvar-PYTHONSAFEPATH
@@ -454,12 +468,15 @@ object Run extends ScalaCommand[RunOptions] with BuildCommandHelpers {
454468
scratchDirOpt: Option[os.Path],
455469
asJar: Boolean
456470
): Either[BuildException, Either[Seq[Seq[String]], Seq[(Process, Option[() => Unit])]]] = {
457-
allBuilds
458-
.groupedByCrossParams.toSeq
471+
val crossBuilds = allBuilds.groupedByCrossParams.toSeq
472+
val shouldLogCrossInfo = crossBuilds.size > 1
473+
if shouldLogCrossInfo then
474+
logger.log(
475+
s"Running ${crossBuilds.size} cross builds, one for each Scala version and platform combination."
476+
)
477+
crossBuilds
459478
.map { (crossBuildParams, builds) =>
460-
logger.debug(
461-
s"Running build for Scala '${crossBuildParams.scalaVersion}' and platform '${crossBuildParams.platform}'"
462-
)
479+
if shouldLogCrossInfo then logger.debug(s"Running build for ${crossBuildParams.asString}")
463480
val build = builds.head
464481
either {
465482
build.options.platform.value match {
@@ -480,15 +497,15 @@ object Run extends ScalaCommand[RunOptions] with BuildCommandHelpers {
480497
}
481498
val res =
482499
Package.linkJs(
483-
builds,
484-
jsDest,
485-
Some(mainClass),
500+
builds = builds,
501+
dest = jsDest,
502+
mainClassOpt = Some(mainClass),
486503
addTestInitializer = false,
487-
linkerConfig,
488-
value(build.options.scalaJsOptions.fullOpt),
489-
build.options.scalaJsOptions.noOpt.getOrElse(false),
490-
logger,
491-
scratchDirOpt
504+
config = linkerConfig,
505+
fullOpt = value(build.options.scalaJsOptions.fullOpt),
506+
noOpt = build.options.scalaJsOptions.noOpt.getOrElse(false),
507+
logger = logger,
508+
scratchDirOpt = scratchDirOpt
492509
).map { outputPath =>
493510
val jsDom = build.options.scalaJsOptions.dom.getOrElse(false)
494511
if (showCommand)
@@ -572,9 +589,9 @@ object Run extends ScalaCommand[RunOptions] with BuildCommandHelpers {
572589
)
573590
else {
574591
val proc = Runner.runNative(
575-
launcher.toIO,
576-
args,
577-
logger,
592+
launcher = launcher.toIO,
593+
args = args,
594+
logger = logger,
578595
allowExecve = allowExecve,
579596
extraEnv = extraEnv
580597
)
@@ -634,12 +651,12 @@ object Run extends ScalaCommand[RunOptions] with BuildCommandHelpers {
634651
}
635652
else {
636653
val proc = Runner.runJvm(
637-
build.options.javaHome().value.javaCommand,
638-
allJavaOpts,
639-
builds.flatMap(_.fullClassPathMaybeAsJar(asJar)).distinct,
640-
mainClass,
641-
args,
642-
logger,
654+
javaCommand = build.options.javaHome().value.javaCommand,
655+
javaArgs = allJavaOpts,
656+
classPath = builds.flatMap(_.fullClassPathMaybeAsJar(asJar)).distinct,
657+
mainClass = mainClass,
658+
args = args,
659+
logger = logger,
643660
allowExecve = allowExecve,
644661
extraEnv = pythonExtraEnv,
645662
useManifest = build.options.notForBloopOptions.runWithManifest,
@@ -650,39 +667,39 @@ object Run extends ScalaCommand[RunOptions] with BuildCommandHelpers {
650667
case mode: RunMode.SparkSubmit =>
651668
value {
652669
RunSpark.run(
653-
builds,
654-
mainClass,
655-
args,
656-
mode.submitArgs,
657-
logger,
658-
allowExecve,
659-
showCommand,
660-
scratchDirOpt
670+
builds = builds,
671+
mainClass = mainClass,
672+
args = args,
673+
submitArgs = mode.submitArgs,
674+
logger = logger,
675+
allowExecve = allowExecve,
676+
showCommand = showCommand,
677+
scratchDirOpt = scratchDirOpt
661678
)
662679
}
663680
case mode: RunMode.StandaloneSparkSubmit =>
664681
value {
665682
RunSpark.runStandalone(
666-
builds,
667-
mainClass,
668-
args,
669-
mode.submitArgs,
670-
logger,
671-
allowExecve,
672-
showCommand,
673-
scratchDirOpt
683+
builds = builds,
684+
mainClass = mainClass,
685+
args = args,
686+
submitArgs = mode.submitArgs,
687+
logger = logger,
688+
allowExecve = allowExecve,
689+
showCommand = showCommand,
690+
scratchDirOpt = scratchDirOpt
674691
)
675692
}
676693
case RunMode.HadoopJar =>
677694
value {
678695
RunHadoop.run(
679-
builds,
680-
mainClass,
681-
args,
682-
logger,
683-
allowExecve,
684-
showCommand,
685-
scratchDirOpt
696+
builds = builds,
697+
mainClass = mainClass,
698+
args = args,
699+
logger = logger,
700+
allowExecve = allowExecve,
701+
showCommand = showCommand,
702+
scratchDirOpt = scratchDirOpt
686703
)
687704
}
688705
}
@@ -706,17 +723,15 @@ object Run extends ScalaCommand[RunOptions] with BuildCommandHelpers {
706723
)(f: os.Path => T): Either[BuildException, T] = {
707724
val dest = os.temp(prefix = "main", suffix = if (esModule) ".mjs" else ".js")
708725
try Package.linkJs(
709-
builds,
710-
dest,
711-
mainClassOpt,
712-
addTestInitializer,
713-
config,
714-
fullOpt,
715-
noOpt,
716-
logger
717-
).map { outputPath =>
718-
f(outputPath)
719-
}
726+
builds = builds,
727+
dest = dest,
728+
mainClassOpt = mainClassOpt,
729+
addTestInitializer = addTestInitializer,
730+
config = config,
731+
fullOpt = fullOpt,
732+
noOpt = noOpt,
733+
logger = logger
734+
).map(outputPath => f(outputPath))
720735
finally if (os.exists(dest)) os.remove(dest)
721736
}
722737

modules/cli/src/main/scala/scala/cli/commands/util/BuildCommandHelpers.scala

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
11
package scala.cli.commands.util
22

33
import scala.build.errors.BuildException
4-
import scala.build.{Build, Builds, Logger, Os}
4+
import scala.build.{Build, Builds, CrossBuildParams, Logger, Os}
55
import scala.cli.commands.ScalaCommand
66
import scala.cli.commands.shared.SharedOptions
77
import scala.cli.commands.util.ScalacOptionsUtil.*
88

99
trait BuildCommandHelpers { self: ScalaCommand[?] =>
10-
case class CrossBuildParams(scalaVersion: String, platform: String)
1110
extension (b: Seq[Build.Successful]) {
1211
def groupedByCrossParams: Map[CrossBuildParams, Seq[Build.Successful]] =
13-
b.groupBy { b =>
14-
CrossBuildParams(
15-
b.options.scalaOptions.scalaVersion.map(_.asString).toString,
16-
b.options.platform.toString
17-
)
18-
}
12+
b.groupBy(bb => CrossBuildParams(bb.options))
1913
}
2014
extension (successfulBuild: Build.Successful) {
2115
def retainedMainClass(

0 commit comments

Comments
 (0)