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(write_source_files): fix nested directories #65

Merged
merged 14 commits into from
Apr 6, 2022

Conversation

jbedard
Copy link
Collaborator

@jbedard jbedard commented Apr 4, 2022

No description provided.

Comment on lines 136 to 146
genrule(
name = "subdir",
outs = ["subdir_test"],
cmd = "mkdir -p $@/a/b/c; echo 'test' > $@/a/b/c/test.txt",
)

write_source_files(
name = "write_subdir",
diff_test = False,
files = {"subdir_test": ":subdir_test"},
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Want to add a comment to connect this to the integration test?

mkdir -p "$out"
cp -fR "$in"/* "$out"
chmod 664 "$out"/*
cp -fRL "$in"/* "$out"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think capital -R is or will be deprecated on mac? I recall @gregmagolan had a PR out about that.

Copy link
Collaborator

Choose a reason for hiding this comment

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

What is the L for?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

L makes it follow symlinks instead of copy them.

If bazel creates a directory with symlinks to other locations we don't want to just copy the links but copy the content they point to. Otherwise we end up with symlinks into the sandbox copied into the source dir...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The rules_nodejs pkg_web seems to create these symlinks which is where we saw the problem. I think pkg_web creates a directory structure for the package but then the files within those directories are symlinks to the original source of files being "packaged". Basically avoid copying files all over the place and use symlinks as much as possible.

When writing that package into the source dir we want to copy the real files and not the symlinks...

Copy link
Collaborator

Choose a reason for hiding this comment

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

-R is the correct one with consistent meaning on both platforms. It is the lowercase -r that has a different meaning on macos vs linux.

@jbedard jbedard requested a review from kormide April 6, 2022 17:01
@jbedard
Copy link
Collaborator Author

jbedard commented Apr 6, 2022

So far I've failed to write a test for:

  • the symlink issues (-L on cp) EDIT: done: e6fc9d0
  • files not copying due to lack of write permission, the e2e test only reproduces files not copying due to lack of execute permission on directories EDIT: done: 97aabaf

@@ -164,11 +164,12 @@ echo "Copying $in to $out in $PWD"

if [[ -f "$in" ]]; then
cp -f "$in" "$out"
chmod 664 "$out"
chmod +w "$out"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So these only add write permission for the current user. Should it be for all? Seems like bazel normally does -r-xr-xr-x (makes all 3 the same). Should we do similar and add w for all?

Copy link
Collaborator

Choose a reason for hiding this comment

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

User and group is probably safe?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

Copy link
Collaborator

@kormide kormide left a comment

Choose a reason for hiding this comment

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

👍

mkdir -p "$out"
cp -fR "$in"/* "$out"
chmod 664 "$out"/*
cp -fRL "$in"/* "$out"
Copy link
Collaborator

Choose a reason for hiding this comment

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

-R is the correct one with consistent meaning on both platforms. It is the lowercase -r that has a different meaning on macos vs linux.

@gregmagolan gregmagolan merged commit 0f30bf9 into bazel-contrib:main Apr 6, 2022
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.

3 participants