Skip to content

Cannot override client version using bzlmod #62

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

Open
racosta opened this issue Jan 17, 2025 · 2 comments · May be fixed by #63
Open

Cannot override client version using bzlmod #62

racosta opened this issue Jan 17, 2025 · 2 comments · May be fixed by #63
Assignees
Labels
bug Something isn't working

Comments

@racosta
Copy link

racosta commented Jan 17, 2025

The way the module extension is implemented doesn't actually allow you to override client versions because there will then be a name collision.

To reproduce, edit internal/test/bcr/MODULE.bazel. Notice, I haven't even tried to change versions yet, just re-use the defaults.

diff --git a/internal/test/bcr/MODULE.bazel b/internal/test/bcr/MODULE.bazel
index 0e2af0b..4938d37 100644
--- a/internal/test/bcr/MODULE.bazel
+++ b/internal/test/bcr/MODULE.bazel
@@ -9,5 +9,6 @@ local_path_override(
     path = "../../..",
 )
 openapi_gen = use_extension("@openapi_tools_generator_bazel//:extension.bzl", "openapi_gen")
+openapi_gen.client()
 use_repo(openapi_gen, "openapi_tools_generator_bazel_cli")

Then, from the internal/test/bcr directory: bazel build ... yields

❯ bazel build ...
ERROR: /home/user/.cache/bazel/_bazel_user/bd3dd79c0d936347dcd08a9f7a9427e7/external/bazel_tools/tools/build_defs/repo/jvm.bzl:306:24: Traceback (most recent call last):
        File "/home/user/.cache/bazel/_bazel_user/bd3dd79c0d936347dcd08a9f7a9427e7/external/openapi_tools_generator_bazel+/extension.bzl", line 7, column 38, in _openapi_generator_impl
                jvm_maven_import_external(
        File "/home/user/.cache/bazel/_bazel_user/bd3dd79c0d936347dcd08a9f7a9427e7/external/bazel_tools/tools/build_defs/repo/jvm.bzl", line 306, column 24, in jvm_maven_import_external
                jvm_import_external(
Error in repository_rule: A repo named openapi_tools_generator_bazel_cli is already generated by this module extension at /home/user/.cache/bazel/_bazel_user/bd3dd79c0d936347dcd08a9f7a9427e7/external/bazel_tools/tools/build_defs/repo/jvm.bzl:306:24
ERROR: Analysis of target '//:pylib' failed; build aborted: error evaluating module extension @@openapi_tools_generator_bazel+//:extension.bzl%openapi_gen
INFO: Elapsed time: 0.405s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
ERROR: Build did NOT complete successfully

This is because this nested for loop is adding duplicated repos with the name openapi_tools_generator_bazel_cli. I'm not 100% sure how the resolution should be done. The names of the repos can either be adjusted to include the version (which would then require users to always specify the openapi_generator_cli attribute to the openapi_generator rule), or there can be some logic to decide which version should be used (max version?).

Temporarily we are resolving it by applying a patch which modifies the default value to what we need it to be, but I'd love to have this fixed properly. I can contribute, but I don't know the best practices for bazel module extensions well enough to know what the solution should be.

@tempacc21 tempacc21 linked a pull request Jan 18, 2025 that will close this issue
@BradHolmes
Copy link
Contributor

Thank you for the report, and I would like to get this fixed before we release to the bazel central registry.

I'm not yet sure the best way to solve it. I got some feedback from bzlmod experts to consider either a toolchain or to somehow let users declare their own tool. I hope to work on that the next few days.

@BradHolmes
Copy link
Contributor

I adopted the idea of a 2nd test of an older OpenAPI generator version in PR #64 -- can you see if that will work for you?

@nucle nucle added the bug Something isn't working label Mar 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants