@@ -9,6 +9,8 @@ import Keys._
9
9
10
10
import com .typesafe .tools .mima .plugin .MimaPlugin .autoImport ._
11
11
import de .heikoseeberger .sbtheader .HeaderPlugin .autoImport ._
12
+ import sbtbuildinfo .BuildInfoPlugin
13
+ import sbtbuildinfo .BuildInfoPlugin .autoImport ._
12
14
import ScriptedPlugin .autoImport ._
13
15
14
16
import java .util .Arrays
@@ -282,6 +284,20 @@ object Build {
282
284
if (condition) List (testDir)
283
285
else Nil
284
286
287
+ private def buildInfoOrStubs (config : Configuration , stubsBaseDir : Def .Initialize [File ]) = {
288
+ if (isGeneratingForIDE) {
289
+ Def .settings(
290
+ unmanagedSourceDirectories in config +=
291
+ stubsBaseDir.value / " scala-ide-stubs"
292
+ )
293
+ } else {
294
+ Def .settings(
295
+ BuildInfoPlugin .buildInfoScopedSettings(config),
296
+ BuildInfoPlugin .buildInfoDefaultSettings,
297
+ )
298
+ }
299
+ }
300
+
285
301
val previousArtifactSetting : Seq [Setting [_]] = Def .settings(
286
302
/* Do not fail mimaReportBinaryIssues when mimaPreviousArtifacts is empty.
287
303
* We specifically set it to empty below when binary compat is irrelevant.
@@ -915,34 +931,41 @@ object Build {
915
931
unmanagedSourceDirectories in Test +=
916
932
baseDirectory.value.getParentFile.getParentFile / " shared/src/test/scala" ,
917
933
918
- if (isGeneratingForIDE) {
919
- unmanagedSourceDirectories in Test +=
920
- baseDirectory.value.getParentFile.getParentFile / " shared/src/test/scala-ide-stubs"
921
- } else {
922
- sourceGenerators in Test += Def .task {
934
+ buildInfoOrStubs(Test , Def .setting(
935
+ baseDirectory.value.getParentFile.getParentFile / " shared/src/test" )),
936
+
937
+ buildInfoPackage in Test := " org.scalajs.linker.testutils" ,
938
+ buildInfoObject in Test := " StdlibHolder" ,
939
+ buildInfoOptions in Test += BuildInfoOption .PackagePrivate ,
940
+ buildInfoKeys in Test := {
941
+ val previousLibsTask = Def .task {
923
942
val s = streams.value
924
943
val log = s.log
925
944
val lm = dependencyResolution.value
926
945
val binVer = scalaBinaryVersion.value
927
946
928
947
val retrieveDir = s.cacheDirectory / " previous-stdlibs"
929
948
930
- val previousStdLibs = previousVersions.map { version =>
949
+ previousVersions.map { version =>
931
950
val jars = lm.retrieve(" org.scala-js" % s " scalajs-library_ $binVer" % version intransitive(),
932
951
scalaModuleInfo = None , retrieveDir, log)
933
952
.fold(w => throw w.resolveException, _.distinct)
934
953
assert(jars.size == 1 , jars.toString())
935
- version -> jars.head
954
+ version -> jars.head.getAbsolutePath
936
955
}.toMap
937
-
938
- ConstantHolderGenerator .generate(
939
- (sourceManaged in Test ).value,
940
- " org.scalajs.linker.testutils.StdlibHolder" ,
941
- " minilib" -> (packageMinilib in (library, Compile )).value,
942
- " fulllib" -> (packageBin in (library, Compile )).value,
943
- " previousLibs" -> previousStdLibs,
944
- )
945
956
}.taskValue
957
+
958
+ Seq (
959
+ BuildInfoKey .map(previousLibsTask) {
960
+ case (_, v) => " previousLibs" -> v
961
+ },
962
+ BuildInfoKey .map(packageMinilib in (library, Compile )) {
963
+ case (_, v) => " minilib" -> v.getAbsolutePath
964
+ },
965
+ BuildInfoKey .map(packageBin in (library, Compile )) {
966
+ case (_, v) => " fulllib" -> v.getAbsolutePath
967
+ },
968
+ )
946
969
},
947
970
948
971
previousArtifactSetting,
@@ -2062,39 +2085,36 @@ object Build {
2062
2085
}
2063
2086
},
2064
2087
2065
- if (isGeneratingForIDE) {
2066
- unmanagedSourceDirectories in Compile +=
2067
- baseDirectory.value / " src/main/scala-ide-stubs"
2068
- } else {
2069
- sourceGenerators in Compile += Def .task {
2070
- val stage = scalaJSStage.value
2088
+ buildInfoOrStubs(Compile , Def .setting(baseDirectory.value / " src/main" )),
2071
2089
2072
- val linkerConfig = stage match {
2073
- case FastOptStage => (scalaJSLinkerConfig in ( Compile , fastLinkJS)).value
2074
- case FullOptStage => (scalaJSLinkerConfig in ( Compile , fullLinkJS)).value
2075
- }
2090
+ buildInfoPackage in Compile := " org.scalajs.testsuite.utils " ,
2091
+ buildInfoOptions in Compile += BuildInfoOption . PackagePrivate ,
2092
+ buildInfoKeys in Compile := {
2093
+ val stage = scalaJSStage.value
2076
2094
2077
- val moduleKind = linkerConfig.moduleKind
2078
- val sems = linkerConfig.semantics
2079
-
2080
- ConstantHolderGenerator .generate(
2081
- (sourceManaged in Compile ).value,
2082
- " org.scalajs.testsuite.utils.BuildInfo" ,
2083
- " scalaVersion" -> scalaVersion.value,
2084
- " hasSourceMaps" -> MyScalaJSPlugin .wantSourceMaps.value,
2085
- " isNoModule" -> (moduleKind == ModuleKind .NoModule ),
2086
- " isESModule" -> (moduleKind == ModuleKind .ESModule ),
2087
- " isCommonJSModule" -> (moduleKind == ModuleKind .CommonJSModule ),
2088
- " isFullOpt" -> (stage == Stage .FullOpt ),
2089
- " compliantAsInstanceOfs" -> (sems.asInstanceOfs == CheckedBehavior .Compliant ),
2090
- " compliantArrayIndexOutOfBounds" -> (sems.arrayIndexOutOfBounds == CheckedBehavior .Compliant ),
2091
- " compliantModuleInit" -> (sems.moduleInit == CheckedBehavior .Compliant ),
2092
- " strictFloats" -> sems.strictFloats,
2093
- " productionMode" -> sems.productionMode,
2094
- " esVersion" -> linkerConfig.esFeatures.esVersion.edition,
2095
- " useECMAScript2015Semantics" -> linkerConfig.esFeatures.useECMAScript2015Semantics,
2096
- )
2097
- }.taskValue
2095
+ val linkerConfig = stage match {
2096
+ case FastOptStage => (scalaJSLinkerConfig in (Compile , fastLinkJS)).value
2097
+ case FullOptStage => (scalaJSLinkerConfig in (Compile , fullLinkJS)).value
2098
+ }
2099
+
2100
+ val moduleKind = linkerConfig.moduleKind
2101
+ val sems = linkerConfig.semantics
2102
+
2103
+ Seq [BuildInfoKey ](
2104
+ scalaVersion,
2105
+ " hasSourceMaps" -> MyScalaJSPlugin .wantSourceMaps.value,
2106
+ " isNoModule" -> (moduleKind == ModuleKind .NoModule ),
2107
+ " isESModule" -> (moduleKind == ModuleKind .ESModule ),
2108
+ " isCommonJSModule" -> (moduleKind == ModuleKind .CommonJSModule ),
2109
+ " isFullOpt" -> (stage == Stage .FullOpt ),
2110
+ " compliantAsInstanceOfs" -> (sems.asInstanceOfs == CheckedBehavior .Compliant ),
2111
+ " compliantArrayIndexOutOfBounds" -> (sems.arrayIndexOutOfBounds == CheckedBehavior .Compliant ),
2112
+ " compliantModuleInit" -> (sems.moduleInit == CheckedBehavior .Compliant ),
2113
+ " strictFloats" -> sems.strictFloats,
2114
+ " productionMode" -> sems.productionMode,
2115
+ " esVersion" -> linkerConfig.esFeatures.esVersion.edition,
2116
+ " useECMAScript2015Semantics" -> linkerConfig.esFeatures.useECMAScript2015Semantics,
2117
+ )
2098
2118
},
2099
2119
2100
2120
/* Generate a scala source file that throws exceptions in
0 commit comments