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 --output-format json for Rustdoc on nightly #74955

Merged
merged 1 commit into from
Jul 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/librustdoc/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ impl Options {
let output_format = match matches.opt_str("output-format") {
Some(s) => match OutputFormat::try_from(s.as_str()) {
Ok(o) => {
if o.is_json() && !show_coverage {
if o.is_json() && !(show_coverage || nightly_options::is_nightly_build()) {
diag.struct_err("json output format isn't supported for doc generation")
.emit();
return Err(1);
Expand Down Expand Up @@ -626,7 +626,9 @@ fn check_deprecated_options(matches: &getopts::Matches, diag: &rustc_errors::Han

for flag in deprecated_flags.iter() {
if matches.opt_present(flag) {
if *flag == "output-format" && matches.opt_present("show-coverage") {
if *flag == "output-format"
&& (matches.opt_present("show-coverage") || nightly_options::is_nightly_build())
{
continue;
}
let mut err =
Expand Down
47 changes: 47 additions & 0 deletions src/librustdoc/json/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use crate::clean;
use crate::config::{RenderInfo, RenderOptions};
use crate::error::Error;
use crate::formats::cache::Cache;
use crate::formats::FormatRenderer;

use rustc_span::edition::Edition;

#[derive(Clone)]
pub struct JsonRenderer {}

impl FormatRenderer for JsonRenderer {
fn init(
_krate: clean::Crate,
_options: RenderOptions,
_render_info: RenderInfo,
_edition: Edition,
_cache: &mut Cache,
) -> Result<(Self, clean::Crate), Error> {
unimplemented!()
}

fn item(&mut self, _item: clean::Item, _cache: &Cache) -> Result<(), Error> {
unimplemented!()
}

fn mod_item_in(
&mut self,
_item: &clean::Item,
_item_name: &str,
_cache: &Cache,
) -> Result<(), Error> {
unimplemented!()
}

fn mod_item_out(&mut self, _item_name: &str) -> Result<(), Error> {
unimplemented!()
}

fn after_krate(&mut self, _krate: &clean::Crate, _cache: &Cache) -> Result<(), Error> {
unimplemented!()
}

fn after_run(&mut self, _diag: &rustc_errors::Handler) -> Result<(), Error> {
unimplemented!()
}
}
44 changes: 30 additions & 14 deletions src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ mod error;
mod fold;
crate mod formats;
pub mod html;
mod json;
mod markdown;
mod passes;
mod test;
Expand Down Expand Up @@ -450,6 +451,28 @@ fn wrap_return(diag: &rustc_errors::Handler, res: Result<(), String>) -> i32 {
}
}

fn run_renderer<T: formats::FormatRenderer>(
krate: clean::Crate,
renderopts: config::RenderOptions,
render_info: config::RenderInfo,
diag: &rustc_errors::Handler,
edition: rustc_span::edition::Edition,
) -> i32 {
match formats::run_format::<T>(krate, renderopts, render_info, &diag, edition) {
Ok(_) => rustc_driver::EXIT_SUCCESS,
Err(e) => {
let mut msg = diag.struct_err(&format!("couldn't generate documentation: {}", e.error));
let file = e.file.display().to_string();
if file.is_empty() {
msg.emit()
} else {
msg.note(&format!("failed to create or modify \"{}\"", file)).emit()
}
rustc_driver::EXIT_FAILURE
}
}
}

fn main_options(options: config::Options) -> i32 {
let diag = core::new_handler(options.error_format, None, &options.debugging_options);

Expand Down Expand Up @@ -480,6 +503,7 @@ fn main_options(options: config::Options) -> i32 {
let result = rustc_driver::catch_fatal_errors(move || {
let crate_name = options.crate_name.clone();
let crate_version = options.crate_version.clone();
let output_format = options.output_format;
let (mut krate, renderinfo, renderopts) = core::run_core(options);

info!("finished with rustc");
Expand All @@ -502,20 +526,12 @@ fn main_options(options: config::Options) -> i32 {
info!("going to format");
let (error_format, edition, debugging_options) = diag_opts;
let diag = core::new_handler(error_format, None, &debugging_options);
match formats::run_format::<html::render::Context>(
krate, renderopts, renderinfo, &diag, edition,
) {
Ok(_) => rustc_driver::EXIT_SUCCESS,
Err(e) => {
let mut msg =
diag.struct_err(&format!("couldn't generate documentation: {}", e.error));
let file = e.file.display().to_string();
if file.is_empty() {
msg.emit()
} else {
msg.note(&format!("failed to create or modify \"{}\"", file)).emit()
}
rustc_driver::EXIT_FAILURE
match output_format {
None | Some(config::OutputFormat::Html) => {
run_renderer::<html::render::Context>(krate, renderopts, renderinfo, &diag, edition)
}
Some(config::OutputFormat::Json) => {
run_renderer::<json::JsonRenderer>(krate, renderopts, renderinfo, &diag, edition)
}
}
});
Expand Down