-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Bundle scala cli in scala command #20351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4426f99
8fda9cf
f6c27b6
0bf7e75
db7c254
709e91f
b01a91f
84c6969
aeafc08
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
name: Test CLI Launchers on all the platforms | ||
on: | ||
pull_request: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
linux-x86_64: | ||
name: Deploy and Test on Linux x64 architecture | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v4 | ||
with: | ||
java-version: '17' | ||
distribution: 'temurin' | ||
cache: 'sbt' | ||
- name: Build and test launcher command | ||
run: ./project/scripts/native-integration/bashTests | ||
env: | ||
LAUNCHER_EXPECTED_PROJECT: "dist-linux-x86_64" | ||
|
||
linux-aarch64: | ||
name: Deploy and Test on Linux ARM64 architecture | ||
runs-on: macos-latest | ||
if: ${{ false }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v4 | ||
with: | ||
java-version: '17' | ||
distribution: 'temurin' | ||
cache: 'sbt' | ||
# https://github.com/actions/runner-images/issues/9369 | ||
- name: Install sbt | ||
run: brew install sbt | ||
- name: Build and test launcher command | ||
run: ./project/scripts/native-integration/bashTests | ||
env: | ||
LAUNCHER_EXPECTED_PROJECT: "dist-linux-aarch64" | ||
|
||
mac-x86_64: | ||
name: Deploy and Test on Mac x64 architecture | ||
runs-on: macos-13 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v4 | ||
with: | ||
java-version: '17' | ||
distribution: 'temurin' | ||
cache: 'sbt' | ||
# https://github.com/actions/runner-images/issues/9369 | ||
- name: Install sbt | ||
run: brew install sbt | ||
- name: Build and test launcher command | ||
run: ./project/scripts/native-integration/bashTests | ||
env: | ||
LAUNCHER_EXPECTED_PROJECT: "dist-mac-x86_64" | ||
|
||
mac-aarch64: | ||
name: Deploy and Test on Mac ARM64 architecture | ||
runs-on: macos-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v4 | ||
with: | ||
java-version: '17' | ||
distribution: 'temurin' | ||
cache: 'sbt' | ||
# https://github.com/actions/runner-images/issues/9369 | ||
- name: Install sbt | ||
run: brew install sbt | ||
- name: Build and test launcher command | ||
run: ./project/scripts/native-integration/bashTests | ||
env: | ||
LAUNCHER_EXPECTED_PROJECT: "dist-mac-aarch64" | ||
|
||
win-x86_64: | ||
name: Deploy and Test on Windows x64 architecture | ||
runs-on: windows-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v4 | ||
with: | ||
java-version: '17' | ||
distribution: 'temurin' | ||
cache: 'sbt' | ||
- name: Build the launcher command | ||
run: sbt "dist-win-x86_64/pack" | ||
- name: Run the launcher command tests | ||
run: './project/scripts/native-integration/winTests.bat' | ||
shell: cmd |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!/usr/bin/env bash | ||
|
||
unset cygwin mingw msys darwin | ||
|
||
# COLUMNS is used together with command line option '-pageWidth'. | ||
if command -v tput >/dev/null 2>&1; then | ||
export COLUMNS="$(tput -Tdumb cols)" | ||
fi | ||
|
||
case "`uname`" in | ||
CYGWIN*) cygwin=true | ||
;; | ||
MINGW*) mingw=true | ||
;; | ||
MSYS*) msys=true | ||
;; | ||
Darwin*) darwin=true | ||
;; | ||
esac | ||
|
||
unset DIST_PROJECT DIST_DIR | ||
|
||
if [[ ${cygwin-} || ${mingw-} || ${msys-} ]]; then | ||
DIST_PROJECT="dist-win-x86_64" | ||
DIST_DIR="dist/win-x86_64" | ||
else | ||
# OS and arch logic taken from https://github.com/VirtusLab/scala-cli/blob/main/scala-cli.sh | ||
unset arch ARCH_NORM | ||
arch=$(uname -m) | ||
if [[ "$arch" == "aarch64" ]] || [[ "$arch" == "x86_64" ]]; then | ||
ARCH_NORM="$arch" | ||
elif [[ "$arch" == "amd64" ]]; then | ||
ARCH_NORM="x86_64" | ||
elif [[ "$arch" == "arm64" ]]; then | ||
ARCH_NORM="aarch64" | ||
else | ||
ARCH_NORM="unknown" | ||
fi | ||
|
||
if [ "$(expr substr $(uname -s) 1 5 2>/dev/null)" == "Linux" ]; then | ||
if [[ "$ARCH_NORM" == "unknown" ]]; then | ||
echo >&2 "unknown Linux CPU architecture, defaulting to JVM launcher" | ||
DIST_PROJECT="dist" | ||
DIST_DIR="dist" | ||
else | ||
DIST_PROJECT="dist-linux-$ARCH_NORM" | ||
DIST_DIR="dist/linux-$ARCH_NORM" | ||
fi | ||
elif [ "$(uname)" == "Darwin" ]; then | ||
if [[ "$ARCH_NORM" == "unknown" ]]; then | ||
echo >&2 "unknown Darwin CPU architecture, defaulting to JVM launcher" | ||
DIST_PROJECT="dist" | ||
DIST_DIR="dist" | ||
else | ||
DIST_PROJECT="dist-mac-$ARCH_NORM" | ||
DIST_DIR="dist/mac-$ARCH_NORM" | ||
fi | ||
else | ||
echo >&2 "unknown OS, defaulting to JVM launcher" | ||
DIST_PROJECT="dist" | ||
DIST_DIR="dist" | ||
fi | ||
fi |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,37 @@ | |
|
||
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" >& /dev/null && pwd)/.." | ||
|
||
"$ROOT/bin/common" "$ROOT/dist/target/pack/bin/scala" "$@" | ||
scala_args() { | ||
|
||
declare -a CLI_ARGS | ||
declare -a SCRIPT_ARGS | ||
declare DISABLE_BLOOP=1 | ||
|
||
while (( "$#" )); do | ||
case "$1" in | ||
"--") | ||
shift | ||
SCRIPT_ARGS+=("--") | ||
SCRIPT_ARGS+=("$@") | ||
break | ||
;; | ||
"clean" | "version" | "--version" | "-version" | "help" | "--help" | "-help") | ||
CLI_ARGS+=("$1") | ||
DISABLE_BLOOP=0 # clean command should not add --offline --server=false | ||
shift | ||
;; | ||
*) | ||
CLI_ARGS+=("$1") | ||
shift | ||
;; | ||
esac | ||
done | ||
|
||
if [ $DISABLE_BLOOP -eq 1 ]; then | ||
CLI_ARGS+=("--offline" "--server=false") | ||
fi | ||
|
||
echo "--power ${CLI_ARGS[@]} ${SCRIPT_ARGS[@]}" | ||
Comment on lines
+5
to
+35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After discussion with @Gedochao, we should not be filtering arguments here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is just a test command used only for testing, it automatically adds There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, this is actually an old comment that I forgot to remove. Sorry for that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still don't feel this is necessary... passing those arguments explicitly in the tests would make them more readable IMO, rather than embedding them in this script. |
||
} | ||
|
||
"$ROOT/bin/common" "scala" $(scala_args "$@") |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,7 +57,7 @@ class TestScripts { | |
s"bin/scalac script did not run properly. Output:$lineSep$dotcOutput" | ||
) | ||
|
||
val (retDotr, dotrOutput) = executeScript("./bin/scala HelloWorld") | ||
val (retDotr, dotrOutput) = executeScript("./bin/scala -M HelloWorld") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is slightly confusing, since just passing |
||
assert( | ||
retDotr == 0 && dotrOutput == "hello world\n", | ||
s"Running hello world exited with status: $retDotr and output: $dotrOutput" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -266,6 +266,22 @@ object MainGenericRunner { | |
run(settings.withExecuteMode(ExecuteMode.Run)) | ||
else | ||
run(settings.withExecuteMode(ExecuteMode.Repl)) | ||
end run | ||
|
||
val ranByCoursierBootstrap = | ||
sys.props.isDefinedAt("coursier.mainJar") | ||
|| sys.props.get("bootstrap.mainClass").contains("dotty.tools.MainGenericRunner") | ||
|
||
val silenced = sys.props.get("scala.use_legacy_launcher") == Some("true") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We may want to document this prop clearly somewhere later, once we release this. |
||
|
||
if !silenced then | ||
Console.err.println(s"[warning] MainGenericRunner class is deprecated since Scala 3.5.0, and Scala CLI features will not work.") | ||
Console.err.println(s"[warning] Please be sure to update to the Scala CLI launcher to use the new features.") | ||
if ranByCoursierBootstrap then | ||
Console.err.println(s"[warning] It appears that your Coursier-based Scala installation is misconfigured.") | ||
Console.err.println(s"[warning] To update to the new Scala CLI runner, please update (coursier, cs) commands first before re-installing scala.") | ||
Console.err.println(s"[warning] Check the Scala 3.5.0 release notes to troubleshoot your installation.") | ||
|
||
|
||
run(settings) match | ||
case Some(ex: (StringDriverException | ScriptingException)) => errorFn(ex.getMessage) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -166,7 +166,7 @@ object CoursierScalaTests: | |
case Nil => args | ||
case _ => "--" +: args | ||
val newJOpts = jOpts.map(s => s"--java-opt ${s.stripPrefix("-J")}").mkString(" ") | ||
execCmd("./cs", (s"""launch "org.scala-lang:scala3-compiler_3:${sys.env("DOTTY_BOOTSTRAPPED_VERSION")}" $newJOpts --main-class "$entry" --property "scala.usejavacp=true"""" +: newOptions)*)._2 | ||
execCmd("./cs", (s"""launch "org.scala-lang:scala3-compiler_3:${sys.env("DOTTY_BOOTSTRAPPED_VERSION")}" $newJOpts --main-class "$entry" --property "scala.usejavacp=true" --property "scala.use_legacy_launcher=true"""" +: newOptions)*)._2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should probably update coursier ourselves when the new release is up with @bishaboshas's changes in coursier/coursier#2975 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cs launch always runs the main class of the artifact you give it, so it makes no difference. |
||
|
||
/** Get coursier script */ | ||
@BeforeClass def setup(): Unit = | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -1,8 +1,8 @@ | ||||
#!bin/scala -classpath 'dist/target/pack/lib/*' | ||||
|
||||
#!/usr/bin/env bin/scala | ||||
// This file is a Scala CLI script. | ||||
import java.nio.file.Paths | ||||
|
||||
def main(args: Array[String]): Unit = | ||||
// def main(args: Array[String]): Unit = // MIGRATION: Scala CLI expects `*.sc` files to be straight-line code | ||||
val cwd = Paths.get(".").toAbsolutePath.normalize.toString.norm | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if it makes sense to keep this comment, or can we just remove it.
Suggested change
|
||||
printf("cwd: %s\n", cwd) | ||||
printf("classpath: %s\n", sys.props("java.class.path").norm) | ||||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
// this file is intended to be ran as an argument to the dotty.tools.scripting.ScriptingDriver class | ||
|
||
def main(args: Array[String]): Unit = | ||
println("Hello " + util.Properties.propOrNull("key")) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// This file is a Scala CLI script. | ||
|
||
println("Hello " + util.Properties.propOrNull("key")) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#!/usr/bin/env scala | ||
#!/usr/bin/env fake-program-to-test-hashbang-removal | ||
# comment | ||
STUFF=nada | ||
!# | ||
|
Uh oh!
There was an error while loading. Please reload this page.