Skip to content

Commit 8fda9cf

Browse files
committed
Add native launchers, Restore CI tests on Windows
1 parent 4426f99 commit 8fda9cf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+444
-230
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ jobs:
230230
shell: cmd
231231

232232
- name: build binary
233-
run: sbt "dist/pack" & bash -version
233+
run: sbt "dist-win-x64/pack" & bash -version
234234
shell: cmd
235235

236236
- name: cygwin tests
@@ -270,7 +270,7 @@ jobs:
270270
uses: actions/checkout@v4
271271

272272
- name: Test
273-
run: sbt ";dist/pack ;scala3-bootstrapped/compile ;scala3-bootstrapped/test"
273+
run: sbt ";dist-win-x64/pack ;scala3-bootstrapped/compile ;scala3-bootstrapped/test"
274274
shell: cmd
275275

276276
- name: Scala.js Test

bin/scala

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

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

5-
"$ROOT/bin/common" "$ROOT/dist/target/pack/bin/scala" "--power" "$@" "--offline" "--server=false"
5+
scala_args() {
6+
7+
declare -a CLI_ARGS
8+
declare -a SCRIPT_ARGS
9+
declare DISABLE_BLOOP=1
10+
11+
while (( "$#" )); do
12+
case "$1" in
13+
"--")
14+
shift
15+
SCRIPT_ARGS+=("--")
16+
SCRIPT_ARGS+=("$@")
17+
break
18+
;;
19+
"clean")
20+
CLI_ARGS+=("$1")
21+
DISABLE_BLOOP=0 # clean command should not add --offline --server=false
22+
shift
23+
;;
24+
*)
25+
CLI_ARGS+=("$1")
26+
shift
27+
;;
28+
esac
29+
done
30+
31+
if [ $DISABLE_BLOOP -eq 1 ]; then
32+
CLI_ARGS+=("--offline" "--server=false")
33+
fi
34+
35+
echo "--power ${CLI_ARGS[@]} ${SCRIPT_ARGS[@]}"
36+
}
37+
38+
"$ROOT/bin/common" "$ROOT/dist/target/pack/bin/scala" $(scala_args "$@")

build.sbt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ 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`
32+
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`
35+
val `dist-linux-aarch64` = Build.`dist-linux-aarch64`
3136
val `community-build` = Build.`community-build`
3237
val `sbt-community-build` = Build.`sbt-community-build`
3338
val `scala3-presentation-compiler` = Build.`scala3-presentation-compiler`

compiler/test-resources/scripting/argfileClasspath.sc

Lines changed: 0 additions & 9 deletions
This file was deleted.

compiler/test-resources/scripting/classpathReport.sc renamed to compiler/test-resources/scripting/classpathReport_scalacli.sc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env bin/scala
2-
2+
// This file is a Scala CLI script.
33
import java.nio.file.Paths
44

55
// def main(args: Array[String]): Unit = // MIGRATION: Scala CLI expects `*.sc` files to be straight-line code

compiler/test-resources/scripting/cpArgumentsFile.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
// this file is intended to be ran as an argument to the dotty.tools.scripting.ScriptingDriver class
2+
13
def main(args: Array[String]): Unit =
24
println("Hello " + util.Properties.propOrNull("key"))

compiler/test-resources/scripting/envtestNu.sc

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// This file is a Scala CLI script.
2+
3+
println("Hello " + util.Properties.propOrNull("key"))

compiler/test-resources/scripting/hashBang.sc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env scala
1+
#!/usr/bin/env fake-program-to-test-hashbang-removal
22
# comment
33
STUFF=nada
44
!#

compiler/test-resources/scripting/hashBang.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
#!/usr/bin/env scala
1+
#!/usr/bin/env fake-program-to-test-hashbang-removal
22
# comment
33
STUFF=nada
44
!#
5-
5+
// everything above this point should be ignored by the compiler
66
def main(args: Array[String]): Unit =
77
System.err.printf("mainClassFromStack: %s\n",mainFromStack)
88
assert(mainFromStack.contains("hashBang"),s"fromStack[$mainFromStack]")

compiler/test-resources/scripting/scriptName.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env scala
1+
// this file is intended to be ran as an argument to the dotty.tools.scripting.ScriptingDriver class
22

33
def main(args: Array[String]): Unit =
44
val name = Option(sys.props("script.name")) match {

compiler/test-resources/scripting/scriptPath.sc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!dist/target/pack/bin/scala
1+
// this file is intended to be ran as an argument to the dotty.tools.scripting.ScriptingDriver class
22

33
def main(args: Array[String]): Unit =
44
args.zipWithIndex.foreach { case (arg,i) => printf("arg %d: [%s]\n",i,arg) }

compiler/test-resources/scripting/scriptPathNu.sc renamed to compiler/test-resources/scripting/scriptPath_scalacli.sc

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

55
args.zipWithIndex.foreach { case (arg,i) => printf("arg %d: [%s]\n",i,arg) }
66

7-
if !scriptPath.endsWith("scriptPathNu.sc") then
7+
if !scriptPath.endsWith("scriptPath_scalacli.sc") then
88
printf( s"incorrect script.path defined as [$scriptPath]")
99
else
1010
printf("scriptPath: %s\n", scriptPath) // report the value

compiler/test-resources/scripting/showArgs.sc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env bin/scala
1+
// this file is intended to be ran as an argument to the dotty.tools.scripting.ScriptingDriver class
22

33
// precise output format expected by BashScriptsTests.scala
44
def main(args: Array[String]): Unit =
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env bin/scala
22

3+
// This file is a Scala CLI script.
4+
35
// precise output format expected by BashScriptsTests.scala
4-
// MIGRATION: Scala CLI expects `*.sc` files to be straight-line code
56
for (a,i) <- args.zipWithIndex do
67
printf(s"arg %2d:[%s]\n",i,a)

compiler/test-resources/scripting/sqlDateError.sc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env bin/scala
1+
// this file is intended to be ran as an argument to the dotty.tools.scripting.ScriptingDriver class
22

33
def main(args: Array[String]): Unit = {
44
println(new java.sql.Date(100L))

compiler/test-resources/scripting/sqlDateErrorNu.sc

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bin/scala
2+
3+
// This file is a Scala CLI script.
4+
5+
println(new java.sql.Date(100L))
6+
System.err.println("SCALA_OPTS="+Option(System.getenv("SCALA_OPTS")).getOrElse(""))

compiler/test-resources/scripting/touchFile.sc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env scala
1+
// this file is intended to be ran as an argument to the dotty.tools.scripting.ScriptingDriver class
22

33
import java.io.File
44

compiler/test-resources/scripting/unglobClasspath.sc

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// This file is a Scala CLI script.
2+
3+
import dotty.tools.tasty.TastyFormat
4+
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5+
// not visible on default classpath, "compiler/test/dotty/tools/scripting/ClasspathTests.scala"
6+
// adds it to classpath via a compiler argument `-classpath 'org/scala-lang/tasty-core_3/$VERSION/*'`
7+
8+
val cp = sys.props("java.class.path")
9+
printf("unglobbed classpath: %s\n", cp)

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class ClasspathTest {
1515

1616
def pathsep = sys.props("path.separator")
1717

18+
def isWindows: Boolean = scala.util.Properties.isWin
19+
1820
//
1921
// Cope with wildcard classpath entries, exercised with -classpath <cp>
2022
//
@@ -23,7 +25,7 @@ class ClasspathTest {
2325
@Test def testWildcards(): Unit =
2426
val outDir = Files.createTempDirectory("classpath-test")
2527
try
26-
val compilerLib = "dist/target/pack/lib"
28+
val compilerLib = s"${if isWindows then "dist-win-x64" else "dist"}/target/pack/lib"
2729
val libdir = Paths.get(compilerLib).toFile
2830
if libdir.exists then
2931
val libjarFiles = libdir.listFiles.toList.take(5)

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ import ScriptTestEnv.*
1616
class BashExitCodeTests:
1717
private var myTmpDir: String | Null = null
1818
private lazy val tmpDir = { myTmpDir = Files.createTempDirectory("exit-code-tests").toFile.absPath; myTmpDir }
19-
@After def cleanup(): Unit = if myTmpDir != null then io.Directory(myTmpDir).deleteRecursively()
19+
@After def cleanup(): Unit = {
20+
if myTmpDir != null then io.Directory(myTmpDir).deleteRecursively()
21+
22+
cleanupScalaCLIDirs()
23+
}
2024

2125
/** Verify the exit code of running `cmd args*`. */
2226
def verifyExit(cmd: String, args: String*)(expectedExitCode: Int): Unit =

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ object BashScriptsTests:
2525
def testFiles = scripts("/scripting")
2626

2727
@AfterClass def cleanup: Unit = {
28+
cleanupScalaCLIDirs()
29+
2830
val af = argsfile.toFile
29-
if (af.exists) {
31+
if af.exists then
3032
af.delete()
31-
}
3233
}
34+
3335
printf("osname[%s]\n", osname)
3436
printf("uname[%s]\n", ostypeFull)
3537
printf("using JAVA_HOME=%s\n", envJavaHome)
@@ -50,7 +52,7 @@ object BashScriptsTests:
5052
val testScriptArgs = Seq(
5153
"a", "b", "c", "-repl", "-run", "-script", "-debug"
5254
)
53-
val Seq(showArgsScript, showArgsScalaCli) = Seq("showArgs.sc", "showArgsNu.sc").map { name =>
55+
val Seq(showArgsScript, showArgsScalaCli) = Seq("showArgs.sc", "showArgs_scalacli.sc").map { name =>
5456
testFiles.find(_.getName == name).get.absPath
5557
}
5658

@@ -66,7 +68,7 @@ object BashScriptsTests:
6668
}
6769
file
6870

69-
val Seq(envtestNuSc, envtestScala) = Seq("envtestNu.sc", "envtest.scala").map { testFile(_) }
71+
val Seq(envtestNuSc, envtestScala) = Seq("envtest_scalacli.sc", "envtest.scala").map { testFile(_) }
7072

7173
// create command line with given options, execute specified script, return stdout
7274
def callScript(tag: String, script: String, keyPre: String): String =
@@ -173,13 +175,13 @@ class BashScriptsTests:
173175
assert(stdout == expectedOutput)
174176

175177
/*
176-
* verify that scriptPathNu.sc sees a valid script.path property,
177-
* and that it's value is the path to "scriptPathNu.sc".
178+
* verify that scriptPath_scalacli.sc sees a valid script.path property,
179+
* and that it's value is the path to "scriptPath_scalacli.sc".
178180
*/
179181
@Category(Array(classOf[BootstrappedOnlyTests]))
180182
@Test def verifyScriptPathProperty =
181183
assumeFalse("Scripts do not yet support Scala 2 library TASTy", Properties.usingScalaLibraryTasty)
182-
val scriptFile = testFiles.find(_.getName == "scriptPathNu.sc").get
184+
val scriptFile = testFiles.find(_.getName == "scriptPath_scalacli.sc").get
183185
val expected = s"${scriptFile.getName}"
184186
printf("===> verify valid system property script.path is reported by script [%s]\n", scriptFile.getName)
185187
printf("calling scriptFile: %s\n", scriptFile)
@@ -196,7 +198,7 @@ class BashScriptsTests:
196198
*/
197199
@Test def verifyScalaOpts =
198200
assumeFalse("Scripts do not yet support Scala 2 library TASTy", Properties.usingScalaLibraryTasty)
199-
val scriptFile = testFiles.find(_.getName == "classpathReport.sc").get
201+
val scriptFile = testFiles.find(_.getName == "classpathReport_scalacli.sc").get
200202
printf("===> verify SCALA_OPTS='@argsfile' is properly handled by `dist/bin/scala`\n")
201203
val envPairs = List(("SCALA_OPTS", s"@$argsfile"))
202204
val (validTest, exitCode, stdout, stderr) = bashCommand(scriptFile.absPath, envPairs)
@@ -219,7 +221,7 @@ class BashScriptsTests:
219221
*/
220222
@Test def sqlDateTest =
221223
assumeFalse("Scripts do not yet support Scala 2 library TASTy", Properties.usingScalaLibraryTasty)
222-
val scriptBase = "sqlDateErrorNu"
224+
val scriptBase = "sqlDateError_scalacli"
223225
val scriptFile = testFiles.find(_.getName == s"$scriptBase.sc").get
224226
val testJar = testFile(s"$scriptBase.jar") // jar should not be created when scriptFile runs
225227
val tj = Paths.get(testJar).toFile

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@ import org.junit.{Test, Ignore, AfterClass}
1111
import vulpix.TestConfiguration
1212
import ScriptTestEnv.*
1313

14-
/** Test java command line generated by bin/scala and bin/scalac */
14+
object ClasspathTests:
15+
@AfterClass def cleanup: Unit = {
16+
cleanupScalaCLIDirs()
17+
}
1518

19+
/** Test java command line generated by bin/scala and bin/scalac */
1620
class ClasspathTests:
1721
/*
1822
* Test disabled (temporarily).
@@ -24,7 +28,7 @@ class ClasspathTests:
2428
@Ignore
2529
@Test def hashbangClasspathVerifyTest = {
2630
// only interested in classpath test scripts
27-
val testScriptName = "classpathReport.sc"
31+
val testScriptName = "classpathReport_scalacli.sc"
2832
val testScript = scripts("/scripting").find { _.getName.matches(testScriptName) } match
2933
case None => sys.error(s"test script not found: ${testScriptName}")
3034
case Some(file) => file
@@ -39,7 +43,7 @@ class ClasspathTests:
3943

4044
cmd.foreach { printf("[%s]\n", _) }
4145

42-
// classpathReport.sc is expected to produce two lines:
46+
// classpathReport_scalacli.sc is expected to produce two lines:
4347
// cwd: <current-working-directory-seen-by-the-script>
4448
// classpath: <classpath-seen-by-the-script>
4549

@@ -51,10 +55,10 @@ class ClasspathTests:
5155
// convert scriptCp to a list of files
5256
val hashbangJars: List[File] = scriptCp.split(psep).map { _.toFile }.toList
5357
val hashbangClasspathJars = hashbangJars.map { _.name }.sorted.distinct // get jar basenames, remove duplicates
54-
val packlibDir: String = ??? /* ??? was s"$scriptCwd/$packLibDir" */ // classpathReport.sc specifies a wildcard classpath in this directory
58+
val packlibDir: String = ??? /* ??? was s"$scriptCwd/$packLibDir" */ // classpathReport_scalacli.sc specifies a wildcard classpath in this directory
5559
val packlibJars: List[File] = listJars(packlibDir) // classpath entries expected to have been reported by the script
5660

57-
printf("%d jar files in dist/target/pack/lib\n", packlibJars.size)
61+
printf(s"%d jar files in $packDir/lib\n", packlibJars.size)
5862
printf("%d test script jars in classpath\n", hashbangClasspathJars.size)
5963

6064
val (diff: Set[File], msg: String) = if (packlibJars.size > hashbangClasspathJars.size) {
@@ -63,7 +67,7 @@ class ClasspathTests:
6367
(hashbangJars.toSet -- packlibJars.toSet , "only in hashbang classpath")
6468
}
6569
// verify that the script hasbang classpath setting was effective at supplementing the classpath
66-
// (a minimal subset of jars below dist/target/pack/lib are always be in the classpath)
70+
// (a minimal subset of jars below dist*/target/pack/lib are always be in the classpath)
6771
val missingClasspathEntries = if hashbangClasspathJars.size != packlibJars.size then
6872
printf("packlib dir [%s]\n", packlibDir)
6973
printf("hashbangClasspathJars: %s\n", hashbangJars.map { _.relpath.norm }.mkString("\n ", "\n ", ""))
@@ -78,7 +82,7 @@ class ClasspathTests:
7882
* verify classpath is unglobbed by MainGenericRunner.
7983
*/
8084
@Test def unglobClasspathVerifyTest = {
81-
val testScriptName = "unglobClasspath.sc"
85+
val testScriptName = "unglobClasspath_scalacli.sc"
8286
val testScript = scripts("/scripting").find { _.name.matches(testScriptName) } match
8387
case None => sys.error(s"test script not found: ${testScriptName}")
8488
case Some(file) => file

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ class ExpressionTest:
5555

5656
object ExpressionTest:
5757

58+
@AfterClass def cleanup(): Unit = {
59+
cleanupScalaCLIDirs()
60+
}
61+
5862
def main(args: Array[String]): Unit =
5963
val tests = new ExpressionTest
6064
println("\n=== verifyCommandLineExpression ===")

0 commit comments

Comments
 (0)