Skip to content

Rules scripting #4887

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

Merged
merged 5 commits into from
Jan 5, 2022
Merged

Rules scripting #4887

merged 5 commits into from
Jan 5, 2022

Conversation

sschuberth
Copy link
Member

Please have a look at the individual commit messages for the details.

@sschuberth sschuberth force-pushed the rules-scripting branch 2 times, most recently from 6ac13fc to 3c043c2 Compare December 22, 2021 14:58
@sschuberth
Copy link
Member Author

@oss-review-toolkit/kotlin-devs, while this is still a draft, could some of you maybe confirm that this offers proper syntax hightlighting and auto-completion in IntelliJ for evaluator/src/main/resources/rules/no_gpl.rules.kts now (but not for examples/example.rules.kts; that is expected as that script is not part of any module)?

README.md Outdated
| Kotlin script (DSL) | Evaluator | `$ORT_CONFIG_DIR/rules.kts` | Empty (n/a) |
| Format | Scope | Default location | Default value |
| ------ | ----- |---------------------------------| ------------- |
| Kotlin script (DSL) | Evaluator | `$ORT_CONFIG_DIR/ort.rules.kts` | Empty (n/a) |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a tendency towards evaluator.rules.kts as the default name.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine with me, as "ort" is already part of the parent directory, and it opens the possibility to have more (non-evaluator) rules in the future.

@mnonnenmacher
Copy link
Member

mnonnenmacher commented Dec 22, 2021

@oss-review-toolkit/kotlin-devs, while this is still a draft, could some of you maybe confirm that this offers proper syntax hightlighting and auto-completion in IntelliJ for evaluator/src/main/resources/rules/no_gpl.rules.kts now (but not for examples/example.rules.kts; that is expected as that script is not part of any module)?

Does not work for me. After Gradle sync I get this when opening no_gpl.rules.kts:
"No script runtime was found in the classpath: class 'kotlin.script.templates.standard.ScriptTemplateWithArgs' not found. Please add kotlin-script-runtime.jar to the module dependencies."

If I apply the suggested fix it adds implementation(kotlin("script-runtime")) to the evaluator module but then I get compilation errors like Unresolved reference: PackageRule.

@sschuberth
Copy link
Member Author

sschuberth commented Dec 22, 2021

Does not work for me.

Could you additionally try to build from the command line once (I usually do this via ./gradlew :cli:run --args="--version"), then do a Gradle sync from the IDE, and then open the script file again?

If I apply the suggested fix it adds implementation(kotlin("script-runtime")) to the evaluator module but then I get compilation errors like Unresolved reference: PackageRule.

That's an odd suggestion... none of the examples at https://github.com/Kotlin/kotlin-script-examples has that dependency.

@sschuberth sschuberth force-pushed the rules-scripting branch 2 times, most recently from 9134381 to e83f82c Compare December 22, 2021 16:56
@MarcelBochtler
Copy link
Member

Could you additionally try to build from the command line once (I usually do this via ./gradlew :cli:run --args="--version"), then do a Gradle sync from the IDE, and then open the script file again?

Works very well for me after building it from command line.

@mnonnenmacher
Copy link
Member

Could you additionally try to build from the command line once (I usually do this via ./gradlew :cli:run --args="--version"), then do a Gradle sync from the IDE, and then open the script file again?

Works very well for me after building it from command line.

Same here, very nice.

@sschuberth
Copy link
Member Author

I'd like to move examples.rules.kts to a Kotlin module so that completion works. What do you guys think about simply replacing the overly simplistic no_gpl.rules.kts with examples.rules.kts as a resource? Should we then symlink this to the examples directory, even if that might break things for Windows users?

@sschuberth sschuberth force-pushed the rules-scripting branch 5 times, most recently from 72f8962 to dbe19c6 Compare December 24, 2021 14:39
@mnonnenmacher
Copy link
Member

I'd like to move examples.rules.kts to a Kotlin module so that completion works. What do you guys think about simply replacing the overly simplistic no_gpl.rules.kts with examples.rules.kts as a resource? Should we then symlink this to the examples directory, even if that might break things for Windows users?

Does this solution only work within this Gradle project, or is it possible to create a minimal Gradle project that depends on the evaluator to have working completion? If it is possible I would prefer such a project and put it in the examples folder.
And I would not like a symlink, I would rather have a file that contains something like "// See: path/to/evalutor.rules.kts".

@sschuberth
Copy link
Member Author

is it possible to create a minimal Gradle project that depends on the evaluator to have working completion?

It should indeed be possible to create a "rules-only" project by depending on the scripting-utils artifact, and I like the idea to create such an example. However, I'll do that in a separate PR then.

@sschuberth sschuberth marked this pull request as ready for review January 3, 2022 11:52
@sschuberth sschuberth requested review from a team as code owners January 3, 2022 11:52
@mnonnenmacher mnonnenmacher added evaluator About the evaluator tool breaking change labels Jan 3, 2022
Having a dedicated extension allows to associate script configurations
to that extension.

Signed-off-by: Sebastian Schuberth <[email protected]>
This is to align with other default filenames that already have
constants.

Signed-off-by: Sebastian Schuberth <[email protected]>
Modules that want to have support in IntelliJ IDEA for ORT Kotlin scripts
need to depend on this module so that the script configurations are
available in the compiler's classpath.

For references that helped during the implementation see [1][2][3].

[1]: https://discuss.kotlinlang.org/t/make-auto-completion-work-in-kotlin-scripts-with-context
[2]: https://github.com/Kotlin/kotlin-script-examples/tree/master/jvm/basic/jvm-maven-deps
[3]: https://github.com/Kotlin/KEEP/blob/master/proposals/scripting-support.md

Signed-off-by: Sebastian Schuberth <[email protected]>
This adds proper syntax highlighting and auto-completion support for Rules
Scripts inside IntelliJ IDEA, like for example for the

    evaluator/src/main/resources/rules/no_gpl.rules.kts

resource. Resolves #2950.

Signed-off-by: Sebastian Schuberth <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
evaluator About the evaluator tool
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants