Compute the right output filenames for rustdoc invocations that request the JSON format #12100
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR try to resolve?
cargo
currently assumes that all invocations ofcargo rustdoc
produce HTML files as outputs.This assumption breaks down for invocations of
cargo rustdoc
that instructrustdoc
to produce documentation in a different format (i.e. JSON).As a consequence, running the very same command multiple times (
cargo +nightly rustdoc --lib -p <NAME> -- -Zunstable-options -wjson
) recomputes the documentation every single time, instead of detecting that the pre-existing file is still fresh.This PR fixes the logic in
cargo
to correctly detect the output filename when the JSON format is required.How should we test and review this PR?
I've added a test to confirm that:
<crate name>.json
);Additional information
An alternative implementation strategy could see us adding
--output-format
as acargo rustdoc
option, rather than trying to parse the extra arguments being passed torustdoc
.