-
Notifications
You must be signed in to change notification settings - Fork 153
provide a way to access paths of source files #3799
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
provide a way to access paths of source files #3799
Conversation
suggested changes Co-authored-by: Piotr Chabelski <ged.subfan@gmail.com>
|
This implements #3800 |
scriptPath that's available independent of script filename extension.scriptPath not restricted to '.sc' scripts
|
Perhaps it would be better to use the System property An update to the documentation is also needed. A slightly different approach would be to set environment variable "_" if not already defined. There would be less need to document it since SHELL environments already define it correctly, and would mostly extend the coverage to Windows CMD and powershell and possibly IDE contexts. |
|
Here's a suprise I discovered w.r.t. the nightly build. After running the following script, named "biz.scala": #!/usr/bin/env -S scala-cli.exe shebang -S 3.nightly
object Biz {
def main(args: Array[String]): Unit = {
printf("[%s]\n", scriptPath)
}
}I expected to see this: But instead, I got this: Then I looked at the wrapper, which has an odd double-extension: .scala-build/scala-cli-july17_62d441ef6c-c8768589e0/src_generated/main/biz.scala.scala final class biz$_ {
def args = biz_sc.args$
def scriptPath = """./biz.scala"""
/*<script>*/
... |
|
I reverted a side-effect of my previous PR that causes .scala files to be treated as scripts. I intended to push it in its' own branch, but accidentally added it here. |
==> X scala.cli.integration.RunTestsDefault.print command 2.628s java.io.IOException: Cannot run program "_=/home/runner/work/scala-cli/scala-cli/out/integration/tmpDirBase.dest/working-dir/run-1138417905/test-587/simple.sc" (in directory "/home/runner/work/scala-cli/scala-cli/out/integration/tmpDirBase.dest/working-dir/run-1138417905/test-587"): error=2, No such file or directorystill need to fix this test failure. |
|
Another thought - if you're adding this feature to |
|
And - please add tests for the possible input configurations (including odd ones, like snippets and such). |
Gedochao
left a comment
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.
Having the list in a property is perhaps less elegant than the old scriptPath field, since it also takes away the ability to differentiate the paths from the code in individual sources... but I'm not sure how useful that is.
And that being said, I do not think we want to generate an extra field (or anything, really) for non-script inputs, so perhaps that's the best we could do, indeed.
I'm still trying to figure out how to compose a command line to run an individual test. Is it documented somewhere? the JVM test runs for hours on my system ... Here's what I tried: It seems to want cliKind() as |
The most recent changes need to be in a separate PR, I'll do that today. |
Co-authored-by: Piotr Chabelski <ged.subfan@gmail.com>
Oh, I see. The test I mentioned earlier, you can run it like this: ./mill -i integration.test.jvm 'scala.cli.integration.RunTestsDefault.print*command' |
The current implementation should work for anything jvm-based. Not sure how to extend it to '.js' or '.native', suggestions are welcome. |
Looking into it ... |
jvm-based is enough. |
scriptPath not restricted to '.sc' scripts|
@philwalk thanks for the contribution! |
Provides property
scala.sourcesfor determining the source files(s) for non-script scala-cli source types.This provides a universal
scriptPathfunction that's not restricted to '.sc' files. Without it, a working '.sc' file can't be easily converted to a '.scala' program if it accesses thescriptPathwrapper field.Example usage: file
printSourcePath.scala:Currently, scripts are able to access
scriptPath(the path to the script), but.scalafiles have no equivalent, except in limited cases. For example, the following code works in SHELL environments, but not in CMD.EXE or powershell.Other approaches based on scala3 macros or stack-walking either provide less than the full path, or only work in some environments.
This eliminates a limitation scala has suffered relative to virtually all other scripting platforms:
usagemessages that include the source pathDoesn't replace the
scriptPathmethod in the script wrapper class, but fills in most if not all of the gaps in availability of source file path.