-
-
Notifications
You must be signed in to change notification settings - Fork 276
Allow root module's override tags to take precedence over the overridees from transitive deps. #1278
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
Draft
jin
wants to merge
1
commit into
bazel-contrib:master
Choose a base branch
from
jin:root-overrides
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Allow root module's override tags to take precedence over the overridees from transitive deps. #1278
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -227,13 +227,22 @@ def maven_impl(mctx): | |
| # module attempts to update a maven repo (which is normally undesired behaviour) | ||
| repo_name_2_module_name = {} | ||
|
|
||
| for mod in mctx.modules: | ||
| # First compute the overrides. The order of the transitive overrides do not matter, but the root | ||
| # overrides take precedence over all transitive ones. | ||
| for idx, mod in enumerate(reversed(mctx.modules)): | ||
| # Rotate the root module to the last to be visited. | ||
| is_root_module = idx == (len(mctx.modules) - 1) | ||
| for override in mod.tags.override: | ||
| value = str(override.target) | ||
| current = overrides.get(override.coordinates, None) | ||
| to_use = _fail_if_different("Target of override for %s" % override.coordinates, current, value, [None]) | ||
| overrides.update({override.coordinates: to_use}) | ||
| if is_root_module: | ||
| # Allow the root module's overrides to take precedence over any transitive overrides. | ||
| to_use = value | ||
| else: | ||
| current = overrides.get(override.coordinates, None) | ||
| to_use = _fail_if_different("Target of override for %s" % override.coordinates, current, value, [None]) | ||
| overrides.update({override.coordinates: value}) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe |
||
|
|
||
| for mod in mctx.modules: | ||
| for artifact in mod.tags.artifact: | ||
| _check_repo_name(repo_name_2_module_name, artifact.name, mod.name) | ||
|
|
||
|
|
||
This file contains hidden or 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 hidden or 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,18 @@ | ||
| module(name = "transitive_module_can_override", version = "0.0.0") | ||
|
|
||
| bazel_dep(name = "rules_jvm_external", version = "0.0") | ||
| local_path_override( | ||
| module_name = "rules_jvm_external", | ||
| path = "../../../..", | ||
| ) | ||
|
|
||
| maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven") | ||
| maven.install( | ||
| name = "root_module_can_override", | ||
| artifacts = ["com.squareup.okhttp3:okhttp:4.12.0"], | ||
| ) | ||
|
|
||
| maven.override( | ||
| coordinates = "com.squareup.okhttp3:okhttp3", | ||
| target = "//:poison_pill_non_existent_target", | ||
| ) |
31 changes: 31 additions & 0 deletions
31
tests/integration/override_targets/root_module_can_override_test.sh
This file contains hidden or 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,31 @@ | ||
| # --- begin runfiles.bash initialization v2 --- | ||
| # Copy-pasted from the Bazel Bash runfiles library v2. | ||
| set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash | ||
| source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ | ||
| source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \ | ||
| source "$0.runfiles/$f" 2>/dev/null || \ | ||
| source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ | ||
| source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ | ||
| { echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e | ||
| # --- end runfiles.bash initialization v2 --- | ||
|
|
||
| set -euox pipefail | ||
|
|
||
| deps_file=$(rlocation rules_jvm_external/tests/integration/override_targets/root_module_can_override) | ||
|
|
||
| function clean_up_workspace_names() { | ||
| local file_name="$1" | ||
| local target="$2" | ||
| # The first `sed` command replaces `@@` with `@`. The second extracts the visible name | ||
| # from the bzlmod mangled workspace name | ||
| cat "$file_name" | sed -e 's|^@@|@|g; s|\r||g' | sed -e 's|^@[^/]*[+~]|@|g; s|\r||g' | grep "$target" | ||
| cat "$file_name" | sed -e 's|^@@|@|g; s|\r||g' | sed -e 's|^@[^/]*[+~]|@|g; s|\r||g' | grep -q "$target" | ||
| } | ||
|
|
||
| if ! clean_up_workspace_names "$deps_file" "@root_module_can_override//:com_squareup_okhttp3_okhttp"; then | ||
| exit 1 | ||
| fi | ||
|
|
||
| if ! clean_up_workspace_names "$deps_file" "@root_module_can_override//:com_squareup_javapoet"; then | ||
| exit 1 | ||
| fi |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This should be marked as a
dev_dependencyso that consumers of us don't try and look uptransitive_module_can_overridein the BCR.