-
Notifications
You must be signed in to change notification settings - Fork 447
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
rust_doc: strip directory prefix from archive names #474
rust_doc: strip directory prefix from archive names #474
Conversation
The Zip archives emitted by `rust_doc` rules used to contain a long `/bazel-bin/k8-fastbuild/path/to/target` prefix before each archive entry name. This made it hard to work with the generated archive. This patch adds a transformation to This could be written in Starlark using the `DirectoryExapnder` API, but that was only introduced in Bazel 3.4.0. Since we have a minimum Bazel version of 0.17.1, we instead write the helper as a small Python script. Fixes bazelbuild#471. Test Plan: Unit tests included. As an end-to-end test, run ``` cd examples/ && bazel build //hello_world:hello_world_doc && unzip -l bazel-bin/hello_world/hello_world_doc.zip ``` to list the contents of the built `hello_world_doc.zip` archive. Before this patch, the result was like: ``` Archive: bazel-bin/hello_world/hello_world_doc.zip Length Date Time Name --------- ---------- ----- ---- 0 2010-01-01 00:00 bazel-out/k8-fastbuild/bin/hello_world/hello_world_doc/.lock 1792 2010-01-01 00:00 bazel-out/k8-fastbuild/bin/hello_world/hello_world_doc/COPYRIGHT.txt 4421 2010-01-01 00:00 bazel-out/k8-fastbuild/bin/hello_world/hello_world_doc/FiraSans-LICENSE.txt ... 2132 2010-01-01 00:00 bazel-out/k8-fastbuild/bin/hello_world/hello_world_doc/storage.js 1180 2010-01-01 00:00 bazel-out/k8-fastbuild/bin/hello_world/hello_world_doc/theme.js 3764 2010-01-01 00:00 bazel-out/k8-fastbuild/bin/hello_world/hello_world_doc/wheel.svg --------- ------- 890555 38 files ``` After this patch: ``` Archive: bazel-bin/hello_world/hello_world_doc.zip Length Date Time Name --------- ---------- ----- ---- 0 2010-01-01 00:00 .lock 1792 2010-01-01 00:00 COPYRIGHT.txt 4421 2010-01-01 00:00 FiraSans-LICENSE.txt ... 2132 2010-01-01 00:00 storage.js 1180 2010-01-01 00:00 theme.js 3764 2010-01-01 00:00 wheel.svg --------- ------- 890555 38 files ``` wchargin-branch: rustdoc-strip-prefix wchargin-source: 29978cf3bdb7de6cee154f8c11d0251574c2b104
wchargin-branch: rustdoc-strip-prefix wchargin-source: 69b2e78f1f52c88609aff631c908471c7521c5f7
util/dir_zipper/dir_zipper_lib.py
Outdated
rel = f[len(strip_prefix) :] | ||
spec = "%s=%s" % (rel, f) | ||
args.append(spec) |
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.
Is similar logic not possible within starlark?
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.
The logic is possible in Starlark; the tricky bit is expanding the
directory to its list of contents. I haven’t found a way to do that
other than using the DirectoryExpander
API added in Bazel 3.4.0.
If there is such a way, I would be very happy to switch to it instead of
calling out to this utility.
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 the quick review! Happy to discuss further.
util/dir_zipper/dir_zipper_lib.py
Outdated
rel = f[len(strip_prefix) :] | ||
spec = "%s=%s" % (rel, f) | ||
args.append(spec) |
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.
The logic is possible in Starlark; the tricky bit is expanding the
directory to its list of contents. I haven’t found a way to do that
other than using the DirectoryExpander
API added in Bazel 3.4.0.
If there is such a way, I would be very happy to switch to it instead of
calling out to this utility.
wchargin-branch: rustdoc-strip-prefix wchargin-source: 40227180c7f910d9f76716cf42621e08e5f808a1
wchargin-branch: rustdoc-strip-prefix wchargin-source: 8c46290195fc0668f3126589fd07ee863df8749f
wchargin-branch: rustdoc-strip-prefix wchargin-source: 838287ca34eb69c27f62e4a0900dbb7ac6a3ebd0
What's the status here? Is this ready for review again? |
No; I haven’t gotten around to addressing all comments. Will re-request |
wchargin-branch: rustdoc-strip-prefix wchargin-source: ea88a0484df0608cb08521fb4cde2d4dc7904553
wchargin-branch: rustdoc-strip-prefix wchargin-source: ea88a0484df0608cb08521fb4cde2d4dc7904553
Friendly ping here. This change sounds like a great addition 😃 |
wchargin-branch: rustdoc-strip-prefix wchargin-source: aba05e35e129db74d032bcbfdb7764233a2d94ce
Okay: I’ve rebased master. This patch seems to work fine. I’m having |
The Zip archives emitted by
rust_doc
rules used to contain a long/bazel-bin/k8-fastbuild/bin/path/to/target
prefix before each archiveentry name. This made it hard to work with the generated archive. This
patch adds a transformation to strip the bin-dir prefix, leaving only
the path to the target. We leave the path to the target so that multiple
rust_doc
zip outputs within one workspace can be meaningfully expandedinto the same directory.
This could be written in Starlark using the
DirectoryExpander
API, butthat was only introduced in Bazel 3.4.0. Since we have a minimum Bazel
version of 0.17.1, we instead write the helper as a small Rust script.
Fixes #471.
Test Plan:
Unit tests included. As an end-to-end test, run
to list the contents of the built
hello_world_doc.zip
archive. Beforethis patch, the result was like:
After this patch:
wchargin-branch: rustdoc-strip-prefix