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

Match annotations behavior of kotlinc #388

Open
gabrielfeo opened this issue Jan 11, 2023 · 1 comment
Open

Match annotations behavior of kotlinc #388

gabrielfeo opened this issue Jan 11, 2023 · 1 comment

Comments

@gabrielfeo
Copy link

gabrielfeo commented Jan 11, 2023

It'd be great if kscript could match behavior to be 100% compatible with the 'Kotlin scripting support' annotations. Even if one writes a script aiming for the standard compiler command, I could run it with kscript and benefit from caching and its other features.

vararg support

Adding multiple repositories with a single annotation (source):

@file:Repository("https://jitpack.io", "https://repo.maven.apache.org/maven2")
@file:DependsOn("com.github.gabrielfeo:gradle-enterprise-api-kotlin:0.11.0", "org.jetbrains.kotlinx:dataframe:0.9.1")

but kscript doesn't support vararg in Repository, parsing the second arg as a repository username:

[kscript] Adding repository: Repository(id=, url=https://jitpack.io, user=https://repo.maven.apache.org/maven2, password=)

Line break support

Breaking line inside annotations is supported by kotlinc, but isn't supported by kscript:

Line break in DependsOn

@file:Repository("https://repo.maven.apache.org/maven2")
@file:DependsOn(
    "com.squareup.okio:okio:3.3.0",
    "org.jetbrains.kotlinx:dataframe:0.9.1",
)
[kscript] Adding repository: Repository(id=, url=https://repo.maven.apache.org/maven2, user=, password=)
[kscript] [ERROR] Compilation of scriplet failed:
[kscript] [ERROR] Command     : 'bash -c /opt/homebrew/Cellar/kotlin/1.8.0/libexec/bin/kotlinc   -d '/Users/gabriel.feo/.cache/kscript/jar_6d5e6178bda10b7c462025e5f8fe444a/scriplet.jar' '/Users/gabriel.feo/.cache/kscript/jar_6d5e6178bda10b7c462025e5f8fe444a/Dataframe_test_main.kts' '/Users/gabriel.feo/.cache/kscript/jar_6d5e6178bda10b7c462025e5f8fe444a/Main_Dataframe_test_main.kt''
[kscript] [ERROR] Exit Code   : 1   
[kscript] [ERROR] Stdout      : ''
[kscript] [ERROR] Stderr      : '/Users/gabriel.feo/.cache/kscript/jar_6d5e6178bda10b7c462025e5f8fe444a/Dataframe_test_main.kts:6:2: error: expecting an expression[nl])[nl] ^[nl]/Users/gabriel.feo/.cache/kscript/jar_6d5e6178bda10b7c462025e5f8fe444a/Dataframe_test_main.kts:3:7: error: unresolved reference: DependsOn[nl]@file:DependsOn([nl]      ^[nl]'
[kscript] [ERROR]

Line break in Repository

@file:Repository(
    "https://jitpack.io",
    "https://repo.maven.apache.org/maven2",
)
@file:DependsOn("com.squareup.okio:okio:3.3.0", "org.jetbrains.kotlinx:dataframe:0.9.1")
[kscript] Adding repository: Repository(id=, url=, user=, password=)

Note: using multiple Repository and DependsOn annotations has the same behavior in both kotlinc and kscript, a good workaround to make scripts compatible with both

@file:Repository("https://jitpack.io")
@file:Repository("https://repo.maven.apache.org/maven2")
@file:DependsOn("com.github.gabrielfeo:gradle-enterprise-api-kotlin:0.11.0")
@file:DependsOn("org.jetbrains.kotlinx:dataframe:0.9.1")
@gabrielfeo gabrielfeo changed the title Match kotlinc behavior for Repository annotation Match annotations behavior of kotlinc Jan 11, 2023
@aartiPl
Copy link
Collaborator

aartiPl commented Jan 11, 2023

Yes, your comment is entirely valid. My ultimate goal is to switch to Kotlin scripting backend while keeping all the excellent features of KScript (like interoperability with shell, caching, etc.). The only question is how much effort to put in to stay perfectly compatible, while in the long run, I will switch to Kotlin scripting anyway. Currently, in my opinion, it is not worthy of effort, as I would like to switch to the Kotlin scripting backend after version 4.2, which I am about to release. But still, if anyone wants to improve KScript with such features, I am happy to apply patches.

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