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

Rebuild necessary packages when reusing build plan #969

Merged
merged 13 commits into from
Aug 1, 2018
44 changes: 35 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ categories = ["development-tools"]
build = "build.rs"

[dependencies]
cargo = { git = "https://github.com/rust-lang/cargo", rev = "af9e40c26b4ea2ebd6f31ee86ee61d5ac1c74eb0" }
cargo = { git = "https://github.com/rust-lang/cargo", rev = "1ec8c70d00afa77deafb8fbd4c1d07fb68b2b556" }
cargo_metadata = "0.5.2"
clippy_lints = { git = "https://github.com/rust-lang-nursery/rust-clippy", rev = "1f656173723dce4efc3fc90ff5763a2186ec9089", optional = true }
env_logger = "0.5"
Expand Down
31 changes: 17 additions & 14 deletions src/build/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use serde_json;
use crate::actions::progress::ProgressUpdate;
use rls_data::Analysis;
use crate::build::{BufWriter, BuildResult, CompilationContext, Internals, PackageArg};
use crate::build::plan::Plan;
use crate::build::environment::{self, Environment, EnvironmentLock};
use crate::config::Config;
use rls_vfs::Vfs;
Expand Down Expand Up @@ -119,14 +120,7 @@ fn run_cargo(

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

let build_dir = {
let mut compilation_cx = compilation_cx.lock().unwrap();
// Since Cargo build routine will try to regenerate the unit dep graph,
// we need to clear the existing dep graph.
compilation_cx.build_plan.clear();

compilation_cx.build_dir.as_ref().unwrap().clone()
};
let build_dir = compilation_cx.lock().unwrap().build_dir.clone().unwrap();

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

let packages = match package_arg {
PackageArg::Unknown | PackageArg::All => vec![],
PackageArg::Package(s) => vec![s]
let (all, packages) = match package_arg {
PackageArg::Default => (false, vec![]),
PackageArg::Packages(pkgs) => (false, pkgs.into_iter().collect())
};

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

let spec = Packages::from_flags(false, Vec::new(), packages)?;
let spec = Packages::from_flags(all, Vec::new(), packages)?;

let pkg_names = spec.into_package_id_specs(&ws)?.iter()
.map(|pkg_spec| pkg_spec.name().to_owned())
.collect();
trace!("Specified packages to be built by Cargo: {:#?}", pkg_names);

// Since Cargo build routine will try to regenerate the unit dep graph,
// we need to clear the existing dep graph.
compilation_cx.lock().unwrap().build_plan = Plan::for_packages(pkg_names);

let compile_opts = CompileOptions {
spec,
Expand Down Expand Up @@ -330,7 +333,7 @@ impl Executor for RlsExecutor {
self.is_primary_crate(id)
}

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

// Prepare modified cargo-generated args/envs for future rustc calls
Expand Down
12 changes: 6 additions & 6 deletions src/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use log::{log, trace};

use self::environment::EnvironmentLock;

use std::collections::HashMap;
use std::collections::{HashMap, HashSet};
use std::ffi::OsString;
use std::io::{self, Write};
use std::mem;
Expand Down Expand Up @@ -159,12 +159,10 @@ impl CompilationContext {
}

#[derive(Debug, Clone, Eq, PartialEq)]
/// Specified set of packages to be built by Cargo.
pub enum PackageArg {
Unknown,
// --all
All,
// -p ...
Package(String),
Default,
Packages(HashSet<String>),
}

/// Status of the build queue.
Expand Down Expand Up @@ -550,6 +548,8 @@ impl Internals {
};
cx.build_plan.prepare_work(&manifest_path, &modified, needs_to_run_cargo)
};
trace!("Specified work: {:?}", work);

match work {
// Cargo performs the full build and returns
// appropriate diagnostics/analysis data
Expand Down
Loading