Skip to content

Commit b74fca1

Browse files
authored
Merge pull request #2531 from dotty-staging/command-line
Fixes to CLI and version reporting.
2 parents dffccfa + 084901c commit b74fca1

File tree

3 files changed

+35
-46
lines changed

3 files changed

+35
-46
lines changed

compiler/src/dotty/tools/dotc/config/CompilerCommand.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ object CompilerCommand extends DotClass {
115115
else if (settings.version.value) {
116116
ctx.echo(versionMsg)
117117
Nil
118+
} else if (!Properties.isJavaAtLeast("1.8")) {
119+
ctx.error("Dotty requires Java 8 to run")
120+
Nil
118121
}
119122
else if (shouldStopWithInfo) {
120123
ctx.echo(infoMessage)

compiler/src/dotty/tools/dotc/config/Properties.scala

Lines changed: 18 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import java.util.jar.Attributes.{ Name => AttributeName }
77

88
/** Loads `library.properties` from the jar. */
99
object Properties extends PropertiesTrait {
10-
protected def propCategory = "library"
10+
protected def propCategory = "compiler"
1111
protected def pickJarBasedOn = classOf[Option[_]]
1212

1313
/** Scala manifest attributes.
@@ -56,36 +56,7 @@ trait PropertiesTrait {
5656
def scalaPropOrElse(name: String, alt: String): String = scalaProps.getProperty(name, alt)
5757
def scalaPropOrEmpty(name: String): String = scalaPropOrElse(name, "")
5858
def scalaPropOrNone(name: String): Option[String] = Option(scalaProps.getProperty(name))
59-
60-
/** The numeric portion of the runtime Scala version, if this is a final
61-
* release. If for instance the versionString says "version 2.9.0.final",
62-
* this would return Some("2.9.0").
63-
*
64-
* @return Some(version) if this is a final release build, None if
65-
* it is an RC, Beta, etc. or was built from source, or if the version
66-
* cannot be read.
67-
*/
68-
val releaseVersion =
69-
for {
70-
v <- scalaPropOrNone("maven.version.number")
71-
if !(v endsWith "-SNAPSHOT")
72-
} yield v
73-
74-
/** The development Scala version, if this is not a final release.
75-
* The precise contents are not guaranteed, but it aims to provide a
76-
* unique repository identifier (currently the svn revision) in the
77-
* fourth dotted segment if the running version was built from source.
78-
*
79-
* @return Some(version) if this is a non-final version, None if this
80-
* is a final release or the version cannot be read.
81-
*/
82-
val developmentVersion =
83-
for {
84-
v <- scalaPropOrNone("maven.version.number")
85-
if v endsWith "-SNAPSHOT"
86-
ov <- scalaPropOrNone("version.number")
87-
} yield ov
88-
59+
8960
/** Either the development or release version if known, otherwise
9061
* the empty string.
9162
*/
@@ -94,8 +65,16 @@ trait PropertiesTrait {
9465
/** The version number of the jar this was loaded from plus "version " prefix,
9566
* or "version (unknown)" if it cannot be determined.
9667
*/
97-
val versionString = "version " + "0.01" //scalaPropOrElse("version.number", "(unknown)")" +
98-
val copyrightString = "(c) 2013 LAMP/EPFL" // scalaPropOrElse("copyright.string", "(c) 2002-2011 LAMP/EPFL")
68+
val versionString = {
69+
val v = scalaPropOrElse("version.number", "(unknown)")
70+
"version " + scalaPropOrElse("version.number", "(unknown)") + {
71+
if (v.contains("SNAPSHOT") || v.contains("NIGHTLY")) {
72+
"-git-" + scalaPropOrElse("git.hash", "(unknown)")
73+
} else ""
74+
}
75+
}
76+
77+
val copyrightString = scalaPropOrElse("copyright.string", "(c) 2002-2017 LAMP/EPFL")
9978

10079
/** This is the encoding to use reading in source files, overridden with -encoding
10180
* Note that it uses "prop" i.e. looks in the scala jar, not the system properties.
@@ -140,26 +119,21 @@ trait PropertiesTrait {
140119
def jdkHome = envOrElse("JDK_HOME", envOrElse("JAVA_HOME", javaHome))
141120

142121
def versionMsg = "Scala %s %s -- %s".format(propCategory, versionString, copyrightString)
143-
def scalaCmd = if (isWin) "scala.bat" else "scala"
144-
def scalacCmd = if (isWin) "scalac.bat" else "scalac"
122+
def scalaCmd = if (isWin) "dotr.bat" else "dotr"
123+
def scalacCmd = if (isWin) "dotc.bat" else "dotc"
145124

146125
/** Can the java version be determined to be at least as high as the argument?
147126
* Hard to properly future proof this but at the rate 1.7 is going we can leave
148127
* the issue for our cyborg grandchildren to solve.
149128
*/
150129
def isJavaAtLeast(version: String) = {
151130
val okVersions = version match {
152-
case "1.5" => List("1.5", "1.6", "1.7")
153-
case "1.6" => List("1.6", "1.7")
154-
case "1.7" => List("1.7")
131+
case "1.5" => List("1.5", "1.6", "1.7", "1.8")
132+
case "1.6" => List("1.6", "1.7", "1.8")
133+
case "1.7" => List("1.7", "1.8")
134+
case "1.8" => List("1.8")
155135
case _ => Nil
156136
}
157137
okVersions exists (javaVersion startsWith _)
158138
}
159-
160-
// provide a main method so version info can be obtained by running this
161-
def main(args: Array[String]): Unit = {
162-
val writer = new PrintWriter(Console.err, true)
163-
writer println versionMsg
164-
}
165139
}

project/Build.scala

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import sbt.Keys._
22
import sbt._
33
import complete.DefaultParsers._
4-
import java.io.{ RandomAccessFile, File }
4+
import java.io.{File, RandomAccessFile}
55
import java.nio.channels.FileLock
66
import java.nio.file.Files
7+
import java.util.Calendar
8+
79
import scala.reflect.io.Path
810
import sbtassembly.AssemblyKeys.assembly
911

@@ -405,8 +407,18 @@ object Build {
405407

406408
// Generate compiler.properties, used by sbt
407409
resourceGenerators in Compile += Def.task {
410+
import java.util._
411+
import java.text._
408412
val file = (resourceManaged in Compile).value / "compiler.properties"
409-
val contents = s"version.number=${version.value}"
413+
val dateFormat = new SimpleDateFormat("yyyyMMdd-HHmmss")
414+
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"))
415+
val contents = //2.11.11.v20170413-090219-8a413ba7cc
416+
s"""version.number=${version.value}
417+
|maven.version.number=${version.value}
418+
|git.hash=${VersionUtil.gitHash}
419+
|osgi.version.number=${version.value}-v${dateFormat.format(Calendar.getInstance().getTime)}
420+
|copyright.string=Copyright 2002-${Calendar.getInstance().get(Calendar.YEAR)}, LAMP/EPFL
421+
""".stripMargin
410422

411423
if (!(file.exists && IO.read(file) == contents)) {
412424
IO.write(file, contents)

0 commit comments

Comments
 (0)