Skip to content
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

Kotlin Scripting support #379

Open
aartiPl opened this issue Sep 8, 2022 · 3 comments
Open

Kotlin Scripting support #379

aartiPl opened this issue Sep 8, 2022 · 3 comments

Comments

@aartiPl
Copy link
Collaborator

aartiPl commented Sep 8, 2022

All the issues connected with the implementation of the Kotlin Scripting engine in KScript.

@aartiPl
Copy link
Collaborator Author

aartiPl commented Sep 14, 2022

@ligee, @ileasile - as I have mentioned in #Kotlin/KEEP, I have an initial implementation of support for Kotlin Scripting in kscript. Those files are mostly a copy of Kotlin Scripting files - I have divided the evaluation into 2 phases: compilation and execution because I want to get compilation messages first, and then the output of the application, not everything at the end.

The problems which I have encountered:

  1. Compiler sees the incorrect path of the root file, and I don't know how to modify this path programmatically.
    Please look at KscriptHost.kt 'compile' function. I am setting the path of the file explicitly in line 57. But during compilation, the path of the root file is always resolved to the current directory.
    See the below screenshot for details:
    obraz

(As you can see, I am starting the script from home dir; internally, kscript is resolving script dir correctly, but I don't know how to pass it to the compiler, and as a result, the path is resolved incorrectly)

  1. Is it necessary to provide jar cache through system properties?

  2. How to get all compiled file names and paths (needed for creating the IntelliJ project)?

  3. How to get all dependencies (needed for creating of IntelliJ project)?

  4. How to implement URL resolving with caching files locally?

As there is lacking documentation, it is difficult to determine what's wrong with my implementation. Can you help with the above problems (the first one is very practical as I am currently on it; for others, it would be nice to get some hints, at least)?

@aartiPl
Copy link
Collaborator Author

aartiPl commented Sep 15, 2022

I have renamed the branch to kscript_4.5 - it's too early to release Kotlin Scripting in the next version.
https://github.com/kscripting/kscript/tree/kscript_4.5

@ligee
Copy link

ligee commented Sep 19, 2022

@aartiPl, it is great to see your efforts to implement kscript on top of the scripting API.
Let's have a look at your questions:

  1. if you're talking about scriptFileLocation - this variable is set by the compiler, and used inside the evaluator for script to be able to access its own path (e.g. by default via the __FILE__ variable).
    If you need to set the script's "virtual path" for diagnostics and maybe imports, you need to implement your own variant of the SourceCode rather than use toScriptSource function, or alternatively use FileScriptSource and pass a correct file to it along with the text.

  2. What do you mean by jar cache, and where do you provide it via the system properties?

  3. The scripts are by default do not compile into files, they are kept in memory. If you need them as class files, you need to use pseudo-evaluation into a cache. You can find an example of this functiunality around usages of this class - https://github.com/JetBrains/kotlin/blob/3e19e9d190f800da551650cdcbbdbb9f7c845f07/libraries/scripting/jvm-host-test/test/kotlin/script/experimental/jvmhost/test/CachingTest.kt#L342
    (BTW, quite likely you can use the same approach for generating the whole IntelliJ project.)

  4. All dependencies are stored in the dependencies property of the compilation configuration, and you can get the resulting configuration from the compiled script and it will include also the dependencies resolved from maven and other sources, if applicable.

  5. I guess you mean some variant of the @Import handling. In the main-kts, it is implemented here - https://github.com/JetBrains/kotlin/blob/ca2f37f6ebe9dd7349cc4cab1e1ab1ddfdb5976e/libraries/tools/kotlin-main-kts/src/org/jetbrains/kotlin/mainKts/scriptDef.kt#L176
    and you can adapt this code for your case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants