@@ -20,11 +20,12 @@ use failure::{self, format_err};
2020use serde_json;
2121
2222use crate :: actions:: progress:: ProgressUpdate ;
23- use crate :: build:: environment:: { self , Environment , EnvironmentLock } ;
24- use crate :: build:: plan:: Plan ;
2523use crate :: build:: { BufWriter , BuildResult , CompilationContext , Internals , PackageArg } ;
24+ use crate :: build:: cargo_plan:: CargoPlan ;
25+ use crate :: build:: environment:: { self , Environment , EnvironmentLock } ;
26+ use crate :: build:: plan:: BuildPlan ;
2627use crate :: config:: Config ;
27- use log:: { debug, error , trace, warn} ;
28+ use log:: { debug, trace, warn} ;
2829use rls_data:: Analysis ;
2930use rls_vfs:: Vfs ;
3031
@@ -34,7 +35,6 @@ use std::ffi::OsString;
3435use std:: fmt:: Write ;
3536use std:: fs:: { read_dir, remove_file} ;
3637use std:: path:: { Path , PathBuf } ;
37- use std:: process:: Command ;
3838use std:: sync:: atomic:: { AtomicBool , Ordering } ;
3939use std:: sync:: mpsc:: Sender ;
4040use std:: sync:: { Arc , Mutex } ;
@@ -188,7 +188,8 @@ fn run_cargo(
188188
189189 // Since Cargo build routine will try to regenerate the unit dep graph,
190190 // we need to clear the existing dep graph.
191- compilation_cx. lock ( ) . unwrap ( ) . build_plan = Plan :: for_packages ( pkg_names) ;
191+ compilation_cx. lock ( ) . unwrap ( ) . build_plan =
192+ BuildPlan :: Cargo ( CargoPlan :: with_packages ( & manifest_path, pkg_names) ) ;
192193
193194 let compile_opts = CompileOptions {
194195 spec,
@@ -328,12 +329,12 @@ impl Executor for RlsExecutor {
328329 /// is fresh and won't be compiled.
329330 fn init ( & self , cx : & Context < ' _ , ' _ > , unit : & Unit < ' _ > ) {
330331 let mut compilation_cx = self . compilation_cx . lock ( ) . unwrap ( ) ;
331- let plan = & mut compilation_cx. build_plan ;
332+ let plan = compilation_cx. build_plan . as_cargo_mut ( )
333+ . expect ( "Build plan should be properly initialized before running Cargo" ) ;
334+
332335 let only_primary = |unit : & Unit < ' _ > | self . is_primary_crate ( unit. pkg . package_id ( ) ) ;
333336
334- if let Err ( err) = plan. emplace_dep_with_filter ( unit, cx, & only_primary) {
335- error ! ( "{:?}" , err) ;
336- }
337+ plan. emplace_dep_with_filter ( unit, cx, & only_primary) ;
337338 }
338339
339340 fn force_rebuild ( & self , unit : & Unit < ' _ > ) -> bool {
@@ -431,8 +432,8 @@ impl Executor for RlsExecutor {
431432 . collect ( ) ;
432433 let envs = cargo_cmd. get_envs ( ) . clone ( ) ;
433434
434- let sysroot =
435- current_sysroot ( ) . expect ( "need to specify SYSROOT env var or use rustup or multirust" ) ;
435+ let sysroot = super :: rustc :: current_sysroot ( )
436+ . expect ( "need to specify SYSROOT env var or use rustup or multirust" ) ;
436437
437438 {
438439 let config = self . config . lock ( ) . unwrap ( ) ;
@@ -494,7 +495,8 @@ impl Executor for RlsExecutor {
494495 // Cache executed command for the build plan
495496 {
496497 let mut cx = self . compilation_cx . lock ( ) . unwrap ( ) ;
497- cx. build_plan . cache_compiler_job ( id, target, mode, & cmd) ;
498+ let plan = cx. build_plan . as_cargo_mut ( ) . unwrap ( ) ;
499+ plan. cache_compiler_job ( id, target, mode, & cmd) ;
498500 }
499501
500502 // Prepare modified cargo-generated args/envs for future rustc calls
@@ -646,25 +648,6 @@ fn parse_arg(args: &[OsString], arg: &str) -> Option<String> {
646648 None
647649}
648650
649- fn current_sysroot ( ) -> Option < String > {
650- let home = env:: var ( "RUSTUP_HOME" ) . or_else ( |_| env:: var ( "MULTIRUST_HOME" ) ) ;
651- let toolchain = env:: var ( "RUSTUP_TOOLCHAIN" ) . or_else ( |_| env:: var ( "MULTIRUST_TOOLCHAIN" ) ) ;
652- if let ( Ok ( home) , Ok ( toolchain) ) = ( home, toolchain) {
653- Some ( format ! ( "{}/toolchains/{}" , home, toolchain) )
654- } else {
655- let rustc_exe = env:: var ( "RUSTC" ) . unwrap_or_else ( |_| "rustc" . to_owned ( ) ) ;
656- env:: var ( "SYSROOT" ) . map ( |s| s. to_owned ( ) ) . ok ( ) . or_else ( || {
657- Command :: new ( rustc_exe)
658- . arg ( "--print" )
659- . arg ( "sysroot" )
660- . output ( )
661- . ok ( )
662- . and_then ( |out| String :: from_utf8 ( out. stdout ) . ok ( ) )
663- . map ( |s| s. trim ( ) . to_owned ( ) )
664- } )
665- }
666- }
667-
668651/// `flag_str` is a string of command line args for Rust. This function removes any
669652/// duplicate flags.
670653fn dedup_flags ( flag_str : & str ) -> String {
0 commit comments