106
106
use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
107
107
use rustc_data_structures:: svh:: Svh ;
108
108
use rustc_data_structures:: { base_n, flock} ;
109
+ use rustc_errors:: ErrorReported ;
109
110
use rustc_fs_util:: { link_or_copy, LinkOrCopy } ;
110
111
use rustc_session:: { CrateDisambiguator , Session } ;
111
112
@@ -189,9 +190,9 @@ pub fn prepare_session_directory(
189
190
sess : & Session ,
190
191
crate_name : & str ,
191
192
crate_disambiguator : CrateDisambiguator ,
192
- ) {
193
+ ) -> Result < ( ) , ErrorReported > {
193
194
if sess. opts . incremental . is_none ( ) {
194
- return ;
195
+ return Ok ( ( ) ) ;
195
196
}
196
197
197
198
let _timer = sess. timer ( "incr_comp_prepare_session_directory" ) ;
@@ -201,9 +202,7 @@ pub fn prepare_session_directory(
201
202
// {incr-comp-dir}/{crate-name-and-disambiguator}
202
203
let crate_dir = crate_path ( sess, crate_name, crate_disambiguator) ;
203
204
debug ! ( "crate-dir: {}" , crate_dir. display( ) ) ;
204
- if create_dir ( sess, & crate_dir, "crate" ) . is_err ( ) {
205
- return ;
206
- }
205
+ create_dir ( sess, & crate_dir, "crate" ) ?;
207
206
208
207
// Hack: canonicalize the path *after creating the directory*
209
208
// because, on windows, long paths can cause problems;
@@ -217,7 +216,7 @@ pub fn prepare_session_directory(
217
216
crate_dir. display( ) ,
218
217
err
219
218
) ) ;
220
- return ;
219
+ return Err ( ErrorReported ) ;
221
220
}
222
221
} ;
223
222
@@ -232,16 +231,11 @@ pub fn prepare_session_directory(
232
231
233
232
// Lock the new session directory. If this fails, return an
234
233
// error without retrying
235
- let ( directory_lock, lock_file_path) = match lock_directory ( sess, & session_dir) {
236
- Ok ( e) => e,
237
- Err ( _) => return ,
238
- } ;
234
+ let ( directory_lock, lock_file_path) = lock_directory ( sess, & session_dir) ?;
239
235
240
236
// Now that we have the lock, we can actually create the session
241
237
// directory
242
- if create_dir ( sess, & session_dir, "session" ) . is_err ( ) {
243
- return ;
244
- }
238
+ create_dir ( sess, & session_dir, "session" ) ?;
245
239
246
240
// Find a suitable source directory to copy from. Ignore those that we
247
241
// have already tried before.
@@ -257,7 +251,7 @@ pub fn prepare_session_directory(
257
251
) ;
258
252
259
253
sess. init_incr_comp_session ( session_dir, directory_lock, false ) ;
260
- return ;
254
+ return Ok ( ( ) ) ;
261
255
} ;
262
256
263
257
debug ! ( "attempting to copy data from source: {}" , source_directory. display( ) ) ;
@@ -278,7 +272,7 @@ pub fn prepare_session_directory(
278
272
}
279
273
280
274
sess. init_incr_comp_session ( session_dir, directory_lock, true ) ;
281
- return ;
275
+ return Ok ( ( ) ) ;
282
276
} else {
283
277
debug ! ( "copying failed - trying next directory" ) ;
284
278
@@ -478,7 +472,7 @@ fn generate_session_dir_path(crate_dir: &Path) -> PathBuf {
478
472
directory_path
479
473
}
480
474
481
- fn create_dir ( sess : & Session , path : & Path , dir_tag : & str ) -> Result < ( ) , ( ) > {
475
+ fn create_dir ( sess : & Session , path : & Path , dir_tag : & str ) -> Result < ( ) , ErrorReported > {
482
476
match std_fs:: create_dir_all ( path) {
483
477
Ok ( ( ) ) => {
484
478
debug ! ( "{} directory created successfully" , dir_tag) ;
@@ -492,13 +486,16 @@ fn create_dir(sess: &Session, path: &Path, dir_tag: &str) -> Result<(), ()> {
492
486
path. display( ) ,
493
487
err
494
488
) ) ;
495
- Err ( ( ) )
489
+ Err ( ErrorReported )
496
490
}
497
491
}
498
492
}
499
493
500
494
/// Allocate the lock-file and lock it.
501
- fn lock_directory ( sess : & Session , session_dir : & Path ) -> Result < ( flock:: Lock , PathBuf ) , ( ) > {
495
+ fn lock_directory (
496
+ sess : & Session ,
497
+ session_dir : & Path ,
498
+ ) -> Result < ( flock:: Lock , PathBuf ) , ErrorReported > {
502
499
let lock_file_path = lock_file_path ( session_dir) ;
503
500
debug ! ( "lock_directory() - lock_file: {}" , lock_file_path. display( ) ) ;
504
501
@@ -510,13 +507,23 @@ fn lock_directory(sess: &Session, session_dir: &Path) -> Result<(flock::Lock, Pa
510
507
) {
511
508
// the lock should be exclusive
512
509
Ok ( lock) => Ok ( ( lock, lock_file_path) ) ,
513
- Err ( err ) => {
514
- sess. err ( & format ! (
510
+ Err ( lock_err ) => {
511
+ let mut err = sess. struct_err ( & format ! (
515
512
"incremental compilation: could not create \
516
- session directory lock file: {}",
517
- err
513
+ session directory lock file: {}",
514
+ lock_err
518
515
) ) ;
519
- Err ( ( ) )
516
+ if flock:: Lock :: error_unsupported ( & lock_err) {
517
+ err. note ( & format ! (
518
+ "the filesystem for the incremental path at {} \
519
+ does not appear to support locking, consider changing the \
520
+ incremental path to a filesystem that supports locking \
521
+ or disable incremental compilation",
522
+ session_dir. display( )
523
+ ) ) ;
524
+ }
525
+ err. emit ( ) ;
526
+ Err ( ErrorReported )
520
527
}
521
528
}
522
529
}
0 commit comments