From 4dcae2cb734e402845cf31b762131b248ac4c776 Mon Sep 17 00:00:00 2001 From: Eric Peters Date: Fri, 20 Aug 2021 19:47:19 -0700 Subject: [PATCH] Add --sbt-cache argument and update localCacheDirectory key description --- .../src/test/scala/RunnerTest.scala | 9 +------- .../src/test/scala/ScriptTest.scala | 12 +++++++++- launcher-package/src/universal/bin/sbt.bat | 22 +++++++++++++++++++ main/src/main/scala/sbt/Keys.scala | 2 +- sbt | 5 +++++ 5 files changed, 40 insertions(+), 10 deletions(-) diff --git a/launcher-package/integration-test/src/test/scala/RunnerTest.scala b/launcher-package/integration-test/src/test/scala/RunnerTest.scala index 721fff23e..6d43be04a 100755 --- a/launcher-package/integration-test/src/test/scala/RunnerTest.scala +++ b/launcher-package/integration-test/src/test/scala/RunnerTest.scala @@ -6,7 +6,7 @@ import java.io.File object SbtRunnerTest extends SimpleTestSuite with PowerAssertions { // 1.3.0, 1.3.0-M4 - private val versionRegEx = "\\d(\\.\\d+){2}(-\\w+)?" + private[test] val versionRegEx = "\\d(\\.\\d+){2}(-\\w+)?" lazy val isWindows: Boolean = sys.props("os.name").toLowerCase(java.util.Locale.ENGLISH).contains("windows") lazy val sbtScript = @@ -49,13 +49,6 @@ object SbtRunnerTest extends SimpleTestSuite with PowerAssertions { () } - test("sbt --script-version should print sbtVersion") { - val out = sbtProcess("--script-version").!!.trim - val expectedVersion = "^"+versionRegEx+"$" - assert(out.matches(expectedVersion)) - () - } - test("sbt --sbt-jar should run") { val out = sbtProcess("compile", "-v", "--sbt-jar", "../target/universal/stage/bin/sbt-launch.jar").!!.linesIterator.toList assert(out.contains[String]("../target/universal/stage/bin/sbt-launch.jar") || diff --git a/launcher-package/integration-test/src/test/scala/ScriptTest.scala b/launcher-package/integration-test/src/test/scala/ScriptTest.scala index 1db0c50dc..570f0b0dd 100644 --- a/launcher-package/integration-test/src/test/scala/ScriptTest.scala +++ b/launcher-package/integration-test/src/test/scala/ScriptTest.scala @@ -109,7 +109,6 @@ object SbtScriptTest extends SimpleTestSuite with PowerAssertions { assert(out.contains[String]("-Xss6M")) } - makeTest( name = "sbt with -Dhttp.proxyHost=proxy -Dhttp.proxyPort=8080 in SBT_OPTS", sbtOpts = "-Dhttp.proxyHost=proxy -Dhttp.proxyPort=8080", @@ -169,4 +168,15 @@ object SbtScriptTest extends SimpleTestSuite with PowerAssertions { if (isWindows) cancel("Test not supported on windows") assert(out.contains[String]("-Dsbt.ivy.home=/ivy/dir")) } + + test("sbt --script-version should print sbtVersion") { + val out = sbtProcess("--script-version").!!.trim + val expectedVersion = "^"+SbtRunnerTest.versionRegEx+"$" + assert(out.matches(expectedVersion)) + () + } + + makeTest("--sbt-cache")("--sbt-cache", "./cachePath") { out: List[String] => + assert(out.contains[String](s"-Dsbt.global.localcache=./cachePath")) + } } diff --git a/launcher-package/src/universal/bin/sbt.bat b/launcher-package/src/universal/bin/sbt.bat index cda987c9e..1a59fd9e1 100755 --- a/launcher-package/src/universal/bin/sbt.bat +++ b/launcher-package/src/universal/bin/sbt.bat @@ -42,6 +42,8 @@ set sbt_args_ivy= set sbt_args_supershell= set sbt_args_timings= set sbt_args_traces= +set sbt_args_sbt_boot= +set sbt_args_sbt_cache= set sbt_args_sbt_create= set sbt_args_sbt_dir= set sbt_args_sbt_version= @@ -259,6 +261,21 @@ if defined _sbt_boot_arg ( ) ) +if "%~0" == "-sbt-cache" set _sbt_cache_arg=true +if "%~0" == "--sbt-cache" set _sbt_cache_arg=true + +if defined _sbt_cache_arg ( + set _sbt_cache_arg= + if not "%~1" == "" ( + set sbt_args_sbt_cache=%1 + shift + goto args_loop + ) else ( + echo "%~0" is missing a value + goto error + ) +) + if "%~0" == "-sbt-jar" set _sbt_jar=true if "%~0" == "--sbt-jar" set _sbt_jar=true @@ -587,6 +604,10 @@ if defined sbt_args_sbt_boot ( set _SBT_OPTS=-Dsbt.boot.directory=!sbt_args_sbt_boot! !_SBT_OPTS! ) +if defined sbt_args_sbt_cache ( + set _SBT_OPTS=-Dsbt.global.localcache=!sbt_args_sbt_cache! !_SBT_OPTS! +) + if defined sbt_args_ivy ( set _SBT_OPTS=-Dsbt.ivy.home=!sbt_args_ivy! !_SBT_OPTS! ) @@ -932,6 +953,7 @@ echo --timings display task timings report on shutdown echo --sbt-create start sbt even if current directory contains no sbt project echo --sbt-dir ^ path to global settings/plugins directory ^(default: ~/.sbt^) echo --sbt-boot ^ path to shared boot directory ^(default: ~/.sbt/boot in 0.11 series^) +echo --sbt-cache ^ path to global cache directory ^(default: operating system specific^) echo --ivy ^ path to local Ivy repository ^(default: ~/.ivy2^) echo --mem ^ set memory options ^(default: %sbt_default_mem%^) echo --no-share use all local caches; no sharing diff --git a/main/src/main/scala/sbt/Keys.scala b/main/src/main/scala/sbt/Keys.scala index b271fbc1e..21c678fad 100644 --- a/main/src/main/scala/sbt/Keys.scala +++ b/main/src/main/scala/sbt/Keys.scala @@ -392,7 +392,7 @@ object Keys { val pushRemoteCacheTo = settingKey[Option[Resolver]]("The resolver to publish remote cache to.") val remoteCacheResolvers = settingKey[Seq[Resolver]]("Resolvers for remote cache.") val remoteCachePom = taskKey[File]("Generates a pom for publishing when publishing Maven-style.") - val localCacheDirectory = settingKey[File]("Directory to pull the remote cache to.") + val localCacheDirectory = settingKey[File]("Operating system specific cache directory.") val usePipelining = settingKey[Boolean]("Use subproject pipelining for compilation.").withRank(BSetting) val exportPipelining = settingKey[Boolean]("Product early output so downstream subprojects can do pipelining.").withRank(BSetting) diff --git a/sbt b/sbt index 7fb865514..ef5e6ebc7 100755 --- a/sbt +++ b/sbt @@ -538,6 +538,7 @@ Usage: `basename "$0"` [options] --sbt-create start sbt even if current directory contains no sbt project --sbt-dir path to global settings/plugins directory (default: ~/.sbt) --sbt-boot path to shared boot directory (default: ~/.sbt/boot in 0.11 series) + --sbt-cache path to global cache directory (default: operating system specific) --ivy path to local Ivy repository (default: ~/.ivy2) --mem set memory options (default: $sbt_default_mem) --no-share use all local caches; no sharing @@ -648,6 +649,10 @@ process_args () { -batch|--batch) exec