Skip to content

Commit 2aaf1a1

Browse files
committed
address review
1 parent c8ae057 commit 2aaf1a1

File tree

5 files changed

+59
-91
lines changed

5 files changed

+59
-91
lines changed

library/src/scala/util/Properties.scala

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import scala.annotation.tailrec
2020

2121
/** Loads `library.properties` from the jar. */
2222
object Properties extends PropertiesTrait {
23-
protected def propCategory = "library"
23+
protected def propCategory = "library3"
2424
protected def pickJarBasedOn: Class[Option[?]] = classOf[Option[?]]
2525

2626
/** Scala manifest attributes.
@@ -34,7 +34,6 @@ private[scala] trait PropertiesTrait {
3434

3535
/** The name of the properties file */
3636
protected val propFilename = "/" + propCategory + ".properties"
37-
protected val lib3Filename = "/library3.properties"
3837

3938
/** The loaded properties */
4039
protected lazy val scalaProps: java.util.Properties = {
@@ -43,12 +42,6 @@ private[scala] trait PropertiesTrait {
4342
if (stream ne null)
4443
quietlyDispose(props.load(stream), stream.close)
4544

46-
// If available in the same jar as the stdlib classes, overlay Scala 3
47-
// runtime properties contained in `library3.properties` (e.g., version.number).
48-
val lib3Stream = pickJarBasedOn.getResourceAsStream(lib3Filename)
49-
if (lib3Stream ne null)
50-
quietlyDispose(props.load(lib3Stream), lib3Stream.close)
51-
5245
props
5346
}
5447

project/Build.scala

Lines changed: 49 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,48 @@ object Build {
433433

434434
private lazy val currentYear: String = java.util.Calendar.getInstance().get(java.util.Calendar.YEAR).toString
435435

436+
private val shellBanner: String =
437+
"""%n ________ ___ / / ___
438+
|%n / __/ __// _ | / / / _ |
439+
|%n __\\ \\/ /__/ __ |/ /__/ __ |
440+
|%n /____/\\___/_/ |_/____/_/ | |
441+
|%n |/ %s""".stripMargin.replace("\n", "")
442+
443+
// Common generator for properties files
444+
lazy val generatePropertiesFile = (contents: String, file: File) => Def.task {
445+
if (!(file.exists && IO.read(file) == contents)) {
446+
IO.write(file, contents)
447+
}
448+
Seq(file)
449+
}
450+
451+
// Generate compiler.properties consumed by sbt
452+
lazy val generateCompilerProperties: Def.Initialize[Task[Seq[File]]] = {
453+
import java.util._
454+
import java.text._
455+
val file = (Compile / resourceManaged).value / "compiler.properties"
456+
val dateFormat = new SimpleDateFormat("yyyyMMdd-HHmmss")
457+
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"))
458+
val contents = //2.11.11.v20170413-090219-8a413ba7cc
459+
s"""version.number=${version.value}
460+
|maven.version.number=${version.value}
461+
|git.hash=${VersionUtil.gitHash}
462+
|copyright.string=Copyright 2002-$currentYear, LAMP/EPFL
463+
""".stripMargin
464+
generatePropertiesFile(contents, file)
465+
}
466+
467+
// Generate library3.properties consumed by scala.util.Properties
468+
lazy val generateLibrary3Properties: Def.Initialize[Task[Seq[File]]] = {
469+
val file = (Compile / resourceManaged).value / "library3.properties"
470+
val contents = s"""version.number=${version.value}
471+
|maven.version.number=${version.value}
472+
|copyright.string=Copyright 2002-$currentYear, LAMP/EPFL
473+
|shell.banner=${shellBanner}
474+
|""".stripMargin
475+
generatePropertiesFile(contents, file)
476+
}
477+
436478
def scalacOptionsDocSettings(includeExternalMappings: Boolean = true) = {
437479
val extMap = Seq("-external-mappings:" +
438480
(if (includeExternalMappings) ".*scala/.*::scaladoc3::https://dotty.epfl.ch/api/," else "") +
@@ -700,25 +742,7 @@ object Build {
700742
scalacOptions += "-Wconf:cat=deprecation&origin=scala\\.collection\\.mutable\\.AnyRefMap.*:s",
701743

702744
// Generate compiler.properties, used by sbt
703-
(Compile / resourceGenerators) += Def.task {
704-
import java.util._
705-
import java.text._
706-
val file = (Compile / resourceManaged).value / "compiler.properties"
707-
val dateFormat = new SimpleDateFormat("yyyyMMdd-HHmmss")
708-
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"))
709-
val contents = //2.11.11.v20170413-090219-8a413ba7cc
710-
s"""version.number=${version.value}
711-
|maven.version.number=${version.value}
712-
|git.hash=${VersionUtil.gitHash}
713-
|copyright.string=Copyright 2002-$currentYear, LAMP/EPFL
714-
""".stripMargin
715-
716-
if (!(file.exists && IO.read(file) == contents)) {
717-
IO.write(file, contents)
718-
}
719-
720-
Seq(file)
721-
}.taskValue,
745+
(Compile / resourceGenerators) += generateCompilerProperties.taskValue,
722746

723747
// get libraries onboard
724748
libraryDependencies ++= Seq(
@@ -1916,19 +1940,8 @@ object Build {
19161940
customMimaReportBinaryIssues("MiMaFilters.Scala3Library"),
19171941
// Should we also patch .sjsir files
19181942
keepSJSIR := false,
1919-
Compile / resourceGenerators += Def.task {
1920-
val file = (Compile / resourceManaged).value / "library3.properties"
1921-
val contents =
1922-
s"""version.number=${version.value}
1923-
|maven.version.number=${version.value}
1924-
|""".stripMargin
1925-
1926-
if (!(file.exists && IO.read(file) == contents)) {
1927-
IO.write(file, contents)
1928-
}
1929-
1930-
Seq(file)
1931-
}.taskValue,
1943+
// Generate Scala 3 runtime properties overlay
1944+
Compile / resourceGenerators += generateLibrary3Properties.taskValue
19321945
)
19331946

19341947
/* Configuration of the org.scala-lang:scala3-library_3:*.**.**-nonbootstrapped project */
@@ -2054,19 +2067,8 @@ object Build {
20542067
customMimaReportBinaryIssues("MiMaFilters.Scala3Library"),
20552068
// Should we also patch .sjsir files
20562069
keepSJSIR := false,
2057-
Compile / resourceGenerators += Def.task {
2058-
val file = (Compile / resourceManaged).value / "library3.properties"
2059-
val contents =
2060-
s"""version.number=${version.value}
2061-
|maven.version.number=${version.value}
2062-
|""".stripMargin
2063-
2064-
if (!(file.exists && IO.read(file) == contents)) {
2065-
IO.write(file, contents)
2066-
}
2067-
2068-
Seq(file)
2069-
}.taskValue,
2070+
// Generate Scala 3 runtime properties overlay
2071+
Compile / resourceGenerators += generateLibrary3Properties.taskValue,
20702072
)
20712073

20722074
/* Configuration of the org.scala-lang:scala3-library_3:*.**.**-bootstrapped project */
@@ -2470,25 +2472,7 @@ object Build {
24702472
// Project specific target folder. sbt doesn't like having two projects using the same target folder
24712473
target := target.value / "scala3-compiler-nonbootstrapped",
24722474
// Generate compiler.properties, used by sbt
2473-
Compile / resourceGenerators += Def.task {
2474-
import java.util._
2475-
import java.text._
2476-
val file = (Compile / resourceManaged).value / "compiler.properties"
2477-
val dateFormat = new SimpleDateFormat("yyyyMMdd-HHmmss")
2478-
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"))
2479-
val contents = //2.11.11.v20170413-090219-8a413ba7cc
2480-
s"""version.number=${version.value}
2481-
|maven.version.number=${version.value}
2482-
|git.hash=${VersionUtil.gitHash}
2483-
|copyright.string=Copyright 2002-$currentYear, LAMP/EPFL
2484-
""".stripMargin
2485-
2486-
if (!(file.exists && IO.read(file) == contents)) {
2487-
IO.write(file, contents)
2488-
}
2489-
2490-
Seq(file)
2491-
}.taskValue,
2475+
Compile / resourceGenerators += generateCompilerProperties.taskValue,
24922476
// sbt adds all the projects to scala-tool config which breaks building the scalaInstance
24932477
// as a workaround, I build it manually by only adding the compiler
24942478
managedScalaInstance := false,
@@ -2638,25 +2622,7 @@ object Build {
26382622
// Project specific target folder. sbt doesn't like having two projects using the same target folder
26392623
target := target.value / "scala3-compiler-bootstrapped",
26402624
// Generate compiler.properties, used by sbt
2641-
Compile / resourceGenerators += Def.task {
2642-
import java.util._
2643-
import java.text._
2644-
val file = (Compile / resourceManaged).value / "compiler.properties"
2645-
val dateFormat = new SimpleDateFormat("yyyyMMdd-HHmmss")
2646-
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"))
2647-
val contents = //2.11.11.v20170413-090219-8a413ba7cc
2648-
s"""version.number=${version.value}
2649-
|maven.version.number=${version.value}
2650-
|git.hash=${VersionUtil.gitHash}
2651-
|copyright.string=Copyright 2002-$currentYear, LAMP/EPFL
2652-
""".stripMargin
2653-
2654-
if (!(file.exists && IO.read(file) == contents)) {
2655-
IO.write(file, contents)
2656-
}
2657-
2658-
Seq(file)
2659-
}.taskValue,
2625+
Compile / resourceGenerators += generateCompilerProperties.taskValue,
26602626
// Configure to use the non-bootstrapped compiler
26612627
managedScalaInstance := false,
26622628
scalaInstance := {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
OK
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// scalajs: --skip
2+
object Test {
3+
def main(args: Array[String]): Unit = {
4+
val v = dotty.tools.dotc.config.Properties.versionNumberString
5+
if (v.nonEmpty) println("OK") else println("FAIL " + v)
6+
}
7+
}

tests/run/properties-version-string.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// scalajs: --skip
12
object Test {
23
def main(args: Array[String]): Unit = {
34
val v = scala.util.Properties.versionNumberString

0 commit comments

Comments
 (0)