From 420af615a8034dda3aa0ef6afa3587b7d40daf36 Mon Sep 17 00:00:00 2001 From: Hamza Remmal Date: Thu, 23 Oct 2025 22:01:21 +0100 Subject: [PATCH] chore: drop `scala_legacy` and `MainGenericRunner` --- bin/scalaQ | 6 - .../src/dotty/tools/MainGenericCompiler.scala | 17 +- .../src/dotty/tools/MainGenericRunner.scala | 297 ------------------ .../tools/coursier/CoursierScalaTests.scala | 191 ----------- compiler/test-coursier/run/envtest.scala | 4 - compiler/test-coursier/run/myargs.txt | 1 - compiler/test-coursier/run/myfile.scala | 4 - .../tools/scripting/ClasspathTests.scala | 41 --- dist/bin/scala_legacy | 72 ----- tests/run-with-compiler/i14541.check | 2 - tests/run-with-compiler/i14541.scala | 14 - 11 files changed, 15 insertions(+), 634 deletions(-) delete mode 100755 bin/scalaQ delete mode 100644 compiler/src/dotty/tools/MainGenericRunner.scala delete mode 100644 compiler/test-coursier/dotty/tools/coursier/CoursierScalaTests.scala delete mode 100644 compiler/test-coursier/run/envtest.scala delete mode 100755 compiler/test-coursier/run/myargs.txt delete mode 100644 compiler/test-coursier/run/myfile.scala delete mode 100755 dist/bin/scala_legacy delete mode 100644 tests/run-with-compiler/i14541.check delete mode 100644 tests/run-with-compiler/i14541.scala diff --git a/bin/scalaQ b/bin/scalaQ deleted file mode 100755 index c14a2f0372ff..000000000000 --- a/bin/scalaQ +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env bash - -ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" >& /dev/null && pwd)/.." -. $ROOT/bin/commonQ - -java -cp $cp dotty.tools.MainGenericRunner -usejavacp "$@" diff --git a/compiler/src/dotty/tools/MainGenericCompiler.scala b/compiler/src/dotty/tools/MainGenericCompiler.scala index ad522a9f6810..eb95ddc95442 100644 --- a/compiler/src/dotty/tools/MainGenericCompiler.scala +++ b/compiler/src/dotty/tools/MainGenericCompiler.scala @@ -87,6 +87,20 @@ object MainGenericCompiler { val classpathSeparator: String = File.pathSeparator + def processClasspath(cp: String, tail: List[String]): (List[String], List[String]) = + val cpEntries = cp.split(classpathSeparator).toList + val singleEntryClasspath: Boolean = cpEntries.take(2).size == 1 + val globdir: String = if singleEntryClasspath then cp.replaceAll("[\\\\/][^\\\\/]*$", "") else "" // slash/backslash agnostic + def validGlobbedJar(s: String): Boolean = s.startsWith(globdir) && ((s.toLowerCase.endsWith(".jar") || s.toLowerCase.endsWith(".zip"))) + if singleEntryClasspath && validGlobbedJar(cpEntries.head) then + // reassemble globbed wildcard classpath + // globdir is wildcard directory for globbed jar files, reconstruct the intended classpath + val cpJars = tail.takeWhile( f => validGlobbedJar(f) ) + val remainingArgs = tail.drop(cpJars.size) + (remainingArgs, cpEntries ++ cpJars) + else + (tail, cpEntries) + @sharable val javaOption = raw"""-J(.*)""".r @sharable val javaPropOption = raw"""-D(.+?)=(.?)""".r @tailrec @@ -122,11 +136,10 @@ object MainGenericCompiler { case "-with-compiler" :: tail => process(tail, settings.withCompiler) case ("-cp" | "-classpath" | "--class-path") :: cp :: tail => - val (tailargs, newEntries) = MainGenericRunner.processClasspath(cp, tail) + val (tailargs, newEntries) = processClasspath(cp, tail) process(tailargs, settings.copy(classPath = settings.classPath ++ newEntries.filter(_.nonEmpty))) case "-Oshort" :: tail => // Nothing is to be done here. Request that the user adds the relevant flags manually. - // i.e this has no effect when MainGenericRunner is invoked programatically. val addTC="-XX:+TieredCompilation" val tStopAtLvl="-XX:TieredStopAtLevel=1" println(s"ignoring deprecated -Oshort flag, please add `-J$addTC` and `-J$tStopAtLvl` flags manually") diff --git a/compiler/src/dotty/tools/MainGenericRunner.scala b/compiler/src/dotty/tools/MainGenericRunner.scala deleted file mode 100644 index 3f645ea803a4..000000000000 --- a/compiler/src/dotty/tools/MainGenericRunner.scala +++ /dev/null @@ -1,297 +0,0 @@ -package dotty.tools - -import scala.annotation.tailrec -import scala.io.Source -import scala.util.Try -import java.io.File -import java.lang.Thread -import scala.annotation.internal.sharable -import dotty.tools.dotc.util.ClasspathFromClassloader -import dotty.tools.runner.ObjectRunner -import dotty.tools.dotc.config.Properties.envOrNone -import dotty.tools.io.Jar -import dotty.tools.runner.ScalaClassLoader -import java.nio.file.Paths -import dotty.tools.dotc.config.CommandLineParser -import dotty.tools.scripting.{StringDriver, StringDriverException, ScriptingException} - -enum ExecuteMode: - case Guess - case Script - case Repl - case Run - case PossibleRun - case Expression - -case class Settings( - verbose: Boolean = false, - classPath: List[String] = List.empty, - executeMode: ExecuteMode = ExecuteMode.Guess, - exitCode: Int = 0, - javaArgs: List[String] = List.empty, - scalaArgs: List[String] = List.empty, - residualArgs: List[String] = List.empty, - possibleEntryPaths: List[String] = List.empty, - scriptArgs: List[String] = List.empty, - targetScript: String = "", - targetExpression: String = "", - targetToRun: String = "", - save: Boolean = false, - modeShouldBePossibleRun: Boolean = false, - modeShouldBeRun: Boolean = false, - compiler: Boolean = false, -) { - def withExecuteMode(em: ExecuteMode): Settings = this.executeMode match - case ExecuteMode.Guess | ExecuteMode.PossibleRun => - this.copy(executeMode = em) - case _ => - println(s"execute_mode==[$executeMode], attempted overwrite by [$em]") - this.copy(exitCode = 1) - end withExecuteMode - - def withScalaArgs(args: String*): Settings = - this.copy(scalaArgs = scalaArgs.appendedAll(args.toList)) - - def withJavaArgs(args: String*): Settings = - this.copy(javaArgs = javaArgs.appendedAll(args.toList)) - - def withResidualArgs(args: String*): Settings = - this.copy(residualArgs = residualArgs.appendedAll(args.toList)) - - def withPossibleEntryPaths(args: String*): Settings = - this.copy(possibleEntryPaths = possibleEntryPaths.appendedAll(args.toList)) - - def withScriptArgs(args: String*): Settings = - this.copy(scriptArgs = scriptArgs.appendedAll(args.toList)) - - def withTargetScript(file: String): Settings = - Try(Source.fromFile(file)).toOption match - case Some(_) => this.copy(targetScript = file) - case None => - println(s"not found $file") - this.copy(exitCode = 2) - end withTargetScript - - def withTargetToRun(targetToRun: String): Settings = - this.copy(targetToRun = targetToRun) - - def withExpression(scalaSource: String): Settings = - this.copy(targetExpression = scalaSource) - - def withSave: Settings = - this.copy(save = true) - - def noSave: Settings = - this.copy(save = false) - - def withModeShouldBePossibleRun: Settings = - this.copy(modeShouldBePossibleRun = true) - - def withModeShouldBeRun: Settings = - this.copy(modeShouldBeRun = true) - - def withCompiler: Settings = - this.copy(compiler = true) -} - -object MainGenericRunner { - - val classpathSeparator: String = File.pathSeparator - - def processClasspath(cp: String, tail: List[String]): (List[String], List[String]) = - val cpEntries = cp.split(classpathSeparator).toList - val singleEntryClasspath: Boolean = cpEntries.take(2).size == 1 - val globdir: String = if singleEntryClasspath then cp.replaceAll("[\\\\/][^\\\\/]*$", "") else "" // slash/backslash agnostic - def validGlobbedJar(s: String): Boolean = s.startsWith(globdir) && ((s.toLowerCase.endsWith(".jar") || s.toLowerCase.endsWith(".zip"))) - if singleEntryClasspath && validGlobbedJar(cpEntries.head) then - // reassemble globbed wildcard classpath - // globdir is wildcard directory for globbed jar files, reconstruct the intended classpath - val cpJars = tail.takeWhile( f => validGlobbedJar(f) ) - val remainingArgs = tail.drop(cpJars.size) - (remainingArgs, cpEntries ++ cpJars) - else - (tail, cpEntries) - - @sharable val javaOption = raw"""-J(.*)""".r - @sharable val scalaOption = raw"""@.*""".r - @sharable val colorOption = raw"""-color:.*""".r - @tailrec - def processArgs(args: List[String], settings: Settings): Settings = args match - case Nil => - settings - case "-run" :: fqName :: tail => - processArgs(tail, settings.withExecuteMode(ExecuteMode.Run).withTargetToRun(fqName)) - case ("-cp" | "-classpath" | "--class-path") :: cp :: tail => - val (tailargs, newEntries) = processClasspath(cp, tail) - processArgs(tailargs, settings.copy(classPath = settings.classPath ++ newEntries.filter(_.nonEmpty))) - case ("-version" | "--version") :: _ => - settings.copy( - executeMode = ExecuteMode.Repl, - residualArgs = List("-version") - ) - case ("-v" | "-verbose" | "--verbose") :: tail => - processArgs( - tail, - settings.copy( - verbose = true, - residualArgs = settings.residualArgs :+ "-verbose" - ) - ) - case "-save" :: tail => - processArgs(tail, settings.withSave) - case "-nosave" :: tail => - processArgs(tail, settings.noSave) - case "-with-compiler" :: tail => - processArgs(tail, settings.withCompiler) - case (o @ javaOption(striped: String)) :: tail => - processArgs(tail, settings.withJavaArgs(striped).withScalaArgs(o)) - case (o @ scalaOption(_*)) :: tail => - val remainingArgs = CommandLineParser.expandArg(o) ++ tail - processArgs(remainingArgs, settings) - case (o @ colorOption(_*)) :: tail => - processArgs(tail, settings.withScalaArgs(o)) - case "-e" :: expression :: tail => - val mainSource = s"@main def main(args: String *): Unit =\n ${expression}" - settings - .withExecuteMode(ExecuteMode.Expression) - .withExpression(mainSource) - .withScriptArgs(tail*) - .noSave // -save not useful here - case arg :: tail => - val line = Try(Source.fromFile(arg).getLines().toList).toOption.flatMap(_.headOption) - lazy val hasScalaHashbang = { val s = line.getOrElse("") ; s.startsWith("#!") && s.contains("scala") } - if arg.endsWith(".scala") || arg.endsWith(".sc") || hasScalaHashbang then - settings - .withExecuteMode(ExecuteMode.Script) - .withTargetScript(arg) - .withScriptArgs(tail*) - else - val newSettings = if arg.startsWith("-") then settings else settings.withPossibleEntryPaths(arg).withModeShouldBePossibleRun - processArgs(tail, newSettings.withResidualArgs(arg)) - end processArgs - - def process(args: Array[String]): Boolean = - val scalaOpts = envOrNone("SCALA_OPTS").toArray.flatMap(_.split(" ")).filter(_.nonEmpty) - val allArgs = scalaOpts ++ args - val settings = processArgs(allArgs.toList, Settings()) - if settings.exitCode != 0 then System.exit(settings.exitCode) - - def removeCompiler(cp: Array[String]) = - if (!settings.compiler) then // Let's remove compiler from the classpath - val compilerLibs = Seq("scala3-compiler", "scala3-interfaces", "tasty-core", "scala-asm", "scala3-staging", "scala3-tasty-inspector") - cp.filterNot(c => compilerLibs.exists(c.contains)) - else - cp - - def run(settings: Settings): Option[Throwable] = settings.executeMode match - case ExecuteMode.Repl => - val properArgs = - List("-classpath", settings.classPath.mkString(classpathSeparator)).filter(Function.const(settings.classPath.nonEmpty)) - ++ settings.residualArgs - repl.Main.main(properArgs.toArray) - None - - case ExecuteMode.PossibleRun => - val newClasspath = (settings.classPath :+ ".").flatMap(_.split(classpathSeparator).filter(_.nonEmpty)).map(File(_).toURI.toURL) - import dotty.tools.runner.RichClassLoader.* - val newClassLoader = ScalaClassLoader.fromURLsParallelCapable(newClasspath) - val targetToRun = settings.possibleEntryPaths.to(LazyList).find { entryPath => - newClassLoader.tryToLoadClass(entryPath).orElse { - Option.when(Jar.isJarOrZip(dotty.tools.io.Path(entryPath)))(Jar(entryPath).mainClass).flatten - }.isDefined - } - val newSettings = targetToRun match - case Some(fqName) => - settings.withTargetToRun(fqName).copy(residualArgs = settings.residualArgs.filterNot(fqName.==)).withExecuteMode(ExecuteMode.Run) - case None => - settings.withExecuteMode(ExecuteMode.Repl) - run(newSettings) - - case ExecuteMode.Run => - val scalaClasspath = ClasspathFromClassloader(Thread.currentThread().getContextClassLoader).split(classpathSeparator) - val newClasspath = (settings.classPath.flatMap(_.split(classpathSeparator).filter(_.nonEmpty)) ++ removeCompiler(scalaClasspath) :+ ".").map(File(_).toURI.toURL) - ObjectRunner.runAndCatch(newClasspath, settings.targetToRun, settings.residualArgs).flatMap { - case ex: ClassNotFoundException if ex.getMessage == settings.targetToRun => - val file = settings.targetToRun - Jar(file).mainClass match - case Some(mc) => - ObjectRunner.runAndCatch(newClasspath :+ File(file).toURI.toURL, mc, settings.residualArgs) - case None => - Some(IllegalArgumentException(s"No main class defined in manifest in jar: $file")) - case ex => Some(ex) - } - - case ExecuteMode.Script => - val targetScript = Paths.get(settings.targetScript).toFile - val targetJar = settings.targetScript.replaceAll("[.][^\\/]*$", "")+".jar" - val precompiledJar = File(targetJar) - val mainClass = if !precompiledJar.isFile then "" else Jar(targetJar).mainClass.getOrElse("") - val jarIsValid = mainClass.nonEmpty && precompiledJar.lastModified >= targetScript.lastModified && settings.save - if jarIsValid then - // precompiledJar exists, is newer than targetScript, and manifest defines a mainClass - sys.props("script.path") = targetScript.toPath.toAbsolutePath.normalize.toString - val scalaClasspath = ClasspathFromClassloader(Thread.currentThread().getContextClassLoader).split(classpathSeparator) - val newClasspath = (settings.classPath.flatMap(_.split(classpathSeparator).filter(_.nonEmpty)) ++ removeCompiler(scalaClasspath) :+ ".").map(File(_).toURI.toURL) - if mainClass.nonEmpty then - ObjectRunner.runAndCatch(newClasspath :+ File(targetJar).toURI.toURL, mainClass, settings.scriptArgs) - else - Some(IllegalArgumentException(s"No main class defined in manifest in jar: $precompiledJar")) - - else - val properArgs = - List("-classpath", settings.classPath.mkString(classpathSeparator)).filter(Function.const(settings.classPath.nonEmpty)) - ++ settings.residualArgs - ++ (if settings.save then List("-save") else Nil) - ++ settings.scalaArgs - ++ List("-script", settings.targetScript) - ++ settings.scriptArgs - scripting.Main.process(properArgs.toArray) - - case ExecuteMode.Expression => - val cp = settings.classPath match { - case Nil => "" - case list => list.mkString(classpathSeparator) - } - val cpArgs = if cp.isEmpty then Nil else List("-classpath", cp) - val properArgs = cpArgs ++ settings.residualArgs ++ settings.scalaArgs - val driver = StringDriver(properArgs.toArray, settings.targetExpression) - driver.compileAndRun(settings.classPath) - - case ExecuteMode.Guess => - if settings.modeShouldBePossibleRun then - run(settings.withExecuteMode(ExecuteMode.PossibleRun)) - else if settings.modeShouldBeRun then - 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") - - 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) - case e @ Some(ex) => errorFn("", e) - case _ => true - - def errorFn(str: String, e: Option[Throwable] = None): Boolean = - if (str.nonEmpty) Console.err.println(str) - e.foreach(_.printStackTrace()) - false - - def main(args: Array[String]): Unit = - if (!process(args)) System.exit(1) - -} diff --git a/compiler/test-coursier/dotty/tools/coursier/CoursierScalaTests.scala b/compiler/test-coursier/dotty/tools/coursier/CoursierScalaTests.scala deleted file mode 100644 index f44774141947..000000000000 --- a/compiler/test-coursier/dotty/tools/coursier/CoursierScalaTests.scala +++ /dev/null @@ -1,191 +0,0 @@ -package dotty -package tools -package coursier - -import scala.language.unsafeNulls - -import java.io.File -import java.nio.file.{Path, Paths, Files} -import scala.sys.process._ -import org.junit.Test -import org.junit.BeforeClass -import org.junit.Assert._ -import scala.collection.mutable.ListBuffer - -import java.net.URLClassLoader -import java.net.URL - -class CoursierScalaTests: - - private def scripts(path: String): Array[File] = { - val dir = new File(getClass.getResource(path).getPath) - assert(dir.exists && dir.isDirectory, "Couldn't load scripts dir") - dir.listFiles - } - - extension (f: File) private def absPath = - f.getAbsolutePath.replace('\\', '/') - - extension (str: String) private def dropExtension = - str.reverse.dropWhile(_ != '.').drop(1).reverse - - // classpath tests are managed by scripting.ClasspathTests.scala - def testFiles = scripts("/scripting").filter { ! _.getName.startsWith("classpath") } - - // Cannot run tests in parallel, more info here: https://stackoverflow.com/questions/6345660/java-executing-bash-script-error-26-text-file-busy - @Test def allTests = - def scriptArgs() = - val scriptPath = scripts("/scripting").find(_.getName == "showArgs.sc").get.absPath - val testScriptArgs = Seq("a", "b", "c", "-repl", "-run", "-script", "-debug") - - val args = scriptPath +: testScriptArgs - val output = CoursierScalaTests.csScalaCmd(args*) - val expectedOutput = List( - "arg 0:[a]", - "arg 1:[b]", - "arg 2:[c]", - "arg 3:[-repl]", - "arg 4:[-run]", - "arg 5:[-script]", - "arg 6:[-debug]", - ) - for (line, expect) <- output zip expectedOutput do - printf("expected: %-17s\nactual : %s\n", expect, line) - assertEquals(expectedOutput, output) - scriptArgs() - - def scriptPath() = - val scriptPath = scripts("/scripting").find(_.getName == "scriptPath.sc").get.absPath - val args = scriptPath - val output = CoursierScalaTests.csScalaCmd(args) - assertTrue(output.mkString("\n").startsWith("script.path:")) - assertTrue(output.mkString("\n").endsWith("scriptPath.sc")) - scriptPath() - - def scriptEnvDashJDashD() = - val scriptPath = scripts("/scripting").find(_.getName == "envtest.sc").get.absPath - val args = scriptPath - val output = CoursierScalaTests.csScalaCmd("-J-Dkey=World", args) - assertEquals(output.mkString("\n"), "Hello World") - scriptEnvDashJDashD() - - def version() = - val output = CoursierScalaTests.csScalaCmd("-version") - assertTrue(output.mkString("\n").contains(sys.env("DOTTY_BOOTSTRAPPED_VERSION"))) - version() - - def emptyArgsEqualsRepl() = - val output = CoursierScalaTests.csScalaCmdWithStdin(Seq.empty, Some("println(\"Hello World\")\n:quit")) - assertTrue(output.mkString("\n").contains("Hello World")) - emptyArgsEqualsRepl() - - def run() = - val output = CoursierScalaTests.csScalaCmd("-classpath", scripts("/run").head.getParentFile.getParent, "-run", "run.myfile") - assertEquals(output.mkString("\n"), "Hello") - run() - - def runDashJDashD() = - val output = CoursierScalaTests.csScalaCmd("-J-Dkey=World", "-classpath", scripts("/run").head.getParentFile.getParent, "-run", "run.envtest") - assertEquals(output.mkString("\n"), "Hello World") - runDashJDashD() - - def notOnlyOptionsEqualsRun() = - val output = CoursierScalaTests.csScalaCmd("-classpath", scripts("/run").head.getParentFile.getParent, "run.myfile") - assertEquals(output.mkString("\n"), "Hello") - notOnlyOptionsEqualsRun() - - def help() = - val output = CoursierScalaTests.csScalaCmd("-help") - assertTrue(output.mkString("\n").contains("Usage: scala ")) - help() - - def jar() = - val source = new File(getClass.getResource("/run/myfile.scala").getPath) - val output = CoursierScalaTests.csScalaCmd("-save", source.absPath) - assertEquals(output.mkString("\n"), "Hello") - assertTrue(source.getParentFile.listFiles.find(_.getName == "myfile.jar").isDefined) - jar() - - def runThatJar() = - val source = new File(getClass.getResource("/run/myfile.jar").getPath) - val output = CoursierScalaTests.csScalaCmd(source.absPath) - assertEquals(output.mkString("\n"), "Hello") - runThatJar() - - def compileFilesToJarAndRun() = - val source = new File(getClass.getResource("/run/myfile.scala").getPath) - val prefix = source.getParent - - val o1source = Paths.get(prefix, "automain.jar").toAbsolutePath.toString - val output1 = CoursierScalaTests.csScalaCompilerCmd("-d", o1source, source.absPath) - assertEquals(output1.mkString("\n"), "") - - val o2source = Paths.get(prefix, "custommain.jar").toAbsolutePath.toString - val output2 = CoursierScalaTests.csScalaCompilerCmd("-d", o2source, "-Xmain-class", "run.myfile", source.absPath) - assertEquals(output2.mkString("\n"), "") - - val output3 = CoursierScalaTests.csScalaCmd(o1source) - assertEquals(output3.mkString("\n"), "Hello") - - val output4 = CoursierScalaTests.csScalaCmd(o2source) - assertEquals(output4.mkString("\n"), "Hello") - compileFilesToJarAndRun() - - def replWithArgs() = - val output = CoursierScalaTests.csScalaCmdWithStdin(Seq("-source", "3.0-migration"), Some("println(\"Hello World\")\n:quit")) - assertTrue(output.mkString("\n").contains("Hello World")) - replWithArgs() - - def argumentFile() = - // verify that an arguments file is accepted - // verify that setting a user classpath does not remove compiler libraries from the classpath. - // arguments file contains "-classpath .", adding current directory to classpath. - val source = new File(getClass.getResource("/run/myfile.scala").getPath) - val argsFile = new File(getClass.getResource("/run/myargs.txt").getPath) - val output = CoursierScalaTests.csScalaCmd(s"@$argsFile", source.absPath) - assertEquals(output.mkString("\n"), "Hello") - argumentFile() - -object CoursierScalaTests: - - private def execCmd(command: String, options: Seq[String] = Seq.empty, stdin: Option[String] = None): (Int, List[String]) = - val cmd = (command :: options.toList).toSeq.mkString(" ") - val out = new ListBuffer[String] - val process = stdin match - case Some(input) => Process(cmd) #< new java.io.ByteArrayInputStream(input.getBytes) - case None => Process(cmd) - val code = process.!(ProcessLogger(out += _, out += _)) - (code, out.toList) - - def csScalaCmd(options: String*): List[String] = - csScalaCmdWithStdin(options, None) - - def csScalaCmdWithStdin(options: Seq[String], stdin: Option[String]): List[String] = - csCmd("dotty.tools.MainGenericRunner", options, stdin) - - def csScalaCompilerCmd(options: String*): List[String] = - csCmd("dotty.tools.dotc.Main", options) - - private def csCmd(entry: String, options: Seq[String], stdin: Option[String] = None): List[String] = - val (jOpts, args) = options.partition(_.startsWith("-J")) - val newOptions = args match - 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" --property "scala.use_legacy_launcher=true"""" +: newOptions), stdin)._2 - - /** Get coursier script */ - @BeforeClass def setup(): Unit = - val launcherLocation = "https://github.com/coursier/launchers/raw/master" - val launcherName = execCmd("uname")._2.head.toLowerCase match - case "linux" => "cs-x86_64-pc-linux" - case "darwin" => "cs-x86_64-apple-darwin" - case other => fail(s"Unsupported OS for coursier launcher: $other") - - def runAndCheckCmd(cmd: String, options: String*): Unit = - val (code, out) = execCmd(cmd, options) - if code != 0 then - fail(s"Failed to run $cmd ${options.mkString(" ")}, exit code: $code, output: ${out.mkString("\n")}") - - runAndCheckCmd("curl", s"-fLo cs $launcherLocation/$launcherName") - runAndCheckCmd("chmod", "+x cs") diff --git a/compiler/test-coursier/run/envtest.scala b/compiler/test-coursier/run/envtest.scala deleted file mode 100644 index bf416c9519ce..000000000000 --- a/compiler/test-coursier/run/envtest.scala +++ /dev/null @@ -1,4 +0,0 @@ -package run - -object envtest extends App: - println("Hello " + sys.props("key")) diff --git a/compiler/test-coursier/run/myargs.txt b/compiler/test-coursier/run/myargs.txt deleted file mode 100755 index a0d2d24986de..000000000000 --- a/compiler/test-coursier/run/myargs.txt +++ /dev/null @@ -1 +0,0 @@ --classpath . diff --git a/compiler/test-coursier/run/myfile.scala b/compiler/test-coursier/run/myfile.scala deleted file mode 100644 index c9ed2cfb1683..000000000000 --- a/compiler/test-coursier/run/myfile.scala +++ /dev/null @@ -1,4 +0,0 @@ -package run - -object myfile extends App: - println("Hello") diff --git a/compiler/test/dotty/tools/scripting/ClasspathTests.scala b/compiler/test/dotty/tools/scripting/ClasspathTests.scala index 0244e208af3c..21377e125542 100755 --- a/compiler/test/dotty/tools/scripting/ClasspathTests.scala +++ b/compiler/test/dotty/tools/scripting/ClasspathTests.scala @@ -78,44 +78,3 @@ class ClasspathTests: assert(hashbangClasspathJars.size == packlibJars.size) } - /* - * verify classpath is unglobbed by MainGenericRunner. - */ - @Ignore - @Test def unglobClasspathVerifyTest = { - val testScriptName = "unglobClasspath_scalacli.sc" - val testScript = scripts("/scripting").find { _.name.matches(testScriptName) } match - case None => sys.error(s"test script not found: ${testScriptName}") - case Some(file) => file - - val relpath = testScript.toPath.relpath.norm - val scalaCommand = scalaPath.relpath.norm - printf("===> unglobClasspathVerifyTest for script [%s]\n", relpath) - printf("bash is [%s]\n", bashExe) - - if packBinScalaExists then - val sv = packScalaVersion - val tastyDirGlob = s"$packMavenDir/org/scala-lang/tasty-core_3/$sv/*" - // ^^^^^^^^^^^^^ - // the classpath is a glob pattern that should be unglobbed by scala command, - // otherwise the script could not compile because it references a class - // from tasty-core - - val bashCmdline = Seq( - "set +x ;", - "SCALA_OPTS=", - scalaCommand, "run", "--classpath", s"'$tastyDirGlob'", "--power", "--offline", "--server=false", relpath - ).mkString(" ") - val cmd = Array(bashExe, "-c", bashCmdline) - - cmd.foreach { printf("[%s]\n", _) } - - // test script reports the classpath it sees - val scriptOutput = exec(cmd*) - val scriptCp = findTaggedLine("unglobbed classpath", scriptOutput) - printf("%s\n", scriptCp) - val classpathJars = scriptCp.split(psep).map { _.getName }.sorted.distinct - //classpathJars.foreach { printf("%s\n", _) } - assert(classpathJars.size > 1) - } - diff --git a/dist/bin/scala_legacy b/dist/bin/scala_legacy deleted file mode 100755 index 62755801819b..000000000000 --- a/dist/bin/scala_legacy +++ /dev/null @@ -1,72 +0,0 @@ -#!/usr/bin/env bash - -# Try to autodetect real location of the script -if [ -z "${PROG_HOME-}" ] ; then - ## resolve links - $0 may be a link to PROG_HOME - PRG="$0" - - # need this for relative symlinks - while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG="`dirname "$PRG"`/$link" - fi - done - - saveddir=`pwd` - - PROG_HOME=`dirname "$PRG"`/.. - - # make it fully qualified - PROG_HOME=`cd "$PROG_HOME" && pwd` - - cd "$saveddir" -fi - -source "$PROG_HOME/libexec/common" - -while [[ $# -gt 0 ]]; do - case "$1" in - -D*) - # pass to scala as well: otherwise we lose it sometimes when we - # need it, e.g. communicating with a server compiler. - # respect user-supplied -Dscala.usejavacp - addJava "$1" - addScala "$1" - shift - ;; - -J*) - # as with -D, pass to scala even though it will almost - # never be used. - addJava "${1:2}" - addScala "$1" - shift - ;; - -classpath*) - if [ "$1" != "${1##* }" ]; then - # -classpath and its value have been supplied in a single string e.g. "-classpath 'lib/*'" - A=$1 ; shift # consume $1 before adding its substrings back - set -- $A "$@" # split $1 on whitespace and put it back - else - addScala "$1" - shift - fi - ;; - *) - addScala "$1" - shift - ;; - esac -done - -# exec here would prevent onExit from being called, leaving terminal in unusable state -compilerJavaClasspathArgs -[ -z "${ConEmuPID-}" -o -n "${cygwin-}" ] && export MSYSTEM= PWD= # workaround for #12405 -eval "\"$JAVACMD\"" "${java_args[@]}" "-Dscala.home=\"$PROG_HOME\"" "-classpath \"$jvm_cp_args\"" "-Dscala.expandjavacp=true" "dotty.tools.MainGenericRunner" "-classpath \"$jvm_cp_args\"" "${scala_args[@]}" -scala_exit_status=$? - - -onExit diff --git a/tests/run-with-compiler/i14541.check b/tests/run-with-compiler/i14541.check deleted file mode 100644 index 38b710956004..000000000000 --- a/tests/run-with-compiler/i14541.check +++ /dev/null @@ -1,2 +0,0 @@ -hello raw world -hello run world diff --git a/tests/run-with-compiler/i14541.scala b/tests/run-with-compiler/i14541.scala deleted file mode 100644 index 2b942007c5b6..000000000000 --- a/tests/run-with-compiler/i14541.scala +++ /dev/null @@ -1,14 +0,0 @@ - -// test argument processing and "execution mode" in runner -object Test: - import dotty.tools.runner.RichClassLoader.* - val classpath = dotty.tools.dotc.util.ClasspathFromClassloader(getClass.getClassLoader) - def main(args: Array[String]): Unit = - getClass.getClassLoader.run("echo", List("hello", "raw", "world")) - // caution: uses "SCALA_OPTS" - sys.props("scala.use_legacy_launcher") = "true" - dotty.tools.MainGenericRunner.main(Array("--class-path", classpath, "echo", "hello", "run", "world")) - -@main def echo(args: String*): Unit = println { - args.mkString(" ") -}