Skip to content

Commit 2358466

Browse files
committed
address review
1 parent c8ae057 commit 2358466

File tree

5 files changed

+64
-93
lines changed

5 files changed

+64
-93
lines changed

library/src/scala/util/Properties.scala

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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: 55 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,54 @@ 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 = (fileName: String, contents: Def.Initialize[String]) => Def.task {
445+
val file = (Compile / resourceManaged).value / fileName
446+
val data = contents.value
447+
if (!(file.exists && IO.read(file) == data)) {
448+
IO.write(file, data)
449+
}
450+
Seq(file)
451+
}
452+
453+
// Generate compiler.properties consumed by sbt
454+
lazy val generateCompilerProperties: Def.Initialize[Task[Seq[File]]] = {
455+
import java.util._
456+
import java.text._
457+
val dateFormat = new SimpleDateFormat("yyyyMMdd-HHmmss")
458+
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"))
459+
460+
val fileName = "compiler.properties"
461+
val contents = Def.setting {
462+
s"""version.number=${version.value}
463+
|maven.version.number=${version.value}
464+
|git.hash=${VersionUtil.gitHash}
465+
|copyright.string=Copyright 2002-$currentYear, LAMP/EPFL
466+
|""".stripMargin
467+
}
468+
generatePropertiesFile(fileName, contents)
469+
}
470+
471+
// Generate library.properties consumed by scala.util.Properties
472+
lazy val generateLibraryProperties: Def.Initialize[Task[Seq[File]]] = {
473+
val fileName = "library.properties"
474+
val contents = Def.setting {
475+
s"""version.number=${version.value}
476+
|maven.version.number=${version.value}
477+
|copyright.string=Copyright 2002-$currentYear, LAMP/EPFL
478+
|shell.banner=${shellBanner}
479+
|""".stripMargin
480+
}
481+
generatePropertiesFile(fileName, contents)
482+
}
483+
436484
def scalacOptionsDocSettings(includeExternalMappings: Boolean = true) = {
437485
val extMap = Seq("-external-mappings:" +
438486
(if (includeExternalMappings) ".*scala/.*::scaladoc3::https://dotty.epfl.ch/api/," else "") +
@@ -700,25 +748,7 @@ object Build {
700748
scalacOptions += "-Wconf:cat=deprecation&origin=scala\\.collection\\.mutable\\.AnyRefMap.*:s",
701749

702750
// 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,
751+
(Compile / resourceGenerators) += generateCompilerProperties.taskValue,
722752

723753
// get libraries onboard
724754
libraryDependencies ++= Seq(
@@ -1916,19 +1946,8 @@ object Build {
19161946
customMimaReportBinaryIssues("MiMaFilters.Scala3Library"),
19171947
// Should we also patch .sjsir files
19181948
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,
1949+
// Generate library.properties, used by scala.util.Properties
1950+
Compile / resourceGenerators += generateLibraryProperties.taskValue
19321951
)
19331952

19341953
/* Configuration of the org.scala-lang:scala3-library_3:*.**.**-nonbootstrapped project */
@@ -2054,19 +2073,8 @@ object Build {
20542073
customMimaReportBinaryIssues("MiMaFilters.Scala3Library"),
20552074
// Should we also patch .sjsir files
20562075
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,
2076+
// Generate Scala 3 runtime properties overlay
2077+
Compile / resourceGenerators += generateLibraryProperties.taskValue,
20702078
)
20712079

20722080
/* Configuration of the org.scala-lang:scala3-library_3:*.**.**-bootstrapped project */
@@ -2470,25 +2478,7 @@ object Build {
24702478
// Project specific target folder. sbt doesn't like having two projects using the same target folder
24712479
target := target.value / "scala3-compiler-nonbootstrapped",
24722480
// 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,
2481+
Compile / resourceGenerators += generateCompilerProperties.taskValue,
24922482
// sbt adds all the projects to scala-tool config which breaks building the scalaInstance
24932483
// as a workaround, I build it manually by only adding the compiler
24942484
managedScalaInstance := false,
@@ -2638,25 +2628,7 @@ object Build {
26382628
// Project specific target folder. sbt doesn't like having two projects using the same target folder
26392629
target := target.value / "scala3-compiler-bootstrapped",
26402630
// 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,
2631+
Compile / resourceGenerators += generateCompilerProperties.taskValue,
26602632
// Configure to use the non-bootstrapped compiler
26612633
managedScalaInstance := false,
26622634
scalaInstance := {
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+
assert(v.nonEmpty && v.startsWith("3."))
6+
}
7+
}

tests/run/properties-version-string.check

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
// scalajs: --skip
12
object Test {
23
def main(args: Array[String]): Unit = {
34
val v = scala.util.Properties.versionNumberString
4-
if (v.nonEmpty && !v.startsWith("2.")) println("OK")
5-
else println("FAIL " + v)
5+
assert(v.nonEmpty && v.startsWith("3."))
66
}
77
}

0 commit comments

Comments
 (0)