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

Fix pkg_tar directory entries #647

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jameshilliard
Copy link

Directories appear to work for zip files but not tar files.

This should ensure we don't try to process directories as normal files.

Fixes issues like:

rules_pkg/pkg/private/tar/tar_writer.py", line 242, in add_file
    with open(file_content, 'rb') as f:
IsADirectoryError: [Errno 21] Is a directory: 'bazel-out/darwin-fastbuild/bin/py/selenium/webdriver/common/devtools/v106'

@AutomatedTester
Copy link

This PR works well, I've got it in the Selenium tree for now.

@nacl
Copy link
Collaborator

nacl commented Dec 7, 2022

Could you provide test cases for this?

If this is supporting what I think it is (passing in directory labels that are not TreeArtifacts), I am hesitant to support this any further, as is not a best practice. @aiuto may have a differing opinion.

Please correct me if I'm wrong, but the relevant code in the Selenium tree is a genrule that looks to be emitting a directory, which is unfortunately unsound (the documentation's words, not mine) and IIRC Bazel emits a warning saying something to this point. This IMO should instead be a first-class rule that emits a TreeArtifact (via ctx.actions.declare_directory, if you didn't already know).

@jameshilliard
Copy link
Author

Could you provide test cases for this?

Hmm, is there a similar case that I should base one off of?

If this is supporting what I think it is (passing in directory labels that are not TreeArtifacts), I am hesitant to support this any further, as is not a best practice. @aiuto may have a differing opinion.

Well...it's apparently supported for zip files already so the inconsistency with tar files is problematic.

Please correct me if I'm wrong, but the relevant code in the Selenium tree is a genrule that looks to be emitting a directory, which is unfortunately unsound (the documentation's words, not mine) and IIRC Bazel emits a warning saying something to this point. This IMO should instead be a first-class rule that emits a TreeArtifact (via ctx.actions.declare_directory, if you didn't already know).

Yeah, I think that probably also needs to be changed, although I'm not very familiar with bazel in general so making tar work like zip files seemed easier for a short term fix.

@aiuto
Copy link
Collaborator

aiuto commented Dec 7, 2022

I worry about this too. It looks like it will pull in trees that might not have been staged, so it may do what you want for local builds but not remote builds. If zip does that, it is probably an accidental side effect. Both support tree artifacts as inputs.

As far as tests, there already are tests for tree artifacts in tests/tar/BUILD.

Directories appear to work for zip files but not tar files.

This should ensure we don't try to process directories as normal
files.

Fixes issues like:
rules_pkg/pkg/private/tar/tar_writer.py", line 242, in add_file
    with open(file_content, 'rb') as f:
IsADirectoryError: [Errno 21] Is a directory: 'bazel-out/darwin-fastbuild/bin/py/selenium/webdriver/common/devtools/v106'
@jameshilliard
Copy link
Author

As far as tests, there already are tests for tree artifacts in tests/tar/BUILD.

Test which reproduces the error is added.

Copy link
Collaborator

@aiuto aiuto left a comment

Choose a reason for hiding this comment

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

This PR is trying to add a feature that will not work all the time. If you are building a tree of files you can't explicitly name or enumerate, the only bazel supported way is to use ctx.actions.declare_directory to make a tree artifact.

genrule(
name = "generate_dir_file",
outs = ["lib"],
cmd = "mkdir -p $@; echo 1 >$@/nsswitch.conf",
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is not a case we should actively support. It doesn't work in remote build situations.

Copy link
Author

Choose a reason for hiding this comment

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

Well the behavior is at least currently inconsistent with zip files so not sure what best option here is.

Copy link
Author

Choose a reason for hiding this comment

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

Does this ctx.actions.declare_directory based rule look correct?

Copy link
Collaborator

Choose a reason for hiding this comment

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

That looks mostly right. It does a declare_directory, then passes the .path of that to some tool to fill in.

@aiuto
Copy link
Collaborator

aiuto commented Dec 8, 2022

Maybe, but that case should be working already.

@@ -309,7 +309,10 @@ def add_manifest_entry(self, entry_list, file_attributes):
elif entry.entry_type == manifest.ENTRY_IS_EMPTY_FILE:
self.add_empty_file(entry.dest, **attrs)
else:
self.add_file(entry.src, entry.dest, **attrs)
if os.path.isdir(entry.src):
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is not the place we should fix it.
For correctness, it needs to be in pkg.bzl, where we test that the input file has is_directory set. But we are already doing that.

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

Successfully merging this pull request may close these issues.

4 participants