forked from aspect-build/aspect-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request aspect-build#1 from gonzojive/apparent-loads
feat(gazelle/kotlin): Implement language.ModuleAwareLanguage.
- Loading branch information
Showing
10 changed files
with
166 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,60 @@ | ||
A Kotlin gazelle plugin, etracted from https://github.com/aspect-build/aspect-cli | ||
A Kotlin plugin for [bazel's gazelle | ||
tool](https://github.com/bazelbuild/bazel-gazelle/tree/master) for automatically | ||
generating BUILD.bazel files from Kotlin source code. | ||
|
||
This repository is only for debugging. It is not intended for usage. | ||
### Fork status | ||
This code was extracted from https://github.com/aspect-build/aspect-cli. I would | ||
like to merge it upstream depending on how the conversation goes with the | ||
original authors. See https://github.com/aspect-build/aspect-cli/issues/750 for | ||
discussion. | ||
|
||
|
||
# Usage | ||
|
||
|
||
# Dependency resolution | ||
|
||
Gazelle must resolve what Bazel labels (like `@foo//bar/baz`) a Kotlin file depends on. | ||
The rules followed by this plugin are as follows: | ||
|
||
1. The dependencies of a Kotlin file are determined from the explicit imports in | ||
the file. Fully-qualified identifiers present elsewhere in the file are not | ||
considered when determining dependencies. | ||
|
||
2. The resolution algorithm (as implemented in `gazelle/kotlin/resolver.go`) | ||
|
||
3. An identifier matches a [Maven | ||
artifact](https://maven.apache.org/repositories/artifacts.html) if one of the | ||
packages declared as an export of that artifact is a package prefix | ||
|
||
4. If the import to be resolved is in the library index, the import will be resolved to that library. If `-index=true`, Gazelle builds an index of library rules in the current repository before starting dependency resolution, and this is how most dependencies are resolved. | ||
|
||
1. For Kotlin, the match is based on the importpath attribute. | ||
|
||
2. For proto, the match is based on the srcs attribute. | ||
|
||
|
||
# Terminology | ||
|
||
**identifier** is used to refer to what the Kotlin spec calls an | ||
[identifier](https://kotlinlang.org/spec/syntax-and-grammar.html#grammar-rule-identifier). | ||
This is a fully-qualified or partially-qualified name. Fully-qualified | ||
identifiers are used in `package` and `import` statements in Kotlin files. | ||
|
||
**parent identifier**: In this document and in the code base, "parent identifier" means | ||
an identifier with the last dot-delimited component removed. Sometimes it may be loosely | ||
used to refer to all the ancestor identifiers as well (parent, parent of parent, etc.). | ||
|
||
# Directives | ||
|
||
Many [gazelle directives](https://github.com/bazelbuild/bazel-gazelle#directives) are generic | ||
and will apply the the behavior of the Kotlin plugin. | ||
|
||
The Kotlin plugin has additional directives for configuring behavior: | ||
|
||
## gazelle:java_maven_install_file | ||
|
||
Specifies where the `maven_install.json` file is located. | ||
|
||
This directive is defined by the [rules_jvm gazelle plugin](), and the Kotlin | ||
plugins hares logic with the Java plugin to parse it. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
load("@rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library") | ||
|
||
kt_jvm_library( | ||
name = "root", | ||
srcs = [ | ||
"lib.kt", | ||
"libs.kts", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module( | ||
name = "simple", | ||
version = "0.0.1", | ||
) | ||
|
||
bazel_dep(name = "rules_kotlin", version = "1.9.6") | ||
bazel_dep(name = "rules_jvm_external", version = "6.4") | ||
|
||
maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven") | ||
|
||
maven.install( | ||
artifacts = [ | ||
"com.google.truth:truth:1.1.2", | ||
"junit:junit:4.13.2", | ||
], | ||
lock_file = "//:maven_install.json", | ||
repositories = [ | ||
"https://repo1.maven.org/maven2", | ||
], | ||
) | ||
use_repo(maven, "maven") |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Hello World Program | ||
|
||
fun hello() { | ||
println("Hello world!") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Hello World Program | ||
|
||
fun hello() { | ||
println("Hello world!") | ||
} |