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

rust_doc: strip directory prefix from archive names #474

Merged
merged 9 commits into from
Dec 12, 2020

Conversation

wchargin
Copy link
Contributor

@wchargin wchargin commented Nov 4, 2020

The Zip archives emitted by rust_doc rules used to contain a long
/bazel-bin/k8-fastbuild/bin/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 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 expanded
into the same directory.

This could be written in Starlark using the DirectoryExpander 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 Rust script.

Fixes #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   hello_world/hello_world_doc/.lock
     1792  2010-01-01 00:00   hello_world/hello_world_doc/COPYRIGHT.txt
     4421  2010-01-01 00:00   hello_world/hello_world_doc/FiraSans-LICENSE.txt
...
     2132  2010-01-01 00:00   hello_world/hello_world_doc/storage.js
     1180  2010-01-01 00:00   hello_world/hello_world_doc/theme.js
     3764  2010-01-01 00:00   hello_world/hello_world_doc/wheel.svg
---------                     -------
   890555                     38 files

wchargin-branch: rustdoc-strip-prefix

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
@google-cla google-cla bot added the cla: yes label Nov 4, 2020
wchargin-branch: rustdoc-strip-prefix
wchargin-source: 69b2e78f1f52c88609aff631c908471c7521c5f7
Comment on lines 23 to 25
rel = f[len(strip_prefix) :]
spec = "%s=%s" % (rel, f)
args.append(spec)
Copy link
Collaborator

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?

Copy link
Contributor Author

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.

rust/repositories.bzl Outdated Show resolved Hide resolved
rust/private/rustdoc.bzl Outdated Show resolved Hide resolved
Copy link
Contributor Author

@wchargin wchargin 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 the quick review! Happy to discuss further.

Comment on lines 23 to 25
rel = f[len(strip_prefix) :]
spec = "%s=%s" % (rel, f)
args.append(spec)
Copy link
Contributor Author

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.

rust/private/rustdoc.bzl Outdated Show resolved Hide resolved
rust/repositories.bzl Outdated Show resolved Hide resolved
wchargin-branch: rustdoc-strip-prefix
wchargin-source: 40227180c7f910d9f76716cf42621e08e5f808a1
wchargin-branch: rustdoc-strip-prefix
wchargin-source: 8c46290195fc0668f3126589fd07ee863df8749f
wchargin-branch: rustdoc-strip-prefix
wchargin-source: 838287ca34eb69c27f62e4a0900dbb7ac6a3ebd0
@UebelAndre
Copy link
Collaborator

What's the status here? Is this ready for review again?

@wchargin
Copy link
Contributor Author

No; I haven’t gotten around to addressing all comments. Will re-request
review through the GitHub UI once I have.

wchargin-branch: rustdoc-strip-prefix
wchargin-source: ea88a0484df0608cb08521fb4cde2d4dc7904553
wchargin-branch: rustdoc-strip-prefix
wchargin-source: ea88a0484df0608cb08521fb4cde2d4dc7904553
@UebelAndre
Copy link
Collaborator

Friendly ping here. This change sounds like a great addition 😃

wchargin-branch: rustdoc-strip-prefix
wchargin-source: aba05e35e129db74d032bcbfdb7764233a2d94ce
@wchargin
Copy link
Contributor Author

wchargin commented Dec 3, 2020

Okay: I’ve rebased master. This patch seems to work fine. I’m having
trouble with the build setup for #475, but I agree that this patch is
nice to have by itself, so feel free to merge if you like.

@wchargin wchargin requested a review from dfreese December 3, 2020 23:43
@dfreese dfreese merged commit 4780f35 into bazelbuild:master Dec 12, 2020
@wchargin wchargin deleted the wchargin-rustdoc-strip-prefix branch December 13, 2020 20:37
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.

rustdoc: zip output should not have bazel-out/k8-fastbuild/... prefix
3 participants