-
Notifications
You must be signed in to change notification settings - Fork 31
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
Add Bazel support, fixes #88 #439
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the reason for having both is_enabled
and enabled
? 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.