Skip to content

Commit

Permalink
fix: Only fix "primary" packages by default
Browse files Browse the repository at this point in the history
The previous heuristic for fixing packages was to fix all packages in a
workspace, aka those with path dependencies. Instead this commit switches cargo
over to only fixing the "primary" package, or those requested on the command
line or implicitly via cwd.

This will later help us identify which packages are being targeted so we can
provide tailored warnings and errors for mixed up transition steps.
  • Loading branch information
alexcrichton committed Jul 30, 2018
1 parent af6e295 commit 7691deb
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/cargo/core/compiler/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ pub struct Context<'a, 'cfg: 'a> {
pub links: Links<'a>,
pub used_in_plugin: HashSet<Unit<'a>>,
pub jobserver: Client,
primary_packages: HashSet<&'a PackageId>,
unit_dependencies: HashMap<Unit<'a>, Vec<Unit<'a>>>,
files: Option<CompilationFiles<'a, 'cfg>>,
}
Expand Down Expand Up @@ -129,6 +130,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
jobserver,
build_script_overridden: HashSet::new(),

primary_packages: HashSet::new(),
unit_dependencies: HashMap::new(),
files: None,
})
Expand Down Expand Up @@ -321,6 +323,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
Some(target) => Some(Layout::new(self.bcx.ws, Some(target), dest)?),
None => None,
};
self.primary_packages.extend(units.iter().map(|u| u.pkg.package_id()));

build_unit_dependencies(units, self.bcx, &mut self.unit_dependencies)?;
self.build_used_in_plugin_map(units)?;
Expand Down Expand Up @@ -487,6 +490,10 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
let dir = self.files().layout(unit.kind).incremental().display();
Ok(vec!["-C".to_string(), format!("incremental={}", dir)])
}

pub fn is_primary_package(&self, unit: &Unit<'a>) -> bool {
self.primary_packages.contains(unit.pkg.package_id())
}
}

#[derive(Default)]
Expand Down
7 changes: 5 additions & 2 deletions src/cargo/core/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,14 @@ fn compile<'a, 'cfg: 'a>(
}

fn rustc<'a, 'cfg>(
mut cx: &mut Context<'a, 'cfg>,
cx: &mut Context<'a, 'cfg>,
unit: &Unit<'a>,
exec: &Arc<Executor>,
) -> CargoResult<Work> {
let mut rustc = prepare_rustc(cx, &unit.target.rustc_crate_types(), unit)?;
if cx.is_primary_package(unit) {
rustc.env("CARGO_PRIMARY_PACKAGE", "1");
}
let build_plan = cx.bcx.build_config.build_plan;

let name = unit.pkg.name().to_string();
Expand Down Expand Up @@ -195,7 +198,7 @@ fn rustc<'a, 'cfg>(
} else {
root.join(&cx.files().file_stem(unit))
}.with_extension("d");
let dep_info_loc = fingerprint::dep_info_loc(&mut cx, unit);
let dep_info_loc = fingerprint::dep_info_loc(cx, unit);

rustc.args(&cx.bcx.rustflags_args(unit)?);
let json_messages = cx.bcx.build_config.json_messages();
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/ops/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ pub fn fix_maybe_exec_rustc() -> CargoResult<bool> {
// not the best heuristic but matches what Cargo does today at least.
let mut fixes = FixedCrate::default();
if let Some(path) = filename {
if !Path::new(&path).is_absolute() {
if env::var("CARGO_PRIMARY_PACKAGE").is_ok() {
trace!("start rustfixing {:?}", path);
fixes = rustfix_crate(&lock_addr, rustc.as_ref(), &path)?;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ fn fix_path_deps() {
.build();

assert_that(
p.cargo("fix --allow-no-vcs")
p.cargo("fix --allow-no-vcs -p foo -p bar")
.env("__CARGO_FIX_YOLO", "1"),
execs()
.with_status(0)
Expand Down

0 comments on commit 7691deb

Please sign in to comment.