-
Notifications
You must be signed in to change notification settings - Fork 277
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use
apparent_repo_name
only on repository_ctx
Repurposed `apparent_repo_name` to only work for `repository_ctx` objects, not repository or module names in general. Removed `generated_rule_name` from `repositories.bzl`, since it's no longer necessary. Technically we could eliminate `apparent_repo_name` by making `generated_rule_name` a mandatory attribute of `_jvm_import_external`. However, this feels ultimately clunky and unnecessary. This update to `apparent_repo_name` required removing `_update_external_target_path` and updating `_target_path_by_default_prefixes` to remove `external/<canonical_repo_name>` prefixes. This represents a breaking change for files referencing `external/<repo_name>` paths, but the quick fix is to delete that prefix in the code. This matches the behavior in the same function regarding `resources/` and `java/` prefixes.
- Loading branch information
Showing
6 changed files
with
27 additions
and
47 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,37 +1,21 @@ | ||
"""Utilities for working with Bazel modules""" | ||
|
||
_repo_attr = ( | ||
"repo_name" if hasattr(Label("//:all"), "repo_name") else "workspace_name" | ||
) | ||
|
||
def apparent_repo_name(label_or_name): | ||
"""Return a repository's apparent repository name. | ||
Can be replaced with a future bazel-skylib implementation, if accepted into | ||
that repo. | ||
def apparent_repo_name(repository_ctx): | ||
"""Generates a repository's apparent name from a repository_ctx object. | ||
Args: | ||
label_or_name: a Label or repository name string | ||
repository_ctx: a repository_ctx object | ||
Returns: | ||
The apparent repository name | ||
An apparent repo name derived from repository_ctx.name | ||
""" | ||
repo_name = getattr(label_or_name, _repo_attr, label_or_name).lstrip("@") | ||
delimiter_indices = [] | ||
repo_name = repository_ctx.name | ||
|
||
# Bazed on this pattern from the Bazel source: | ||
# com.google.devtools.build.lib.cmdline.RepositoryName.VALID_REPO_NAME | ||
for i in range(len(repo_name)): | ||
for i in range(len(repo_name) - 1, -1, -1): | ||
c = repo_name[i] | ||
if not (c.isalnum() or c in "_-."): | ||
delimiter_indices.append(i) | ||
|
||
if len(delimiter_indices) == 0: | ||
# Already an apparent repo name, apparently. | ||
return repo_name | ||
|
||
if len(delimiter_indices) == 1: | ||
# The name is for a top level module, possibly containing a version ID. | ||
return repo_name[:delimiter_indices[0]] | ||
return repo_name[i + 1:] | ||
|
||
return repo_name[delimiter_indices[-1] + 1:] | ||
return repo_name |
This file contains 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 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 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 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 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