Comments (3)
@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:
- 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:
(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)
-
Is it necessary to provide jar cache through system properties?
-
How to get all compiled file names and paths (needed for creating the IntelliJ project)?
-
How to get all dependencies (needed for creating of IntelliJ project)?
-
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)?
from kscript.
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
from kscript.
@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:
-
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 theSourceCode
rather than usetoScriptSource
function, or alternatively useFileScriptSource
and pass a correct file to it along with the text. -
What do you mean by jar cache, and where do you provide it via the system properties?
-
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.) -
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. -
I guess you mean some variant of the
@Import
handling. In themain-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.
from kscript.
Related Issues (20)
- Create kscript package for scoop HOT 7
- Don't work @file:Import("absolute/path/to/myutils.kt") HOT 2
- Basic hello world example does not work with interpreter HOT 1
- Allow setting an alternate kotlinc binary (or use kotlinc-jvm)
- Add an option to suppress final error output HOT 10
- [Windows] path to kotlinc not quoted HOT 4
- How to load text file via relative path? HOT 2
- kscript --interactive does not resolve the variables defined inside .kts file HOT 1
- kscript environment variable substitution for repositories no longer works HOT 6
- Does not work with Kotlin 1.9.0 HOT 12
- Can kscript used in Android project written in kotlin HOT 1
- Can you change kscript's included java version? HOT 1
- [question] daemon concept HOT 4
- Does not support spaces in KOTLIN_HOME variable.
- --package is broken in 4.2.3 - doesn't include stuff in local dependencies
- Fresh checkout of repo causes failure on `gradle run` and other ways of invoking `kscript` fail for the same reason
- kscript downloading Kotlin Native jars during dependency resolution - why? HOT 1
- Example in README with @file:Import fails
- Use version 4.2.3 on Dockerfile
- Does not work with Kotlin 2.0.0 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kscript.