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

Commit 2fd403a

Browse files
committed
Properly initialize build plan when Cargo-building for the first time
1 parent 7d1914d commit 2fd403a

File tree

2 files changed

+16
-21
lines changed

2 files changed

+16
-21
lines changed

src/build/cargo.rs

Lines changed: 6 additions & 5 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;
@@ -123,7 +124,7 @@ fn run_cargo(
123124
let mut compilation_cx = compilation_cx.lock().unwrap();
124125
// Since Cargo build routine will try to regenerate the unit dep graph,
125126
// we need to clear the existing dep graph.
126-
compilation_cx.build_plan.clear();
127+
compilation_cx.build_plan = Plan::for_packages(package_arg.clone());
127128

128129
compilation_cx.build_dir.as_ref().unwrap().clone()
129130
};
@@ -147,9 +148,9 @@ fn run_cargo(
147148
enable_nightly_features();
148149
let ws = Workspace::new(&manifest_path, &config)?;
149150

150-
let packages = match package_arg {
151-
PackageArg::All => vec![],
152-
PackageArg::Package(s) => vec![s]
151+
let (all, packages) = match package_arg {
152+
PackageArg::All => (true, vec![]),
153+
PackageArg::Package(s) => (false, vec![s])
153154
};
154155

155156
// TODO: It might be feasible to keep this CargoOptions structure cached and regenerate
@@ -172,7 +173,7 @@ fn run_cargo(
172173
(opts, rustflags, rls_config.clear_env_rust_log, rls_config.cfg_test)
173174
};
174175

175-
let spec = Packages::from_flags(false, Vec::new(), packages)?;
176+
let spec = Packages::from_flags(all, Vec::new(), packages)?;
176177

177178
let compile_opts = CompileOptions {
178179
spec,

src/build/plan.rs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,29 +60,27 @@ crate struct Plan {
6060
// An object for finding the package which a file belongs to and this inferring
6161
// a package argument.
6262
package_map: Option<PackageMap>,
63-
// The package argument used in the last Cargo build.
64-
prev_package_arg: Option<PackageArg>,
63+
/// Packages for which this build plan was prepared.
64+
/// Used to detect if the plan can reused when building certain packages.
65+
built_packages: PackageArg,
6566
}
6667

6768
impl Plan {
6869
crate fn new() -> Plan {
70+
Self::for_packages(PackageArg::All)
71+
}
72+
73+
crate fn for_packages(pkgs: PackageArg) -> Plan {
6974
Plan {
7075
units: HashMap::new(),
7176
dep_graph: HashMap::new(),
7277
rev_dep_graph: HashMap::new(),
7378
compiler_jobs: HashMap::new(),
7479
package_map: None,
75-
prev_package_arg: None,
80+
built_packages: pkgs,
7681
}
7782
}
7883

79-
crate fn clear(&mut self) {
80-
self.units = HashMap::new();
81-
self.dep_graph = HashMap::new();
82-
self.rev_dep_graph = HashMap::new();
83-
self.compiler_jobs = HashMap::new();
84-
}
85-
8684
/// Returns whether a build plan has cached compiler invocations and dep
8785
/// graph so it's at all able to return a job queue via `prepare_work`.
8886
crate fn is_ready(&self) -> bool {
@@ -315,11 +313,7 @@ impl Plan {
315313
.as_ref()
316314
.unwrap()
317315
.compute_package_arg(modified);
318-
let package_arg_changed = match self.prev_package_arg {
319-
Some(ref ppa) => ppa != &package_arg,
320-
None => true,
321-
};
322-
self.prev_package_arg = Some(package_arg.clone());
316+
let package_arg_changed = self.built_packages != package_arg;
323317

324318
if !self.is_ready() || requested_cargo || package_arg_changed {
325319
return WorkStatus::NeedsCargo(package_arg);
@@ -405,7 +399,7 @@ impl PackageMap {
405399
}
406400
}
407401

408-
// Fine each package in the workspace and record the root directory and package name.
402+
// Find each package in the workspace and record the root directory and package name.
409403
fn discover_package_paths(manifest_path: &Path) -> HashMap<PathBuf, String> {
410404
trace!("read metadata {:?}", manifest_path);
411405
let metadata = match cargo_metadata::metadata(Some(manifest_path)) {

0 commit comments

Comments
 (0)