Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Commit ecd29a7

Browse files
authored
Merge pull request #969 from Xanewok/issue-876
Rebuild necessary packages when reusing build plan
2 parents d0098da + efab68a commit ecd29a7

File tree

7 files changed

+451
-148
lines changed

7 files changed

+451
-148
lines changed

Cargo.lock

Lines changed: 35 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ categories = ["development-tools"]
1313
build = "build.rs"
1414

1515
[dependencies]
16-
cargo = { git = "https://github.com/rust-lang/cargo", rev = "af9e40c26b4ea2ebd6f31ee86ee61d5ac1c74eb0" }
16+
cargo = { git = "https://github.com/rust-lang/cargo", rev = "1ec8c70d00afa77deafb8fbd4c1d07fb68b2b556" }
1717
cargo_metadata = "0.5.2"
1818
clippy_lints = { git = "https://github.com/rust-lang-nursery/rust-clippy", rev = "1f656173723dce4efc3fc90ff5763a2186ec9089", optional = true }
1919
env_logger = "0.5"

src/build/cargo.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use serde_json;
1919
use crate::actions::progress::ProgressUpdate;
2020
use rls_data::Analysis;
2121
use crate::build::{BufWriter, BuildResult, CompilationContext, Internals, PackageArg};
22+
use crate::build::plan::Plan;
2223
use crate::build::environment::{self, Environment, EnvironmentLock};
2324
use crate::config::Config;
2425
use rls_vfs::Vfs;
@@ -119,14 +120,7 @@ fn run_cargo(
119120

120121
let mut restore_env = Environment::push_with_lock(&HashMap::new(), None, lock_guard);
121122

122-
let build_dir = {
123-
let mut compilation_cx = compilation_cx.lock().unwrap();
124-
// Since Cargo build routine will try to regenerate the unit dep graph,
125-
// we need to clear the existing dep graph.
126-
compilation_cx.build_plan.clear();
127-
128-
compilation_cx.build_dir.as_ref().unwrap().clone()
129-
};
123+
let build_dir = compilation_cx.lock().unwrap().build_dir.clone().unwrap();
130124

131125
// Note that this may not be equal build_dir when inside a workspace member
132126
let manifest_path = important_paths::find_root_manifest_for_wd(&build_dir)?;
@@ -147,9 +141,9 @@ fn run_cargo(
147141
enable_nightly_features();
148142
let ws = Workspace::new(&manifest_path, &config)?;
149143

150-
let packages = match package_arg {
151-
PackageArg::Unknown | PackageArg::All => vec![],
152-
PackageArg::Package(s) => vec![s]
144+
let (all, packages) = match package_arg {
145+
PackageArg::Default => (false, vec![]),
146+
PackageArg::Packages(pkgs) => (false, pkgs.into_iter().collect())
153147
};
154148

155149
// TODO: It might be feasible to keep this CargoOptions structure cached and regenerate
@@ -172,7 +166,16 @@ fn run_cargo(
172166
(opts, rustflags, rls_config.clear_env_rust_log, rls_config.cfg_test)
173167
};
174168

175-
let spec = Packages::from_flags(false, Vec::new(), packages)?;
169+
let spec = Packages::from_flags(all, Vec::new(), packages)?;
170+
171+
let pkg_names = spec.into_package_id_specs(&ws)?.iter()
172+
.map(|pkg_spec| pkg_spec.name().to_owned())
173+
.collect();
174+
trace!("Specified packages to be built by Cargo: {:#?}", pkg_names);
175+
176+
// Since Cargo build routine will try to regenerate the unit dep graph,
177+
// we need to clear the existing dep graph.
178+
compilation_cx.lock().unwrap().build_plan = Plan::for_packages(pkg_names);
176179

177180
let compile_opts = CompileOptions {
178181
spec,
@@ -330,7 +333,7 @@ impl Executor for RlsExecutor {
330333
self.is_primary_crate(id)
331334
}
332335

333-
fn exec(&self, mut cargo_cmd: ProcessBuilder, id: &PackageId, target: &Target) -> CargoResult<()> {
336+
fn exec(&self, mut cargo_cmd: ProcessBuilder, id: &PackageId, target: &Target, mode: CompileMode) -> CargoResult<()> {
334337
// Use JSON output so that we can parse the rustc output.
335338
cargo_cmd.arg("--error-format=json");
336339
// Delete any stale data. We try and remove any json files with
@@ -461,7 +464,7 @@ impl Executor for RlsExecutor {
461464
// Cache executed command for the build plan
462465
{
463466
let mut cx = self.compilation_cx.lock().unwrap();
464-
cx.build_plan.cache_compiler_job(id, target, &cmd);
467+
cx.build_plan.cache_compiler_job(id, target, mode, &cmd);
465468
}
466469

467470
// Prepare modified cargo-generated args/envs for future rustc calls

src/build/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use log::{log, trace};
2222

2323
use self::environment::EnvironmentLock;
2424

25-
use std::collections::HashMap;
25+
use std::collections::{HashMap, HashSet};
2626
use std::ffi::OsString;
2727
use std::io::{self, Write};
2828
use std::mem;
@@ -159,12 +159,10 @@ impl CompilationContext {
159159
}
160160

161161
#[derive(Debug, Clone, Eq, PartialEq)]
162+
/// Specified set of packages to be built by Cargo.
162163
pub enum PackageArg {
163-
Unknown,
164-
// --all
165-
All,
166-
// -p ...
167-
Package(String),
164+
Default,
165+
Packages(HashSet<String>),
168166
}
169167

170168
/// Status of the build queue.
@@ -550,6 +548,8 @@ impl Internals {
550548
};
551549
cx.build_plan.prepare_work(&manifest_path, &modified, needs_to_run_cargo)
552550
};
551+
trace!("Specified work: {:?}", work);
552+
553553
match work {
554554
// Cargo performs the full build and returns
555555
// appropriate diagnostics/analysis data

0 commit comments

Comments
 (0)