mirror of https://github.com/sbt/sbt.git
[2.x] fix: handle --script-version sbt 2.x project dirs (#8715)
When in an sbt 2.x project directory, the script used to delegate to sbtn before checking --script-version, so 'sbt --script-version' ran sbtn and failed. Now we print the script version and exit before the native client branch.
This commit is contained in:
parent
f6319f19a3
commit
de2c27abeb
|
|
@ -0,0 +1,7 @@
|
|||
package foo
|
||||
|
||||
object Hello {
|
||||
def main(args: Array[String]): Unit = {
|
||||
println("hello")
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
lazy val root = (project in file("."))
|
||||
.settings(
|
||||
scalaVersion := "3.8.1",
|
||||
name := "Hello",
|
||||
)
|
||||
|
|
@ -0,0 +1 @@
|
|||
sbt.version=2.0.0-RC8
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
import verify._
|
||||
|
||||
object HelloTest extends BasicTestSuite {
|
||||
test("addition") {
|
||||
assert(2 == 1 + 1)
|
||||
}
|
||||
}
|
||||
|
|
@ -113,11 +113,21 @@ object RunnerScriptTest extends verify.BasicTestSuite with ShellScriptUtil:
|
|||
if (isWindows) cancel("Test not supported on windows")
|
||||
else assert(out.contains[String]("-Dsbt.ivy.home=/ivy/dir"))
|
||||
|
||||
testOutput("sbt --script-version should print sbtVersion")("--script-version"):
|
||||
(out: List[String]) =>
|
||||
val expectedVersion = "^" + ExtendedRunnerTest.versionRegEx + "$"
|
||||
assert(out.mkString(System.lineSeparator()).trim.matches(expectedVersion))
|
||||
()
|
||||
testOutput(
|
||||
"sbt --script-version should print sbtVersion (sbt 1.x project)",
|
||||
citestVariant = "citest",
|
||||
)("--script-version"): (out: List[String]) =>
|
||||
val expectedVersion = "^" + ExtendedRunnerTest.versionRegEx + "$"
|
||||
assert(out.mkString(System.lineSeparator()).trim.matches(expectedVersion))
|
||||
()
|
||||
|
||||
testOutput(
|
||||
"sbt --script-version should print sbtVersion (sbt 2.x project)",
|
||||
citestVariant = "citest2",
|
||||
)("--script-version"): (out: List[String]) =>
|
||||
val expectedVersion = "^" + ExtendedRunnerTest.versionRegEx + "$"
|
||||
assert(out.mkString(System.lineSeparator()).trim.matches(expectedVersion))
|
||||
()
|
||||
|
||||
testOutput("--sbt-cache")("--sbt-cache", "./cachePath"): (out: List[String]) =>
|
||||
assert(out.contains[String]("-Dsbt.global.localcache=./cachePath"))
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ trait ShellScriptUtil extends BasicTestSuite {
|
|||
machineSbtoptsContents: String = "",
|
||||
jvmoptsFileContents: String = "",
|
||||
windowsSupport: Boolean = true,
|
||||
citestVariant: String = "citest",
|
||||
)(args: String*)(f: List[String] => Any) =
|
||||
if !windowsSupport && isWindows then
|
||||
test(name):
|
||||
|
|
@ -46,7 +47,7 @@ trait ShellScriptUtil extends BasicTestSuite {
|
|||
else
|
||||
test(name) {
|
||||
val workingDirectory = Files.createTempDirectory("sbt-launcher-package-test").toFile
|
||||
val citestDir = new File("launcher-package/citest")
|
||||
val citestDir = new File("launcher-package", citestVariant)
|
||||
// Clean target directory if it exists to avoid copying temporary files that may be deleted during copy
|
||||
val targetDir = new File(citestDir, "target")
|
||||
if (targetDir.exists()) {
|
||||
|
|
|
|||
8
sbt
8
sbt
|
|
@ -570,8 +570,6 @@ run() {
|
|||
detect_working_directory
|
||||
if [[ $print_sbt_version ]]; then
|
||||
execRunner "$java_cmd" -jar "$sbt_jar" "sbtVersion" | tail -1 | sed -e 's/\[info\]//g'
|
||||
elif [[ $print_sbt_script_version ]]; then
|
||||
echo "$init_sbt_version"
|
||||
elif [[ $print_version ]]; then
|
||||
if [[ -n "$is_this_dir_sbt" ]]; then
|
||||
execRunner "$java_cmd" -jar "$sbt_jar" "sbtVersion" | tail -1 | sed -e 's/\[info\]/sbt version in this project:/g'
|
||||
|
|
@ -905,6 +903,12 @@ args1=( "${cli_options[@]}" "${cli_commands[@]}" "${sbt_additional_commands[@]}"
|
|||
process_args "${args1[@]}"
|
||||
vlog "[sbt_options] $(declare -p sbt_options)"
|
||||
|
||||
# Handle --script-version before native client so it works on sbt 2.x project dirs (#8711)
|
||||
if [[ $print_sbt_script_version ]]; then
|
||||
echo "$init_sbt_version"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ "$(isRunNativeClient)" == "true" ]]; then
|
||||
set -- "${residual_args[@]}"
|
||||
argumentCount=$#
|
||||
|
|
|
|||
Loading…
Reference in New Issue