From b68e8542856a4a4d46a7fd74d9455ad62fe20a78 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Mon, 16 Sep 2019 14:08:14 -0400 Subject: [PATCH] Compute 'rustdoc --crate-type' support when Compilation is created --- src/cargo/core/compiler/build_context/mod.rs | 5 ++-- src/cargo/core/compiler/compilation.rs | 29 ++++++++++---------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/cargo/core/compiler/build_context/mod.rs b/src/cargo/core/compiler/build_context/mod.rs index 04dc112157f..9cb34e3390e 100644 --- a/src/cargo/core/compiler/build_context/mod.rs +++ b/src/cargo/core/compiler/build_context/mod.rs @@ -1,6 +1,5 @@ use std::collections::HashMap; use std::path::{Path, PathBuf}; -use std::rc::Rc; use std::str; use log::debug; @@ -34,7 +33,7 @@ pub struct BuildContext<'a, 'cfg> { pub packages: &'a PackageSet<'cfg>, /// Information about the compiler. - pub rustc: Rc, + pub rustc: Rustc, /// Build information for the host arch. pub host_config: TargetConfig, /// Build information for the target. @@ -54,7 +53,7 @@ impl<'a, 'cfg> BuildContext<'a, 'cfg> { units: &'a UnitInterner<'a>, extra_compiler_args: HashMap, Vec>, ) -> CargoResult> { - let rustc = Rc::new(config.load_global_rustc(Some(ws))?); + let rustc = config.load_global_rustc(Some(ws))?; let host_config = TargetConfig::new(config, &rustc.host)?; let target_config = match build_config.requested_target.as_ref() { diff --git a/src/cargo/core/compiler/compilation.rs b/src/cargo/core/compiler/compilation.rs index 3613aad2fe6..dcd2e1923bf 100644 --- a/src/cargo/core/compiler/compilation.rs +++ b/src/cargo/core/compiler/compilation.rs @@ -2,7 +2,6 @@ use std::collections::{BTreeSet, HashMap, HashSet}; use std::env; use std::ffi::OsStr; use std::path::PathBuf; -use std::rc::Rc; use semver::Version; @@ -76,7 +75,7 @@ pub struct Compilation<'cfg> { primary_unit_rustc_process: Option, target_runner: Option<(PathBuf, Vec)>, - rustc: Rc, + supports_rustdoc_crate_type: bool, } impl<'cfg> Compilation<'cfg> { @@ -113,7 +112,7 @@ impl<'cfg> Compilation<'cfg> { host: bcx.host_triple().to_string(), target: bcx.target_triple().to_string(), target_runner: target_runner(bcx)?, - rustc: bcx.rustc.clone(), + supports_rustdoc_crate_type: supports_rustdoc_crate_type(bcx.config, &bcx.rustc)?, }) } @@ -139,17 +138,6 @@ impl<'cfg> Compilation<'cfg> { Ok(p) } - fn supports_rustdoc_crate_type(&self) -> CargoResult { - // NOTE: Unconditionally return 'true' once support for - // rustdoc '--crate-type' rides to stable - let mut crate_type_test = process(self.config.rustdoc()?); - // If '--crate-type' is not supported by rustcoc, this command - // will exit with an error. Otherwise, it will print a help message, - // and exit successfully - crate_type_test.args(&["--crate-type", "proc-macro", "--help"]); - Ok(self.rustc.cached_output(&crate_type_test).is_ok()) - } - /// See `process`. pub fn rustdoc_process(&self, pkg: &Package, target: &Target) -> CargoResult { let mut p = self.fill_env(process(&*self.config.rustdoc()?), pkg, false)?; @@ -157,7 +145,7 @@ impl<'cfg> Compilation<'cfg> { p.arg(format!("--edition={}", target.edition())); } - if self.supports_rustdoc_crate_type()? { + if self.supports_rustdoc_crate_type { for crate_type in target.rustc_crate_types() { p.arg("--crate-type").arg(crate_type); } @@ -331,3 +319,14 @@ fn target_runner(bcx: &BuildContext<'_, '_>) -> CargoResult CargoResult { + // NOTE: Unconditionally return 'true' once support for + // rustdoc '--crate-type' rides to stable + let mut crate_type_test = process(config.rustdoc()?); + // If '--crate-type' is not supported by rustcoc, this command + // will exit with an error. Otherwise, it will print a help message, + // and exit successfully + crate_type_test.args(&["--crate-type", "proc-macro", "--help"]); + Ok(rustc.cached_output(&crate_type_test).is_ok()) +}