cargo
cargo copied to clipboard
Impossible to generate JSON documentation from `cargo rustdoc`
It seems like cargo
unconditionally creates a directory and adds a -o
argument making it impossible to generate JSON documentation of a crate.
Maybe cargo should not append the -o
argument if the extra opts supplied by the user includes -o
? or maybe cargo doc
should have an option to generate JSON documentation?
➜ /tmp cargo new foo
➜ /tmp cd foo
➜ foo git:(master) ✗ cargo rustdoc --verbose -- -w json
Documenting foo v0.1.0 (file:///private/tmp/foo)
Running `rustdoc src/lib.rs --crate-name foo -o /private/tmp/foo/target/doc -w json -L dependency=/private/tmp/foo/target/debug -L dependency=/private/tmp/foo/target/debug/deps`
thread '<unnamed>' panicked at 'failed to write json: Is a directory (os error 21)', ../src/librustdoc/lib.rs:298
Could not document `foo`.
Caused by:
Process didn't exit successfully: `rustdoc src/lib.rs --crate-name foo -o /private/tmp/foo/target/doc -w json -L dependency=/private/tmp/foo/target/debug -L dependency=/private/tmp/foo/target/debug/deps` (exit code: 101)
➜ foo git:(master) ✗ cargo rustdoc --verbose -- -w json -o doc.json
Documenting foo v0.1.0 (file:///private/tmp/foo)
Running `rustdoc src/lib.rs --crate-name foo -o /private/tmp/foo/target/doc -w json -o doc.json -L dependency=/private/tmp/foo/target/debug -L dependency=/private/tmp/foo/target/debug/deps`
Option 'output' given more than once.
Could not document `foo`.
Caused by:
Process didn't exit successfully: `rustdoc src/lib.rs --crate-name foo -o /private/tmp/foo/target/doc -w json -o doc.json -L dependency=/private/tmp/foo/target/debug -L dependency=/private/tmp/foo/target/debug/deps` (exit code: 1)
Would you accept a PR adding the --output-format
flag to cargo doc
?
This is kinda similar to how you can't specify -o
and --out-dir
to cargo rustc
, so I'm not sure what the best way to handle this would be.
This is perhaps able to be closed as fixed, since cargo rustdoc -- -Zunstable-options --output-format json
works fine on nightly at the moment.
This is perhaps able to be closed as fixed, since
cargo rustdoc -- -Zunstable-options --output-format json
works fine on nightly at the moment.
Thanks for the triage. We track making --output-format
an option in #12103. Closing.