Skip to content

Commit 478c7a4

Browse files
committed
Replace ConstantHolderGenerator with the BuildInfo plugin
1 parent e41949e commit 478c7a4

File tree

3 files changed

+68
-96
lines changed

3 files changed

+68
-96
lines changed

project/Build.scala

Lines changed: 66 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import Keys._
99

1010
import com.typesafe.tools.mima.plugin.MimaPlugin.autoImport._
1111
import de.heikoseeberger.sbtheader.HeaderPlugin.autoImport._
12+
import sbtbuildinfo.BuildInfoPlugin
13+
import sbtbuildinfo.BuildInfoPlugin.autoImport._
1214
import ScriptedPlugin.autoImport._
1315

1416
import java.util.Arrays
@@ -282,6 +284,20 @@ object Build {
282284
if (condition) List(testDir)
283285
else Nil
284286

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+
285301
val previousArtifactSetting: Seq[Setting[_]] = Def.settings(
286302
/* Do not fail mimaReportBinaryIssues when mimaPreviousArtifacts is empty.
287303
* We specifically set it to empty below when binary compat is irrelevant.
@@ -915,34 +931,41 @@ object Build {
915931
unmanagedSourceDirectories in Test +=
916932
baseDirectory.value.getParentFile.getParentFile / "shared/src/test/scala",
917933

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 {
923942
val s = streams.value
924943
val log = s.log
925944
val lm = dependencyResolution.value
926945
val binVer = scalaBinaryVersion.value
927946

928947
val retrieveDir = s.cacheDirectory / "previous-stdlibs"
929948

930-
val previousStdLibs = previousVersions.map { version =>
949+
previousVersions.map { version =>
931950
val jars = lm.retrieve("org.scala-js" % s"scalajs-library_$binVer" % version intransitive(),
932951
scalaModuleInfo = None, retrieveDir, log)
933952
.fold(w => throw w.resolveException, _.distinct)
934953
assert(jars.size == 1, jars.toString())
935-
version -> jars.head
954+
version -> jars.head.getAbsolutePath
936955
}.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-
)
945956
}.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+
)
946969
},
947970

948971
previousArtifactSetting,
@@ -2062,39 +2085,36 @@ object Build {
20622085
}
20632086
},
20642087

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")),
20712089

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
20762094

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+
)
20982118
},
20992119

21002120
/* Generate a scala source file that throws exceptions in

project/ConstantHolderGenerator.scala

Lines changed: 0 additions & 50 deletions
This file was deleted.

project/build.sbt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ addSbtPlugin("org.scalastyle" % "scalastyle-sbt-plugin" % "1.0.0")
66

77
addSbtPlugin("org.portable-scala" % "sbt-platform-deps" % "1.0.1")
88

9+
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.11.0")
10+
911
libraryDependencies += "com.google.jimfs" % "jimfs" % "1.1"
1012

1113
libraryDependencies += "org.eclipse.jgit" % "org.eclipse.jgit.pgm" % "3.2.0.201312181205-r"

0 commit comments

Comments
 (0)