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

feat(package-manager): Add initial support for Bazel #8409

Merged
merged 4 commits into from
Mar 23, 2024

Conversation

haikoschol
Copy link
Contributor

This PR introduces a very limited Analyzer plugin for the Bazel build system. It only covers projects that use bzlmod for managing dependencies. Therefore it expects Bazel 7.0 or later, where bzlmod is the default.

So far the implementation has only been tested with a small toy example project.

A few things that are not covered, which very likely need to be added in subsequent iterations are:

  • Patches that can be applied to the source artifact of dependencies during the build process (e.g. https://github.com/bazelbuild/bazel-central-registry/blob/main/modules/glog/0.5.0/source.json#L4)
  • Linking: Since this is C/C++, dynamic and static linking is possible. Right now all dependency relationships have static linkage because Bazel is generally biased towards static linking.
  • Build targets are not taken into account. I'm not sure how this would look like yet, maybe as different scopes.
  • There are no Bazel specific PURLs yet.

@haikoschol haikoschol requested a review from a team as a code owner March 13, 2024 11:41
@sschuberth sschuberth self-assigned this Mar 13, 2024
Copy link
Member

@mnonnenmacher mnonnenmacher left a comment

Choose a reason for hiding this comment

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

I haven't looked at the code, but please also add an entry to the package manager list in website/docs/tools/advisor.md and mention the limitations / mark it as experimental.

@sschuberth
Copy link
Member

I haven't looked at the code, but please also add an entry to the package manager list in website/docs/tools/advisor.md and mention the limitations / mark it as experimental.

@haikoschol that should say website/docs/tools/analyzer.md, obviously.

@haikoschol haikoschol requested a review from a team as a code owner March 14, 2024 03:32
@haikoschol haikoschol force-pushed the bzlmod-cc branch 2 times, most recently from 626067b to cb5d40d Compare March 14, 2024 04:30
@haikoschol
Copy link
Contributor Author

haikoschol commented Mar 14, 2024

I realized that I added a quick & dirty way to install Bazel in the Dockerfile for testing purposes. I removed that from the latest commit on this branch and am currently working on adding it "properly" in a subsequent commit.

edit: Since the PR is not ready to merge from my side until Bazel is added in Docker, I converted it to a draft.

@haikoschol haikoschol marked this pull request as draft March 14, 2024 08:39
@haikoschol haikoschol force-pushed the bzlmod-cc branch 5 times, most recently from 46ee3fa to f81c719 Compare March 14, 2024 11:46
@haikoschol
Copy link
Contributor Author

I have no idea why this markdown-links check thinks https://bazel.build/ is a dead link.

@haikoschol haikoschol marked this pull request as ready for review March 14, 2024 12:06
@haikoschol haikoschol force-pushed the bzlmod-cc branch 2 times, most recently from 6c0275f to e6d6150 Compare March 15, 2024 05:16
@haikoschol
Copy link
Contributor Author

I made the egregious mistake of assuming the "update branch" button would do the right thing. Instead it introduced a merge commit, which AFAIK is extremely verboten in ORT. How do I fix this?

@sschuberth
Copy link
Member

Instead it introduced a merge commit, which AFAIK is extremely verboten in ORT.

Exactly! 👮🏻‍♂️ 😆

How do I fix this?

Well, your local branch should still have your latest changes, so just force-push that to the remote branch for this PR. Afterwards, you can either click on "Update with rebase" from the drop-down, or just rebase locally and force-push once more.

@haikoschol haikoschol force-pushed the bzlmod-cc branch 2 times, most recently from 583359a to 4686f39 Compare March 19, 2024 11:00
@haikoschol haikoschol force-pushed the bzlmod-cc branch 3 times, most recently from e991237 to 09039c1 Compare March 19, 2024 13:48
@fviernau
Copy link
Member

I could probably find a couple of more nits, but I propose to draw a line here and merge it, once my last remaining open comments are addressed. (Some nits can still be fixed in future iterations) Is this ok with you as well @sschuberth @mnonnenmacher ?

@@ -403,6 +403,25 @@ RUN mkdir -p $DOTNET_HOME/bin \
FROM scratch AS dotnet
COPY --from=dotnetbuild /opt/dotnet /opt/dotnet

#------------------------------------------------------------------------
Copy link
Member

Choose a reason for hiding this comment

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

@sschuberth @mnonnenmacher do we still use the "legacy" Docker? (Should we update that one as well)

Copy link
Member

Choose a reason for hiding this comment

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

Yes, it's e.g. used as part of the Jenkinsfile.

Copy link
Member

Choose a reason for hiding this comment

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

So, Dockerfile-legacy should be updated in this PR / commit as well ?!

Copy link
Member

Choose a reason for hiding this comment

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

Ideally, yes. But going forward I'd like to avoid the need to maintain Dockerfile-legacy in addition to Dockerfile, and I hope @mnonnenmacher's Docker experiments to be the basis for such a change.

That said, I'm not sure whether it's worth to put effort into maintaining Dockerfile-legacy just now, as part of this initial implementation. I'd also be fine either adding Bazel support to Dockerfile-legacy later, or replacing the whole Docker stuff with a more streamlined solution, whatever comes first.

# BAZEL
FROM base as bazelbuild

ARG BAZEL_VERSION=7.0.1
Copy link
Member

Choose a reason for hiding this comment

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

We have that .versions file. I believe that BAZEL_VERSION needs to go there as well, but not sure if this should be done in this commit, or in the following one.

Copy link
Member

Choose a reason for hiding this comment

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

@heliocastro would you review the docker related bits as well, I guess you know this .versions mechanism ;-)

@haikoschol haikoschol force-pushed the bzlmod-cc branch 2 times, most recently from 909d3b9 to 85794f3 Compare March 20, 2024 11:00
@sschuberth
Copy link
Member

I could probably find a couple of more nits, but I propose to draw a line here and merge it, once my last remaining open comments are addressed. (Some nits can still be fixed in future iterations) Is this ok with you as well @sschuberth @mnonnenmacher ?

I first wanted the discussion between you and @haikoschol to settle down, but now that it comes to an end, I'd like to do a brief review myself, too. But please approve nonetheless if you're happy. As auto-merge is not on, we can have more reviews after that.

@fviernau
Copy link
Member

I first wanted the discussion between you and @haikoschol to settle down, but now that it comes to an end, I'd like to do a brief review myself, too. But please approve nonetheless if you're happy. As auto-merge is not on, we can have more reviews after that.

Kotlin wise, it LGTM I agree with merge. Not approving now as there are open comments regarding the Docker bits. You may however start yourself already reviewing the Kotlin bits (I won't request further change on Kotlin side here).

@sschuberth
Copy link
Member

@haikoschol, import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory now needs to be changed to import retrofit2.converter.kotlinx.serialization.asConverterFactory, see https://github.com/oss-review-toolkit/ort/pull/8440/files.

@sschuberth
Copy link
Member

Regarding the failing markdown-links check, please add an entry for https://bazel.build/ to https://github.com/oss-review-toolkit/ort/blob/main/mlc_config.json.

@sschuberth
Copy link
Member

Apparently funTest-docker still fail as bazel cannot be found. I suspect this is due to the known problems with our current Docker / PR setup, which doe snot reliably use a Docker image build from changes within the same PR. Not sure if it's worth fixing that setup as part of this PR. But I'll at least ensure that the Bazel funTests will pass for me locally.

@haikoschol
Copy link
Contributor Author

Apparently funTest-docker still fail as bazel cannot be found. I suspect this is due to the known problems with our current Docker / PR setup, which doe snot reliably use a Docker image build from changes within the same PR. Not sure if it's worth fixing that setup as part of this PR. But I'll at least ensure that the Bazel funTests will pass for me locally.

@fviernau suggested to move the Docker changes to a separate PR that gets merged before. Should I give that a go?

@sschuberth
Copy link
Member

@fviernau suggested to move the Docker changes to a separate PR that gets merged before. Should I give that a go?

If I can verify that funTest pass locally for me, I'd be fine with keeping things as-is. But I did not yet find the time to test, nor for a code review. I'll try today.

@heliocastro
Copy link
Contributor

The PR for fixing the race condition on funtest Docker is almost done, but the tests need be done in my private repo to avoid polute ort registry, since it involves upload docker images and version matching
Sorry for the delay, but i'm working on this in private time, with is diminished

A Bazel module registry, such as https://bcr.bazel.build,
is used to store metadata of dependencies managed by bzlmod.

Signed-off-by: Haiko Schol <[email protected]>
@sschuberth sschuberth merged commit 3126b41 into oss-review-toolkit:main Mar 23, 2024
34 of 35 checks passed
@haikoschol haikoschol deleted the bzlmod-cc branch April 5, 2024 04:33
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

Successfully merging this pull request may close these issues.

5 participants