cargo icon indicating copy to clipboard operation
cargo copied to clipboard

Impossible to generate JSON documentation from `cargo rustdoc`

Open utkarshkukreti opened this issue 8 years ago • 3 comments

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)

utkarshkukreti avatar Nov 29 '15 09:11 utkarshkukreti

Would you accept a PR adding the --output-format flag to cargo doc?

utkarshkukreti avatar Nov 29 '15 14:11 utkarshkukreti

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.

alexcrichton avatar Nov 30 '15 19:11 alexcrichton

This is perhaps able to be closed as fixed, since cargo rustdoc -- -Zunstable-options --output-format json works fine on nightly at the moment.

obi1kenobi avatar Jul 12 '22 19:07 obi1kenobi

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.

weihanglo avatar May 14 '23 12:05 weihanglo