@@ -865,18 +865,15 @@ impl LocalFingerprint {
865
865
mtime_cache,
866
866
checksum_cache,
867
867
& dep_info,
868
- info. files . iter ( ) . map ( |file| {
869
- let checksum = info. checksum . get ( file. as_path ( ) ) . cloned ( ) ;
870
- ( file, checksum)
871
- } ) ,
868
+ info. files . iter ( ) . map ( |( file, checksum) | ( file, * checksum) ) ,
872
869
* checksum,
873
870
) )
874
871
} else {
875
872
Ok ( find_stale_file (
876
873
mtime_cache,
877
874
checksum_cache,
878
875
& dep_info,
879
- info. files . into_iter ( ) . map ( |p | ( p, None ) ) ,
876
+ info. files . into_iter ( ) . map ( |( p , _checksum ) | ( p, None ) ) ,
880
877
* checksum,
881
878
) )
882
879
}
@@ -1935,16 +1932,15 @@ pub fn parse_dep_info(
1935
1932
} ;
1936
1933
let mut ret = RustcDepInfo :: default ( ) ;
1937
1934
ret. env = info. env ;
1938
- ret. files . extend (
1939
- info. files
1940
- . into_iter ( )
1941
- . map ( |( ty, path) | make_absolute_path ( ty, pkg_root, target_root, path) ) ,
1942
- ) ;
1943
- for ( ty, path, file_len, checksum) in info. checksum {
1944
- let path = make_absolute_path ( ty, pkg_root, target_root, path) ;
1945
- ret. checksum
1946
- . insert ( path, ( file_len, Checksum :: from_str ( & checksum) ?) ) ;
1947
- }
1935
+ ret. files
1936
+ . extend ( info. files . into_iter ( ) . map ( |( ty, path, checksum_info) | {
1937
+ (
1938
+ make_absolute_path ( ty, pkg_root, target_root, path) ,
1939
+ checksum_info. and_then ( |( file_len, checksum) | {
1940
+ Checksum :: from_str ( & checksum) . ok ( ) . map ( |c| ( file_len, c) )
1941
+ } ) ,
1942
+ )
1943
+ } ) ) ;
1948
1944
Ok ( Some ( ret) )
1949
1945
}
1950
1946
@@ -2201,21 +2197,14 @@ pub fn translate_dep_info(
2201
2197
Some ( ( ty, path. to_owned ( ) ) )
2202
2198
} ;
2203
2199
2204
- for file in depinfo. files {
2205
- let Some ( serializable_path ) = serialize_path ( file) else {
2200
+ for ( file, checksum_info ) in depinfo. files {
2201
+ let Some ( ( path_type , path ) ) = serialize_path ( file) else {
2206
2202
continue ;
2207
2203
} ;
2208
- on_disk_info. files . push ( serializable_path) ;
2209
- }
2210
- for ( file, ( file_len, checksum) ) in depinfo. checksum {
2211
- let Some ( serializable_path) = serialize_path ( file) else {
2212
- continue ;
2213
- } ;
2214
- on_disk_info. checksum . push ( (
2215
- serializable_path. 0 ,
2216
- serializable_path. 1 ,
2217
- file_len,
2218
- checksum. to_string ( ) ,
2204
+ on_disk_info. files . push ( (
2205
+ path_type,
2206
+ path,
2207
+ checksum_info. map ( |( len, checksum) | ( len, checksum. to_string ( ) ) ) ,
2219
2208
) ) ;
2220
2209
}
2221
2210
paths:: write ( cargo_dep_info, on_disk_info. serialize ( ) ?) ?;
@@ -2226,7 +2215,7 @@ pub fn translate_dep_info(
2226
2215
#[ derive( Default ) ]
2227
2216
pub struct RustcDepInfo {
2228
2217
/// The list of files that the main target in the dep-info file depends on.
2229
- pub files : Vec < PathBuf > ,
2218
+ pub files : Vec < ( PathBuf , Option < ( u64 , Checksum ) > ) > ,
2230
2219
/// The list of environment variables we found that the rustc compilation
2231
2220
/// depends on.
2232
2221
///
@@ -2235,10 +2224,6 @@ pub struct RustcDepInfo {
2235
2224
/// means that the env var wasn't actually set and the compilation depends
2236
2225
/// on it not being set.
2237
2226
pub env : Vec < ( String , Option < String > ) > ,
2238
-
2239
- /// If provided by rustc, a mapping that ties a file to the checksum and file size
2240
- /// at the time rustc ingested it.
2241
- pub checksum : HashMap < PathBuf , ( u64 , Checksum ) > ,
2242
2227
}
2243
2228
2244
2229
/// Same as [`RustcDepInfo`] except avoids absolute paths as much as possible to
@@ -2248,9 +2233,8 @@ pub struct RustcDepInfo {
2248
2233
/// Cargo will read it for crates on all future compilations.
2249
2234
#[ derive( Default ) ]
2250
2235
struct EncodedDepInfo {
2251
- files : Vec < ( DepInfoPathType , PathBuf ) > ,
2236
+ files : Vec < ( DepInfoPathType , PathBuf , Option < ( u64 , String ) > ) > ,
2252
2237
env : Vec < ( String , Option < String > ) > ,
2253
- checksum : Vec < ( DepInfoPathType , PathBuf , u64 , String ) > ,
2254
2238
}
2255
2239
2256
2240
impl EncodedDepInfo {
@@ -2264,8 +2248,19 @@ impl EncodedDepInfo {
2264
2248
1 => DepInfoPathType :: TargetRootRelative ,
2265
2249
_ => return None ,
2266
2250
} ;
2267
- let bytes = read_bytes ( bytes) ?;
2268
- files. push ( ( ty, paths:: bytes2path ( bytes) . ok ( ) ?) ) ;
2251
+ let path_bytes = read_bytes ( bytes) ?;
2252
+ let path = paths:: bytes2path ( path_bytes) . ok ( ) ?;
2253
+ let has_checksum = read_bool ( bytes) ?;
2254
+ let checksum_info = has_checksum
2255
+ . then ( || {
2256
+ let file_len = read_u64 ( bytes) ;
2257
+ let checksum_string = read_bytes ( bytes)
2258
+ . map ( Vec :: from)
2259
+ . and_then ( |v| String :: from_utf8 ( v) . ok ( ) ) ;
2260
+ file_len. zip ( checksum_string)
2261
+ } )
2262
+ . flatten ( ) ;
2263
+ files. push ( ( ty, path, checksum_info) ) ;
2269
2264
}
2270
2265
2271
2266
let nenv = read_usize ( bytes) ?;
@@ -2279,29 +2274,7 @@ impl EncodedDepInfo {
2279
2274
} ;
2280
2275
env. push ( ( key, val) ) ;
2281
2276
}
2282
- let nchecksum = read_usize ( bytes) ?;
2283
- let mut checksum = Vec :: with_capacity ( nchecksum) ;
2284
- for _ in 0 ..nchecksum {
2285
- let ty = match read_u8 ( bytes) ? {
2286
- 0 => DepInfoPathType :: PackageRootRelative ,
2287
- 1 => DepInfoPathType :: TargetRootRelative ,
2288
- _ => return None ,
2289
- } ;
2290
- let path_bytes = read_bytes ( bytes) ?;
2291
- let file_len = read_u64 ( bytes) ?;
2292
- let checksum_bytes = read_bytes ( bytes) ?;
2293
- checksum. push ( (
2294
- ty,
2295
- paths:: bytes2path ( path_bytes) . ok ( ) ?,
2296
- file_len,
2297
- from_utf8 ( checksum_bytes) . ok ( ) ?. to_string ( ) ,
2298
- ) ) ;
2299
- }
2300
- return Some ( EncodedDepInfo {
2301
- files,
2302
- env,
2303
- checksum,
2304
- } ) ;
2277
+ return Some ( EncodedDepInfo { files, env } ) ;
2305
2278
2306
2279
fn read_usize ( bytes : & mut & [ u8 ] ) -> Option < usize > {
2307
2280
let ret = bytes. get ( ..4 ) ?;
@@ -2315,6 +2288,12 @@ impl EncodedDepInfo {
2315
2288
Some ( u64:: from_le_bytes ( ret. try_into ( ) . unwrap ( ) ) )
2316
2289
}
2317
2290
2291
+ fn read_bool ( bytes : & mut & [ u8 ] ) -> Option < bool > {
2292
+ let ret = bytes. get ( 0 ) . map ( |b| * b != 0 ) ?;
2293
+ * bytes = & bytes[ 1 ..] ;
2294
+ Some ( ret)
2295
+ }
2296
+
2318
2297
fn read_u8 ( bytes : & mut & [ u8 ] ) -> Option < u8 > {
2319
2298
let ret = * bytes. get ( 0 ) ?;
2320
2299
* bytes = & bytes[ 1 ..] ;
@@ -2333,12 +2312,17 @@ impl EncodedDepInfo {
2333
2312
let mut ret = Vec :: new ( ) ;
2334
2313
let dst = & mut ret;
2335
2314
write_usize ( dst, self . files . len ( ) ) ;
2336
- for ( ty, file) in self . files . iter ( ) {
2315
+ for ( ty, file, checksum_info ) in self . files . iter ( ) {
2337
2316
match ty {
2338
2317
DepInfoPathType :: PackageRootRelative => dst. push ( 0 ) ,
2339
2318
DepInfoPathType :: TargetRootRelative => dst. push ( 1 ) ,
2340
2319
}
2341
2320
write_bytes ( dst, paths:: path2bytes ( file) ?) ;
2321
+ write_bool ( dst, checksum_info. is_some ( ) ) ;
2322
+ if let Some ( ( len, checksum) ) = checksum_info {
2323
+ write_u64 ( dst, * len) ;
2324
+ write_bytes ( dst, checksum) ;
2325
+ }
2342
2326
}
2343
2327
2344
2328
write_usize ( dst, self . env . len ( ) ) ;
@@ -2352,17 +2336,6 @@ impl EncodedDepInfo {
2352
2336
}
2353
2337
}
2354
2338
}
2355
-
2356
- write_usize ( dst, self . checksum . len ( ) ) ;
2357
- for ( ty, file, file_len, checksum) in self . checksum . iter ( ) {
2358
- match ty {
2359
- DepInfoPathType :: PackageRootRelative => dst. push ( 0 ) ,
2360
- DepInfoPathType :: TargetRootRelative => dst. push ( 1 ) ,
2361
- }
2362
- write_bytes ( dst, paths:: path2bytes ( file) ?) ;
2363
- write_u64 ( dst, * file_len) ;
2364
- write_bytes ( dst, checksum) ;
2365
- }
2366
2339
return Ok ( ret) ;
2367
2340
2368
2341
fn write_bytes ( dst : & mut Vec < u8 > , val : impl AsRef < [ u8 ] > ) {
@@ -2378,6 +2351,10 @@ impl EncodedDepInfo {
2378
2351
fn write_u64 ( dst : & mut Vec < u8 > , val : u64 ) {
2379
2352
dst. extend ( & u64:: to_le_bytes ( val) ) ;
2380
2353
}
2354
+
2355
+ fn write_bool ( dst : & mut Vec < u8 > , val : bool ) {
2356
+ dst. push ( u8:: from ( val) ) ;
2357
+ }
2381
2358
}
2382
2359
}
2383
2360
@@ -2398,39 +2375,42 @@ pub fn parse_rustc_dep_info(rustc_dep_info: &Path) -> CargoResult<RustcDepInfo>
2398
2375
None => None ,
2399
2376
} ;
2400
2377
ret. env . push ( ( unescape_env ( env_var) ?, env_val) ) ;
2401
- } else if let Some ( rest) = line. strip_prefix ( "# checksum:" ) {
2402
- let mut parts = rest. splitn ( 3 , ' ' ) ;
2403
- let Some ( checksum) = parts. next ( ) . map ( Checksum :: from_str) . transpose ( ) ? else {
2404
- continue ;
2405
- } ;
2406
- let Some ( Ok ( file_len) ) = parts
2407
- . next ( )
2408
- . and_then ( |s| s. strip_prefix ( "file_len:" ) . map ( |s| s. parse :: < u64 > ( ) ) )
2409
- else {
2410
- continue ;
2411
- } ;
2412
- let Some ( path) = parts. next ( ) . map ( PathBuf :: from) else {
2413
- continue ;
2414
- } ;
2415
-
2416
- ret. checksum . insert ( path, ( file_len, checksum) ) ;
2417
2378
} else if let Some ( pos) = line. find ( ": " ) {
2418
2379
if found_deps {
2419
2380
continue ;
2420
2381
}
2382
+ let mut parsing_checksum_index = None ;
2383
+ let mut last_seen_checksum = None ;
2421
2384
found_deps = true ;
2422
2385
let mut deps = line[ pos + 2 ..] . split_whitespace ( ) ;
2423
2386
2424
2387
while let Some ( s) = deps. next ( ) {
2425
- let mut file = s. to_string ( ) ;
2426
- while file. ends_with ( '\\' ) {
2427
- file. pop ( ) ;
2428
- file. push ( ' ' ) ;
2429
- file. push_str ( deps. next ( ) . ok_or_else ( || {
2388
+ let mut word = s. to_string ( ) ;
2389
+ if word == "#" {
2390
+ parsing_checksum_index = Some ( 0 ) ;
2391
+ continue ;
2392
+ }
2393
+ while word. ends_with ( '\\' ) {
2394
+ word. pop ( ) ;
2395
+ word. push ( ' ' ) ;
2396
+ word. push_str ( deps. next ( ) . ok_or_else ( || {
2430
2397
internal ( "malformed dep-info format, trailing \\ " . to_string ( ) )
2431
2398
} ) ?) ;
2432
2399
}
2433
- ret. files . push ( file. into ( ) ) ;
2400
+ if let Some ( parsing_checksum_index) = parsing_checksum_index. as_mut ( ) {
2401
+ // By now files list is built, checksum data is provided in the same order as
2402
+ // the file list
2403
+ if let Some ( checksum) = word. strip_prefix ( "checksum:" ) {
2404
+ last_seen_checksum = Some ( Checksum :: from_str ( checksum) ?) ;
2405
+ } else if let Some ( file_len) = word. strip_prefix ( "file_len:" ) {
2406
+ let file_len = file_len. parse :: < u64 > ( ) ?;
2407
+ let file_entry = & mut ret. files [ * parsing_checksum_index] ;
2408
+ file_entry. 1 = last_seen_checksum. take ( ) . map ( |c| ( file_len, c) ) ;
2409
+ * parsing_checksum_index += 1 ;
2410
+ }
2411
+ } else {
2412
+ ret. files . push ( ( word. into ( ) , None ) ) ;
2413
+ }
2434
2414
}
2435
2415
}
2436
2416
}
0 commit comments