@@ -38,7 +38,7 @@ object Build {
3838 final case class Successful (
3939 inputs : Inputs ,
4040 options : BuildOptions ,
41- scalaParams : ScalaParameters ,
41+ scalaParams : Option [ ScalaParameters ] ,
4242 scope : Scope ,
4343 sources : Sources ,
4444 artifacts : Artifacts ,
@@ -76,14 +76,15 @@ object Build {
7676 }
7777 }
7878
79- def crossKey : CrossKey =
80- CrossKey (
79+ def crossKey : CrossKey = {
80+ val optKey = scalaParams.map { params =>
8181 BuildOptions .CrossKey (
82- scalaParams .scalaVersion,
82+ params .scalaVersion,
8383 options.platform.value
84- ),
85- scope
86- )
84+ )
85+ }
86+ CrossKey (optKey, scope)
87+ }
8788 }
8889
8990 final case class Failed (
@@ -405,34 +406,37 @@ object Build {
405406 inputs : Inputs
406407 ): Either [BuildException , Option [ScalaNativeCompatibilityError ]] =
407408 either {
408- val scalaVersion = value(options.scalaParams).scalaVersion
409- val nativeVersion = options.scalaNativeOptions.numeralVersion
410- val isCompatible = nativeVersion match {
411- case Some (snNumeralVer) =>
412- if (snNumeralVer < SNNumeralVersion (0 , 4 , 1 ) && Properties .isWin)
413- false
414- else if (scalaVersion.startsWith(" 3.0" ))
415- false
416- else if (scalaVersion.startsWith(" 3" ))
417- snNumeralVer >= SNNumeralVersion (0 , 4 , 3 )
418- else if (scalaVersion.startsWith(" 2.13" ))
419- true
420- else if (scalaVersion.startsWith(" 2.12" ))
421- inputs.sourceFiles().forall {
422- case _ : Inputs .AnyScript => false
423- case _ => true
424- }
425- else false
426- case None => false
427- }
428- if (isCompatible) None
429- else
430- Some (
431- new ScalaNativeCompatibilityError (
432- scalaVersion,
433- options.scalaNativeOptions.finalVersion
409+ val scalaParamsOpt = value(options.scalaParams)
410+ scalaParamsOpt.flatMap { scalaParams =>
411+ val scalaVersion = scalaParams.scalaVersion
412+ val nativeVersion = options.scalaNativeOptions.numeralVersion
413+ val isCompatible = nativeVersion match {
414+ case Some (snNumeralVer) =>
415+ if (snNumeralVer < SNNumeralVersion (0 , 4 , 1 ) && Properties .isWin)
416+ false
417+ else if (scalaVersion.startsWith(" 3.0" ))
418+ false
419+ else if (scalaVersion.startsWith(" 3" ))
420+ snNumeralVer >= SNNumeralVersion (0 , 4 , 3 )
421+ else if (scalaVersion.startsWith(" 2.13" ))
422+ true
423+ else if (scalaVersion.startsWith(" 2.12" ))
424+ inputs.sourceFiles().forall {
425+ case _ : Inputs .AnyScript => false
426+ case _ => true
427+ }
428+ else false
429+ case None => false
430+ }
431+ if (isCompatible) None
432+ else
433+ Some (
434+ new ScalaNativeCompatibilityError (
435+ scalaVersion,
436+ options.scalaNativeOptions.finalVersion
437+ )
434438 )
435- )
439+ }
436440 }
437441
438442 def build (
@@ -652,59 +656,67 @@ object Build {
652656
653657 val releaseFlagVersion = releaseFlag(options, compilerJvmVersionOpt, logger).map(_.toString)
654658
655- val scalaCompilerParams = {
659+ val scalaCompilerParamsOpt = artifacts.scalaOpt match {
660+ case Some (scalaArtifacts) =>
661+ val params = value(options.scalaParams).getOrElse {
662+ sys.error(
663+ " Should not happen (inconsistency between Scala parameters in BuildOptions and ScalaArtifacts)"
664+ )
665+ }
656666
657- val params = value(options.scalaParams)
667+ val pluginScalacOptions = scalaArtifacts.compilerPlugins.distinct.map {
668+ case (_, _, path) =>
669+ ScalacOpt (s " -Xplugin: $path" )
670+ }
658671
659- val pluginScalacOptions = artifacts.compilerPlugins.distinct.map {
660- case (_, _, path) =>
661- ScalacOpt (s " -Xplugin: $path" )
662- }
672+ val semanticDbScalacOptions =
673+ if (generateSemanticDbs)
674+ if (params.scalaVersion.startsWith(" 2." ))
675+ Seq (
676+ " -Yrangepos" ,
677+ " -P:semanticdb:failures:warning" ,
678+ " -P:semanticdb:synthetics:on" ,
679+ s " -P:semanticdb:sourceroot: ${inputs.workspace}"
680+ ).map(ScalacOpt (_))
681+ else
682+ Seq (
683+ " -Xsemanticdb" ,
684+ " -sourceroot" ,
685+ inputs.workspace.toString
686+ ).map(ScalacOpt (_))
687+ else Nil
688+
689+ val sourceRootScalacOptions =
690+ if (params.scalaVersion.startsWith(" 2." )) Nil
691+ else Seq (" -sourceroot" , inputs.workspace.toString).map(ScalacOpt (_))
692+
693+ val scalaJsScalacOptions =
694+ if (options.platform.value == Platform .JS && ! params.scalaVersion.startsWith(" 2." ))
695+ Seq (ScalacOpt (" -scalajs" ))
696+ else Nil
697+
698+ val scalacReleaseV = releaseFlagVersion
699+ .map(v => List (" -release" , v).map(ScalacOpt (_)))
700+ .getOrElse(Nil )
701+
702+ val scalacOptions =
703+ options.scalaOptions.scalacOptions.map(_.value) ++
704+ pluginScalacOptions ++
705+ semanticDbScalacOptions ++
706+ sourceRootScalacOptions ++
707+ scalaJsScalacOptions ++
708+ scalacReleaseV
709+
710+ val compilerParams = ScalaCompilerParams (
711+ scalaVersion = params.scalaVersion,
712+ scalaBinaryVersion = params.scalaBinaryVersion,
713+ scalacOptions = scalacOptions.toSeq.map(_.value),
714+ compilerClassPath = scalaArtifacts.compilerClassPath
715+ )
716+ Some (compilerParams)
663717
664- val semanticDbScalacOptions =
665- if (generateSemanticDbs)
666- if (params.scalaVersion.startsWith(" 2." ))
667- Seq (
668- " -Yrangepos" ,
669- " -P:semanticdb:failures:warning" ,
670- " -P:semanticdb:synthetics:on" ,
671- s " -P:semanticdb:sourceroot: ${inputs.workspace}"
672- ).map(ScalacOpt (_))
673- else
674- Seq (
675- " -Xsemanticdb" ,
676- " -sourceroot" ,
677- inputs.workspace.toString
678- ).map(ScalacOpt (_))
679- else Nil
680-
681- val sourceRootScalacOptions =
682- if (params.scalaVersion.startsWith(" 2." )) Nil
683- else Seq (" -sourceroot" , inputs.workspace.toString).map(ScalacOpt (_))
684-
685- val scalaJsScalacOptions =
686- if (options.platform.value == Platform .JS && ! params.scalaVersion.startsWith(" 2." ))
687- Seq (ScalacOpt (" -scalajs" ))
688- else Nil
689-
690- val scalacReleaseV = releaseFlagVersion
691- .map(v => List (" -release" , v).map(ScalacOpt (_)))
692- .getOrElse(Nil )
693-
694- val scalacOptions =
695- options.scalaOptions.scalacOptions.map(_.value) ++
696- pluginScalacOptions ++
697- semanticDbScalacOptions ++
698- sourceRootScalacOptions ++
699- scalaJsScalacOptions ++
700- scalacReleaseV
701-
702- ScalaCompilerParams (
703- scalaVersion = params.scalaVersion,
704- scalaBinaryVersion = params.scalaBinaryVersion,
705- scalacOptions = scalacOptions.toSeq.map(_.value),
706- compilerClassPath = artifacts.compilerClassPath
707- )
718+ case None =>
719+ None
708720 }
709721
710722 val javacOptions = {
@@ -755,7 +767,7 @@ object Build {
755767 workspace = inputs.workspace,
756768 classesDir = classesDir0,
757769 scaladocDir = scaladocDir,
758- scalaCompiler = Some (scalaCompilerParams) ,
770+ scalaCompiler = scalaCompilerParamsOpt ,
759771 scalaJsOptions =
760772 if (options.platform.value == Platform .JS ) Some (options.scalaJsOptions.config(logger))
761773 else None ,
@@ -783,46 +795,64 @@ object Build {
783795 compilerJvmVersionOpt : Option [Positioned [Int ]],
784796 scope : Scope ,
785797 compiler : ScalaCompiler ,
786- logger : Logger
798+ logger : Logger ,
799+ buildClient : BloopBuildClient
787800 ): Either [BuildException , (os.Path , Option [ScalaParameters ], Artifacts , Project , Boolean )] =
788801 either {
789802
790- val params = value(options.scalaParams)
803+ val options0 =
804+ if (sources.hasJava && ! sources.hasScala)
805+ options.copy(
806+ scalaOptions = options.scalaOptions.copy(
807+ scalaVersion0 = options.scalaOptions.scalaVersion0.orElse {
808+ Some (MaybeScalaVersion .none)
809+ }
810+ )
811+ )
812+ else
813+ options
814+ val params = value(options0.scalaParams)
791815
792- val classesDir0 = classesDir(inputs.workspace, inputs.projectName, scope)
816+ val scopeParams =
817+ if (scope == Scope .Main ) Nil
818+ else Seq (scope.name)
793819
794- val artifacts = value(options.artifacts(logger ))
820+ buildClient.setProjectParams(scopeParams ++ value(options0.projectParams ))
795821
796- value(validate(logger, options) )
822+ val classesDir0 = classesDir(inputs.workspace, inputs.projectName, scope )
797823
798- val project = value {
799- buildProject(
800- inputs,
801- sources,
802- generatedSources,
803- options,
804- compilerJvmVersionOpt,
805- scope,
806- logger
807- )
808- }
824+ val artifacts = value(options0.artifacts(logger))
809825
810- val projectChanged = compiler.prepareProject(project, logger )
826+ value(validate(logger, options0) )
811827
812- if (compiler.usesClassDir && projectChanged && os.isDir(classesDir0)) {
813- logger.debug(s " Clearing $classesDir0" )
814- os.list(classesDir0).foreach { p =>
815- logger.debug(s " Removing $p" )
816- try os.remove.all(p)
817- catch {
818- case ex : FileSystemException =>
819- logger.debug(s " Ignoring $ex while cleaning up $p" )
828+ val project = value {
829+ buildProject(
830+ inputs,
831+ sources,
832+ generatedSources,
833+ options0,
834+ compilerJvmVersionOpt,
835+ scope,
836+ logger
837+ )
838+ }
839+
840+ val projectChanged = compiler.prepareProject(project, logger)
841+
842+ if (compiler.usesClassDir && projectChanged && os.isDir(classesDir0)) {
843+ logger.debug(s " Clearing $classesDir0" )
844+ os.list(classesDir0).foreach { p =>
845+ logger.debug(s " Removing $p" )
846+ try os.remove.all(p)
847+ catch {
848+ case ex : FileSystemException =>
849+ logger.debug(s " Ignoring $ex while cleaning up $p" )
850+ }
820851 }
821852 }
822- }
823853
824- (classesDir0, params, artifacts, project, projectChanged)
825- }
854+ (classesDir0, params, artifacts, project, projectChanged)
855+ }
826856
827857 def buildOnce (
828858 inputs : Inputs ,
0 commit comments