Repro:
touch WORKSPACE
cat > BUILD <<EOD
load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")
pkg_tar(
name = "repro",
files = ["a/b/c.sh"],
strip_prefix = "a/b",
)
EOD
mkdir -p a/b
touch a/b/c.sh
bazel build :repro
tar -tf bazel-bin/repro.tar
I believe the particular line is here:
https://github.com/bazelbuild/bazel/blob/master/tools/build_defs/pkg/path.bzl#L51
else: # Relative to a sub-directory
return _short_path_dirname(out) + "/" + data_path
which fails to account for the fact that _short_path_dirname may return "". As a result, the returned data_path incorrectly includes a /.
@jasonchoimtt I could not reproduce the bug. The version I used is 0.3.1. It build project you provided correctly.
Sorry, I should have elaborated more. I expect the tarball to contain:
./
./c.sh
since I strip_prefix a/b.
But instead it produces a tarball with (I'm on 0.3.0):
./
./a/
./a/b/
./a/b/c.sh
Can you reproduce this? If not, I can test on 0.3.1 later to verify.
The output I have is
tar -tf bazel-bin/repro.tar
./
./a/
./a/b/
./a/b/c.sh
I missed some info. I think I reproduced the bug you have.
That shows the problem I am reporting. If I am not mistaken, the intended behavior of strip_prefix = "a/b" is that it should remove a/b and so put c.sh at the root of the tarball. But as shown above this does not happen.
Am I right or did I misinterpret the documentation?
You are absolutely right. I read too fast and missed some key info. If you provide strip_prefix, it should behave like you expecting. But Bazel did not.
@jasonchoimtt I just fixed it. I am preparing pull request now. Hopefully, my changes can be merged into mater in near future. :)
Thank you! Free to close this issue. :)
@hermione521 Could you close this issue, I do not have the access to close it.