From 86d492c0b79b265a596cae1e4d8fd05cc1b11d53 Mon Sep 17 00:00:00 2001 From: Stefan Zeiger Date: Tue, 6 Sep 2016 21:55:16 +0200 Subject: Store buildcharacter.properties in scala-compiler.jar MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In addition to all the individual projects’ version properties files that we already keep in `scala-compiler.jar` we now write a new `scala-buildcharacter.properties` which is identical to the `buildcharacter.properties` written to the root directory by `generateBuildCharacterPropertiesFile`. The new task `extractBuildCharacterPropertiesFile` extracts it from the bootstrap Scala compiler and writes the usual `buildcharacter.properties`. This can be used to reproduce the exact version information for all modules in builds that start from an arbitrary published Scala version instead of being triggered directly by a bootstrap job. --- build.sbt | 15 +++++++++++++++ project/VersionUtil.scala | 9 ++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/build.sbt b/build.sbt index 1105902a9d..0d27038a9f 100644 --- a/build.sbt +++ b/build.sbt @@ -364,6 +364,7 @@ lazy val reflect = configureAsSubproject(project) lazy val compiler = configureAsSubproject(project) .settings(generatePropertiesFileSettings: _*) + .settings(generateBuildCharacterFileSettings: _*) .settings(Osgi.settings: _*) .settings( name := "scala-compiler", @@ -371,6 +372,8 @@ lazy val compiler = configureAsSubproject(project) libraryDependencies ++= Seq(antDep, asmDep), // These are only needed for the POM: libraryDependencies ++= Seq(scalaXmlDep, jlineDep % "optional"), + buildCharacterPropertiesFile := (resourceManaged in Compile).value / "scala-buildcharacter.properties", + resourceGenerators in Compile += generateBuildCharacterPropertiesFile.map(file => Seq(file)).taskValue, // this a way to make sure that classes from interactive and scaladoc projects // end up in compiler jar. note that we need to use LocalProject references // (with strings) to deal with mutual recursion @@ -740,6 +743,18 @@ lazy val root: Project = (project in file(".")) publish := {}, publishLocal := {}, commands ++= ScriptCommands.all, + extractBuildCharacterPropertiesFile := { + val jar = (scalaInstance in bootstrap).value.compilerJar + val bc = buildCharacterPropertiesFile.value + val packagedName = "scala-buildcharacter.properties" + IO.withTemporaryDirectory { tmp => + val extracted = IO.unzip(jar, tmp, new SimpleFilter(_ == packagedName)).headOption.getOrElse { + throw new RuntimeException(s"No file $packagedName found in bootstrap compiler $jar") + } + IO.copyFile(extracted, bc) + bc + } + }, // Generate (Product|TupleN|Function|AbstractFunction)*.scala files and scaladoc stubs for all AnyVal sources. // They should really go into a managedSources dir instead of overwriting sources checked into git but scaladoc // source links (could be fixed by shipping these sources with the scaladoc bundles) and scala-js source maps diff --git a/project/VersionUtil.scala b/project/VersionUtil.scala index 1c2fff27b7..fde55a5969 100644 --- a/project/VersionUtil.scala +++ b/project/VersionUtil.scala @@ -8,8 +8,10 @@ import BuildSettings.autoImport._ object VersionUtil { lazy val copyrightString = settingKey[String]("Copyright string.") lazy val versionProperties = settingKey[Versions]("Version properties.") - lazy val generateVersionPropertiesFile = taskKey[File]("Generating version properties file.") - lazy val generateBuildCharacterPropertiesFile = taskKey[File]("Generating buildcharacter.properties file.") + lazy val buildCharacterPropertiesFile = settingKey[File]("The file which gets generated by generateBuildCharacterPropertiesFile") + lazy val generateVersionPropertiesFile = taskKey[File]("Generate version properties file.") + lazy val generateBuildCharacterPropertiesFile = taskKey[File]("Generate buildcharacter.properties file.") + lazy val extractBuildCharacterPropertiesFile = taskKey[File]("Extract buildcharacter.properties file from bootstrap scala-compiler.") lazy val globalVersionSettings = Seq[Setting[_]]( // Set the version properties globally (they are the same for all projects) @@ -24,6 +26,7 @@ object VersionUtil { ) lazy val generateBuildCharacterFileSettings = Seq[Setting[_]]( + buildCharacterPropertiesFile := ((baseDirectory in ThisBuild).value / "buildcharacter.properties"), generateBuildCharacterPropertiesFile := generateBuildCharacterPropertiesFileImpl.value ) @@ -101,7 +104,7 @@ object VersionUtil { writeProps(v.toMap ++ versionProps ++ Map( "maven.version.base" -> v.mavenBase, "maven.version.suffix" -> v.mavenSuffix - ), (baseDirectory in ThisBuild).value / "buildcharacter.properties") + ), buildCharacterPropertiesFile.value) } private def writeProps(m: Map[String, String], propFile: File): File = { -- cgit v1.2.3