mirror of
https://github.com/rust-lang/cargo
synced 2024-08-25 10:35:53 +00:00
Remove more unused code
This commit is contained in:
parent
d29ac156f2
commit
8331d7d151
|
@ -8,7 +8,6 @@ use crate::util::errors::CargoResult;
|
|||
use crate::util::interning::InternedString;
|
||||
use crate::util::Rustc;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::ffi::OsString;
|
||||
use std::path::PathBuf;
|
||||
|
||||
mod target_info;
|
||||
|
@ -32,7 +31,7 @@ pub struct BuildContext<'a, 'cfg> {
|
|||
pub build_config: &'a BuildConfig,
|
||||
|
||||
/// Extra compiler args for either `rustc` or `rustdoc`.
|
||||
pub extra_compiler_args: HashMap<Unit, Vec<OsString>>,
|
||||
pub extra_compiler_args: HashMap<Unit, Vec<String>>,
|
||||
|
||||
/// Package downloader.
|
||||
///
|
||||
|
@ -60,7 +59,7 @@ impl<'a, 'cfg> BuildContext<'a, 'cfg> {
|
|||
packages: PackageSet<'cfg>,
|
||||
build_config: &'a BuildConfig,
|
||||
profiles: Profiles,
|
||||
extra_compiler_args: HashMap<Unit, Vec<OsString>>,
|
||||
extra_compiler_args: HashMap<Unit, Vec<String>>,
|
||||
target_data: RustcTargetData<'cfg>,
|
||||
roots: Vec<Unit>,
|
||||
unit_graph: UnitGraph,
|
||||
|
@ -124,7 +123,7 @@ impl<'a, 'cfg> BuildContext<'a, 'cfg> {
|
|||
&self.target_data.info(unit.kind).rustdocflags
|
||||
}
|
||||
|
||||
pub fn extra_args_for(&self, unit: &Unit) -> Option<&Vec<OsString>> {
|
||||
pub fn extra_args_for(&self, unit: &Unit) -> Option<&Vec<String>> {
|
||||
self.extra_compiler_args.get(unit)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -101,43 +101,6 @@ pub struct Compilation<'cfg> {
|
|||
target_runners: HashMap<CompileKind, Option<(PathBuf, Vec<String>)>>,
|
||||
}
|
||||
|
||||
impl Doctest {
|
||||
pub fn rustdoc_process(&self, compilation: &Compilation<'_>) -> CargoResult<ProcessBuilder> {
|
||||
let Doctest {
|
||||
args,
|
||||
unstable_opts,
|
||||
unit,
|
||||
linker: _,
|
||||
script_meta,
|
||||
} = self;
|
||||
|
||||
let mut p = compilation.rustdoc_process(unit, *script_meta)?;
|
||||
p.arg("--crate-name").arg(&unit.target.crate_name());
|
||||
p.arg("--test");
|
||||
|
||||
for &rust_dep in &[
|
||||
&compilation.deps_output[&unit.kind],
|
||||
&compilation.deps_output[&CompileKind::Host],
|
||||
] {
|
||||
let mut arg = OsString::from("dependency=");
|
||||
arg.push(rust_dep);
|
||||
p.arg("-L").arg(arg);
|
||||
}
|
||||
|
||||
for native_dep in compilation.native_dirs.iter() {
|
||||
p.arg("-L").arg(native_dep);
|
||||
}
|
||||
|
||||
p.args(args);
|
||||
|
||||
if *unstable_opts {
|
||||
p.arg("-Zunstable-options");
|
||||
}
|
||||
|
||||
Ok(p)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'cfg> Compilation<'cfg> {
|
||||
pub fn new<'a>(bcx: &BuildContext<'a, 'cfg>) -> CargoResult<Compilation<'cfg>> {
|
||||
let mut rustc = bcx.rustc().process();
|
||||
|
|
|
@ -1001,7 +1001,6 @@ impl<'cfg> DrainState<'cfg> {
|
|||
let target_name = unit.target.name();
|
||||
match unit.mode {
|
||||
CompileMode::Doc { .. } => format!("{}(doc)", pkg_name),
|
||||
CompileMode::Docscrape { .. } => format!("{}(docscrape)", pkg_name),
|
||||
CompileMode::RunCustomBuild => format!("{}(build)", pkg_name),
|
||||
CompileMode::Test | CompileMode::Check { test: true } => match unit.target.kind() {
|
||||
TargetKind::Lib(_) => format!("{}(test)", target_name),
|
||||
|
|
|
@ -665,7 +665,7 @@ fn rustdoc(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Work> {
|
|||
.arg("--scrape-examples-target-crate")
|
||||
.arg(root.pkg.name());
|
||||
}
|
||||
} else if cx.bcx.scrape_units.len() > 0 {
|
||||
} else if cx.bcx.scrape_units.len() > 0 && cx.bcx.roots.contains(unit) {
|
||||
rustdoc.arg("-Zunstable-options");
|
||||
|
||||
for scrape_unit in &cx.bcx.scrape_units {
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
//! repeats until the queue is empty.
|
||||
|
||||
use std::collections::{BTreeSet, HashMap, HashSet};
|
||||
use std::ffi::OsString;
|
||||
use std::hash::{Hash, Hasher};
|
||||
use std::sync::Arc;
|
||||
|
||||
|
@ -545,24 +544,6 @@ pub fn create_bcx<'a, 'cfg>(
|
|||
Default::default()
|
||||
};
|
||||
|
||||
let fmt_unit = |u: &Unit| format!("{} {:?} / {:?}", u.target.name(), u.target.kind(), u.mode);
|
||||
let fmt_units = |v: &[Unit]| v.iter().map(|u| fmt_unit(u)).collect::<Vec<_>>().join(", ");
|
||||
let fmt_graph = |g: &UnitGraph| {
|
||||
g.iter()
|
||||
.map(|(k, vs)| {
|
||||
format!(
|
||||
"{} =>\n{}",
|
||||
fmt_unit(k),
|
||||
vs.iter()
|
||||
.map(|u| format!(" {}", fmt_unit(&u.unit)))
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n")
|
||||
)
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n")
|
||||
};
|
||||
|
||||
let mut unit_graph = build_unit_dependencies(
|
||||
ws,
|
||||
&pkg_set,
|
||||
|
@ -577,9 +558,6 @@ pub fn create_bcx<'a, 'cfg>(
|
|||
&profiles,
|
||||
interner,
|
||||
)?;
|
||||
println!("SCRAPE UNITS: {}", fmt_units(&scrape_units));
|
||||
println!("BEFORE ROOTS: {}", fmt_units(&units));
|
||||
println!("BEFORE GRAPH: {}", fmt_graph(&unit_graph));
|
||||
|
||||
// TODO: In theory, Cargo should also dedupe the roots, but I'm uncertain
|
||||
// what heuristics to use in that case.
|
||||
|
@ -607,8 +585,6 @@ pub fn create_bcx<'a, 'cfg>(
|
|||
scrape_units = new_graph.1;
|
||||
unit_graph = new_graph.2;
|
||||
}
|
||||
println!("AFTER UNITS: {}", fmt_units(&units));
|
||||
println!("AFTER GRAPH: {}", fmt_graph(&unit_graph));
|
||||
|
||||
let mut extra_compiler_args = HashMap::new();
|
||||
if let Some(args) = extra_args {
|
||||
|
@ -620,10 +596,7 @@ pub fn create_bcx<'a, 'cfg>(
|
|||
extra_args_name
|
||||
);
|
||||
}
|
||||
extra_compiler_args.insert(
|
||||
units[0].clone(),
|
||||
args.into_iter().map(OsString::from).collect::<Vec<_>>(),
|
||||
);
|
||||
extra_compiler_args.insert(units[0].clone(), args);
|
||||
}
|
||||
|
||||
for unit in &units {
|
||||
|
@ -643,7 +616,7 @@ pub fn create_bcx<'a, 'cfg>(
|
|||
extra_compiler_args
|
||||
.entry(unit.clone())
|
||||
.or_default()
|
||||
.extend(args.into_iter().map(OsString::from));
|
||||
.extend(args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -164,7 +164,13 @@ fn run_doc_tests(
|
|||
let doctest_in_workspace = config.cli_unstable().doctest_in_workspace;
|
||||
|
||||
for doctest_info in &compilation.to_doc_test {
|
||||
let Doctest { unit, linker, .. } = doctest_info;
|
||||
let Doctest {
|
||||
args,
|
||||
unstable_opts,
|
||||
unit,
|
||||
linker,
|
||||
script_meta,
|
||||
} = doctest_info;
|
||||
|
||||
if !doctest_xcompile {
|
||||
match unit.kind {
|
||||
|
@ -179,7 +185,9 @@ fn run_doc_tests(
|
|||
}
|
||||
|
||||
config.shell().status("Doc-tests", unit.target.name())?;
|
||||
let mut p = doctest_info.rustdoc_process(compilation)?;
|
||||
let mut p = compilation.rustdoc_process(unit, *script_meta)?;
|
||||
p.arg("--crate-name").arg(&unit.target.crate_name());
|
||||
p.arg("--test");
|
||||
|
||||
if doctest_in_workspace {
|
||||
add_path_args(ws, unit, &mut p);
|
||||
|
@ -211,6 +219,19 @@ fn run_doc_tests(
|
|||
}
|
||||
}
|
||||
|
||||
for &rust_dep in &[
|
||||
&compilation.deps_output[&unit.kind],
|
||||
&compilation.deps_output[&CompileKind::Host],
|
||||
] {
|
||||
let mut arg = OsString::from("dependency=");
|
||||
arg.push(rust_dep);
|
||||
p.arg("-L").arg(arg);
|
||||
}
|
||||
|
||||
for native_dep in compilation.native_dirs.iter() {
|
||||
p.arg("-L").arg(native_dep);
|
||||
}
|
||||
|
||||
for arg in test_args {
|
||||
p.arg("--test-args").arg(arg);
|
||||
}
|
||||
|
@ -219,6 +240,12 @@ fn run_doc_tests(
|
|||
p.arg("--test-args").arg("--quiet");
|
||||
}
|
||||
|
||||
p.args(args);
|
||||
|
||||
if *unstable_opts {
|
||||
p.arg("-Zunstable-options");
|
||||
}
|
||||
|
||||
config
|
||||
.shell()
|
||||
.verbose(|shell| shell.status("Running", p.to_string()))?;
|
||||
|
|
|
@ -266,11 +266,11 @@ fn can_run_doc_tests() {
|
|||
.with_stderr_contains(
|
||||
"\
|
||||
[DOCTEST] foo
|
||||
[RUNNING] `rustdoc [..]--test \
|
||||
[RUNNING] `rustdoc [..]--test [..]src/lib.rs \
|
||||
[..] \
|
||||
--extern bar=[CWD]/target/debug/deps/libbar-[..].rlib \
|
||||
--extern baz=[CWD]/target/debug/deps/libbar-[..].rlib \
|
||||
[..]src/lib.rs`
|
||||
[..]`
|
||||
",
|
||||
)
|
||||
.run();
|
||||
|
|
Loading…
Reference in a new issue