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

rustdoc: Add unstable option to only emit shared/crate-specific files #83478

Merged
merged 5 commits into from
Apr 2, 2021
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
43 changes: 43 additions & 0 deletions src/librustdoc/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::convert::TryFrom;
use std::ffi::OsStr;
use std::fmt;
use std::path::PathBuf;
use std::str::FromStr;

use rustc_data_structures::fx::FxHashMap;
use rustc_session::config::{self, parse_crate_types_from_list, parse_externs, CrateType};
Expand Down Expand Up @@ -266,6 +267,34 @@ crate struct RenderOptions {
/// If `true`, generate a JSON file in the crate folder instead of HTML redirection files.
crate generate_redirect_map: bool,
crate unstable_features: rustc_feature::UnstableFeatures,
crate emit: Vec<EmitType>,
}

#[derive(Copy, Clone, Debug, PartialEq, Eq)]
crate enum EmitType {
Unversioned,
Toolchain,
InvocationSpecific,
}

impl FromStr for EmitType {
type Err = ();

fn from_str(s: &str) -> Result<Self, Self::Err> {
use EmitType::*;
match s {
"unversioned-shared-resources" => Ok(Unversioned),
"toolchain-shared-resources" => Ok(Toolchain),
"invocation-specific" => Ok(InvocationSpecific),
_ => Err(()),
}
}
}

impl RenderOptions {
crate fn should_emit_crate(&self) -> bool {
self.emit.is_empty() || self.emit.contains(&EmitType::InvocationSpecific)
}
}

impl Options {
Expand Down Expand Up @@ -334,6 +363,19 @@ impl Options {
// check for deprecated options
check_deprecated_options(&matches, &diag);

let mut emit = Vec::new();
for list in matches.opt_strs("emit") {
for kind in list.split(',') {
match kind.parse() {
Ok(kind) => emit.push(kind),
Err(()) => {
diag.err(&format!("unrecognized emission type: {}", kind));
return Err(1);
}
}
}
}

let to_check = matches.opt_strs("check-theme");
if !to_check.is_empty() {
let paths = theme::load_css_paths(static_files::themes::LIGHT.as_bytes());
Expand Down Expand Up @@ -641,6 +683,7 @@ impl Options {
unstable_features: rustc_feature::UnstableFeatures::from_environment(
crate_name.as_deref(),
),
emit,
},
crate_name,
output_format,
Expand Down
5 changes: 5 additions & 0 deletions src/librustdoc/formats/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,15 @@ crate fn run_format<'tcx, T: FormatRenderer<'tcx>>(
) -> Result<(), Error> {
let prof = &tcx.sess.prof;

let emit_crate = options.should_emit_crate();
let (mut format_renderer, krate) = prof
.extra_verbose_generic_activity("create_renderer", T::descr())
.run(|| T::init(krate, options, edition, cache, tcx))?;

if !emit_crate {
return Ok(());
}

// Render the crate documentation
let crate_name = krate.name;
let mut work = vec![(format_renderer.make_child_renderer(), krate.module)];
Expand Down
18 changes: 5 additions & 13 deletions src/librustdoc/html/render/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,6 @@ crate struct Context<'tcx> {
rustc_data_structures::static_assert_size!(Context<'_>, 152);

impl<'tcx> Context<'tcx> {
pub(super) fn path(&self, filename: &str) -> PathBuf {
// We use splitn vs Path::extension here because we might get a filename
// like `style.min.css` and we want to process that into
// `style-suffix.min.css`. Path::extension would just return `css`
// which would result in `style.min-suffix.css` which isn't what we
// want.
let (base, ext) = filename.split_once('.').unwrap();
let filename = format!("{}{}.{}", base, self.shared.resource_suffix, ext);
self.dst.join(&filename)
}

pub(super) fn tcx(&self) -> TyCtxt<'tcx> {
self.shared.tcx
}
Expand Down Expand Up @@ -299,6 +288,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
) -> Result<(Self, clean::Crate), Error> {
// need to save a copy of the options for rendering the index page
let md_opts = options.clone();
let emit_crate = options.should_emit_crate();
let RenderOptions {
output,
external_html,
Expand Down Expand Up @@ -404,7 +394,9 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {

let dst = output;
scx.ensure_dir(&dst)?;
krate = sources::render(&dst, &mut scx, krate)?;
if emit_crate {
krate = sources::render(&dst, &mut scx, krate)?;
}

// Build our search index
let index = build_index(&krate, &mut cache, tcx);
Expand Down Expand Up @@ -487,7 +479,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
|buf: &mut Buffer| all.print(buf),
&self.shared.style_files,
);
self.shared.fs.write(&final_file, v.as_bytes())?;
self.shared.fs.write(final_file, v.as_bytes())?;

// Generating settings page.
page.title = "Rustdoc settings";
Expand Down
Loading