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

Add unstable --output-format option to cargo rustdoc #12252

Merged
merged 1 commit into from
Jan 11, 2024

Conversation

charmitro
Copy link
Contributor

@charmitro charmitro commented Jun 10, 2023

Add unstable --output-format option to "rustdoc"

We achieved this by:

  • Handle --output-format argument, accepting html or json
  • A new field json in CompileMode::Doc.
  • If json is passed, we append the following in
    prepare_rustdoc:
    1. -Zunstable-options
    2. --output-format=json

Fixes #12103

@rustbot
Copy link
Collaborator

rustbot commented Jun 10, 2023

r? @ehuss

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added A-cli Area: Command-line interface, option parsing, etc. A-cli-help Area: built-in command-line help A-documenting-cargo-itself Area: Cargo's documentation Command-doc Command-rustdoc S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 10, 2023
@charmitro
Copy link
Contributor Author

I'm a little confused about the -Zunstable-options etc. Any comment on that will help.

Copy link
Member

@weihanglo weihanglo 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 contribution!

Haven't read through the entire change. Just wondering if you could add tests that verify without the -Z flag Cargo will fail, for both rustdoc and doc commands.

@charmitro
Copy link
Contributor Author

Thanks for the contribution!

Haven't read through the entire change. Just wondering if you could add tests that verify without the -Z flag Cargo will fail, for both rustdoc and doc commands.

Thanks! Added a couple more.

@charmitro charmitro force-pushed the master branch 5 times, most recently from 3a3bc74 to f3eb1e6 Compare June 11, 2023 08:35
@charmitro charmitro requested a review from weihanglo June 12, 2023 06:52
Copy link
Member

@weihanglo weihanglo 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 contribution. Really appreciate the effort of working on this.

However, the current implementation went a bit off the rails. There are a few parts we can discuss.

Fingerprint detection for <crate>.json

#12103 is an issue originated from #12100. The most important line in description of #12103 is missing in the current patch:

This would allow cargo to reason about it and take it into account in the fingerprinting logic.

If we look into #12100 carefully, we shall the change touched this piece of code:

let path = self
.out_dir(unit)
.join(unit.target.crate_name())
.join("index.html");

This is the core logic Cargo determines where final output artifacts are located. We should do some trict here in order to make the fingerprint (the re-compile detection) takes <crate>.json into account.

In order to do so, Unit or some other types involved in the above code may need to know about --output-format. This is one non-easy part.

Where to pass the --output-format to rustdoc

On the other hand, we need a place to apppend rustdoc --output-format. The current fix found a place target_rustdoc_args, which is just a coincidence. It is for cargo rustdoc -- <args> trailing args only. Cargo should have a way to prevent contributor adding args into it (probably a way to make the semantic clearer). What we need is like --crate-type, which was also a cargo rustc -- --crate-type trailing argument and then got promoted as a normal argument. Presumbly we can follow its tracking issue to see what we can design for --output-format for rustdoc.

Tests to verify the behavior

The current added tests are good enough to verify -Z flag on-off and basic usage of `--output-format. Some cases are missing:

  • Should bail when without -Z unstable-options.
  • No recompile of run the same command multiple times.
  • Recompile if change format.
  • Check if each dependency outputs <crate>json for cargo doc.
  • Check if only the requested package outputs <crate>.json for cargo rustdoc.

Focus on cargo rustdoc maybe?

Chances are that the output <crate>.json may collide with each other. Search collision_doc in this testsuite and you'll find some examples of doc collisions. We may or may not need to fix it. Maybe just make JSON collides like what HTML have done so far. However, if you do feel working on both cargo doc and cargo rustdoc are too distacting, we can focus on cargo rustdoc first. That's also the original issue author suggesting.


Sorry I don't have too many ideas on te implementaion side at this moment. I'll try writing down more thoughts if needed.

src/cargo/ops/cargo_doc.rs Outdated Show resolved Hide resolved
src/cargo/ops/cargo_doc.rs Outdated Show resolved Hide resolved
src/bin/cargo/commands/rustdoc.rs Outdated Show resolved Hide resolved
src/bin/cargo/commands/doc.rs Outdated Show resolved Hide resolved
src/cargo/util/command_prelude.rs Outdated Show resolved Hide resolved
src/doc/man/cargo-doc.md Outdated Show resolved Hide resolved
src/doc/man/includes/options-output-format.md Outdated Show resolved Hide resolved
src/cargo/ops/cargo_doc.rs Outdated Show resolved Hide resolved
src/bin/cargo/commands/rustdoc.rs Outdated Show resolved Hide resolved
@ehuss
Copy link
Contributor

ehuss commented Jun 14, 2023

r? @weihanglo

It looks like you have this covered, but feel free to reassign it back to me if you want.

@rustbot rustbot assigned weihanglo and unassigned ehuss Jun 14, 2023
@charmitro
Copy link
Contributor Author

charmitro commented Jun 17, 2023

Fingerprint detection for <crate>.json

#12103 is an issue originated from #12100. The most important line in description of #12103 is missing in the current patch:

This would allow cargo to reason about it and take it into account in the fingerprinting logic.

If we look into #12100 carefully, we shall the change touched this piece of code:

let path = self
.out_dir(unit)
.join(unit.target.crate_name())
.join("index.html");

This is the core logic Cargo determines where final output artifacts are located. We should do some trict here in order to make the fingerprint (the re-compile detection) takes <crate>.json into account.

In order to do so, Unit or some other types involved in the above code may need to know about --output-format. This is one non-easy part.

Is it safe to say that we should add a, e.g. json: bool or output_format: OutputFormat in CompileMode::Doc so we can determine whether the fingerprint should look for index.html or <crate>.json?

@weihanglo
Copy link
Member

Is it safe to say that we should add a, e.g. json: bool or output_format: OutputFormat in CompileMode::Doc so we can determine whether the fingerprint should look for index.html or <crate>.json?

It's really tempting to do that! I feel a bit uncertain to add more fields onto CompileMode::Doc though I cannot find any better place than that. CompileMode is also already tracked in the fingerprint, so recompile should be automatically detected. I think it worth giving an attempt.

@weihanglo
Copy link
Member

@ehuss do you have any input on adding a new field on CompileMode::Doc? Is there any better alternative?

@ehuss
Copy link
Contributor

ehuss commented Jun 22, 2023

CompileMode::Doc seems like the correct place, especially with output computation and fingerprinting being involved. I would also expect things like calc_outputs to get updated.

@charmitro
Copy link
Contributor Author

CompileMode::Doc seems like the correct place, especially with output computation and fingerprinting being involved. I would also expect things like calc_outputs to get updated.

Ack.

I will move forward with this and the rest of the requested changes and ping back. I will try to focus on cargo rustdoc for now and if the waters are calm I will also propose the cargo doc also.

@rustbot rustbot added the A-layout Area: target output directory layout, naming, and organization label Jun 30, 2023
@charmitro
Copy link
Contributor Author

PR updated. All comments were addressed.

A major change in this revision is allowing --open with --output-format json.

Copy link
Member

@weihanglo weihanglo 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 update!

There are some nits and unresolved comments, and then we're ready to go!

src/bin/cargo/commands/rustdoc.rs Outdated Show resolved Hide resolved
We achieved this by:
   * Handle `--output-format` argument, accepting `html` or `json`
   * If `json` is passed, we append the following in
   `prepare_rustdoc`:
     	1. `-Zunstable-options`
	2. `--output-format`

Fixes rust-lang#12103

Signed-off-by: Charalampos Mitrodimas <charmitro@posteo.net>
@charmitro
Copy link
Contributor Author

Thanks for the update!

There are some nits and unresolved comments, and then we're ready to go!

* [Add unstable `--output-format` option to  `cargo rustdoc` #12252 (comment)](https://github.com/rust-lang/cargo/pull/12252#discussion_r1448324026)

* [Add unstable `--output-format` option to  `cargo rustdoc` #12252 (comment)](https://github.com/rust-lang/cargo/pull/12252#discussion_r1448324634)

Resolved!

@weihanglo
Copy link
Member

Great job!

Thanks a lot for the collaboration :)

@bors r+

@bors
Copy link
Contributor

bors commented Jan 11, 2024

📌 Commit 9276399 has been approved by weihanglo

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 11, 2024
@weihanglo
Copy link
Member

@charmitro

Could you add a new doc entry of https://doc.rust-lang.org/nightly/cargo/reference/unstable.html for this feature?

You can take this as a reference: 4e45f58#diff-e35cef716988e9f7122a9c90479aa9204e61d1f41b094c0d183a44e0ca271eaaR83-R469

I've created the tracking issue here #13283

@charmitro
Copy link
Contributor Author

@charmitro

Could you add a new doc entry of https://doc.rust-lang.org/nightly/cargo/reference/unstable.html for this feature?

You can take this as a reference: 4e45f58#diff-e35cef716988e9f7122a9c90479aa9204e61d1f41b094c0d183a44e0ca271eaaR83-R469

I've created the tracking issue here #13283

In this PR or create a follow-up?

@weihanglo
Copy link
Member

This PR is now in the bors merge queue, so a follow-up would be better :)

charmitro added a commit to charmitro/cargo that referenced this pull request Jan 11, 2024
This is a follow-up to rust-lang#12252.

Signed-off-by: Charalampos Mitrodimas <charmitro@posteo.net>
charmitro added a commit to charmitro/cargo that referenced this pull request Jan 11, 2024
This is a follow-up to rust-lang#12252.

Signed-off-by: Charalampos Mitrodimas <charmitro@posteo.net>
@bors
Copy link
Contributor

bors commented Jan 11, 2024

⌛ Testing commit 9276399 with merge f4e2eac...

@bors
Copy link
Contributor

bors commented Jan 11, 2024

☀️ Test successful - checks-actions
Approved by: weihanglo
Pushing f4e2eac to master...

@bors bors merged commit f4e2eac into rust-lang:master Jan 11, 2024
20 checks passed
charmitro added a commit to charmitro/cargo that referenced this pull request Jan 11, 2024
This is a follow-up to rust-lang#12252.

Signed-off-by: Charalampos Mitrodimas <charmitro@posteo.net>
charmitro added a commit to charmitro/cargo that referenced this pull request Jan 11, 2024
This is a follow-up to rust-lang#12252.

Signed-off-by: Charalampos Mitrodimas <charmitro@posteo.net>
bors added a commit that referenced this pull request Jan 11, 2024
 Add documentation entry for unstable `--output-format` flag

This is a follow-up to #12252 adding a documentation entry for the newly supported unstable flag `--output-format`.
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 13, 2024
Update cargo

8 commits in 3e428a38a34e820a461d2cc082e726d3bda71bcb..84976cd699f4aea56cb3a90ce3eedeed9e20d5a5
2024-01-09 20:46:36 +0000 to 2024-01-12 15:55:43 +0000
- fix(resolver): do not panic when sorting empty summaries (rust-lang/cargo#13287)
- Implementation of shallow libgit2 fetches behind an unstable flag (rust-lang/cargo#13252)
- Add documentation entry for unstable `--output-format` flag (rust-lang/cargo#13284)
- doc: add `public` info in `cargo-add` man page. (rust-lang/cargo#13272)
- More docs on prerelease compat (rust-lang/cargo#13286)
- Add unstable `--output-format` option to  `cargo rustdoc` (rust-lang/cargo#12252)
- feat: Add `rustc` style errors for manifest parsing (rust-lang/cargo#13172)
- Document why `du` function uses mutex (rust-lang/cargo#13273)

r? ghost
@rustbot rustbot added this to the 1.77.0 milestone Jan 13, 2024
stupendoussuperpowers pushed a commit to stupendoussuperpowers/cargo that referenced this pull request Feb 28, 2024
This is a follow-up to rust-lang#12252.

Signed-off-by: Charalampos Mitrodimas <charmitro@posteo.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-build-execution Area: anything dealing with executing the compiler A-cli Area: Command-line interface, option parsing, etc. A-cli-help Area: built-in command-line help A-documenting-cargo-itself Area: Cargo's documentation A-layout Area: target output directory layout, naming, and organization Command-doc Command-rustdoc S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add an unstable --output-format option to cargo rustdoc
5 participants