Merge pull request #6741 from sbt/1.6.x

Merge 1.6.x to develop
This commit is contained in:
eugene yokota 2021-12-07 11:06:03 -05:00 committed by GitHub
commit ccc6cf6818
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 129 additions and 65 deletions

View File

@ -54,7 +54,7 @@ object Util {
System.getProperty("os.name").toLowerCase(Locale.ENGLISH).contains("windows")
lazy val isCygwin: Boolean = {
val os = Option(System.getenv("OSTYPE"))
val os = sys.env.get("OSTYPE")
os match {
case Some(x) => x.toLowerCase(Locale.ENGLISH).contains("cygwin")
case _ => false
@ -64,7 +64,7 @@ object Util {
lazy val isNonCygwinWindows: Boolean = isWindows && !isCygwin
lazy val isCygwinWindows: Boolean = isWindows && isCygwin
lazy val isEmacs: Boolean = Option(System.getenv("INSIDE_EMACS")).isDefined
lazy val isEmacs: Boolean = sys.env.contains("INSIDE_EMACS")
def nil[A]: List[A] = List.empty[A]
def nilSeq[A]: Seq[A] = Seq.empty[A]

View File

@ -308,7 +308,7 @@ object Terminal {
}
private[sbt] lazy val isAnsiSupported: Boolean = logFormatEnabled.getOrElse(useColorDefault)
private[this] val isDumb = "dumb" == System.getenv("TERM")
private[this] val isDumb = Some("dumb") == sys.env.get("TERM")
private[this] def isDumbTerminal = isDumb || System.getProperty("jline.terminal", "") == "none"
private[this] val hasConsole = Option(java.lang.System.console).isDefined
private[this] def useColorDefault: Boolean = {
@ -736,22 +736,20 @@ object Terminal {
val supershell: Boolean
)
private[sbt] val TERMINAL_PROPS = "SBT_TERMINAL_PROPS"
private val props = System.getenv(TERMINAL_PROPS) match {
case null => None
case p =>
p.split(",") match {
case Array(width, height, ansi, color, supershell) =>
Try(
new Props(
width.toInt,
height.toInt,
ansi.toBoolean,
color.toBoolean,
supershell.toBoolean
)
).toOption
case _ => None
}
private val props = sys.env.get(TERMINAL_PROPS) flatMap { p =>
p.split(",") match {
case Array(width, height, ansi, color, supershell) =>
Try(
new Props(
width.toInt,
height.toInt,
ansi.toBoolean,
color.toBoolean,
supershell.toBoolean
)
).toOption
case _ => None
}
}
private[sbt] def startedByRemoteClient = props.isDefined

View File

@ -4,7 +4,8 @@ import minitest._
import java.io.File
object SbtScriptTest extends SimpleTestSuite with PowerAssertions {
lazy val isWindows: Boolean = sys.props("os.name").toLowerCase(java.util.Locale.ENGLISH).contains("windows")
lazy val isWindows: Boolean =
sys.props("os.name").toLowerCase(java.util.Locale.ENGLISH).contains("windows")
lazy val sbtScript =
if (isWindows) new File("target/universal/stage/bin/sbt.bat")
else new File("target/universal/stage/bin/sbt")
@ -12,12 +13,13 @@ object SbtScriptTest extends SimpleTestSuite with PowerAssertions {
private val javaBinDir = new File("integration-test", "bin").getAbsolutePath
private def makeTest(
name: String,
javaOpts: String = "",
sbtOpts: String = "",
name: String,
javaOpts: String = "",
sbtOpts: String = "",
)(args: String*)(f: List[String] => Any) = {
test(name) {
val out = sbtProcessWithOpts(args: _*)(javaOpts = javaOpts, sbtOpts = sbtOpts).!!.linesIterator.toList
val out =
sbtProcessWithOpts(args: _*)(javaOpts = javaOpts, sbtOpts = sbtOpts).!!.linesIterator.toList
f(out)
()
}
@ -26,12 +28,14 @@ object SbtScriptTest extends SimpleTestSuite with PowerAssertions {
def sbtProcess(args: String*) = sbtProcessWithOpts(args: _*)("", "")
def sbtProcessWithOpts(args: String*)(javaOpts: String, sbtOpts: String) = {
val path = sys.env("PATH")
sbt.internal.Process(Seq(sbtScript.getAbsolutePath) ++ args, new File("citest"),
sbt.internal.Process(
Seq(sbtScript.getAbsolutePath) ++ args,
new File("citest"),
"JAVA_OPTS" -> javaOpts,
"SBT_OPTS" -> sbtOpts,
if (isWindows)
"JAVACMD" -> new File(javaBinDir, "java.cmd").getAbsolutePath()
else
else
"PATH" -> (javaBinDir + File.pathSeparator + path)
)
}
@ -48,9 +52,14 @@ object SbtScriptTest extends SimpleTestSuite with PowerAssertions {
assert(out.contains[String]("-Dsbt.color=false"))
}
makeTest("sbt --no-colors in SBT_OPTS", sbtOpts = "--no-colors")("compile", "-v") { out: List[String] =>
if (isWindows) cancel("Test not supported on windows")
assert(out.contains[String]("-Dsbt.log.noformat=true"))
makeTest("sbt --no-colors in SBT_OPTS", sbtOpts = "--no-colors")("compile", "-v") {
out: List[String] =>
if (isWindows) cancel("Test not supported on windows")
assert(out.contains[String]("-Dsbt.log.noformat=true"))
}
makeTest("sbt --no-server")("compile", "--no-server", "-v") { out: List[String] =>
assert(out.contains[String]("-Dsbt.server.autostart=false"))
}
makeTest("sbt --debug-inc")("compile", "--debug-inc", "-v") { out: List[String] =>
@ -77,33 +86,43 @@ object SbtScriptTest extends SimpleTestSuite with PowerAssertions {
assert(out.contains[String]("-Xmx503m"))
}
makeTest("sbt with -mem 503, -Xmx in JAVA_OPTS", javaOpts = "-Xmx1024m")("-mem", "503", "-v") { out: List[String] =>
assert(out.contains[String]("-Xmx503m"))
assert(!out.contains[String]("-Xmx1024m"))
makeTest("sbt with -mem 503, -Xmx in JAVA_OPTS", javaOpts = "-Xmx1024m")("-mem", "503", "-v") {
out: List[String] =>
assert(out.contains[String]("-Xmx503m"))
assert(!out.contains[String]("-Xmx1024m"))
}
makeTest("sbt with -mem 503, -Xmx in SBT_OPTS", sbtOpts = "-Xmx1024m")("-mem", "503", "-v") { out: List[String] =>
assert(out.contains[String]("-Xmx503m"))
assert(!out.contains[String]("-Xmx1024m"))
makeTest("sbt with -mem 503, -Xmx in SBT_OPTS", sbtOpts = "-Xmx1024m")("-mem", "503", "-v") {
out: List[String] =>
assert(out.contains[String]("-Xmx503m"))
assert(!out.contains[String]("-Xmx1024m"))
}
makeTest("sbt with -mem 503, -Xss in JAVA_OPTS", javaOpts = "-Xss6m")("-mem", "503", "-v") { out: List[String] =>
assert(out.contains[String]("-Xmx503m"))
assert(!out.contains[String]("-Xss6m"))
makeTest("sbt with -mem 503, -Xss in JAVA_OPTS", javaOpts = "-Xss6m")("-mem", "503", "-v") {
out: List[String] =>
assert(out.contains[String]("-Xmx503m"))
assert(!out.contains[String]("-Xss6m"))
}
makeTest("sbt with -mem 503, -Xss in SBT_OPTS", sbtOpts = "-Xss6m")("-mem", "503", "-v") { out: List[String] =>
assert(out.contains[String]("-Xmx503m"))
assert(!out.contains[String]("-Xss6m"))
makeTest("sbt with -mem 503, -Xss in SBT_OPTS", sbtOpts = "-Xss6m")("-mem", "503", "-v") {
out: List[String] =>
assert(out.contains[String]("-Xmx503m"))
assert(!out.contains[String]("-Xss6m"))
}
makeTest("sbt with -Xms2048M -Xmx2048M -Xss6M in JAVA_OPTS", javaOpts = "-Xms2048M -Xmx2048M -Xss6M")("-v") { out: List[String] =>
makeTest(
"sbt with -Xms2048M -Xmx2048M -Xss6M in JAVA_OPTS",
javaOpts = "-Xms2048M -Xmx2048M -Xss6M"
)("-v") { out: List[String] =>
assert(out.contains[String]("-Xms2048M"))
assert(out.contains[String]("-Xmx2048M"))
assert(out.contains[String]("-Xss6M"))
}
makeTest("sbt with -Xms2048M -Xmx2048M -Xss6M in SBT_OPTS", sbtOpts = "-Xms2048M -Xmx2048M -Xss6M")( "-v") { out: List[String] =>
makeTest(
"sbt with -Xms2048M -Xmx2048M -Xss6M in SBT_OPTS",
sbtOpts = "-Xms2048M -Xmx2048M -Xss6M"
)("-v") { out: List[String] =>
assert(out.contains[String]("-Xms2048M"))
assert(out.contains[String]("-Xmx2048M"))
assert(out.contains[String]("-Xss6M"))
@ -125,13 +144,18 @@ object SbtScriptTest extends SimpleTestSuite with PowerAssertions {
assert(out.contains[String]("-XX:PermSize=128M"))
}
makeTest("sbt with -XX:+UseG1GC -XX:+PrintGC in JAVA_OPTS", javaOpts = "-XX:+UseG1GC -XX:+PrintGC")("-v") { out: List[String] =>
makeTest(
"sbt with -XX:+UseG1GC -XX:+PrintGC in JAVA_OPTS",
javaOpts = "-XX:+UseG1GC -XX:+PrintGC"
)("-v") { out: List[String] =>
assert(out.contains[String]("-XX:+UseG1GC"))
assert(out.contains[String]("-XX:+PrintGC"))
assert(!out.contains[String]("-XX:+UseG1GC=-XX:+PrintGC"))
}
makeTest("sbt with -XX:-UseG1GC -XX:-PrintGC in SBT_OPTS", sbtOpts = "-XX:+UseG1GC -XX:+PrintGC")( "-v") { out: List[String] =>
makeTest("sbt with -XX:-UseG1GC -XX:-PrintGC in SBT_OPTS", sbtOpts = "-XX:+UseG1GC -XX:+PrintGC")(
"-v"
) { out: List[String] =>
assert(out.contains[String]("-XX:+UseG1GC"))
assert(out.contains[String]("-XX:+PrintGC"))
assert(!out.contains[String]("-XX:+UseG1GC=-XX:+PrintGC"))
@ -140,7 +164,8 @@ object SbtScriptTest extends SimpleTestSuite with PowerAssertions {
test("sbt with -debug in SBT_OPTS appears in sbt commands") {
if (isWindows) cancel("Test not supported on windows")
val out: List[String] = sbtProcessWithOpts("compile", "-v")(javaOpts = "", sbtOpts = "-debug").!!.linesIterator.toList
val out: List[String] =
sbtProcessWithOpts("compile", "-v")(javaOpts = "", sbtOpts = "-debug").!!.linesIterator.toList
// Debug argument must appear in the 'commands' section (after the sbt-launch.jar argument) to work
val sbtLaunchMatcher = """^.+sbt-launch.jar["]{0,1}$""".r
val locationOfSbtLaunchJarArg = out.zipWithIndex.collectFirst {
@ -155,7 +180,9 @@ object SbtScriptTest extends SimpleTestSuite with PowerAssertions {
}
makeTest("sbt --jvm-debug <port>")("--jvm-debug", "12345", "-v") { out: List[String] =>
assert(out.contains[String]("-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=12345"))
assert(
out.contains[String]("-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=12345")
)
}
makeTest("sbt --no-share adds three system properties")("--no-share") { out: List[String] =>
@ -171,7 +198,7 @@ object SbtScriptTest extends SimpleTestSuite with PowerAssertions {
test("sbt --script-version should print sbtVersion") {
val out = sbtProcess("--script-version").!!.trim
val expectedVersion = "^"+SbtRunnerTest.versionRegEx+"$"
val expectedVersion = "^" + SbtRunnerTest.versionRegEx + "$"
assert(out.matches(expectedVersion))
()
}

View File

@ -50,6 +50,7 @@ set sbt_args_sbt_dir=
set sbt_args_sbt_version=
set sbt_args_mem=
set sbt_args_client=
set sbt_args_no_server=
rem users can set SBT_OPTS via .sbtopts
if exist .sbtopts for /F %%A in (.sbtopts) do (
@ -205,6 +206,15 @@ if defined _no_colors_arg (
goto args_loop
)
if "%~0" == "-no-server" set _no_server_arg=true
if "%~0" == "--no-server" set _no_server_arg=true
if defined _no_server_arg (
set _no_server_arg=
set sbt_args_no_server=1
goto args_loop
)
if "%~0" == "-no-global" set _no_global_arg=true
if "%~0" == "--no-global" set _no_global_arg=true
@ -646,6 +656,10 @@ if defined sbt_args_traces (
set _SBT_OPTS=-Dsbt.traces=true !_SBT_OPTS!
)
if defined sbt_args_no_server (
set _SBT_OPTS=-Dsbt.io.virtual=false -Dsbt.server.autostart=false !_SBT_OPTS!
)
rem TODO: _SBT_OPTS needs to be processed as args and diffed against SBT_ARGS
if !sbt_args_print_sbt_version! equ 1 (

View File

@ -139,7 +139,7 @@ class NetworkClient(
private val rebooting = new AtomicBoolean(false)
private lazy val noTab = arguments.completionArguments.contains("--no-tab")
private lazy val noStdErr = arguments.completionArguments.contains("--no-stderr") &&
System.getenv("SBTC_AUTO_COMPLETE") == null
!sys.env.contains("SBTC_AUTO_COMPLETE")
private def mkSocket(file: File): (Socket, Option[String]) = ClientSocket.socket(file, useJNI)

View File

@ -148,6 +148,7 @@ object Defaults extends BuildCommon {
val m = (for (a <- cp; an <- a.metadata get Keys.analysis) yield (a.data, an)).toMap
m.get _
}
private[sbt] def globalDefaults(ss: Seq[Setting[_]]): Seq[Setting[_]] =
Def.defaultSettings(inScope(GlobalScope)(ss))
@ -229,7 +230,7 @@ object Defaults extends BuildCommon {
private[sbt] lazy val globalIvyCore: Seq[Setting[_]] =
Seq(
internalConfigurationMap :== Configurations.internalMap _,
credentials :== Nil,
credentials :== SysProp.sbtCredentialsEnv.toList,
exportJars :== false,
trackInternalDependencies :== TrackLevel.TrackAlways,
exportToInternal :== TrackLevel.TrackAlways,

View File

@ -10,6 +10,15 @@ package sbt.internal
private[sbt] object Banner {
def apply(version: String): Option[String] =
version match {
case v if v.startsWith("1.6.0") =>
Some(s"""
|Here are some highlights of this release:
| - Improved JDK 17 support
| - Improved Build Server Protocol (BSP) support
| - Tab completion of global keys
|See https://eed3si9n.com/sbt-1.6.0-beta for full release notes.
|Hide the banner for this release by running `skipBanner`.
|""".stripMargin.linesIterator.mkString("\n"))
case v if v.startsWith("1.4.0") =>
Some(s"""
|Here are some highlights of this release:

View File

@ -15,8 +15,9 @@ import scala.util.control.NonFatal
import scala.concurrent.duration._
import sbt.internal.util.{ Terminal => ITerminal, Util }
import sbt.internal.util.complete.SizeParser
import sbt.nio.Keys._
import sbt.io.syntax._
import sbt.librarymanagement.ivy.{ Credentials, FileCredentials }
import sbt.nio.Keys._
// See also BuildPaths.scala
// See also LineReader.scala
@ -216,4 +217,7 @@ object SysProp {
.getOrElse(linuxCache)
baseCache.getAbsoluteFile / "v1"
}
val sbtCredentialsEnv: Option[Credentials] =
sys.env.get("SBT_CREDENTIALS").map(raw => new FileCredentials(new File(raw)))
}

View File

@ -70,8 +70,9 @@ private[sbt] class TaskProgress(
pending.clear()
scheduler.shutdownNow()
executor.shutdownNow()
if (!executor.awaitTermination(1, TimeUnit.SECONDS) ||
!scheduler.awaitTermination(1, TimeUnit.SECONDS)) {
if (!executor.awaitTermination(30, TimeUnit.SECONDS) ||
!scheduler.awaitTermination(30, TimeUnit.SECONDS)) {
scala.Console.err.println("timed out closing the executor of supershell")
throw new TimeoutException
}
}

View File

@ -80,11 +80,17 @@ final class BuildServerReporterImpl(
private lazy val exchange = StandardMain.exchange
private val problemsByFile = mutable.Map[Path, Vector[Diagnostic]]()
// sometimes the compiler returns a fake position such as <macro>
// on Windows, this causes InvalidPathException (see #5994 and #6720)
private def toSafePath(ref: VirtualFileRef): Option[Path] =
if (ref.id().contains("<")) None
else Some(converter.toPath(ref))
override def sendSuccessReport(analysis: CompileAnalysis): Unit = {
for {
(source, infos) <- analysis.readSourceInfos.getAllSourceInfos.asScala
filePath <- toSafePath(source)
} {
val filePath = converter.toPath(source)
val diagnostics = infos.getReportedProblems.toSeq.flatMap(toDiagnostic)
val params = PublishDiagnosticsParams(
textDocument = TextDocumentIdentifier(filePath.toUri),
@ -98,8 +104,10 @@ final class BuildServerReporterImpl(
}
override def sendFailureReport(sources: Array[VirtualFile]): Unit = {
for (source <- sources) {
val filePath = converter.toPath(source)
for {
source <- sources
filePath <- toSafePath(source)
} {
val diagnostics = problemsByFile.getOrElse(filePath, Vector())
val params = PublishDiagnosticsParams(
textDocument = TextDocumentIdentifier(filePath.toUri),
@ -116,8 +124,8 @@ final class BuildServerReporterImpl(
for {
id <- problem.position.sourcePath.toOption
diagnostic <- toDiagnostic(problem)
filePath <- toSafePath(VirtualFileRef.of(id))
} {
val filePath = converter.toPath(VirtualFileRef.of(id))
problemsByFile(filePath) = problemsByFile.getOrElse(filePath, Vector()) :+ diagnostic
val params = PublishDiagnosticsParams(
TextDocumentIdentifier(filePath.toUri),

View File

@ -12,10 +12,10 @@ object Dependencies {
sys.env.get("BUILD_VERSION") orElse sys.props.get("sbt.build.version")
// sbt modules
private val ioVersion = nightlyVersion.getOrElse("1.6.0-M1")
private val ioVersion = nightlyVersion.getOrElse("1.6.0-M2")
private val lmVersion =
sys.props.get("sbt.build.lm.version").orElse(nightlyVersion).getOrElse("1.6.0-M1")
val zincVersion = nightlyVersion.getOrElse("1.6.0-M1")
sys.props.get("sbt.build.lm.version").orElse(nightlyVersion).getOrElse("1.6.0-M2")
val zincVersion = nightlyVersion.getOrElse("1.6.0-M2")
private val sbtIO = "org.scala-sbt" %% "io" % ioVersion
@ -77,7 +77,7 @@ object Dependencies {
def addSbtZincCompile = addSbtModule(sbtZincPath, "zincCompileJVM2_12", zincCompile)
def addSbtZincCompileCore = addSbtModule(sbtZincPath, "zincCompileCoreJVM2_12", zincCompileCore)
val lmCoursierShaded = "io.get-coursier" %% "lm-coursier-shaded" % "2.0.8"
val lmCoursierShaded = "io.get-coursier" %% "lm-coursier-shaded" % "2.0.9"
def sjsonNew(n: String) =
Def.setting("com.eed3si9n" %% n % "0.9.1") // contrabandSjsonNewVersion.value

View File

@ -61,7 +61,7 @@ object BuildServerConnection {
// For those who use an old sbt script, the -Dsbt.script is not set
// As a fallback we try to find the sbt script in $PATH
val fileName = if (Properties.isWin) "sbt.bat" else "sbt"
val envPath = Option(System.getenv("PATH")).getOrElse("")
val envPath = sys.env.getOrElse("PATH", "")
val allPaths = envPath.split(File.pathSeparator).map(Paths.get(_))
allPaths
.map(_.resolve(fileName))

4
sbt
View File

@ -1,7 +1,7 @@
#!/usr/bin/env bash
set +e
declare builtin_sbt_version="1.5.5"
declare builtin_sbt_version="1.6.0-RC1"
declare -a residual_args
declare -a java_args
declare -a scalac_args
@ -22,6 +22,7 @@ declare sbt_verbose=
declare sbt_debug=
declare build_props_sbt_version=
declare use_sbtn=
declare no_server=
declare sbtn_command="$SBTN_CMD"
declare sbtn_version="1.4.7"
@ -631,6 +632,7 @@ map_args () {
-traces|--traces) options=( "${options[@]}" "-Dsbt.traces=true" ) && shift ;;
--supershell=*) options=( "${options[@]}" "-Dsbt.supershell=${1:13}" ) && shift ;;
-supershell=*) options=( "${options[@]}" "-Dsbt.supershell=${1:12}" ) && shift ;;
-no-server|--no-server) options=( "${options[@]}" "-Dsbt.io.virtual=false" "-Dsbt.server.autostart=false" ) && shift ;;
--color=*) options=( "${options[@]}" "-Dsbt.color=${1:8}" ) && shift ;;
-color=*) options=( "${options[@]}" "-Dsbt.color=${1:7}" ) && shift ;;
-no-share|--no-share) options=( "${options[@]}" "${noshare_opts[@]}" ) && shift ;;

View File

@ -1,6 +1,6 @@
object ForkTest {
def main(args:Array[String]): Unit = {
val name = Option(System.getenv("flag.name")) getOrElse("flag")
val name = sys.env.getOrElse("flag.name", "flag")
println("Name: " + name)
val cwd = (new java.io.File(name)).getAbsoluteFile
cwd.getParentFile.mkdirs()

View File

@ -1,7 +1,7 @@
import org.scalatest.FlatSpec
class Test extends FlatSpec {
val v = Option(System.getenv("tests.max.value")) getOrElse Int.MaxValue
val v = sys.env.getOrElse("tests.max.value", Int.MaxValue)
"A simple equation" should "hold" in {
assert(Int.MaxValue == v)
}