1
Fork 0

Put back output-format option for show-coverage

This commit is contained in:
Guillaume Gomez 2019-11-16 16:12:09 +01:00
parent 6af4fd385e
commit 8858d71d28
4 changed files with 56 additions and 9 deletions

View file

@ -1,5 +1,6 @@
use std::collections::BTreeMap;
use std::ffi::OsStr;
use std::convert::TryFrom;
use std::fmt;
use std::path::PathBuf;
@ -24,6 +25,33 @@ use crate::opts;
use crate::passes::{self, Condition, DefaultPassOption};
use crate::theme;
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum OutputFormat {
Json,
HTML,
}
impl OutputFormat {
pub fn is_json(&self) -> bool {
match *self {
OutputFormat::Json => true,
_ => false,
}
}
}
impl TryFrom<&str> for OutputFormat {
type Error = String;
fn try_from(value: &str) -> Result<Self, Self::Error> {
match value {
"json" => Ok(OutputFormat::Json),
"html" => Ok(OutputFormat::HTML),
_ => Err(format!("unknown output format `{}`", value)),
}
}
}
/// Configuration options for rustdoc.
#[derive(Clone)]
pub struct Options {
@ -115,6 +143,8 @@ pub struct Options {
pub crate_version: Option<String>,
/// Collected options specific to outputting final pages.
pub render_options: RenderOptions,
/// Output format rendering (used only for "show-coverage" option for the moment)
pub output_format: Option<OutputFormat>,
}
impl fmt::Debug for Options {
@ -425,14 +455,6 @@ impl Options {
}
}
match matches.opt_str("w").as_ref().map(|s| &**s) {
Some("html") | None => {}
Some(s) => {
diag.struct_err(&format!("unknown output format: {}", s)).emit();
return Err(1);
}
}
let index_page = matches.opt_str("index-page").map(|s| PathBuf::from(&s));
if let Some(ref index_page) = index_page {
if !index_page.is_file() {
@ -469,6 +491,23 @@ 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 {
diag.struct_err("json output format isn't supported for doc generation")
.emit();
return Err(1);
}
Some(o)
}
Err(e) => {
diag.struct_err(&e).emit();
return Err(1);
}
}
None => None,
};
let crate_name = matches.opt_str("crate-name");
let proc_macro_crate = crate_types.contains(&CrateType::ProcMacro);
let playground_url = matches.opt_str("playground-url");
@ -553,6 +592,7 @@ impl Options {
generate_search_filter,
generate_redirect_pages,
},
output_format,
})
}
@ -568,6 +608,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") {
continue;
}
let mut err =
diag.struct_warn(&format!("the '{}' flag is considered deprecated", flag));
err.warn(

View file

@ -228,6 +228,7 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
mut manual_passes,
display_warnings,
render_options,
output_format,
..
} = options;
@ -385,6 +386,7 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
let mut renderinfo = RenderInfo::default();
renderinfo.access_levels = access_levels;
renderinfo.output_format = output_format;
let mut ctxt = DocContext {
tcx,

View file

@ -60,7 +60,7 @@ use serde::ser::SerializeSeq;
use serde::{Serialize, Serializer};
use crate::clean::{self, AttributesExt, Deprecation, GetDefId, SelfTy};
use crate::config::RenderOptions;
use crate::config::{OutputFormat, RenderOptions};
use crate::docfs::{DocFS, ErrorStorage, PathError};
use crate::doctree;
use crate::html::escape::Escape;
@ -270,6 +270,7 @@ pub struct RenderInfo {
pub deref_trait_did: Option<DefId>,
pub deref_mut_trait_did: Option<DefId>,
pub owned_box_did: Option<DefId>,
pub output_format: Option<OutputFormat>,
}
// Helper structs for rendering items/sidebars and carrying along contextual

View file

@ -139,6 +139,7 @@ impl Cache {
deref_trait_did,
deref_mut_trait_did,
owned_box_did,
..
} = renderinfo;
let external_paths =