Skip to content

Commit 9abcb25

Browse files
authored
fix: start bloop with jvm version from using directives for JVMs > 17 (#2972)
* fix: start bloop with jvm version from using directives for JVMs > 17 * test fix * start bloop with jvm 17 before test
1 parent 753b099 commit 9abcb25

File tree

15 files changed

+215
-151
lines changed

15 files changed

+215
-151
lines changed

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

Lines changed: 103 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,26 @@ object Build {
213213
)
214214
}
215215

216+
private def allInputs(
217+
inputs: Inputs,
218+
options: BuildOptions,
219+
logger: Logger
220+
)(using ScalaCliInvokeData) =
221+
CrossSources.forInputs(
222+
inputs,
223+
Sources.defaultPreprocessors(
224+
options.archiveCache,
225+
options.internal.javaClassNameVersionOpt,
226+
() => options.javaHome().value.javaCommand
227+
),
228+
logger,
229+
options.suppressWarningOptions,
230+
options.internal.exclude
231+
)
232+
216233
private def build(
217234
inputs: Inputs,
235+
crossSources: CrossSources,
218236
options: BuildOptions,
219237
logger: Logger,
220238
buildClient: BloopBuildClient,
@@ -225,20 +243,6 @@ object Build {
225243
partial: Option[Boolean],
226244
actionableDiagnostics: Option[Boolean]
227245
)(using ScalaCliInvokeData): Either[BuildException, Builds] = either {
228-
// allInputs contains elements from using directives
229-
val (crossSources, allInputs) = value {
230-
CrossSources.forInputs(
231-
inputs,
232-
Sources.defaultPreprocessors(
233-
options.archiveCache,
234-
options.internal.javaClassNameVersionOpt,
235-
() => options.javaHome().value.javaCommand
236-
),
237-
logger,
238-
options.suppressWarningOptions,
239-
options.internal.exclude
240-
)
241-
}
242246
val sharedOptions = crossSources.sharedOptions(options)
243247
val crossOptions = sharedOptions.crossOptions
244248

@@ -274,15 +278,15 @@ object Build {
274278
val scopedSources = value(crossSources.scopedSources(baseOptions))
275279

276280
val mainSources =
277-
value(scopedSources.sources(Scope.Main, baseOptions, allInputs.workspace, logger))
281+
value(scopedSources.sources(Scope.Main, baseOptions, inputs.workspace, logger))
278282
val mainOptions = mainSources.buildOptions
279283

280284
val testSources =
281-
value(scopedSources.sources(Scope.Test, baseOptions, allInputs.workspace, logger))
285+
value(scopedSources.sources(Scope.Test, baseOptions, inputs.workspace, logger))
282286
val testOptions = testSources.buildOptions
283287

284288
val inputs0 = updateInputs(
285-
allInputs,
289+
inputs,
286290
mainOptions, // update hash in inputs with options coming from the CLI or cross-building, not from the sources
287291
Some(testOptions).filter(_ != mainOptions)
288292
)
@@ -556,53 +560,60 @@ object Build {
556560
buildTests: Boolean,
557561
partial: Option[Boolean],
558562
actionableDiagnostics: Option[Boolean]
559-
)(using ScalaCliInvokeData): Either[BuildException, Builds] = {
563+
)(using ScalaCliInvokeData): Either[BuildException, Builds] = either {
560564
val buildClient = BloopBuildClient.create(
561565
logger,
562566
keepDiagnostics = options.internal.keepDiagnostics
563567
)
564-
val classesDir0 = classesRootDir(inputs.workspace, inputs.projectName)
565-
566-
compilerMaker.withCompiler(
567-
inputs.workspace / Constants.workspaceDirName,
568-
classesDir0,
569-
buildClient,
570-
logger
571-
) { compiler =>
572-
docCompilerMakerOpt match {
573-
case None =>
574-
build(
575-
inputs = inputs,
576-
options = options,
577-
logger = logger,
578-
buildClient = buildClient,
579-
compiler = compiler,
580-
docCompilerOpt = None,
581-
crossBuilds = crossBuilds,
582-
buildTests = buildTests,
583-
partial = partial,
584-
actionableDiagnostics = actionableDiagnostics
585-
)
586-
case Some(docCompilerMaker) =>
587-
docCompilerMaker.withCompiler(
588-
inputs.workspace / Constants.workspaceDirName,
589-
classesDir0, // ???
590-
buildClient,
591-
logger
592-
) { docCompiler =>
568+
val classesDir0 = classesRootDir(inputs.workspace, inputs.projectName)
569+
val (crossSources, inputs0) = value(allInputs(inputs, options, logger))
570+
val buildOptions = crossSources.sharedOptions(options)
571+
value {
572+
compilerMaker.withCompiler(
573+
inputs0.workspace / Constants.workspaceDirName,
574+
classesDir0,
575+
buildClient,
576+
logger,
577+
buildOptions
578+
) { compiler =>
579+
docCompilerMakerOpt match {
580+
case None =>
593581
build(
594-
inputs = inputs,
582+
inputs = inputs0,
583+
crossSources = crossSources,
595584
options = options,
596585
logger = logger,
597586
buildClient = buildClient,
598587
compiler = compiler,
599-
docCompilerOpt = Some(docCompiler),
588+
docCompilerOpt = None,
600589
crossBuilds = crossBuilds,
601590
buildTests = buildTests,
602591
partial = partial,
603592
actionableDiagnostics = actionableDiagnostics
604593
)
605-
}
594+
case Some(docCompilerMaker) =>
595+
docCompilerMaker.withCompiler(
596+
inputs0.workspace / Constants.workspaceDirName,
597+
classesDir0, // ???
598+
buildClient,
599+
logger,
600+
buildOptions
601+
) { docCompiler =>
602+
build(
603+
inputs = inputs0,
604+
crossSources = crossSources,
605+
options = options,
606+
logger = logger,
607+
buildClient = buildClient,
608+
compiler = compiler,
609+
docCompilerOpt = Some(docCompiler),
610+
crossBuilds = crossBuilds,
611+
buildTests = buildTests,
612+
partial = partial,
613+
actionableDiagnostics = actionableDiagnostics
614+
)
615+
}
616+
}
606617
}
607618
}
608619
}
@@ -638,35 +649,48 @@ object Build {
638649
)
639650
val threads = BuildThreads.create()
640651
val classesDir0 = classesRootDir(inputs.workspace, inputs.projectName)
641-
val compiler = compilerMaker.create(
642-
inputs.workspace / Constants.workspaceDirName,
643-
classesDir0,
644-
buildClient,
645-
logger
646-
)
647-
val docCompilerOpt = docCompilerMakerOpt.map(_.create(
648-
inputs.workspace / Constants.workspaceDirName,
649-
classesDir0,
650-
buildClient,
651-
logger
652-
))
652+
val info = either {
653+
val (crossSources, inputs0) = value(allInputs(inputs, options, logger))
654+
val sharedOptions = crossSources.sharedOptions(options)
655+
val compiler = value {
656+
compilerMaker.create(
657+
inputs0.workspace / Constants.workspaceDirName,
658+
classesDir0,
659+
buildClient,
660+
logger,
661+
sharedOptions
662+
)
663+
}
664+
val docCompilerOpt = docCompilerMakerOpt.map(_.create(
665+
inputs0.workspace / Constants.workspaceDirName,
666+
classesDir0,
667+
buildClient,
668+
logger,
669+
sharedOptions
670+
)).map(value)
671+
(compiler, docCompilerOpt, crossSources, inputs0)
672+
}
653673

654674
var res: Either[BuildException, Builds] = null
655675

656676
def run(): Unit = {
657677
try {
658-
res = build(
659-
inputs,
660-
options,
661-
logger,
662-
buildClient,
663-
compiler,
664-
docCompilerOpt,
665-
crossBuilds = crossBuilds,
666-
buildTests = buildTests,
667-
partial = partial,
668-
actionableDiagnostics = actionableDiagnostics
669-
)
678+
res =
679+
info.flatMap { case (compiler, docCompilerOpt, crossSources, inputs) =>
680+
build(
681+
inputs,
682+
crossSources,
683+
options,
684+
logger,
685+
buildClient,
686+
compiler,
687+
docCompilerOpt,
688+
crossBuilds = crossBuilds,
689+
buildTests = buildTests,
690+
partial = partial,
691+
actionableDiagnostics = actionableDiagnostics
692+
)
693+
}
670694
action(res)
671695
}
672696
catch {
@@ -678,7 +702,8 @@ object Build {
678702

679703
run()
680704

681-
val watcher = new Watcher(ListBuffer(), threads.fileWatcher, run(), compiler.shutdown())
705+
val watcher =
706+
new Watcher(ListBuffer(), threads.fileWatcher, run(), info.foreach(_._1.shutdown()))
682707

683708
def doWatch(): Unit = {
684709
val elements: Seq[Element] =
@@ -1284,9 +1309,11 @@ object Build {
12841309
runJmh = build.options.jmhOptions.runJmh.map(_ => false)
12851310
)
12861311
)
1312+
val (crossSources, inputs0) = value(allInputs(jmhInputs, updatedOptions, logger))
12871313
val jmhBuilds = value {
12881314
Build.build(
1289-
jmhInputs,
1315+
inputs0,
1316+
crossSources,
12901317
updatedOptions,
12911318
logger,
12921319
buildClient,

modules/build/src/main/scala/scala/build/compiler/BloopCompilerMaker.scala

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ import bloop.rifle.{BloopRifleConfig, BloopServer, BloopThreads}
44
import ch.epfl.scala.bsp4j.BuildClient
55

66
import scala.build.Logger
7-
import scala.build.errors.{FetchingDependenciesError, Severity}
7+
import scala.build.errors.{BuildException, FetchingDependenciesError, Severity}
88
import scala.build.internal.Constants
99
import scala.build.internal.util.WarningMessages
10+
import scala.build.options.BuildOptions
1011
import scala.concurrent.duration.DurationInt
1112
import scala.util.Try
1213

1314
final class BloopCompilerMaker(
14-
config: BloopRifleConfig,
15+
getConfig: BuildOptions => Either[BuildException, BloopRifleConfig],
1516
threads: BloopThreads,
1617
strictBloopJsonCheck: Boolean,
1718
offline: Boolean
@@ -20,37 +21,48 @@ final class BloopCompilerMaker(
2021
workspace: os.Path,
2122
classesDir: os.Path,
2223
buildClient: BuildClient,
23-
logger: Logger
24-
): ScalaCompiler = {
25-
val createBuildServer =
26-
() =>
27-
BloopServer.buildServer(
28-
config,
29-
"scala-cli",
30-
Constants.version,
31-
workspace.toNIO,
32-
classesDir.toNIO,
24+
logger: Logger,
25+
buildOptions: BuildOptions
26+
): Either[BuildException, ScalaCompiler] =
27+
getConfig(buildOptions) match
28+
case Left(ex) if offline =>
29+
logger.diagnostic(WarningMessages.offlineModeBloopJvmNotFound, Severity.Warning)
30+
SimpleScalaCompilerMaker("java", Nil).create(
31+
workspace,
32+
classesDir,
3333
buildClient,
34-
threads,
35-
logger.bloopRifleLogger
34+
logger,
35+
buildOptions
3636
)
37+
case Right(config) =>
38+
val createBuildServer =
39+
() =>
40+
BloopServer.buildServer(
41+
config,
42+
"scala-cli",
43+
Constants.version,
44+
workspace.toNIO,
45+
classesDir.toNIO,
46+
buildClient,
47+
threads,
48+
logger.bloopRifleLogger
49+
)
3750

38-
Try(new BloopCompiler(createBuildServer, 20.seconds, strictBloopJsonCheck))
39-
.toEither
40-
.left.flatMap {
41-
case e if offline =>
42-
e.getCause match
43-
case _: FetchingDependenciesError =>
44-
logger.diagnostic(
45-
WarningMessages.offlineModeBloopNotFound,
46-
Severity.Warning
47-
)
48-
Right(
49-
SimpleScalaCompilerMaker("java", Nil)
50-
.create(workspace, classesDir, buildClient, logger)
51-
)
52-
case _ => Left(e)
53-
case e => Left(e)
54-
}.fold(t => throw t, identity)
55-
}
51+
val res = Try(new BloopCompiler(createBuildServer, 20.seconds, strictBloopJsonCheck))
52+
.toEither
53+
.left.flatMap {
54+
case e if offline =>
55+
e.getCause match
56+
case _: FetchingDependenciesError =>
57+
logger.diagnostic(
58+
WarningMessages.offlineModeBloopNotFound,
59+
Severity.Warning
60+
)
61+
SimpleScalaCompilerMaker("java", Nil)
62+
.create(workspace, classesDir, buildClient, logger, buildOptions)
63+
case _ => Left(e)
64+
case e => Left(e)
65+
}.fold(t => throw t, identity)
66+
Right(res)
67+
case Left(ex) => Left(ex)
5668
}

0 commit comments

Comments
 (0)