-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Minimal scripting support #11379
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
Minimal scripting support #11379
Conversation
1. pass @<argsFile> and -color:* options to compiler 2. add -save|-savecompiled option 3. recognize scripts with #!.*scala regardless of extension 4. if -save is specified and <scriptPath>.jar file is newer than <scriptPath> execute it (no compile) 5. set -Dscript.name for script execution paths (script and .jar) changes to dotty.tools.scripting package: 1. additional compiler args splitting and filtering 2. renamed detectMainMethod to detectMainClassAndMethod, returns both main class name and reflect.Method object 3. on -save option: a. if compile is successful, create same-name jar file in <scriptPath> parent directory b. "java.class.path" appended to context classpath with deduplication c. write "Main-Class" and "Class-Path" to jar manifest added new tests to verify the following: 1. one line and multi-line hash bang sections are ignored by compiler 2. main class name in stack dump is as expected when main class is declared in script 3. main class name in stack dump is as expected when main class is not declared in script 4. script.name property matches scriptFile.getName 5. verify that with -save option jar file with expected name is generated 6. verify that without -save option, no jar file is generated 7. generated jar file is executable via "java -jar <scriptFile>.jar"
1. pass @<argsFile> and -color:* options to compiler 2. add -save|-savecompiled option 3. recognize scripts with #!.*scala regardless of extension 4. if -save is specified and <scriptPath>.jar file is newer than <scriptPath> execute it (no compile) 5. set -Dscript.path for script execution paths (script and .jar) changes to dotty.tools.scripting package: 1. additional compiler args splitting and filtering 2. renamed detectMainMethod to detectMainClassAndMethod, returns both main class name and reflect.Method object 3. on -save option: a. if compile is successful, create same-name jar file in <scriptPath> parent directory b. "java.class.path" appended to context classpath with deduplication c. write "Main-Class" and "Class-Path" to jar manifest added new tests to verify the following: 1. one line and multi-line hash bang sections are ignored by compiler 2. main class name in stack dump is as expected when main class is declared in script 3. main class name in stack dump is as expected when main class is not declared in script 4. script.path property matches scriptFile.absPath 5. verify that with -save option jar file with expected name is generated 6. verify that without -save option, no jar file is generated 7. generated jar file is executable via "java -jar <scriptFile>.jar"
👏 I am eager to test this once it lands in a nightly |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, nice work! After the minor suggestions are addressed, this can be merged.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@anatoliykmetyuk - I have some critical changes to push soon:
The "-compile-only" option is necessary, for example to compile a script to a graalvm native-image without executing the script as part of the compilation. |
+ convert relative to absolute entries in manifest for equivalent classpath. manifest classpath entries would be relative to jar file location, not cwd. + added "-compile-only" option for compile without calling script main + added tests to verify "-compile-only" option + cleanup tests, update comments. + extensive manual experimentation on Windows and Ubuntu + jar file startup latency is 1/3 to 1/4 of compile and invoke latency. + manual tests of graalvm native-image compile of generated script jars
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks @philwalk!
This supercedes #11180
Implements scala3 scripting support with the minimum functionality required for supporting real world scripting:
jvm
startupsScriptingDriver
calls client callback prior to calling scriptmain
method.-save
command line option writes a jar file to the script parent directory (same as scala2)Main-Class
andClass-Path
properties (jar is executable)The client callback is needed to implement the
-save
option with a singlejvm
startup.3rd party tools are able to implement custom implementations following the example in
dotty.tools.scripting.Main
.