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

Commit 87388b9

Browse files
committed
Propagate args and env vars properly if we don't intercept
And update Cargo. Closes #874
1 parent 1188c1e commit 87388b9

File tree

3 files changed

+43
-45
lines changed

3 files changed

+43
-45
lines changed

Cargo.lock

Lines changed: 14 additions & 17 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
@@ -10,7 +10,7 @@ categories = ["development-tools"]
1010
build = "build.rs"
1111

1212
[dependencies]
13-
cargo = { git = "https://github.com/rust-lang/cargo", rev = "9e53ac6e6525da914cb05a85e5e8eff7b5dca81f" }
13+
cargo = { git = "https://github.com/rust-lang/cargo", rev = "22c0f22f5621f1b68558d80a0966d073b9b68932" }
1414
cargo_metadata = "0.5.2"
1515
clippy_lints = { version = "0.0.204", optional = true }
1616
env_logger = "0.5"

src/build/cargo.rs

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ fn run_cargo(
161161
trace!("Cargo compilation options:\n{:?}", opts);
162162
let rustflags = prepare_cargo_rustflags(&rls_config);
163163

164-
165164
for package in &packages {
166165
if ws.members().find(|x| *x.name() == *package).is_none() {
167166
warn!("cargo - couldn't find member package `{}` specified in `analyze_package` configuration", package);
@@ -340,7 +339,7 @@ impl Executor for RlsExecutor {
340339
let cargo_args = cargo_cmd.get_args();
341340
let crate_name =
342341
parse_arg(cargo_args, "--crate-name").expect("no crate-name in rustc command line");
343-
trace!("exec: {}", crate_name);
342+
trace!("exec: {} {:?}", crate_name, cargo_cmd);
344343

345344
// Send off a window/progress notification for this compile target.
346345
// At the moment, we don't know the number of things cargo is going to compile,
@@ -389,9 +388,30 @@ impl Executor for RlsExecutor {
389388
cmd.program(rustc_shim);
390389
cmd.env(::RUSTC_SHIM_ENV_VAR_NAME, "1");
391390

391+
// Add args and envs to cmd.
392+
let mut args: Vec<_> = cargo_args
393+
.iter()
394+
.map(|a| a.clone().into_string().unwrap())
395+
.collect();
396+
let envs = cargo_cmd.get_envs().clone();
397+
392398
let sysroot =
393399
current_sysroot().expect("need to specify SYSROOT env var or use rustup or multirust");
394400

401+
{
402+
let config = self.config.lock().unwrap();
403+
if config.sysroot.is_none() {
404+
args.push("--sysroot".to_owned());
405+
args.push(sysroot);
406+
}
407+
}
408+
cmd.args_replace(&args);
409+
for (k, v) in &envs {
410+
if let Some(v) = v {
411+
cmd.env(k, v);
412+
}
413+
}
414+
395415
// We only want to intercept rustc call targeting current crate to cache
396416
// args/envs generated by cargo so we can run only rustc later ourselves
397417
// Currently we don't cache nor modify build script args
@@ -403,9 +423,11 @@ impl Executor for RlsExecutor {
403423
""
404424
};
405425
trace!(
406-
"rustc not intercepted - {}{}",
426+
"rustc not intercepted - {}{} - args: {:?} envs: {:?}",
407427
id.name(),
408-
build_script_notice
428+
build_script_notice,
429+
cmd.get_args(),
430+
cmd.get_envs(),
409431
);
410432

411433
if ::blacklist::CRATE_BLACKLIST.contains(&&*crate_name) {
@@ -421,37 +443,17 @@ impl Executor for RlsExecutor {
421443
let save_config = serde_json::to_string(&save_config)?;
422444
cmd.env("RUST_SAVE_ANALYSIS_CONFIG", &OsString::from(save_config));
423445

424-
if self.config.lock().unwrap().sysroot.is_none() {
425-
cmd.arg("--sysroot");
426-
cmd.arg(&sysroot);
427-
}
428446
return cmd.exec();
429447
}
430448

431449
trace!(
432450
"rustc intercepted - args: {:?} envs: {:?}",
433-
cargo_args,
434-
cargo_cmd.get_envs()
451+
args,
452+
envs,
435453
);
436454

437455
self.reached_primary.store(true, Ordering::SeqCst);
438456

439-
let mut args: Vec<_> = cargo_args
440-
.iter()
441-
.map(|a| a.clone().into_string().unwrap())
442-
.collect();
443-
444-
{
445-
let config = self.config.lock().unwrap();
446-
447-
if config.sysroot.is_none() {
448-
args.push("--sysroot".to_owned());
449-
args.push(sysroot);
450-
}
451-
452-
cmd.args_replace(&args);
453-
}
454-
455457
// Cache executed command for the build plan
456458
{
457459
let mut cx = self.compilation_cx.lock().unwrap();
@@ -461,7 +463,6 @@ impl Executor for RlsExecutor {
461463
// Prepare modified cargo-generated args/envs for future rustc calls
462464
let rustc = cargo_cmd.get_program().to_owned().into_string().unwrap();
463465
args.insert(0, rustc);
464-
let envs = cargo_cmd.get_envs().clone();
465466

466467
// Store the modified cargo-generated args/envs for future rustc calls
467468
{

0 commit comments

Comments
 (0)