From 3c7135f0231326e3b565f66a1ebed02c093fc495 Mon Sep 17 00:00:00 2001 From: Phil Date: Tue, 7 Nov 2023 17:05:52 -0700 Subject: [PATCH 1/8] fix for #2359, drive-relative paths accepted in Windows SHELL environments --- .gitignore | 3 +++ .../cli/commands/installcompletions/InstallCompletions.scala | 2 +- .../scala/scala/cli/integration/CompileTestDefinitions.scala | 2 +- .../scala/scala/cli/integration/PackageTestDefinitions.scala | 2 +- project/deps.sc | 2 +- 5 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 9c4866b846..9621b9c957 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,6 @@ out/ .scala-build dest/ target/ + +# ignore vim backup files +*.sw[op] diff --git a/modules/cli/src/main/scala/scala/cli/commands/installcompletions/InstallCompletions.scala b/modules/cli/src/main/scala/scala/cli/commands/installcompletions/InstallCompletions.scala index 8a1985b287..079178210c 100644 --- a/modules/cli/src/main/scala/scala/cli/commands/installcompletions/InstallCompletions.scala +++ b/modules/cli/src/main/scala/scala/cli/commands/installcompletions/InstallCompletions.scala @@ -114,7 +114,7 @@ object InstallCompletions extends ScalaCommand[InstallCompletionsOptions] { def getFormat(format: Option[String]): Option[String] = format.map(_.trim).filter(_.nonEmpty) .orElse { - Option(System.getenv("SHELL")).map(_.split(File.separator).last).map { + Option(System.getenv("SHELL")).map(_.split("[\\/]+").last).map { case "bash" => Bash.id case "zsh" => Zsh.id case other => other diff --git a/modules/integration/src/test/scala/scala/cli/integration/CompileTestDefinitions.scala b/modules/integration/src/test/scala/scala/cli/integration/CompileTestDefinitions.scala index d0b532684a..8f691ae9a5 100644 --- a/modules/integration/src/test/scala/scala/cli/integration/CompileTestDefinitions.scala +++ b/modules/integration/src/test/scala/scala/cli/integration/CompileTestDefinitions.scala @@ -585,7 +585,7 @@ abstract class CompileTestDefinitions(val scalaVersionOpt: Option[String]) "." ).call(cwd = root) val classPath = res.out.trim().split(File.pathSeparator) - val classPathFileNames = classPath.map(_.split(Pattern.quote(File.separator)).last) + val classPathFileNames = classPath.map(_.split(Pattern.quote("[\\/]+")).last) expect(classPathFileNames.exists(_.startsWith("spark-core_"))) // usually a duplicate is there if we don't call .distrinct when necessary here or there expect(classPathFileNames.exists(_.startsWith("snappy-java"))) diff --git a/modules/integration/src/test/scala/scala/cli/integration/PackageTestDefinitions.scala b/modules/integration/src/test/scala/scala/cli/integration/PackageTestDefinitions.scala index 934ad354f9..23f8b527f5 100644 --- a/modules/integration/src/test/scala/scala/cli/integration/PackageTestDefinitions.scala +++ b/modules/integration/src/test/scala/scala/cli/integration/PackageTestDefinitions.scala @@ -731,7 +731,7 @@ abstract class PackageTestDefinitions(val scalaVersionOpt: Option[String]) if (actualScalaVersion.startsWith("2.")) actualScalaVersion else { val scalaLibJarName = scalaLibCp.split(File.pathSeparator) - .map(_.split(Pattern.quote(File.separator)).last).find(_.startsWith("scala-library-")) + .map(_.split(Pattern.quote("[\\/]+")).last).find(_.startsWith("scala-library-")) .getOrElse { sys.error(s"scala-library not found in provided class path $scalaLibCp") } diff --git a/project/deps.sc b/project/deps.sc index 2bf8761bb2..1a73557903 100644 --- a/project/deps.sc +++ b/project/deps.sc @@ -140,7 +140,7 @@ object Deps { def munit = ivy"org.scalameta::munit:0.7.29" def nativeTestRunner = ivy"org.scala-native::test-runner:${Versions.scalaNative}" def nativeTools = ivy"org.scala-native::tools:${Versions.scalaNative}" - def osLib = ivy"com.lihaoyi::os-lib:0.9.1" + def osLib = ivy"com.lihaoyi::os-lib:0.9.2" def pprint = ivy"com.lihaoyi::pprint:0.8.1" def pythonInterface = ivy"io.github.alexarchambault.python:interface:0.1.0" def pythonNativeLibs = ivy"ai.kien::python-native-libs:0.2.4" From f9b3332008ffb4d78a88780905e924427bb28b1c Mon Sep 17 00:00:00 2001 From: Phil Date: Thu, 9 Nov 2023 07:49:27 -0700 Subject: [PATCH 2/8] added anti-regression test handling of drive-relative for os.Path --- .../scala/cli/integration/ConfigTests.scala | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/modules/integration/src/test/scala/scala/cli/integration/ConfigTests.scala b/modules/integration/src/test/scala/scala/cli/integration/ConfigTests.scala index e9e39e28a9..ff453a8178 100644 --- a/modules/integration/src/test/scala/scala/cli/integration/ConfigTests.scala +++ b/modules/integration/src/test/scala/scala/cli/integration/ConfigTests.scala @@ -561,4 +561,20 @@ class ConfigTests extends ScalaCliSuite { } } + test("verify os.Path attributes") { + // requires os-lib 0.9.2 or later to succeed in Windows + val dr = os.Path.driveRoot + val testStr = "/omg" + val p = os.Path(testStr) // <<< must not throw Exception + val absPath = p.toString.replace('\\', '/') + val relPath = if (dr.nonEmpty) absPath.drop(2) else absPath + val synPath = s"${os.Path.driveRoot}$relPath" + printf("absPath[%s]\n", absPath) + printf("synPath[%s]\n", synPath) + printf("relPath[%s]\n", relPath) + expect(absPath == synPath) + expect(relPath == testStr) + expect(absPath endsWith testStr) + } + } From ce08732d4c19a98b2a7639d9249c741872d2b7fd Mon Sep 17 00:00:00 2001 From: Phil Date: Thu, 9 Nov 2023 10:26:55 -0700 Subject: [PATCH 3/8] fix classpath-split regex String to accept either forward slash or backslash --- .../scala/scala/cli/integration/CompileTestDefinitions.scala | 2 +- .../scala/scala/cli/integration/PackageTestDefinitions.scala | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/integration/src/test/scala/scala/cli/integration/CompileTestDefinitions.scala b/modules/integration/src/test/scala/scala/cli/integration/CompileTestDefinitions.scala index 8f691ae9a5..7d52a2da36 100644 --- a/modules/integration/src/test/scala/scala/cli/integration/CompileTestDefinitions.scala +++ b/modules/integration/src/test/scala/scala/cli/integration/CompileTestDefinitions.scala @@ -585,7 +585,7 @@ abstract class CompileTestDefinitions(val scalaVersionOpt: Option[String]) "." ).call(cwd = root) val classPath = res.out.trim().split(File.pathSeparator) - val classPathFileNames = classPath.map(_.split(Pattern.quote("[\\/]+")).last) + val classPathFileNames = classPath.map(_.split("[\\\\/]+").last) expect(classPathFileNames.exists(_.startsWith("spark-core_"))) // usually a duplicate is there if we don't call .distrinct when necessary here or there expect(classPathFileNames.exists(_.startsWith("snappy-java"))) diff --git a/modules/integration/src/test/scala/scala/cli/integration/PackageTestDefinitions.scala b/modules/integration/src/test/scala/scala/cli/integration/PackageTestDefinitions.scala index 23f8b527f5..fe652f645d 100644 --- a/modules/integration/src/test/scala/scala/cli/integration/PackageTestDefinitions.scala +++ b/modules/integration/src/test/scala/scala/cli/integration/PackageTestDefinitions.scala @@ -731,7 +731,7 @@ abstract class PackageTestDefinitions(val scalaVersionOpt: Option[String]) if (actualScalaVersion.startsWith("2.")) actualScalaVersion else { val scalaLibJarName = scalaLibCp.split(File.pathSeparator) - .map(_.split(Pattern.quote("[\\/]+")).last).find(_.startsWith("scala-library-")) + .map(_.split("[\\\\/]+").last).find(_.startsWith("scala-library-")) .getOrElse { sys.error(s"scala-library not found in provided class path $scalaLibCp") } From 545d535b783aec7951e341115af0a63ee0a3b4ad Mon Sep 17 00:00:00 2001 From: Phil Date: Sat, 11 Nov 2023 14:45:41 -0700 Subject: [PATCH 4/8] added integration tests for JAVA_HOME setting to RunScriptTestDefinitions.scala --- .../integration/CompileTestDefinitions.scala | 1 - .../scala/cli/integration/ConfigTests.scala | 18 +----- .../integration/PackageTestDefinitions.scala | 1 - .../RunScriptTestDefinitions.scala | 63 +++++++++++++++++++ 4 files changed, 64 insertions(+), 19 deletions(-) diff --git a/modules/integration/src/test/scala/scala/cli/integration/CompileTestDefinitions.scala b/modules/integration/src/test/scala/scala/cli/integration/CompileTestDefinitions.scala index 7d52a2da36..bbba3067e5 100644 --- a/modules/integration/src/test/scala/scala/cli/integration/CompileTestDefinitions.scala +++ b/modules/integration/src/test/scala/scala/cli/integration/CompileTestDefinitions.scala @@ -3,7 +3,6 @@ package scala.cli.integration import com.eed3si9n.expecty.Expecty.expect import java.io.File -import java.util.regex.Pattern import scala.cli.integration.util.BloopUtil diff --git a/modules/integration/src/test/scala/scala/cli/integration/ConfigTests.scala b/modules/integration/src/test/scala/scala/cli/integration/ConfigTests.scala index ff453a8178..9fbd1a5f9a 100644 --- a/modules/integration/src/test/scala/scala/cli/integration/ConfigTests.scala +++ b/modules/integration/src/test/scala/scala/cli/integration/ConfigTests.scala @@ -127,7 +127,7 @@ class ConfigTests extends ScalaCliSuite { TestUtil.putCsInPathViaEnv(root / "bin") val res = os.proc(TestUtil.cli, "--power", "config", "httpProxy.address") - .call(cwd = root, env = extraEnv) + .call(cwd = root, env = extraEnv, mergeErrIntoOut = false) val value = res.out.trim() expect(value == proxyAddr) @@ -561,20 +561,4 @@ class ConfigTests extends ScalaCliSuite { } } - test("verify os.Path attributes") { - // requires os-lib 0.9.2 or later to succeed in Windows - val dr = os.Path.driveRoot - val testStr = "/omg" - val p = os.Path(testStr) // <<< must not throw Exception - val absPath = p.toString.replace('\\', '/') - val relPath = if (dr.nonEmpty) absPath.drop(2) else absPath - val synPath = s"${os.Path.driveRoot}$relPath" - printf("absPath[%s]\n", absPath) - printf("synPath[%s]\n", synPath) - printf("relPath[%s]\n", relPath) - expect(absPath == synPath) - expect(relPath == testStr) - expect(absPath endsWith testStr) - } - } diff --git a/modules/integration/src/test/scala/scala/cli/integration/PackageTestDefinitions.scala b/modules/integration/src/test/scala/scala/cli/integration/PackageTestDefinitions.scala index fe652f645d..c8ae89dc8b 100644 --- a/modules/integration/src/test/scala/scala/cli/integration/PackageTestDefinitions.scala +++ b/modules/integration/src/test/scala/scala/cli/integration/PackageTestDefinitions.scala @@ -6,7 +6,6 @@ import java.io.{File, InputStream} import java.nio.charset.StandardCharsets import java.nio.file.Files import java.util -import java.util.regex.Pattern import java.util.zip.ZipFile import scala.cli.integration.TestUtil.removeAnsiColors diff --git a/modules/integration/src/test/scala/scala/cli/integration/RunScriptTestDefinitions.scala b/modules/integration/src/test/scala/scala/cli/integration/RunScriptTestDefinitions.scala index 87b3018f63..063294a51b 100644 --- a/modules/integration/src/test/scala/scala/cli/integration/RunScriptTestDefinitions.scala +++ b/modules/integration/src/test/scala/scala/cli/integration/RunScriptTestDefinitions.scala @@ -2,6 +2,8 @@ package scala.cli.integration import com.eed3si9n.expecty.Expecty.expect +import java.io.File + import scala.cli.integration.TestUtil.normalizeConsoleOutput import scala.util.Properties @@ -549,4 +551,65 @@ trait RunScriptTestDefinitions { _: RunTestDefinitions => expect(p.out.trim() == "42") } } + + test("verify os.Path attributes") { + // requires os-lib 0.9.2 or later to succeed in Windows + val dr = os.Path.driveRoot + val testStr = "/omg" + val p = os.Path(testStr) // <<< must not throw Exception + val absPath = p.toString.replace('\\', '/') + val relPath = if (dr.nonEmpty) absPath.drop(2) else absPath + val synPath = s"${os.Path.driveRoot}$relPath" + printf("absPath[%s]\n", absPath) + printf("synPath[%s]\n", synPath) + printf("relPath[%s]\n", relPath) + expect(absPath == synPath) + expect(relPath == testStr) + expect(absPath endsWith testStr) + } + + test("verify drive-relative JAVA_HOME works") { + val java8Home = + os.Path(os.proc(TestUtil.cs, "java-home", "--jvm", "zulu:8").call().out.trim(), os.pwd) + + val dr = os.Path.driveRoot + printf("driveRoot: %s\n", dr) + + // forward slash is legal in `Windows` + val javaHomeNoDriveRoot = java8Home.toString.drop(dr.length()).replace('\\', '/') + printf("java8HomeNoDriveRoot: %s\n", javaHomeNoDriveRoot) + expect(javaHomeNoDriveRoot.startsWith("/")) + + val sysPath: String = System.getenv("PATH") + val newPath: String = s"$javaHomeNoDriveRoot/bin" + File.pathSeparator + sysPath + + val extraEnv = Map( + "JAVA_HOME" -> javaHomeNoDriveRoot, + "PATH" -> newPath + ) + + val inputs = TestInputs( + os.rel / "script-with-shebang" -> + s"""|#!/usr/bin/env -S ${TestUtil.cli.mkString(" ")} shebang -S 2.13 + |//> using scala "$actualScalaVersion" + |println(args.toList)""".stripMargin + ) + inputs.fromRoot { root => + val proc = if (!Properties.isWin) { + os.perms.set(root / "script-with-shebang", os.PermSet.fromString("rwx------")) + os.proc("./script-with-shebang", "1", "2", "3", "-v") + } + else + os.proc(TestUtil.cli, "shebang", "script-with-shebang", "1", "2", "3", "-v") + + val output = proc.call(cwd = root, env = extraEnv).out.trim() + + val expectedOutput = "List(1, 2, 3, -v)" + if (output != expectedOutput) + printf("JAVA_HOME test: output is [%s]\n", output) + + expect(output == expectedOutput) + } + } + } From e364fbf93daa13105de0f3e19e7d4173c64da5ef Mon Sep 17 00:00:00 2001 From: philwalk Date: Mon, 13 Nov 2023 07:23:11 -0700 Subject: [PATCH 5/8] apply suggested changes --- .../scala/cli/integration/ConfigTests.scala | 2 +- .../RunScriptTestDefinitions.scala | 20 ------------------- 2 files changed, 1 insertion(+), 21 deletions(-) diff --git a/modules/integration/src/test/scala/scala/cli/integration/ConfigTests.scala b/modules/integration/src/test/scala/scala/cli/integration/ConfigTests.scala index 9fbd1a5f9a..e9e39e28a9 100644 --- a/modules/integration/src/test/scala/scala/cli/integration/ConfigTests.scala +++ b/modules/integration/src/test/scala/scala/cli/integration/ConfigTests.scala @@ -127,7 +127,7 @@ class ConfigTests extends ScalaCliSuite { TestUtil.putCsInPathViaEnv(root / "bin") val res = os.proc(TestUtil.cli, "--power", "config", "httpProxy.address") - .call(cwd = root, env = extraEnv, mergeErrIntoOut = false) + .call(cwd = root, env = extraEnv) val value = res.out.trim() expect(value == proxyAddr) diff --git a/modules/integration/src/test/scala/scala/cli/integration/RunScriptTestDefinitions.scala b/modules/integration/src/test/scala/scala/cli/integration/RunScriptTestDefinitions.scala index 063294a51b..f1059f9dd1 100644 --- a/modules/integration/src/test/scala/scala/cli/integration/RunScriptTestDefinitions.scala +++ b/modules/integration/src/test/scala/scala/cli/integration/RunScriptTestDefinitions.scala @@ -552,32 +552,14 @@ trait RunScriptTestDefinitions { _: RunTestDefinitions => } } - test("verify os.Path attributes") { - // requires os-lib 0.9.2 or later to succeed in Windows - val dr = os.Path.driveRoot - val testStr = "/omg" - val p = os.Path(testStr) // <<< must not throw Exception - val absPath = p.toString.replace('\\', '/') - val relPath = if (dr.nonEmpty) absPath.drop(2) else absPath - val synPath = s"${os.Path.driveRoot}$relPath" - printf("absPath[%s]\n", absPath) - printf("synPath[%s]\n", synPath) - printf("relPath[%s]\n", relPath) - expect(absPath == synPath) - expect(relPath == testStr) - expect(absPath endsWith testStr) - } - test("verify drive-relative JAVA_HOME works") { val java8Home = os.Path(os.proc(TestUtil.cs, "java-home", "--jvm", "zulu:8").call().out.trim(), os.pwd) val dr = os.Path.driveRoot - printf("driveRoot: %s\n", dr) // forward slash is legal in `Windows` val javaHomeNoDriveRoot = java8Home.toString.drop(dr.length()).replace('\\', '/') - printf("java8HomeNoDriveRoot: %s\n", javaHomeNoDriveRoot) expect(javaHomeNoDriveRoot.startsWith("/")) val sysPath: String = System.getenv("PATH") @@ -605,8 +587,6 @@ trait RunScriptTestDefinitions { _: RunTestDefinitions => val output = proc.call(cwd = root, env = extraEnv).out.trim() val expectedOutput = "List(1, 2, 3, -v)" - if (output != expectedOutput) - printf("JAVA_HOME test: output is [%s]\n", output) expect(output == expectedOutput) } From 935b9b40b4a3c0ee712a26a85b2798a86941b5f1 Mon Sep 17 00:00:00 2001 From: philwalk Date: Tue, 21 Nov 2023 08:34:10 -0700 Subject: [PATCH 6/8] fix for cli.base-image.nativeImage in Windows --- .github/scripts/generate-native-image.sh | 4 +++- .github/scripts/generate-os-packages.sh | 4 ++-- .mill-version | 2 +- mill | 15 ++++++++++++++- mill.bat | 0 .../build/tests/ActionableDiagnosticTests.scala | 4 +++- .../scala/scala/cli/commands/CommandUtils.scala | 2 +- .../InstallAndUninstallCompletionsTests.scala | 3 ++- .../integration/RunScriptTestDefinitions.scala | 10 ++++++---- 9 files changed, 32 insertions(+), 12 deletions(-) mode change 100644 => 100755 mill.bat diff --git a/.github/scripts/generate-native-image.sh b/.github/scripts/generate-native-image.sh index fecdd84ecd..23944e8266 100755 --- a/.github/scripts/generate-native-image.sh +++ b/.github/scripts/generate-native-image.sh @@ -10,7 +10,9 @@ export USE_NATIVE_IMAGE_JAVA_PLATFORM_MODULE_SYSTEM=false # Using 'mill -i' so that the Mill process doesn't outlive this invocation if [[ "$OSTYPE" == "msys" ]]; then - ./mill.bat -i ci.copyJvm --dest jvm + if [ ! -d jvm ]; then + ./mill.bat -i ci.copyJvm --dest jvm + fi export JAVA_HOME="$(pwd -W | sed 's,/,\\,g')\\jvm" export GRAALVM_HOME="$JAVA_HOME" export PATH="$(pwd)/bin:$PATH" diff --git a/.github/scripts/generate-os-packages.sh b/.github/scripts/generate-os-packages.sh index 0a7d8d1670..059a3f575c 100755 --- a/.github/scripts/generate-os-packages.sh +++ b/.github/scripts/generate-os-packages.sh @@ -14,7 +14,7 @@ fi ARTIFACTS_DIR="artifacts/" mkdir -p "$ARTIFACTS_DIR" -if [[ "$OSTYPE" == "msys" ]]; then +if [[ -z "$OSTYPE" ]]; then mill="./mill.bat" else mill="./mill" @@ -28,7 +28,7 @@ launcher() { local launcherMillCommand="cli.nativeImage" local launcherName - if [[ "$OSTYPE" == "msys" ]]; then + if [[ "${OS-}" == "Windows_NT" ]]; then launcherName="scala.exe" else launcherName="scala" diff --git a/.mill-version b/.mill-version index af88ba8248..62d5dbdf3c 100644 --- a/.mill-version +++ b/.mill-version @@ -1 +1 @@ -0.11.1 +0.11.5 diff --git a/mill b/mill index 95fd8ca1c2..d497265184 100755 --- a/mill +++ b/mill @@ -53,7 +53,20 @@ elif [[ "$cache_dest" == *.zip ]]; then fi fi -eval "$("$cs" java --env --jvm temurin:17 || "$cs" java --env --jvm openjdk:1.17.0)" +function fixit { + local S + for S in "$@" ; do + echo "$S" | sed -E -e 's#^set #export #' -e 's#%([A-Z_][A-Z_0-9]*)%#${\1}#g' | tr '\\' '/' + done +} +if [[ `uname | grep -E 'CYG*|MSYS*|MING*|UCRT*|ClANG*|GIT*'` ]]; then + # needed for coursier version < 2.1.8, harmless otherwise + IFS=$'\n' + eval "$(fixit `"$cs" java --env --jvm temurin:17` || fixit `"$cs" java --env --jvm openjdk:1.17.0`)" + unset IFS +else + eval "$("$cs" java --env --jvm temurin:17 || "$cs" java --env --jvm openjdk:1.17.0)" +fi # temporary, until we pass JPMS options to native-image, # see https://www.graalvm.org/release-notes/22_2/#native-image diff --git a/mill.bat b/mill.bat old mode 100644 new mode 100755 diff --git a/modules/build/src/test/scala/scala/build/tests/ActionableDiagnosticTests.scala b/modules/build/src/test/scala/scala/build/tests/ActionableDiagnosticTests.scala index cea6f7c5a9..449e6a0712 100644 --- a/modules/build/src/test/scala/scala/build/tests/ActionableDiagnosticTests.scala +++ b/modules/build/src/test/scala/scala/build/tests/ActionableDiagnosticTests.scala @@ -221,7 +221,9 @@ class ActionableDiagnosticTests extends munit.FunSuite { ) val withRepoBuildOptions = baseOptions.copy( classPathOptions = - baseOptions.classPathOptions.copy(extraRepositories = Seq(s"file:${repoTmpDir.toString}")) + baseOptions.classPathOptions.copy(extraRepositories = + Seq(s"file:${repoTmpDir.toString.replace('\\', '/')}") + ) ) testInputs.withBuild(withRepoBuildOptions, buildThreads, None, actionableDiagnostics = true) { (_, _, maybeBuild) => diff --git a/modules/cli/src/main/scala/scala/cli/commands/CommandUtils.scala b/modules/cli/src/main/scala/scala/cli/commands/CommandUtils.scala index 703e6b2185..14f46200a1 100644 --- a/modules/cli/src/main/scala/scala/cli/commands/CommandUtils.scala +++ b/modules/cli/src/main/scala/scala/cli/commands/CommandUtils.scala @@ -18,7 +18,7 @@ object CommandUtils { // Ensure the path to the CLI is absolute def getAbsolutePathToScalaCli(programName: String): String = - if (programName.contains(File.separator)) + if (programName.replace('\\', '/').contains("/")) os.Path(programName, Os.pwd).toString else /* diff --git a/modules/integration/src/test/scala/scala/cli/integration/InstallAndUninstallCompletionsTests.scala b/modules/integration/src/test/scala/scala/cli/integration/InstallAndUninstallCompletionsTests.scala index 5f5cc7f39c..d8b49bfd8c 100644 --- a/modules/integration/src/test/scala/scala/cli/integration/InstallAndUninstallCompletionsTests.scala +++ b/modules/integration/src/test/scala/scala/cli/integration/InstallAndUninstallCompletionsTests.scala @@ -37,7 +37,8 @@ class InstallAndUninstallCompletionsTests extends ScalaCliSuite { } } - if (!Properties.isWin) + def isWinShell: Boolean = Option(System.getenv("OSTYPE")).nonEmpty + if (!Properties.isWin || isWinShell) test("installing and uninstalling completions") { runInstallAndUninstallCompletions() } diff --git a/modules/integration/src/test/scala/scala/cli/integration/RunScriptTestDefinitions.scala b/modules/integration/src/test/scala/scala/cli/integration/RunScriptTestDefinitions.scala index f1059f9dd1..67479199e0 100644 --- a/modules/integration/src/test/scala/scala/cli/integration/RunScriptTestDefinitions.scala +++ b/modules/integration/src/test/scala/scala/cli/integration/RunScriptTestDefinitions.scala @@ -559,14 +559,14 @@ trait RunScriptTestDefinitions { _: RunTestDefinitions => val dr = os.Path.driveRoot // forward slash is legal in `Windows` - val javaHomeNoDriveRoot = java8Home.toString.drop(dr.length()).replace('\\', '/') - expect(javaHomeNoDriveRoot.startsWith("/")) + val javaHomeNoDriveRoot = java8Home.toString.replace('\\', '/') + expect(javaHomeNoDriveRoot.drop(dr.length).startsWith("/")) - val sysPath: String = System.getenv("PATH") + val sysPath: String = System.getenv("PATH").replace('\\', '/') val newPath: String = s"$javaHomeNoDriveRoot/bin" + File.pathSeparator + sysPath val extraEnv = Map( - "JAVA_HOME" -> javaHomeNoDriveRoot, + "JAVA_HOME" -> java8Home.toString, "PATH" -> newPath ) @@ -577,6 +577,8 @@ trait RunScriptTestDefinitions { _: RunTestDefinitions => |println(args.toList)""".stripMargin ) inputs.fromRoot { root => + printf("TestUtil.cli: [%s]\nroot: [%s]", TestUtil.cli, root) + printf("javaHome.cli: [%s]\nroot: [%s]", TestUtil.cli, root) val proc = if (!Properties.isWin) { os.perms.set(root / "script-with-shebang", os.PermSet.fromString("rwx------")) os.proc("./script-with-shebang", "1", "2", "3", "-v") From f733fc2bb4883c88db4bb4568217410438e0530a Mon Sep 17 00:00:00 2001 From: philwalk Date: Wed, 22 Nov 2023 15:52:32 -0700 Subject: [PATCH 7/8] fix JAVA_HOME test; tweak mill script --- .github/scripts/generate-native-image.sh | 4 +--- .mill-version | 2 +- .../scala/cli/integration/RunScriptTestDefinitions.scala | 9 ++++----- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/.github/scripts/generate-native-image.sh b/.github/scripts/generate-native-image.sh index 23944e8266..fecdd84ecd 100755 --- a/.github/scripts/generate-native-image.sh +++ b/.github/scripts/generate-native-image.sh @@ -10,9 +10,7 @@ export USE_NATIVE_IMAGE_JAVA_PLATFORM_MODULE_SYSTEM=false # Using 'mill -i' so that the Mill process doesn't outlive this invocation if [[ "$OSTYPE" == "msys" ]]; then - if [ ! -d jvm ]; then - ./mill.bat -i ci.copyJvm --dest jvm - fi + ./mill.bat -i ci.copyJvm --dest jvm export JAVA_HOME="$(pwd -W | sed 's,/,\\,g')\\jvm" export GRAALVM_HOME="$JAVA_HOME" export PATH="$(pwd)/bin:$PATH" diff --git a/.mill-version b/.mill-version index 62d5dbdf3c..af88ba8248 100644 --- a/.mill-version +++ b/.mill-version @@ -1 +1 @@ -0.11.5 +0.11.1 diff --git a/modules/integration/src/test/scala/scala/cli/integration/RunScriptTestDefinitions.scala b/modules/integration/src/test/scala/scala/cli/integration/RunScriptTestDefinitions.scala index e6c629030c..3da737630a 100644 --- a/modules/integration/src/test/scala/scala/cli/integration/RunScriptTestDefinitions.scala +++ b/modules/integration/src/test/scala/scala/cli/integration/RunScriptTestDefinitions.scala @@ -605,11 +605,11 @@ trait RunScriptTestDefinitions { _: RunTestDefinitions => val dr = os.Path.driveRoot // forward slash is legal in `Windows` - val javaHomeNoDriveRoot = java8Home.toString.replace('\\', '/') - expect(javaHomeNoDriveRoot.drop(dr.length).startsWith("/")) + val javaHome = java8Home.toString.replace('\\', '/') + expect(javaHome.drop(dr.length).startsWith("/")) val sysPath: String = System.getenv("PATH").replace('\\', '/') - val newPath: String = s"$javaHomeNoDriveRoot/bin" + File.pathSeparator + sysPath + val newPath: String = s"$javaHome/bin" + File.pathSeparator + sysPath val extraEnv = Map( "JAVA_HOME" -> java8Home.toString, @@ -623,8 +623,7 @@ trait RunScriptTestDefinitions { _: RunTestDefinitions => |println(args.toList)""".stripMargin ) inputs.fromRoot { root => - printf("TestUtil.cli: [%s]\nroot: [%s]", TestUtil.cli, root) - printf("javaHome.cli: [%s]\nroot: [%s]", TestUtil.cli, root) + printf("TestUtil.cli: [%s]\njavaHome: [%s]\nnewPath: [%s]\n", TestUtil.cli, javaHome, newPath) val proc = if (!Properties.isWin) { os.perms.set(root / "script-with-shebang", os.PermSet.fromString("rwx------")) os.proc("./script-with-shebang", "1", "2", "3", "-v") From 693a06544c49875b854e2941902d362aa1a931df Mon Sep 17 00:00:00 2001 From: philwalk Date: Thu, 23 Nov 2023 08:05:25 -0700 Subject: [PATCH 8/8] Apply suggestions from code review --- mill | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mill b/mill index d497265184..42acfaa82a 100755 --- a/mill +++ b/mill @@ -53,16 +53,17 @@ elif [[ "$cache_dest" == *.zip ]]; then fi fi -function fixit { +function to_bash_syntax { local S for S in "$@" ; do echo "$S" | sed -E -e 's#^set #export #' -e 's#%([A-Z_][A-Z_0-9]*)%#${\1}#g' | tr '\\' '/' done } +# necessary for Windows various shell environments if [[ `uname | grep -E 'CYG*|MSYS*|MING*|UCRT*|ClANG*|GIT*'` ]]; then # needed for coursier version < 2.1.8, harmless otherwise IFS=$'\n' - eval "$(fixit `"$cs" java --env --jvm temurin:17` || fixit `"$cs" java --env --jvm openjdk:1.17.0`)" + eval "$(to_bash_syntax `"$cs" java --env --jvm temurin:17` || to_bash_syntax `"$cs" java --env --jvm openjdk:1.17.0`)" unset IFS else eval "$("$cs" java --env --jvm temurin:17 || "$cs" java --env --jvm openjdk:1.17.0)"