Skip to content

Commit db7c254

Browse files
committed
use native launchers in bash tests
cleanup Build.scala
1 parent 0bf7e75 commit db7c254

28 files changed

+246
-266
lines changed

.github/workflows/ci.yaml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ jobs:
141141

142142
- name: Cmd Tests
143143
run: |
144-
./project/scripts/sbt ";dist/pack; scala3-bootstrapped/compile; scala3-bootstrapped/test ;sbt-test/scripted scala2-compat/*; scala3-compiler-bootstrapped/scala3CompilerCoursierTest:test"
144+
./project/scripts/buildScalaBinary
145+
./project/scripts/sbt ";scala3-bootstrapped/compile ;scala3-bootstrapped/test ;sbt-test/scripted scala2-compat/* ;scala3-compiler-bootstrapped/scala3CompilerCoursierTest:test"
145146
./project/scripts/cmdTests
146147
./project/scripts/bootstrappedOnlyCmdTests
147148
@@ -230,7 +231,7 @@ jobs:
230231
shell: cmd
231232

232233
- name: build binary
233-
run: sbt "dist-win-x64/pack" & bash -version
234+
run: sbt "dist-win-x86_64/pack" & bash -version
234235
shell: cmd
235236

236237
- name: cygwin tests
@@ -269,8 +270,12 @@ jobs:
269270
- name: Git Checkout
270271
uses: actions/checkout@v4
271272

273+
- name: build binary
274+
run: sbt "dist-win-x86_64/pack"
275+
shell: cmd
276+
272277
- name: Test
273-
run: sbt ";dist-win-x64/pack ;scala3-bootstrapped/compile ;scala3-bootstrapped/test"
278+
run: sbt ";scala3-bootstrapped/compile ;scala3-bootstrapped/test"
274279
shell: cmd
275280

276281
- name: Scala.js Test
@@ -596,7 +601,8 @@ jobs:
596601

597602
- name: Test
598603
run: |
599-
./project/scripts/sbt ";dist/pack ;scala3-bootstrapped/compile ;scala3-bootstrapped/test ;sbt-test/scripted scala2-compat/*"
604+
./project/scripts/buildScalaBinary
605+
./project/scripts/sbt ";scala3-bootstrapped/compile ;scala3-bootstrapped/test ;sbt-test/scripted scala2-compat/*"
600606
./project/scripts/cmdTests
601607
./project/scripts/bootstrappedOnlyCmdTests
602608

.github/workflows/launchers.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
workflow_dispatch:
55

66
jobs:
7-
linux-x64:
7+
linux-x86_64:
88
name: Deploy and Test on Linux x64 architecture
99
runs-on: ubuntu-latest
1010
steps:
@@ -16,8 +16,8 @@ jobs:
1616
distribution: 'temurin'
1717
cache: 'sbt'
1818
- name: Build the launcher command
19-
run: sbt "dist-linux-x64/pack"
20-
- run: ./dist/linux-x64/target/pack/bin/scala --version
19+
run: sbt "dist-linux-x86_64/pack"
20+
- run: ./dist/linux-x86_64/target/pack/bin/scala --version
2121

2222
linux-aarch64:
2323
name: Deploy and Test on Linux ARM64 architecture
@@ -37,7 +37,7 @@ jobs:
3737
run: sbt "dist-linux-aarch64/pack"
3838
- run: ./dist/linux-aarch64/target/pack/bin/scala --version
3939

40-
mac-x64:
40+
mac-x86_64:
4141
name: Deploy and Test on Mac x64 architecture
4242
runs-on: macos-13
4343
steps:
@@ -52,8 +52,8 @@ jobs:
5252
- name: Install sbt
5353
run: brew install sbt
5454
- name: Build the launcher command
55-
run: sbt "dist-mac-x64/pack"
56-
- run: ./dist/mac-x64/target/pack/bin/scala --version
55+
run: sbt "dist-mac-x86_64/pack"
56+
- run: ./dist/mac-x86_64/target/pack/bin/scala --version
5757

5858
mac-aarch64:
5959
name: Deploy and Test on Mac ARM64 architecture
@@ -73,7 +73,7 @@ jobs:
7373
run: sbt "dist-mac-aarch64/pack"
7474
- run: ./dist/mac-aarch64/target/pack/bin/scala --version
7575

76-
win-x64:
76+
win-x86_64:
7777
name: Deploy and Test on Windows x64 architecture
7878
runs-on: windows-latest
7979
steps:
@@ -85,5 +85,5 @@ jobs:
8585
distribution: 'temurin'
8686
cache: 'sbt'
8787
- name: Build the launcher command
88-
run: sbt "dist-win-x64/pack"
89-
- run: ./dist/win-x64/target/pack/bin/scala --version
88+
run: sbt "dist-win-x86_64/pack"
89+
- run: ./dist/win-x86_64/target/pack/bin/scala --version

bin/common

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,18 @@ target="$1"
99

1010
shift # Mutates $@ by deleting the first element ($1)
1111

12+
# set the $DIST_PROJECT and $DIST_DIR variables
13+
source "$ROOT/bin/common-platform"
14+
1215
# Marker file used to obtain the date of latest call to sbt-back
13-
version="$ROOT/dist/target/pack/VERSION"
16+
version="$ROOT/$DIST_DIR/target/pack/VERSION"
1417

1518
# Create the target if absent or if file changed in ROOT/compiler
1619
new_files="$(find "$ROOT/compiler" \( -iname "*.scala" -o -iname "*.java" \) -newer "$version" 2> /dev/null)"
1720

1821
if [ ! -f "$version" ] || [ ! -z "$new_files" ]; then
1922
echo "Building Dotty..."
20-
(cd $ROOT && sbt "dist/pack")
23+
(cd $ROOT && sbt "$DIST_PROJECT/pack")
2124
fi
2225

23-
"$target" "$@"
26+
"$ROOT/$DIST_DIR/target/pack/bin/$target" "$@"

bin/common-platform

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env bash
2+
3+
unset cygwin mingw msys darwin
4+
5+
# COLUMNS is used together with command line option '-pageWidth'.
6+
if command -v tput >/dev/null 2>&1; then
7+
export COLUMNS="$(tput -Tdumb cols)"
8+
fi
9+
10+
case "`uname`" in
11+
CYGWIN*) cygwin=true
12+
;;
13+
MINGW*) mingw=true
14+
;;
15+
MSYS*) msys=true
16+
;;
17+
Darwin*) darwin=true
18+
;;
19+
esac
20+
21+
unset DIST_PROJECT DIST_DIR
22+
23+
if [[ ${cygwin-} || ${mingw-} || ${msys-} ]]; then
24+
DIST_PROJECT="dist-win-x86_64"
25+
DIST_DIR="dist/win-x86_64"
26+
else
27+
# OS and arch logic taken from https://github.com/VirtusLab/scala-cli/blob/main/scala-cli.sh
28+
unset arch ARCH_NORM
29+
arch=$(uname -m)
30+
if [[ "$arch" == "aarch64" ]] || [[ "$arch" == "x86_64" ]]; then
31+
ARCH_NORM="$arch"
32+
elif [[ "$arch" == "amd64" ]]; then
33+
ARCH_NORM="x86_64"
34+
elif [[ "$arch" == "arm64" ]]; then
35+
ARCH_NORM="aarch64"
36+
else
37+
ARCH_NORM="unknown"
38+
fi
39+
40+
if [ "$(expr substr $(uname -s) 1 5 2>/dev/null)" == "Linux" ]; then
41+
if [[ "$ARCH_NORM" == "unknown" ]]; then
42+
echo >&2 "unknown Linux CPU architecture, defaulting to JVM launcher"
43+
DIST_PROJECT="dist"
44+
DIST_DIR="dist"
45+
else
46+
DIST_PROJECT="dist-linux-$ARCH_NORM"
47+
DIST_DIR="dist/linux-$ARCH_NORM"
48+
fi
49+
elif [ "$(uname)" == "Darwin" ]; then
50+
if [[ "$ARCH_NORM" == "unknown" ]]; then
51+
echo >&2 "unknown Darwin CPU architecture, defaulting to JVM launcher"
52+
DIST_PROJECT="dist"
53+
DIST_DIR="dist"
54+
else
55+
DIST_PROJECT="dist-mac-$ARCH_NORM"
56+
DIST_DIR="dist/mac-$ARCH_NORM"
57+
fi
58+
else
59+
echo >&2 "unknown OS, defaulting to JVM launcher"
60+
DIST_PROJECT="dist"
61+
DIST_DIR="dist"
62+
fi
63+
fi

bin/scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ scala_args() {
1616
SCRIPT_ARGS+=("$@")
1717
break
1818
;;
19-
"clean")
19+
"clean" | "version" | "--version" | "-version" | "help" | "--help" | "-help")
2020
CLI_ARGS+=("$1")
2121
DISABLE_BLOOP=0 # clean command should not add --offline --server=false
2222
shift
@@ -35,4 +35,4 @@ scala_args() {
3535
echo "--power ${CLI_ARGS[@]} ${SCRIPT_ARGS[@]}"
3636
}
3737

38-
"$ROOT/bin/common" "$ROOT/dist/target/pack/bin/scala" $(scala_args "$@")
38+
"$ROOT/bin/common" "scala" $(scala_args "$@")

bin/scalac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" >& /dev/null && pwd)/.."
44

5-
"$ROOT/bin/common" "$ROOT/dist/target/pack/bin/scalac" "$@"
5+
"$ROOT/bin/common" "scalac" "$@"

bin/scaladoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" >& /dev/null && pwd)/.."
44

5-
"$ROOT/bin/common" "$ROOT/dist/target/pack/bin/scaladoc" "$@"
5+
"$ROOT/bin/common" "scaladoc" "$@"

build.sbt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ val `scaladoc-js-main` = Build.`scaladoc-js-main`
2828
val `scaladoc-js-contributors` = Build.`scaladoc-js-contributors`
2929
val `scala3-bench-run` = Build.`scala3-bench-run`
3030
val dist = Build.dist
31-
val `dist-mac-x64` = Build.`dist-mac-x64`
31+
val `dist-mac-x86_64` = Build.`dist-mac-x86_64`
3232
val `dist-mac-aarch64` = Build.`dist-mac-aarch64`
33-
val `dist-win-x64` = Build.`dist-win-x64`
34-
val `dist-linux-x64` = Build.`dist-linux-x64`
33+
val `dist-win-x86_64` = Build.`dist-win-x86_64`
34+
val `dist-linux-x86_64` = Build.`dist-linux-x86_64`
3535
val `dist-linux-aarch64` = Build.`dist-linux-aarch64`
3636
val `community-build` = Build.`community-build`
3737
val `sbt-community-build` = Build.`sbt-community-build`

compiler/test/dotty/tools/io/ClasspathTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class ClasspathTest {
2525
@Test def testWildcards(): Unit =
2626
val outDir = Files.createTempDirectory("classpath-test")
2727
try
28-
val compilerLib = s"${if isWindows then "dist-win-x64" else "dist"}/target/pack/lib"
28+
val compilerLib = s"${if isWindows then "dist-win-x86_64" else "dist"}/target/pack/lib"
2929
val libdir = Paths.get(compilerLib).toFile
3030
if libdir.exists then
3131
val libjarFiles = libdir.listFiles.toList.take(5)

compiler/test/dotty/tools/scripting/BashExitCodeTests.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class BashExitCodeTests:
3333
}, expectedExitCode, exitCode)
3434

3535
// Helpers for running scala, scalac, and scalac without the output directory ("raw")
36-
def scala(args: String*) = verifyExit(scalaPath, ("--power" +: "--offline" +: "--server=false" +: args)*)
36+
def scala(args: String*) = verifyExit(scalaPath, ("--power" +: args :+ "--offline" :+ "--server=false")*)
3737
def scalacRaw(args: String*) = verifyExit(scalacPath, args*)
3838
def scalac(args: String*) = scalacRaw(("-d" +: tmpDir +: args)*)
3939

compiler/test/dotty/tools/scripting/ScriptTestEnv.scala

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package scripting
55
import scala.language.unsafeNulls
66

77
import java.io.File
8+
import java.util.Locale
89
import java.nio.file.{Path, Paths, Files}
910

1011
import dotty.tools.dotc.config.Properties.*
@@ -46,11 +47,23 @@ object ScriptTestEnv {
4647
if bspDir.isEmpty then bspDir.delete()
4748
}
4849

49-
lazy val packDir: String =
50-
if winshell then
51-
"dist-win-x64/target/pack"
52-
else
53-
"dist/target/pack"
50+
lazy val nativePackDir: Option[String] = {
51+
def nativeDir(os: String, arch: String) = Some(s"dist/$os-$arch/target/pack")
52+
def nativeOs(os: String) = archNorm match
53+
case arch @ ("aarch64" | "x86_64") => nativeDir(os, arch)
54+
case _ => None
55+
56+
if winshell then nativeDir("win", "x86_64") // assume x86_64 for now
57+
else if linux then nativeOs("linux")
58+
else if mac then nativeOs("mac")
59+
else None
60+
}
61+
62+
def jvmPackDir() =
63+
println("warning: unknown OS architecture combination, defaulting to JVM launcher.")
64+
"dist/target/pack"
65+
66+
def packDir: String = nativePackDir.getOrElse(jvmPackDir())
5467

5568
def packBinDir: String = s"$packDir/bin"
5669

@@ -81,11 +94,18 @@ object ScriptTestEnv {
8194

8295
def unameExe = which("uname")
8396
def ostypeFull = if unameExe.nonEmpty then exec(unameExe).mkString else ""
84-
def ostype = ostypeFull.toLowerCase.takeWhile{ cc => cc >= 'a' && cc <='z' || cc >= 'A' && cc <= 'Z' }
97+
def ostype = ostypeFull.toLowerCase(Locale.ROOT).takeWhile{ cc => cc >= 'a' && cc <='z' || cc >= 'A' && cc <= 'Z' }
98+
def archFull = if unameExe.nonEmpty then exec(unameExe, "-m").mkString else ""
99+
def archNorm = archFull match
100+
case "arm64" => "aarch64"
101+
case "amd64" => "x86_64"
102+
case id => id
85103

86104
def cygwin = ostype == "cygwin"
87105
def mingw = ostype == "mingw"
88106
def msys = ostype == "msys"
107+
def linux = ostype == "linux"
108+
def mac = ostype == "darwin"
89109
def winshell: Boolean = cygwin || mingw || msys
90110

91111
def which(str: String) =

dist/bin/cli-common-platform

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
#!/usr/bin/env bash
22

3-
source "$PROG_HOME/bin/common-java"
4-
53
SCALA_CLI_CMD_BASH=("\"$JAVACMD\"" "-jar \"$PROG_HOME/bin/scala-cli.jar\"")

0 commit comments

Comments
 (0)