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

Find runfiles in directories that are themselves runfiles #14335

Closed
wants to merge 1 commit into from

Conversation

fmeum
Copy link
Collaborator

@fmeum fmeum commented Nov 26, 2021

When a target has a runfile that is contained in a directory that is itself one of its runfiles, the runfile will be shadowed by the SymlinkEntry for the directory. While this still allows to resolve the file in the runfiles symlink tree, a manifest-based lookup will fail. Since the manifest is used to create the symlink tree for which it is important that no path is a prefix of another, this can only be fixed in the runfiles libraries.

This PR extends the lookup logic of the Bash, C++, Java, and Python runfiles libraries to also find runfiles contained within directories that are themselves runfiles. It does so by searching the manifest not only for the exact provided rlocation path, but also for all path prefixes. If a prefix is looked up successfully, the corresponding suffix is resolved relative to the looked up path.

Fixes #14336.

@fmeum
Copy link
Collaborator Author

fmeum commented Jan 14, 2022

@mai93 Would you be able to take a look? You reviewed and worked on the last fixes to the runfiles libraries.

@fmeum
Copy link
Collaborator Author

fmeum commented Feb 1, 2022

@meteorcloudy Could you review this PR in case @mai93 is busy?

@meteorcloudy meteorcloudy self-requested a review February 3, 2022 14:14
Copy link
Member

@meteorcloudy meteorcloudy left a comment

Choose a reason for hiding this comment

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

Thanks for fixing this use case!

tools/java/runfiles/testing/RunfilesTest.java Show resolved Hide resolved
@fmeum fmeum force-pushed the runfiles-manifest-dir-lookup branch from b79a5f0 to d18c4ee Compare February 3, 2022 15:42
@@ -48,6 +49,12 @@ using std::vector;

namespace {

#ifdef _WIN32
Copy link
Member

Choose a reason for hiding this comment

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

Do we still need this if we always use /?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I got rid of it.

@fmeum fmeum force-pushed the runfiles-manifest-dir-lookup branch from d18c4ee to 7d6de06 Compare February 3, 2022 17:01
@fmeum
Copy link
Collaborator Author

fmeum commented Feb 3, 2022

@meteorcloudy I pushed the fixes, thanks for the comments.

Would it be okay to leave bash for a follow-up PR? I'm not too familiar with shell scripts and would probably need more time to fix the lookup logic there.

@fmeum fmeum force-pushed the runfiles-manifest-dir-lookup branch from 67a6c85 to c6cea90 Compare February 4, 2022 06:47
@fmeum
Copy link
Collaborator Author

fmeum commented Feb 4, 2022

I gave the Bash implementation a try and it wasn't that bad. This PR now includes fixes for all runfiles libraries shipped with Bazel.

Let me know if you would prefer me to squash the four commits in case you want to import them together.

tools/java/runfiles/testing/RunfilesTest.java Show resolved Hide resolved
echo "$candidate"
return 0
fi
# There is only ever one matching prefix in the runfiles manifest.
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this break statement be inside the if statement?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I actually think it's correct as is, but agree this is confusing and thus added an extensive comment. Let me know what you think.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks! I missed the continue statement in the middle and thought the while loop would never run a second time. Thanks for the explanation!

@fmeum fmeum force-pushed the runfiles-manifest-dir-lookup branch from c6cea90 to 2c004f4 Compare February 4, 2022 18:08
@fmeum
Copy link
Collaborator Author

fmeum commented Feb 4, 2022

I squashed the commits and added a descriptive message.

tools/bash/runfiles/runfiles.bash Outdated Show resolved Hide resolved
When a target has a runfile that is contained in a directory that is itself one
of its runfiles, the runfile will be shadowed by the SymlinkEntry for the
directory. While this still allows to resolve the file in the runfiles symlink
tree, a manifest-based lookup will fail. Since the manifest is used to create the
symlink tree for which it is important that no path is a prefix of another, this
can only be fixed in the runfiles libraries.

This commit extends the lookup logic of the Bash, C++, Java, and Python runfiles
libraries to also find runfiles contained within directories that are themselves
runfiles. It does so by searching the manifest not only for the exact provided
rlocation path, but also for all path prefixes. If a prefix is looked up
successfully, the corresponding suffix is resolved relative to the looked up
path.
@fmeum fmeum force-pushed the runfiles-manifest-dir-lookup branch from 2c004f4 to 2b91de0 Compare February 7, 2022 11:04
@bazel-io bazel-io closed this in 486d153 Feb 7, 2022
@fmeum fmeum deleted the runfiles-manifest-dir-lookup branch February 7, 2022 14:49
fmeum added a commit to fmeum/bazel that referenced this pull request Feb 7, 2022
When a target has a runfile that is contained in a directory that is itself one of its runfiles, the runfile will be shadowed by the `SymlinkEntry` for the directory. While this still allows to resolve the file in the runfiles symlink tree, a manifest-based lookup will fail. Since the manifest is used to create the symlink tree for which it is important that no path is a prefix of another, this can only be fixed in the runfiles libraries.

This PR extends the lookup logic of the Bash, C++, Java, and Python runfiles libraries to also find runfiles contained within directories that are themselves runfiles. It does so by searching the manifest not only for the exact provided rlocation path, but also for all path prefixes. If a prefix is looked up successfully, the corresponding suffix is resolved relative to the looked up path.

Fixes bazelbuild#14336.

Closes bazelbuild#14335.

PiperOrigin-RevId: 426894517
Wyverald pushed a commit that referenced this pull request Feb 7, 2022
When a target has a runfile that is contained in a directory that is itself one of its runfiles, the runfile will be shadowed by the `SymlinkEntry` for the directory. While this still allows to resolve the file in the runfiles symlink tree, a manifest-based lookup will fail. Since the manifest is used to create the symlink tree for which it is important that no path is a prefix of another, this can only be fixed in the runfiles libraries.

This PR extends the lookup logic of the Bash, C++, Java, and Python runfiles libraries to also find runfiles contained within directories that are themselves runfiles. It does so by searching the manifest not only for the exact provided rlocation path, but also for all path prefixes. If a prefix is looked up successfully, the corresponding suffix is resolved relative to the looked up path.

Fixes #14336.

Closes #14335.

PiperOrigin-RevId: 426894517
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Runfiles libraries don't find runfiles in directories that are themselves runfiles when using manifest
2 participants