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

Commit 502a46e

Browse files
authored
Merge pull request #1040 from Xanewok/minor-cleanup
Remove cached args/envs from old single crate mode
2 parents 5fb225d + 1014896 commit 502a46e

File tree

2 files changed

+16
-28
lines changed

2 files changed

+16
-28
lines changed

src/build/cargo.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -500,8 +500,7 @@ impl Executor for RlsExecutor {
500500
// Store the modified cargo-generated args/envs for future rustc calls
501501
{
502502
let mut compilation_cx = self.compilation_cx.lock().unwrap();
503-
compilation_cx.args = args.clone();
504-
compilation_cx.envs = envs.clone();
503+
compilation_cx.needs_rebuild = false;
505504
compilation_cx.cwd = cargo_cmd.get_cwd().map(|p| p.to_path_buf());
506505
}
507506

src/build/mod.rs

+15-26
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use rls_vfs::Vfs;
2323
use self::environment::EnvironmentLock;
2424

2525
use std::collections::{HashMap, HashSet};
26-
use std::ffi::OsString;
2726
use std::io::{self, Write};
2827
use std::mem;
2928
use std::path::{Path, PathBuf};
@@ -136,12 +135,11 @@ impl BuildPriority {
136135
/// Information passed to Cargo/rustc to build.
137136
#[derive(Debug)]
138137
struct CompilationContext {
139-
/// args and envs are saved from Cargo and passed to rustc.
140-
args: Vec<String>,
141-
envs: HashMap<String, Option<OsString>>,
142138
cwd: Option<PathBuf>,
143139
/// The build directory is supplied by the client and passed to Cargo.
144140
build_dir: Option<PathBuf>,
141+
/// Whether needs to perform a Cargo rebuild
142+
needs_rebuild: bool,
145143
/// Build plan, which should know all the inter-package/target dependencies
146144
/// along with args/envs. Only contains inter-package dep-graph for now.
147145
build_plan: BuildPlan,
@@ -150,10 +148,9 @@ struct CompilationContext {
150148
impl CompilationContext {
151149
fn new() -> CompilationContext {
152150
CompilationContext {
153-
args: vec![],
154-
envs: HashMap::new(),
155151
cwd: None,
156152
build_dir: None,
153+
needs_rebuild: true,
157154
build_plan: BuildPlan::new(),
158155
}
159156
}
@@ -263,11 +260,7 @@ impl BuildQueue {
263260
pbh: PostBuildHandler,
264261
) {
265262
trace!("request_build {:?}", priority);
266-
let needs_compilation_ctx_from_cargo = {
267-
let context = self.internals.compilation_cx.lock().unwrap();
268-
context.args.is_empty() && context.envs.is_empty()
269-
};
270-
if needs_compilation_ctx_from_cargo {
263+
if self.internals.compilation_cx.lock().unwrap().needs_rebuild {
271264
priority = BuildPriority::Cargo;
272265
}
273266
let build = PendingBuild {
@@ -487,11 +480,7 @@ impl Internals {
487480
(*compilation_cx).build_dir = Some(new_build_dir.to_owned());
488481
}
489482

490-
if priority.is_cargo() {
491-
// Killing these args indicates we'll do a full Cargo build.
492-
compilation_cx.args = vec![];
493-
compilation_cx.envs = HashMap::new();
494-
}
483+
compilation_cx.needs_rebuild = priority.is_cargo();
495484
}
496485

497486
let result = self.build(progress_sender);
@@ -536,25 +525,25 @@ impl Internals {
536525
return external::build_with_external_cmd(cmd, build_dir.unwrap());
537526
}
538527

539-
// Don't hold this lock when we run Cargo.
540-
let needs_to_run_cargo = self.compilation_cx.lock().unwrap().args.is_empty();
541-
542528
// If the build plan has already been cached, use it, unless Cargo
543529
// has to be specifically rerun (e.g. when build scripts changed)
544530
let work = {
545531
let modified: Vec<_> = self.dirty_files.lock().unwrap().keys().cloned().collect();
532+
546533
let mut cx = self.compilation_cx.lock().unwrap();
547-
let manifest_path =
548-
important_paths::find_root_manifest_for_wd(cx.build_dir.as_ref().unwrap());
549-
let manifest_path = match manifest_path {
550-
Ok(mp) => mp,
534+
let needs_to_run_cargo = cx.needs_rebuild;
535+
let build_dir = cx.build_dir.as_ref().unwrap();
536+
537+
match important_paths::find_root_manifest_for_wd(build_dir) {
538+
Ok(manifest_path) => {
539+
cx.build_plan
540+
.prepare_work(&manifest_path, &modified, needs_to_run_cargo)
541+
}
551542
Err(e) => {
552543
let msg = format!("Error reading manifest path: {:?}", e);
553544
return BuildResult::Err(msg, None);
554545
}
555-
};
556-
cx.build_plan
557-
.prepare_work(&manifest_path, &modified, needs_to_run_cargo)
546+
}
558547
};
559548
trace!("Specified work: {:?}", work);
560549

0 commit comments

Comments
 (0)