@@ -23,7 +23,6 @@ use rls_vfs::Vfs;
23
23
use self :: environment:: EnvironmentLock ;
24
24
25
25
use std:: collections:: { HashMap , HashSet } ;
26
- use std:: ffi:: OsString ;
27
26
use std:: io:: { self , Write } ;
28
27
use std:: mem;
29
28
use std:: path:: { Path , PathBuf } ;
@@ -136,12 +135,11 @@ impl BuildPriority {
136
135
/// Information passed to Cargo/rustc to build.
137
136
#[ derive( Debug ) ]
138
137
struct CompilationContext {
139
- /// args and envs are saved from Cargo and passed to rustc.
140
- args : Vec < String > ,
141
- envs : HashMap < String , Option < OsString > > ,
142
138
cwd : Option < PathBuf > ,
143
139
/// The build directory is supplied by the client and passed to Cargo.
144
140
build_dir : Option < PathBuf > ,
141
+ /// Whether needs to perform a Cargo rebuild
142
+ needs_rebuild : bool ,
145
143
/// Build plan, which should know all the inter-package/target dependencies
146
144
/// along with args/envs. Only contains inter-package dep-graph for now.
147
145
build_plan : BuildPlan ,
@@ -150,10 +148,9 @@ struct CompilationContext {
150
148
impl CompilationContext {
151
149
fn new ( ) -> CompilationContext {
152
150
CompilationContext {
153
- args : vec ! [ ] ,
154
- envs : HashMap :: new ( ) ,
155
151
cwd : None ,
156
152
build_dir : None ,
153
+ needs_rebuild : true ,
157
154
build_plan : BuildPlan :: new ( ) ,
158
155
}
159
156
}
@@ -263,11 +260,7 @@ impl BuildQueue {
263
260
pbh : PostBuildHandler ,
264
261
) {
265
262
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 {
271
264
priority = BuildPriority :: Cargo ;
272
265
}
273
266
let build = PendingBuild {
@@ -487,11 +480,7 @@ impl Internals {
487
480
( * compilation_cx) . build_dir = Some ( new_build_dir. to_owned ( ) ) ;
488
481
}
489
482
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 ( ) ;
495
484
}
496
485
497
486
let result = self . build ( progress_sender) ;
@@ -536,25 +525,25 @@ impl Internals {
536
525
return external:: build_with_external_cmd ( cmd, build_dir. unwrap ( ) ) ;
537
526
}
538
527
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
-
542
528
// If the build plan has already been cached, use it, unless Cargo
543
529
// has to be specifically rerun (e.g. when build scripts changed)
544
530
let work = {
545
531
let modified: Vec < _ > = self . dirty_files . lock ( ) . unwrap ( ) . keys ( ) . cloned ( ) . collect ( ) ;
532
+
546
533
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
+ }
551
542
Err ( e) => {
552
543
let msg = format ! ( "Error reading manifest path: {:?}" , e) ;
553
544
return BuildResult :: Err ( msg, None ) ;
554
545
}
555
- } ;
556
- cx. build_plan
557
- . prepare_work ( & manifest_path, & modified, needs_to_run_cargo)
546
+ }
558
547
} ;
559
548
trace ! ( "Specified work: {:?}" , work) ;
560
549
0 commit comments