Skip to content

Commit c8ae057

Browse files
committed
add properties file for scala3 library
1 parent 5a2cff6 commit c8ae057

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

library/src/scala/util/Properties.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ private[scala] trait PropertiesTrait {
3434

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

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

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+
4552
props
4653
}
4754

project/Build.scala

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1916,6 +1916,19 @@ object Build {
19161916
customMimaReportBinaryIssues("MiMaFilters.Scala3Library"),
19171917
// Should we also patch .sjsir files
19181918
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,
19191932
)
19201933

19211934
/* Configuration of the org.scala-lang:scala3-library_3:*.**.**-nonbootstrapped project */
@@ -2041,6 +2054,19 @@ object Build {
20412054
customMimaReportBinaryIssues("MiMaFilters.Scala3Library"),
20422055
// Should we also patch .sjsir files
20432056
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,
20442070
)
20452071

20462072
/* Configuration of the org.scala-lang:scala3-library_3:*.**.**-bootstrapped project */
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+
object Test {
2+
def main(args: Array[String]): Unit = {
3+
val v = scala.util.Properties.versionNumberString
4+
if (v.nonEmpty && !v.startsWith("2.")) println("OK")
5+
else println("FAIL " + v)
6+
}
7+
}

0 commit comments

Comments
 (0)