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 - (stdin) support in rustdoc #124611

Merged
merged 3 commits into from May 18, 2024
Merged

Add - (stdin) support in rustdoc #124611

merged 3 commits into from May 18, 2024

Conversation

Urgau
Copy link
Contributor

@Urgau Urgau commented May 2, 2024

This PR adds support for the special - input which threats the input as coming from stdin instead of being a filepath.

Doing this also makes rustdoc consistent with rustc and every other tools. Full motivation.

Fixes #123671
r? @fmease

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels May 2, 2024
@rustbot
Copy link
Collaborator

rustbot commented May 2, 2024

The run-make-support library was changed

cc @jieyouxu

Some changes occurred in run-make tests.

cc @jieyouxu

@camelid camelid added the needs-fcp This change is insta-stable, so needs a completed FCP to proceed. label May 2, 2024
fmease added a commit to fmease/rust that referenced this pull request May 3, 2024
Add support for inputing via stdin with run-make-support

This PR adds the facility to set a input bytes that will be passed via the standard input.

This is useful for testing `rustc -` (and soon `rustdoc -`).

In rust-lang#124611 took the approach of having a dedicated `run` method but it is not very convenient to use and would necessitate many functions, one for success, one for fail, ...

Instead this PR takes a different approach and allows setting the input bytes as if it were a parameter and when calling the (now custom) `output` function, we write the input bytes into stdin. I think this gives us maximum flexibility in the implementation and a simple interface for users.

To test this new logic I ported `tests/run-make/stdin-non-utf8/` to an `rmake.rs` one.

r? ``@jieyouxu``
Copy link
Member

@fmease fmease left a comment

Choose a reason for hiding this comment

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

Thanks, that's phenomenal! I have some small suggestions and questions.
Looks good overall but ofc, let's wait for the “rmake stdin” PR of yours that you mentioned. After that I'm gonna ping T-rustdoc and ask them for a FCP-merge.

tests/run-make/stdin-rustdoc/rmake.rs Outdated Show resolved Hide resolved
src/librustdoc/core.rs Show resolved Hide resolved
src/librustdoc/config.rs Outdated Show resolved Hide resolved
src/librustdoc/core.rs Outdated Show resolved Hide resolved
tests/run-make/stdin-rustdoc/rmake.rs Outdated Show resolved Hide resolved
@fmease fmease added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 3, 2024
@fmease
Copy link
Member

fmease commented May 3, 2024

Ofc, technically technically technically speaking this constitutes a breaking change but that's only theoretical in nature. On *nix systems, ppl can name their files -. This PR would break the following:

# Create a file called `-`:
printf 'pub fn omg() {}' > -
# Yes, we've just created a file called `-`.
# On the command-line, run the following to see the output:
< -
# Now document our wonderful crate:
rustdoc - --crate-name dash
# Docs were generated:
"$BROWSER" ./doc/dash/index.html

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request May 3, 2024
Add support for inputing via stdin with run-make-support

This PR adds the facility to set a input bytes that will be passed via the standard input.

This is useful for testing `rustc -` (and soon `rustdoc -`).

In rust-lang#124611 took the approach of having a dedicated `run` method but it is not very convenient to use and would necessitate many functions, one for success, one for fail, ...

Instead this PR takes a different approach and allows setting the input bytes as if it were a parameter and when calling the (now custom) `output` function, we write the input bytes into stdin. I think this gives us maximum flexibility in the implementation and a simple interface for users.

To test this new logic I ported `tests/run-make/stdin-non-utf8/` to an `rmake.rs` one.

r? `@jieyouxu`
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request May 3, 2024
Rollup merge of rust-lang#124612 - Urgau:run-make-stdin, r=jieyouxu

Add support for inputing via stdin with run-make-support

This PR adds the facility to set a input bytes that will be passed via the standard input.

This is useful for testing `rustc -` (and soon `rustdoc -`).

In rust-lang#124611 took the approach of having a dedicated `run` method but it is not very convenient to use and would necessitate many functions, one for success, one for fail, ...

Instead this PR takes a different approach and allows setting the input bytes as if it were a parameter and when calling the (now custom) `output` function, we write the input bytes into stdin. I think this gives us maximum flexibility in the implementation and a simple interface for users.

To test this new logic I ported `tests/run-make/stdin-non-utf8/` to an `rmake.rs` one.

r? `@jieyouxu`
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 3, 2024
src/doc/rustdoc/src/command-line-arguments.md Outdated Show resolved Hide resolved
src/librustdoc/config.rs Outdated Show resolved Hide resolved
src/librustdoc/lib.rs Outdated Show resolved Hide resolved
@fmease
Copy link
Member

fmease commented May 4, 2024

Hey there @rust-lang/rustdoc, I propose merging this1 after an FCP.

This PR updates rustdoc's CLI to recognize the INPUT argument - (dash) as instructing rustdoc to read the source code from STDIN instead of from a path. Apart from the fact that this is a common CLI convention, it's also consistent with rustc's CLI.

Motivation:

  1. Consistency with rustc's CLI
  2. Doing what is expected from CLI applications
  3. Enabling power users of the rustdoc CLI (i.e., rustdoc & rustc devs)
    • to very quickly check if rustdoc accepts certain source code and/or
    • to rapidly generate docs for small snippets
    • for example during a rustdoc meeting where time is key
    • demo:
      1. $ printf 'pub fn f() -> impl Iterator { 0 }' | rustdoc -
      2. "Oh wow, rustdoc accepts this code..."
      3. "...wait — sanity check — rustc hopefully 🤞 doesn't accept that..."
      4. BSBS a.k.a. $ printf 'pub fn f() -> impl Iterator { 0 }' | rustc -
      5. "Indeed 😌, it doesn't"
      6. "Ah yes, now I remember ... rustdoc doesn't run all of rustc's semantic analysis steps, all good"

Maintenance Cost: Very low (next to zero)
Impact: Low

Potential Concerns:

  1. (negligible) It's technically speaking a breaking change on *nix systems. See my comment above
  2. At least on *nix systems (and by extension in WSL), you can already express this, so this new minor feature “doesn't gain us anything”.
    • E.g., printf 'pub fn f() {}' | rustdoc /dev/stdin (sh)
    • E.g., rustdoc <(printf 'pub fn f() {}') (sh)
    • However,
      • these alternatives are more verbose & obscure and
      • they don't work on Windows (outside of WSL) as far as I'm aware (I'm not a Windows dev, so I don't know the specifics)

Footnotes

  1. Modulo some smaller tweaks to the docs & the impl. See my latest review comments.

@fmease fmease added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 4, 2024
@Manishearth
Copy link
Member

I think we should land this, and I'm surprised this wasn't previously supported

@GuillaumeGomez
Copy link
Member

I'm also surprised it's not already there. Let's start the FCP then.

@rfcbot fcp merge

@rfcbot
Copy link

rfcbot commented May 4, 2024

Team member @GuillaumeGomez has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. and removed proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. labels May 4, 2024
@rfcbot
Copy link

rfcbot commented May 8, 2024

🔔 This is now entering its final comment period, as per the review above. 🔔

@fmease fmease removed the needs-fcp This change is insta-stable, so needs a completed FCP to proceed. label May 12, 2024
@riking
Copy link

riking commented May 17, 2024

re alternatives: If someone is actually putting source code in a file named -, you can still operate on it by making a path relative to the current directory: rustdoc ./- or rustdoc .\-.

@rfcbot rfcbot added finished-final-comment-period The final comment period is finished for this PR / Issue. to-announce Announce this issue on triage meeting and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels May 18, 2024
@rfcbot
Copy link

rfcbot commented May 18, 2024

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

This will be merged soon.

@GuillaumeGomez
Copy link
Member

Thanks everyone!

@bors r+

@bors
Copy link
Contributor

bors commented May 18, 2024

📌 Commit 7e1dc74 has been approved by GuillaumeGomez

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-author Status: This is awaiting some action (such as code changes or more information) from the author. S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). labels May 18, 2024
@bors
Copy link
Contributor

bors commented May 18, 2024

⌛ Testing commit 7e1dc74 with merge bb97203...

@bors
Copy link
Contributor

bors commented May 18, 2024

☀️ Test successful - checks-actions
Approved by: GuillaumeGomez
Pushing bb97203 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 18, 2024
@bors bors merged commit bb97203 into rust-lang:master May 18, 2024
7 checks passed
@rustbot rustbot added this to the 1.80.0 milestone May 18, 2024
@Urgau Urgau deleted the rustdoc-stdin branch May 18, 2024 13:07
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (bb97203): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

This benchmark run did not return any relevant results for this metric.

Cycles

Results (primary -4.1%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-4.1% [-4.1%, -4.1%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -4.1% [-4.1%, -4.1%] 1

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 667.741s -> 668.952s (0.18%)
Artifact size: 316.07 MiB -> 316.33 MiB (0.08%)

lnicola pushed a commit to lnicola/rust-analyzer that referenced this pull request May 19, 2024
Add `-` (stdin) support in rustdoc

This PR adds support for the special `-` input which threats the input as coming from *stdin* instead of being a filepath.

Doing this also makes `rustdoc` consistent with `rustc` and ~~every~~ other tools. Full [motivation](rust-lang/rust#124611 (comment)).

Fixes rust-lang/rust#123671
r? `@fmease`
RalfJung pushed a commit to RalfJung/miri that referenced this pull request May 19, 2024
Add `-` (stdin) support in rustdoc

This PR adds support for the special `-` input which threats the input as coming from *stdin* instead of being a filepath.

Doing this also makes `rustdoc` consistent with `rustc` and ~~every~~ other tools. Full [motivation](rust-lang/rust#124611 (comment)).

Fixes rust-lang/rust#123671
r? `@fmease`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. to-announce Announce this issue on triage meeting
Projects
None yet
Development

Successfully merging this pull request may close these issues.

rustdoc doesn't support reading from STDIN via the fake path - (dash)
10 participants