forked from scala/scala3
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes for various problems related to scripting.
1. set $scala_exit_status & trap onExit; script exit code correct whether called via scalac or java -jar 2. added missing 'scala -version' option to via call to 'scalac -version' 3. extended and verified REPL and scripting for Cygwin, MinGW, Msys2, and Windows shells with a cygpath tool 4. MinGW based Windows shell environments require TERM=dumb to support REPL 5. simpify and extend jar manifest classpath to support for changing default drive 6. tested for the following Windows and Linux environments: 7. added tests CYGWIN_NT-10.0 host 3.1.7(0.340/5/3) 2020-08-22 17:48 x86_64 Cygwin MINGW64_NT-10.0-19042 host 3.1.7-340.x86_64 2020-10-23 13:08 UTC x86_64 Msys MSYS_NT-10.0-19042 host 3.1.7-340.x86_64 2020-11-08 12:32 UTC x86_64 Msys Linux host 5.4.0-62-generic scala#70~18.04.1-Ubuntu SMP Tue Jan 12 17:18:00 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux Linux host 5.4.72-microsoft-standard-WSL2 #1 SMP Wed Oct 28 23:40:43 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux Manual test results for executing a script via compile mode and then java -jar mode: uname -a :: CYGWIN_NT-10.0 d5 3.1.7(0.340/5/3) 2020-08-22 17:48 x86_64 Cygwin uname -a :: Linux quadd 5.4.0-62-generic scala#70~18.04.1-Ubuntu SMP Tue Jan 12 17:18:00 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux uname -a :: Linux d5 5.4.72-microsoft-standard-WSL2 #1 SMP Wed Oct 28 23:40:43 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux uname -a :: MINGW64_NT-10.0-19042 d5 3.1.7-340.x86_64 2020-10-23 13:08 UTC x86_64 Msys uname -a :: MSYS_NT-10.0-19042 d5 3.1.7-340.x86_64 2020-11-08 12:32 UTC x86_64 Msys uname -a :: CYGWIN_NT-10.0 d5 3.1.7(0.340/5/3) 2020-08-22 17:48 x86_64 Cygwin
- Loading branch information
Showing
8 changed files
with
141 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/usr/bin/env scala | ||
# comment | ||
STUFF=nada | ||
!# | ||
|
||
def main(args: Array[String]): Unit = | ||
System.err.printf("mainClassFromStack: %s\n",mainFromStack) | ||
assert(mainFromStack.contains("hashBang"),s"fromStack[$mainFromStack]") | ||
|
||
lazy val mainFromStack:String = { | ||
val result = new java.io.StringWriter() | ||
new RuntimeException("stack").printStackTrace(new java.io.PrintWriter(result)) | ||
val stack = result.toString.split("[\r\n]+").toList | ||
//for( s <- stack ){ System.err.printf("[%s]\n",s) } | ||
stack.filter { str => str.contains(".main(") }.map { | ||
_.replaceAll(".*[(]",""). | ||
replaceAll("\\.main\\(.*",""). | ||
replaceAll(".scala.*","") | ||
}.distinct.take(1).mkString("") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env scala | ||
export STUFF=nada | ||
#lots of other stuff that isn't valid scala | ||
!# | ||
object Zoo { | ||
def main(args: Array[String]): Unit = | ||
printf("script.name: %s\n",sys.props("script.name")) | ||
printf("mainClassFromStack: %s\n",mainFromStack) | ||
assert(mainFromStack == "Zoo",s"fromStack[$mainFromStack]") | ||
|
||
lazy val mainFromStack:String = { | ||
val result = new java.io.StringWriter() | ||
new RuntimeException("stack").printStackTrace(new java.io.PrintWriter(result)) | ||
val stack = result.toString.split("[\r\n]+").toList | ||
// for( s <- stack ){ System.err.printf("[%s]\n",s) } | ||
val shortStack = stack.filter { str => str.contains(".main(") && ! str.contains("$") }.map { | ||
_.replaceAll("[.].*","").replaceAll("\\s+at\\s+","") | ||
} | ||
// for( s <- shortStack ){ System.err.printf("[%s]\n",s) } | ||
shortStack.take(1).mkString("|") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/usr/bin/env scala | ||
|
||
def main(args: Array[String]): Unit = | ||
val name = Option(sys.props("script.name")) match { | ||
case None => printf("no script.name property is defined\n") | ||
case Some(name) => | ||
printf("script.name: %s\n",name) | ||
assert(name == "scriptName.scala") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters