Skip to content

Commit 8df7956

Browse files
philwalkGedochao
andauthored
drive-relative paths in Windows SHELL environments (#2516)
* fix for #2359, drive-relative paths accepted in Windows SHELL environments * added anti-regression test handling of drive-relative for os.Path * fix classpath-split regex String to accept either forward slash or backslash * added integration tests for JAVA_HOME setting to RunScriptTestDefinitions.scala * apply suggested changes * fix for cli.base-image.nativeImage in Windows * fix JAVA_HOME test; tweak mill script * Apply suggestions from code review --------- Co-authored-by: Piotr Chabelski <[email protected]>
1 parent 5c243b5 commit 8df7956

File tree

11 files changed

+73
-11
lines changed

11 files changed

+73
-11
lines changed

.github/scripts/generate-os-packages.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fi
1414
ARTIFACTS_DIR="artifacts/"
1515
mkdir -p "$ARTIFACTS_DIR"
1616

17-
if [[ "$OSTYPE" == "msys" ]]; then
17+
if [[ -z "$OSTYPE" ]]; then
1818
mill="./mill.bat"
1919
else
2020
mill="./mill"
@@ -28,7 +28,7 @@ launcher() {
2828
local launcherMillCommand="cli.nativeImage"
2929
local launcherName
3030

31-
if [[ "$OSTYPE" == "msys" ]]; then
31+
if [[ "${OS-}" == "Windows_NT" ]]; then
3232
launcherName="scala.exe"
3333
else
3434
launcherName="scala"

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ out/
88
.scala-build
99
dest/
1010
target/
11+
12+
# ignore vim backup files
13+
*.sw[op]

mill

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,21 @@ elif [[ "$cache_dest" == *.zip ]]; then
5353
fi
5454
fi
5555

56-
eval "$("$cs" java --env --jvm temurin:17 || "$cs" java --env --jvm openjdk:1.17.0)"
56+
function to_bash_syntax {
57+
local S
58+
for S in "$@" ; do
59+
echo "$S" | sed -E -e 's#^set #export #' -e 's#%([A-Z_][A-Z_0-9]*)%#${\1}#g' | tr '\\' '/'
60+
done
61+
}
62+
# necessary for Windows various shell environments
63+
if [[ `uname | grep -E 'CYG*|MSYS*|MING*|UCRT*|ClANG*|GIT*'` ]]; then
64+
# needed for coursier version < 2.1.8, harmless otherwise
65+
IFS=$'\n'
66+
eval "$(to_bash_syntax `"$cs" java --env --jvm temurin:17` || to_bash_syntax `"$cs" java --env --jvm openjdk:1.17.0`)"
67+
unset IFS
68+
else
69+
eval "$("$cs" java --env --jvm temurin:17 || "$cs" java --env --jvm openjdk:1.17.0)"
70+
fi
5771

5872
# temporary, until we pass JPMS options to native-image,
5973
# see https://www.graalvm.org/release-notes/22_2/#native-image

mill.bat

100644100755
File mode changed.

modules/build/src/test/scala/scala/build/tests/ActionableDiagnosticTests.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,9 @@ class ActionableDiagnosticTests extends TestUtil.ScalaCliBuildSuite {
221221
)
222222
val withRepoBuildOptions = baseOptions.copy(
223223
classPathOptions =
224-
baseOptions.classPathOptions.copy(extraRepositories = Seq(s"file:${repoTmpDir.toString}"))
224+
baseOptions.classPathOptions.copy(extraRepositories =
225+
Seq(s"file:${repoTmpDir.toString.replace('\\', '/')}")
226+
)
225227
)
226228
testInputs.withBuild(withRepoBuildOptions, buildThreads, None, actionableDiagnostics = true) {
227229
(_, _, maybeBuild) =>

modules/cli/src/main/scala/scala/cli/commands/CommandUtils.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ object CommandUtils {
1818

1919
// Ensure the path to the CLI is absolute
2020
def getAbsolutePathToScalaCli(programName: String): String =
21-
if (programName.contains(File.separator))
21+
if (programName.replace('\\', '/').contains("/"))
2222
os.Path(programName, Os.pwd).toString
2323
else
2424
/*

modules/cli/src/main/scala/scala/cli/commands/installcompletions/InstallCompletions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ object InstallCompletions extends ScalaCommand[InstallCompletionsOptions] {
114114
def getFormat(format: Option[String]): Option[String] =
115115
format.map(_.trim).filter(_.nonEmpty)
116116
.orElse {
117-
Option(System.getenv("SHELL")).map(_.split(File.separator).last).map {
117+
Option(System.getenv("SHELL")).map(_.split("[\\/]+").last).map {
118118
case "bash" => Bash.id
119119
case "zsh" => Zsh.id
120120
case other => other

modules/integration/src/test/scala/scala/cli/integration/CompileTestDefinitions.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package scala.cli.integration
33
import com.eed3si9n.expecty.Expecty.expect
44

55
import java.io.File
6-
import java.util.regex.Pattern
76

87
import scala.cli.integration.util.BloopUtil
98

@@ -585,7 +584,7 @@ abstract class CompileTestDefinitions(val scalaVersionOpt: Option[String])
585584
"."
586585
).call(cwd = root)
587586
val classPath = res.out.trim().split(File.pathSeparator)
588-
val classPathFileNames = classPath.map(_.split(Pattern.quote(File.separator)).last)
587+
val classPathFileNames = classPath.map(_.split("[\\\\/]+").last)
589588
expect(classPathFileNames.exists(_.startsWith("spark-core_")))
590589
// usually a duplicate is there if we don't call .distrinct when necessary here or there
591590
expect(classPathFileNames.exists(_.startsWith("snappy-java")))

modules/integration/src/test/scala/scala/cli/integration/InstallAndUninstallCompletionsTests.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ class InstallAndUninstallCompletionsTests extends ScalaCliSuite {
3737
}
3838
}
3939

40-
if (!Properties.isWin)
40+
def isWinShell: Boolean = Option(System.getenv("OSTYPE")).nonEmpty
41+
if (!Properties.isWin || isWinShell)
4142
test("installing and uninstalling completions") {
4243
runInstallAndUninstallCompletions()
4344
}

modules/integration/src/test/scala/scala/cli/integration/PackageTestDefinitions.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import java.io.{File, InputStream}
66
import java.nio.charset.StandardCharsets
77
import java.nio.file.Files
88
import java.util
9-
import java.util.regex.Pattern
109
import java.util.zip.ZipFile
1110

1211
import scala.cli.integration.TestUtil.removeAnsiColors
@@ -731,7 +730,7 @@ abstract class PackageTestDefinitions(val scalaVersionOpt: Option[String])
731730
if (actualScalaVersion.startsWith("2.")) actualScalaVersion
732731
else {
733732
val scalaLibJarName = scalaLibCp.split(File.pathSeparator)
734-
.map(_.split(Pattern.quote(File.separator)).last).find(_.startsWith("scala-library-"))
733+
.map(_.split("[\\\\/]+").last).find(_.startsWith("scala-library-"))
735734
.getOrElse {
736735
sys.error(s"scala-library not found in provided class path $scalaLibCp")
737736
}

0 commit comments

Comments
 (0)