-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Add $(rlocationpath(s) ...)
expansion
#16428
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
Conversation
618aecd
to
52fb838
Compare
@lberki Can you review this (or delegate to someone else)? I haven't included any changes to docs yet, but could add them if the rest of the PR looks good. There are no docs on runfiles libraries yet though, so whatever I include in this PR will still be lacking context. |
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.
I was thinking of alternatives and I couldn't come up with any.
If I understand correctly, please confirm, rlocation always needs repo_name/path/in/the/repo
as input. And this can be _main/path/in/the/main/repo
. Right? What happens in the case this is a generated file - that is in bazel-bin/reponame/...
?
Possible alternative would be $(reponame @repo//label)
, but this worse since you'd need to use 2 functions.
About the name. location(s)
function is deprecated. I'm guessing you chose the name so it fits rlocation
function (for example the one here https://github.com/bazelbuild/bazel/blob/master/tools/bash/runfiles/runfiles.bash). So this then looks like rlocation $(rlocation //label)
. Does the plural form make sense here?
Because of deprecation of location
, perhaps consider another name, like repopath
? Maybe rlocation $(repopath //label)
looks better?
Slightly out of scope, but do you think there's a way to simplify copy-pasted lines we have in almost all shell tests https://github.com/bazelbuild/bazel/blob/master/src/test/shell/bazel/archive_contents_test.sh#L20-L40 or https://github.com/bazelbuild/bazel/blob/master/src/test/shell/bazel/android/android_helper.sh#L17-L26?
One more naive question. Can we provide a function that directly returns what rlocation $(rlocation //label)
would return? Eliminating the need for first/external rlocation
.
Also note, the name might cause some confusion when bash's |
Yes, for all files in the main repo, with Bzlmod enabled. Without Bzlmod, this would be
Both generated and source file's use the same
It's also difficult to get the remaining part since
I chose
Your example would be
I think so, yes. In Java, it would be easy to do
See above, do you think
The latter one is more modern and already quite a bit shorter. I don't see a way to fundamentally improve on that. |
Answering these in one as they are related: You wouldn't commonly do this since We could think about ways to make |
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.
Thanks for explanations! This makes it much easier to review. Couple of nits, but overall it looks ok.
src/main/java/com/google/devtools/build/lib/analysis/LocationExpander.java
Show resolved
Hide resolved
@@ -181,8 +189,10 @@ public void otherPathExternalExpansionNoLegacyExternalRunfiles() throws Exceptio | |||
.matches("foo .*-out/.*/external/r/p/foo\\.txt bar"); | |||
assertThat(expander.expand("foo $(execpaths @r//p:foo) bar")) | |||
.matches("foo .*-out/.*/external/r/p/foo\\.txt bar"); | |||
assertThat(expander.expand("foo $(rootpath @r//p:foo) bar")).matches("foo ../r/p/foo.txt bar"); | |||
assertThat(expander.expand("foo $(rootpaths @r//p:foo) bar")).matches("foo ../r/p/foo.txt bar"); | |||
assertThat(expander.expand("foo $(rootpath @r//p:foo) bar")).isEqualTo("foo ../r/p/foo.txt bar"); |
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.
nit: isEqualTo
seems better here, since it's not using a regex like matches
. Can you use isEqualsTo
in all the new code?
The old code should be updated separately, so we don't overload this PR.
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.
I am using isEqualsTo
in all new tests and reverted the changes to existing asserts.
src/main/java/com/google/devtools/build/lib/analysis/LocationExpander.java
Show resolved
Hide resolved
src/test/java/com/google/devtools/build/lib/analysis/LocationExpanderIntegrationTest.java
Show resolved
Hide resolved
52fb838
to
362fe14
Compare
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.
I addressed your comments.
I also added rlocationpath
to the docs and fixed some outdated info about the other location functions.
@@ -181,8 +189,10 @@ public void otherPathExternalExpansionNoLegacyExternalRunfiles() throws Exceptio | |||
.matches("foo .*-out/.*/external/r/p/foo\\.txt bar"); | |||
assertThat(expander.expand("foo $(execpaths @r//p:foo) bar")) | |||
.matches("foo .*-out/.*/external/r/p/foo\\.txt bar"); | |||
assertThat(expander.expand("foo $(rootpath @r//p:foo) bar")).matches("foo ../r/p/foo.txt bar"); | |||
assertThat(expander.expand("foo $(rootpaths @r//p:foo) bar")).matches("foo ../r/p/foo.txt bar"); | |||
assertThat(expander.expand("foo $(rootpath @r//p:foo) bar")).isEqualTo("foo ../r/p/foo.txt bar"); |
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.
I am using isEqualsTo
in all new tests and reverted the changes to existing asserts.
src/test/java/com/google/devtools/build/lib/analysis/LocationExpanderIntegrationTest.java
Show resolved
Hide resolved
src/main/java/com/google/devtools/build/lib/analysis/LocationExpander.java
Show resolved
Hide resolved
c019df0
to
bb60c1e
Compare
The new location expansion pattern `rlocationpath` and its plural version `rlocationpaths` resolve to the path(s) suitable for the Rlocation function offered by runfiles libraries. Compared to the `rootpath` pattern, which can returns '../repo_name/pkg/file` for a file in an external repository and `pkg/file` for a file in the main repository, the path returned by `rlocationpath` is always of the form `repo_name/pkg/file`. Work towards bazelbuild#16124 Fixes bazelbuild#10923
bb60c1e
to
cb3c0cb
Compare
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.
Thanks!
@bazel-io flag |
@sgowroji there might be some trouble merging |
Hello @comius, Above PR is awaiting to merge. What should be done for the internal fixes which we discussed offline, Can you please have a look. Thanks! |
@bazel-io fork 6.0.0 |
@comius If you have no further converns, could you approve? This is the final piece of API I need to be certain about to finalize my BazelCon talk. |
@fmeum Ivo is already importing this PR ;) |
@bazel-io fork 5.4.0 |
The new location expansion pattern
rlocationpath
and its plural versionrlocationpaths
resolve to the path(s) suitable for the Rlocation function offered by runfiles libraries.Compared to the
rootpath
pattern, which can returns../repo_name/pkg/file
for a file in an external repository andpkg/file
for a file in the main repository, the path returned byrlocationpath
is always of the formrepo_name/pkg/file
.RELNOTES: The new path variable
$(rlocationpath ...)
and its plural form$(rlocationpaths ...)
can be used to expand labels to the paths accepted by theRlocation
function of runfiles libraries. This is the preferred way to access data dependencies at runtime and works on all platforms, even when runfiles are not enabled (e.g., on Windows by default).Work towards #16124
Fixes #10923