Conversation
3deacd9 to
4bb14ad
Compare
This commit adds a new Bazel build to this codebase so that Bazel users can build the semanticdb-javac compiler plugin from source and use it in their Bazel build. This commit includes examples of how a Bazel user could potentially enable the compiler plugin dynamically based on a command-line flag, but we don't know if this is the best way to integrate lsif-java with a Bazel codebase. This commit is just an incremental step towards Bazel support, it's not a complete solution yet because the `lsif-java index-semanticdb` command still needs additional functionality to read jar files from the `bazel-bin` directory.
How hard would it be to add this? Any specific reason to do it later vs now? |
|
I'm working on expanding this PR to include full support. We can keep this PR open until all the pieces are ready. |
| config_setting( | ||
| name = "is_enabled", | ||
| flag_values = {":enabled": "true"}, | ||
| ) | ||
|
|
||
| string_flag( | ||
| name = "enabled", | ||
| values = ["true", "false"], | ||
| build_setting_default = "false", | ||
| ) |
There was a problem hiding this comment.
What's the reason for having both is_enabled and enabled? 😅
There was a problem hiding this comment.
One of them defines the name when specifying the flag from the command-line bazel build //... //semanticdb-javac:enabled=true.
The is_enabled target is used as a filter for a select(...) clause.
See official docs https://bazel.build/docs/configurable-attributes
semanticdb-javac/src/main/java/com/sourcegraph/semanticdb_javac/SemanticdbJavacOptions.java
Outdated
Show resolved
Hide resolved
semanticdb-javac/src/main/java/com/sourcegraph/semanticdb_javac/SemanticdbJavacOptions.java
Outdated
Show resolved
Hide resolved
semanticdb-javac/src/main/java/com/sourcegraph/semanticdb_javac/SemanticdbTaskListener.java
Outdated
Show resolved
Hide resolved
| int relativePathDepth = 0; | ||
| int uriPathDepth = uriPath.getNameCount(); | ||
| int absolutePathDepth = absolutePath.getNameCount(); | ||
| while (relativePathDepth < uriPathDepth && relativePathDepth < absolutePathDepth) { | ||
| String uriName = uriPath.getName(uriPathDepth - relativePathDepth - 1).toString(); | ||
| String pathName = absolutePath.getName(absolutePathDepth - relativePathDepth - 1).toString(); | ||
| if (!uriName.equals(pathName)) { | ||
| break; | ||
| } | ||
| relativePathDepth++; | ||
| } |
There was a problem hiding this comment.
suggestion(non-blocking): Perhaps add some unit tests for this function or specifically this logic? It seems a bit tricky.
There was a problem hiding this comment.
Good suggestion. I opened a reminder issue and a // FIXME https://github.com/sourcegraph/lsif-java/issues/444 comment. Don't want to delay this PR further.
- Add LSIF generation support. - Add e2e example on how to import lsif-java as an external repo. - Add cross-repo support for bazelbuild/rules_jvm_external and twitter/bazel-multiversion.
olafurpg
left a comment
There was a problem hiding this comment.
Thank you @varungandhi-src for the detailed review! I appreciate the thoughtful comments and the resulting code is much cleaner.
| config_setting( | ||
| name = "is_enabled", | ||
| flag_values = {":enabled": "true"}, | ||
| ) | ||
|
|
||
| string_flag( | ||
| name = "enabled", | ||
| values = ["true", "false"], | ||
| build_setting_default = "false", | ||
| ) |
There was a problem hiding this comment.
One of them defines the name when specifying the flag from the command-line bazel build //... //semanticdb-javac:enabled=true.
The is_enabled target is used as a filter for a select(...) clause.
See official docs https://bazel.build/docs/configurable-attributes
semanticdb-javac/src/main/java/com/sourcegraph/semanticdb_javac/SemanticdbJavacOptions.java
Outdated
Show resolved
Hide resolved
semanticdb-javac/src/main/java/com/sourcegraph/semanticdb_javac/SemanticdbJavacOptions.java
Outdated
Show resolved
Hide resolved
semanticdb-javac/src/main/java/com/sourcegraph/semanticdb_javac/SemanticdbTaskListener.java
Outdated
Show resolved
Hide resolved
| int relativePathDepth = 0; | ||
| int uriPathDepth = uriPath.getNameCount(); | ||
| int absolutePathDepth = absolutePath.getNameCount(); | ||
| while (relativePathDepth < uriPathDepth && relativePathDepth < absolutePathDepth) { | ||
| String uriName = uriPath.getName(uriPathDepth - relativePathDepth - 1).toString(); | ||
| String pathName = absolutePath.getName(absolutePathDepth - relativePathDepth - 1).toString(); | ||
| if (!uriName.equals(pathName)) { | ||
| break; | ||
| } | ||
| relativePathDepth++; | ||
| } |
There was a problem hiding this comment.
Good suggestion. I opened a reminder issue and a // FIXME https://github.com/sourcegraph/lsif-java/issues/444 comment. Don't want to delay this PR further.
|
I updated a new "bazel" CI job to test the generation e2e for internal usage (within our repo) and external usage (how end-users will consume lsif-java). Once we have snapshot testing logic we can additionally snapshot the generated index files, right now we just test that |
|
The CI tests are s now green in CI! I didn't get dependency pinning working but I don't think it's a problem because we have so few dependencies and they have no conflicts so the resolution will always be the same. |
.github/workflows/ci.yml
Outdated
| - run: bazel run lsif-semanticdb:bazel -- --sourceroot $PWD | ||
| - run: du -h dump.lsif-typed | ||
| - run: bazel build //... --@lsif_java//semanticdb-javac:enabled=true | ||
| working-directory: examples/bazel-example | ||
| - run: bazel run @lsif_java//lsif-semanticdb:bazel -- --sourceroot $PWD |
There was a problem hiding this comment.
| - run: bazel run lsif-semanticdb:bazel -- --sourceroot $PWD | |
| - run: du -h dump.lsif-typed | |
| - run: bazel build //... --@lsif_java//semanticdb-javac:enabled=true | |
| working-directory: examples/bazel-example | |
| - run: bazel run @lsif_java//lsif-semanticdb:bazel -- --sourceroot $PWD | |
| - run: bazel run lsif-semanticdb:bazel -- --sourceroot "$PWD" | |
| - run: du -h dump.lsif-typed | |
| - run: bazel build //... --@lsif_java//semanticdb-javac:enabled=true | |
| working-directory: examples/bazel-example | |
| - run: bazel run @lsif_java//lsif-semanticdb:bazel -- --sourceroot "$PWD" |
In case someone copy-pastes this to run locally, it'll not work if PWD has spaces.
varungandhi-src
left a comment
There was a problem hiding this comment.
LGTM, except for a couple of pending minor comments.
This PR adds a new Bazel build to this codebase so that Bazel users can
build the semanticdb-javac compiler plugin from source and use it in
their Bazel build. This PR does not yet include documentation on how to use this configuration,
but this PR adds an end-to-end example of how to import the lsif-java rules via
include(...)Test plan
See new "bazel" CI job.