Skip to content

Commit

Permalink
Clean up rebase and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
willcrichton committed Jul 17, 2022
1 parent decc3f0 commit 20551a8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 31 deletions.
4 changes: 2 additions & 2 deletions src/cargo/core/compiler/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ pub struct Context<'a, 'cfg> {

/// Map that tracks whether a unit completed successfully. Used in conjuction
/// with the `Unit::can_fail` flag, so jobs can dynamically track at runtime
/// whether their dependencies succeeded or failed. Currently used to for
/// whether their dependencies succeeded or failed. Currently used for
/// the Rustdoc scrape-examples feature to allow Rustdoc to proceed even if
/// examples fail to scrape.
/// examples fail to compile.
pub completed_units: Arc<Mutex<HashMap<Metadata, bool>>>,
}

Expand Down
16 changes: 10 additions & 6 deletions src/cargo/core/compiler/job_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ struct DrainState<'cfg> {
total_units: usize,

queue: DependencyQueue<Unit, Artifact, Job>,
/// Dependency map that is like JobQueue::dep_map, except with Job information removed.
/// Used to determine if a unit's dependencies have failed, see
/// [`DrainState::spawn_work_if_possible`].
dep_map: HashMap<Unit, HashSet<(Unit, Artifact)>>,
messages: Arc<Queue<Message>>,
/// Diagnostic deduplication support.
Expand Down Expand Up @@ -507,14 +510,15 @@ impl<'cfg> JobQueue<'cfg> {
self.queue.queue_finished();

let progress = Progress::with_style("Building", ProgressStyle::Ratio, cx.bcx.config);
let dep_map = self
.queue
.dep_map()
.iter()
.map(|(unit, (deps, _))| (unit.clone(), deps.clone()))
.collect();
let state = DrainState {
total_units: self.queue.len(),
dep_map: self
.queue
.dep_map()
.iter()
.map(|(unit, (deps, _))| (unit.clone(), deps.clone()))
.collect(),
dep_map,
queue: self.queue,
// 100 here is somewhat arbitrary. It is a few screenfulls of
// output, and hopefully at most a few megabytes of memory for
Expand Down
36 changes: 13 additions & 23 deletions src/cargo/core/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use std::ffi::{OsStr, OsString};
use std::fs::{self, File};
use std::io::{BufRead, Write};
use std::path::{Path, PathBuf};
use std::sync::{Arc, Mutex};
use std::sync::Arc;

use anyhow::{Context as _, Error};
use lazycell::LazyCell;
Expand Down Expand Up @@ -263,7 +263,6 @@ fn rustc(cx: &mut Context<'_, '_>, unit: &Unit, exec: &Arc<dyn Executor>) -> Car
let script_metadata = cx.find_build_script_metadata(unit);
let is_local = unit.is_local();
let artifact = unit.artifact;
let completed_units = Arc::clone(&cx.completed_units);

return Ok(Work::new(move |state| {
// Artifacts are in a different location than typical units,
Expand Down Expand Up @@ -293,13 +292,7 @@ fn rustc(cx: &mut Context<'_, '_>, unit: &Unit, exec: &Arc<dyn Executor>) -> Car
)?;
add_plugin_deps(&mut rustc, &script_outputs, &build_scripts, &root_output)?;
}
add_custom_flags(
&mut rustc,
&script_outputs,
script_metadata,
completed_units,
None,
)?;
add_custom_flags(&mut rustc, &script_outputs, script_metadata)?;
}

for output in outputs.iter() {
Expand Down Expand Up @@ -712,9 +705,18 @@ fn rustdoc(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Work> {
&mut rustdoc,
&build_script_outputs.lock().unwrap(),
script_metadata,
completed_units,
scrape_units,
)?;

if let Some(scrape_units) = scrape_units {
let completed_units = completed_units.lock().unwrap();
for (_, output_path) in scrape_units
.iter()
.filter(|(buildkey, _)| completed_units[*buildkey])
{
rustdoc.arg("--with-examples").arg(output_path);
}
}

let crate_dir = doc_dir.join(&crate_name);
if crate_dir.exists() {
// Remove output from a previous build. This ensures that stale
Expand Down Expand Up @@ -1182,8 +1184,6 @@ fn add_custom_flags(
cmd: &mut ProcessBuilder,
build_script_outputs: &BuildScriptOutputs,
metadata: Option<Metadata>,
completed_units: Arc<Mutex<HashMap<Metadata, bool>>>,
scrape_units: Option<HashMap<Metadata, PathBuf>>,
) -> CargoResult<()> {
if let Some(metadata) = metadata {
if let Some(output) = build_script_outputs.get(metadata) {
Expand All @@ -1202,16 +1202,6 @@ fn add_custom_flags(
}
}

if let Some(scrape_units) = scrape_units {
let completed_units = completed_units.lock().unwrap();
for (_, output_path) in scrape_units
.iter()
.filter(|(buildkey, _)| completed_units[*buildkey])
{
cmd.arg("--with-examples").arg(output_path);
}
}

Ok(())
}

Expand Down

0 comments on commit 20551a8

Please sign in to comment.