Skip to content

cargo doc --open always respect request_kind#11804

Closed
0xPoe wants to merge 2 commits intorust-lang:masterfrom
0xPoe:rustin-patch-doc-open
Closed

cargo doc --open always respect request_kind#11804
0xPoe wants to merge 2 commits intorust-lang:masterfrom
0xPoe:rustin-patch-doc-open

Conversation

@0xPoe
Copy link
Member

@0xPoe 0xPoe commented Mar 6, 2023

What does this PR try to resolve?

closes #11728

More details:

The open behavior is as follows:
cargo doc --open:

  • Pick the first root unit that was built for host.
  • If none found, pick the first one(whatever it's target is).

cargo doc --target TARGET --open:

  • Pick the first root unit for the given target.
  • If none found, pick the first one(whatever it's target is).

How should we test and review this PR?

See the unit test.

@rustbot
Copy link
Collaborator

rustbot commented Mar 6, 2023

r? @ehuss

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

@rustbot rustbot added Command-doc S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 6, 2023
Copy link
Member Author

@0xPoe 0xPoe left a comment

Choose a reason for hiding this comment

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

This PR still working in the process. I'll add a test later.

@ehuss
Copy link
Contributor

ehuss commented Mar 6, 2023

My suggestion would be to have the following behavior:

  • cargo doc --open:

    Pick the first root unit that was built for host.
    If none found, pick the first one.

  • cargo doc --target TARGET --open:

    Pick the first root unit for the given target.
    If none found, pick the first one.

This may require extending the Compilation struct to include the necessary information. I would suggest iterating over the root units, filtering out the ones for documentation, and storing the required information (the name and kind).

@0xPoe 0xPoe force-pushed the rustin-patch-doc-open branch from 4f08041 to 1adb8c1 Compare March 7, 2023 02:39
@rustbot rustbot added the A-build-execution Area: anything dealing with executing the compiler label Mar 7, 2023
@0xPoe
Copy link
Member Author

0xPoe commented Mar 7, 2023

  • cargo doc --open:
    Pick the first root unit that was built for host.
    If none found, pick the first one.

How does it interact with forced-target?
My thought is:

  1. if the root unit has forced-target, then open the docs of the first root unit built for forced-target.
  2. If there is no forced-target, then open the docs of the first root unit built for the host.
  • cargo doc --target TARGET --open:
    Pick the first root unit for the given target.
    If none found, pick the first one.
  1. If the first root unit has forced-target and it same with --target TARGET, then he docs of the first root unit built for forced-target.
  2. If it is conflict with --target TARGET bail out an error for it.
  3. If there is no forced-target, then open the docs of the first root unit built for the TARGET.

@ehuss
Copy link
Contributor

ehuss commented Mar 7, 2023

How does it interact with forced-target?

It depends, but for the most part the code should not know or care about forced-target. If there is only one root unit, then that's the one that gets opened (whether it is forced-target or not). If there are multiple, such as in a workspace, and one of those is forced-target and the other is not, then it will open the one that is not forced-target.

As for the "first" entry, that is completely arbitrary, and is currently alphabetical I believe.

The operation should be relatively simple, I think it would be something like:

root_units.iter().find(|unit| unit.kind == requested_kind).next().unwrap_or(root_units[0]);

That's a very rough sketch, but the general shape of what I think it should look like.

@0xPoe 0xPoe force-pushed the rustin-patch-doc-open branch from 181c726 to 83863ea Compare March 8, 2023 02:19
@0xPoe 0xPoe changed the title cargo doc --open respect forced-target cargo doc --open always respect request_kind Mar 8, 2023
@0xPoe
Copy link
Member Author

0xPoe commented Mar 8, 2023

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 8, 2023
@0xPoe 0xPoe force-pushed the rustin-patch-doc-open branch from d85b7a3 to 681e938 Compare March 9, 2023 03:08
@0xPoe 0xPoe force-pushed the rustin-patch-doc-open branch from 681e938 to eb8be9d Compare March 9, 2023 03:11
Copy link
Member Author

@0xPoe 0xPoe left a comment

Choose a reason for hiding this comment

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

Self check

@0xPoe 0xPoe marked this pull request as ready for review March 9, 2023 03:12
@0xPoe
Copy link
Member Author

0xPoe commented Mar 9, 2023

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author. labels Mar 9, 2023
@0xPoe
Copy link
Member Author

0xPoe commented Mar 9, 2023

@ehuss Do you have any suggestion about which target I should use in the test on the stable channel? Thanks!

@ehuss
Copy link
Contributor

ehuss commented Mar 10, 2023

The cargo testsuite has various things to help with cross-compiling. At the start of the function, write:

    if cross_compile::disabled() {
        return;
    }

Then, for the target value, use cross_compile::alternate().

@0xPoe 0xPoe force-pushed the rustin-patch-doc-open branch from eb8be9d to 6cd42f8 Compare March 10, 2023 06:38
@0xPoe
Copy link
Member Author

0xPoe commented Mar 10, 2023

The cargo testsuite has various things to help with cross-compiling. At the start of the function, write:

    if cross_compile::disabled() {
        return;
    }

Then, for the target value, use cross_compile::alternate().

Thanks for your help! It works.

@0xPoe 0xPoe requested a review from ehuss March 10, 2023 07:08
@dramforever
Copy link

Hi, just to confirm, cargo doc -p has-forced-target --open falls into the cargo doc --open case and would find the (only?) target has-forced-target and open its docs with the correct triple, is this right?

@ehuss
Copy link
Contributor

ehuss commented Mar 11, 2023

Hi, just to confirm, cargo doc -p has-forced-target --open falls into the cargo doc --open case and would find the (only?) target has-forced-target and open its docs with the correct triple, is this right?

Yes.

@0xPoe 0xPoe force-pushed the rustin-patch-doc-open branch 2 times, most recently from 2f31cd6 to 7f90e71 Compare March 12, 2023 03:35
@0xPoe 0xPoe force-pushed the rustin-patch-doc-open branch from 7f90e71 to a9847e2 Compare March 12, 2023 03:40
@0xPoe
Copy link
Member Author

0xPoe commented Mar 12, 2023

Hi, just to confirm, cargo doc -p has-forced-target --open falls into the cargo doc --open case and would find the (only?) target has-forced-target and open its docs with the correct triple, is this right?

Added doc_and_open_virtual_manifest_one_project test for it.

@0xPoe 0xPoe requested a review from ehuss March 12, 2023 03:42
@ehuss
Copy link
Contributor

ehuss commented Mar 14, 2023

In thinking about this more, I came up with a concern with this approach, to be followed up at #11728 (comment).

@ehuss
Copy link
Contributor

ehuss commented Mar 14, 2023

@rustbot blocked

@rustbot rustbot added S-blocked and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 14, 2023
@0xPoe
Copy link
Member Author

0xPoe commented Apr 11, 2023

@ehuss What should I do to help this PR move forward? Do you think we still need to wait for more discussion about this behavior?

@weihanglo weihanglo added S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted. and removed S-blocked labels Apr 18, 2023
@weihanglo weihanglo marked this pull request as draft April 18, 2023 21:52
@bors
Copy link
Contributor

bors commented Jan 11, 2024

☔ The latest upstream changes (presumably #12252) made this pull request unmergeable. Please resolve the merge conflicts.

@bors bors added the S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author. label Jan 11, 2024
@rustbot
Copy link
Collaborator

rustbot commented Dec 20, 2024

☔ The latest upstream changes (possibly 081d7ba) made this pull request unmergeable. Please resolve the merge conflicts.

@0xPoe 0xPoe closed this Mar 3, 2026
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 Command-doc S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted. S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

'cargo doc --open' seemingly does nothing if target is different from forced-target

6 participants