@@ -7,7 +7,6 @@ use std::{
77} ;
88
99use anyhow:: { Context , Result } ;
10- use cargo_metadata:: PackageName ;
1110use dashmap:: DashSet ;
1211use walkdir:: WalkDir ;
1312
@@ -19,8 +18,8 @@ use crate::{
1918pub struct HermesArtifact {
2019 pub name : HermesTargetName ,
2120 pub target_kind : HermesTargetKind ,
22- /// The path to the shadow crate's `Cargo.toml`.
23- pub shadow_manifest_path : PathBuf ,
21+ /// The path to the crate's `Cargo.toml`.
22+ pub manifest_path : PathBuf ,
2423 pub start_from : Vec < String > ,
2524}
2625
@@ -37,10 +36,9 @@ impl HermesArtifact {
3736 }
3837
3938 // Double-hash to make sure we can distinguish between e.g.
40- // (shadow_manifest_path, target_name) = ("abc", "def") and ("ab",
41- // "cdef"), which would hash identically if we just hashed their
42- // concatenation.
43- let h0 = hash ( & self . shadow_manifest_path ) ;
39+ // (manifest_path, target_name) = ("abc", "def") and ("ab", "cdef"),
40+ // which would hash identically if we just hashed their concatenation.
41+ let h0 = hash ( & self . manifest_path ) ;
4442 let h1 = hash ( & self . name . target_name ) ;
4543 let h = hash ( & [ h0, h1] ) ;
4644 format ! ( "{}-{}-{:08x}.llbc" , self . name. package_name, self . name. target_name, h)
@@ -54,29 +52,12 @@ impl HermesArtifact {
5452/// 2. Creates symlinks for the remaining skeleton.
5553pub fn build_shadow_crate ( roots : & Roots ) -> Result < Vec < HermesArtifact > > {
5654 log:: trace!( "build_shadow_crate({:?})" , roots) ;
57- let shadow_root = roots. shadow_root ( ) ;
58- if shadow_root. exists ( ) {
59- fs:: remove_dir_all ( & shadow_root) . context ( "Failed to clear shadow root" ) ?;
60- }
61- fs:: create_dir_all ( & shadow_root) . context ( "Failed to create shadow root" ) ?;
6255
6356 let visited_paths = DashSet :: new ( ) ;
6457 let ( err_tx, err_rx) = mpsc:: channel ( ) ;
6558 // Items are `((PackageName, TargetName), ItemPath)`.
6659 let ( path_tx, path_rx) = mpsc:: channel :: < ( HermesTargetName , String ) > ( ) ;
6760
68- let mut shadow_manifest_paths: HashMap < PackageName , PathBuf > = HashMap :: new ( ) ;
69- for target in & roots. roots {
70- if !shadow_manifest_paths. contains_key ( & target. name . package_name ) {
71- let relative_manifest_path = find_package_root ( & target. src_path ) ?
72- . strip_prefix ( & roots. workspace )
73- . context ( "Package root outside workspace" ) ?
74- . join ( "Cargo.toml" ) ;
75- let shadow_manifest_path = shadow_root. join ( & relative_manifest_path) ;
76- shadow_manifest_paths. insert ( target. name . package_name . clone ( ) , shadow_manifest_path) ;
77- }
78- }
79-
8061 let monitor_handle = std:: thread:: spawn ( move || {
8162 let mut error_count = 0 ;
8263 for err in err_rx {
@@ -137,23 +118,17 @@ pub fn build_shadow_crate(roots: &Roots) -> Result<Vec<HermesArtifact>> {
137118 return Err ( anyhow:: anyhow!( "Aborting due to {} previous errors." , count) ) ;
138119 }
139120
140- let skip_paths: HashSet < PathBuf > = visited_paths. into_iter ( ) . collect ( ) ;
141- create_symlink_skeleton ( & roots. workspace , & shadow_root, & roots. cargo_target_dir , & skip_paths) ?;
142-
143121 Ok ( roots
144122 . roots
145123 . iter ( )
146124 . filter_map ( |target| {
147- // We know that every root has a shadow manifest path, because we
148- // inserted one for each package that has a root.
149- let shadow_manifest_path =
150- shadow_manifest_paths. get ( & target. name . package_name ) . unwrap ( ) ;
125+ let manifest_path = find_package_root ( & target. src_path ) . ok ( ) ?. join ( "Cargo.toml" ) ;
151126 let start_from = entry_points. remove ( & target. name ) ?;
152127
153128 Some ( HermesArtifact {
154129 name : target. name . clone ( ) ,
155130 target_kind : target. kind ,
156- shadow_manifest_path : shadow_manifest_path . clone ( ) ,
131+ manifest_path ,
157132 start_from,
158133 } )
159134 } )
@@ -324,61 +299,3 @@ fn resolve_module_path(
324299
325300 None
326301}
327-
328- fn create_symlink_skeleton (
329- source_root : & Path ,
330- dest_root : & Path ,
331- target_dir : & Path ,
332- skip_paths : & HashSet < PathBuf > ,
333- ) -> Result < ( ) > {
334- log:: trace!( "create_symlink_skeleton(source_root: {:?}, dest_root: {:?}, target_dir: {:?}, skip_paths_count: {})" , source_root, dest_root, target_dir, skip_paths. len( ) ) ;
335- let walker = WalkDir :: new ( source_root)
336- . follow_links ( false ) // Security: don't follow symlinks out of the root.
337- . into_iter ( ) ;
338-
339- let filter = |e : & walkdir:: DirEntry | {
340- let p = e. path ( ) ;
341- // Normally, we expect the `dest_root` to be inside of `target_dir`,
342- // so checking both is redundant. However, if we ever add the option
343- // for the user to manually specify a `dest_root` that is outside of
344- // `target_dir`, this check will prevent us from infinitely recursing
345- // into the source root.
346- p != target_dir && p != dest_root && e. file_name ( ) != ".git"
347- } ;
348-
349- for entry in walker. filter_entry ( filter) {
350- let entry = entry. context ( "Failed to read directory entry" ) ?;
351- let src_path = entry. path ( ) ;
352-
353- let relative_path =
354- src_path. strip_prefix ( source_root) . context ( "File is not inside source root" ) ?;
355- let dest_path = dest_root. join ( relative_path) ;
356-
357- if entry. file_type ( ) . is_dir ( ) {
358- fs:: create_dir_all ( & dest_path)
359- . with_context ( || format ! ( "Failed to create shadow directory: {:?}" , dest_path) ) ?;
360- continue ;
361- }
362-
363- if entry. file_type ( ) . is_file ( ) && !skip_paths. contains ( src_path) {
364- make_symlink ( src_path, & dest_path) ?;
365- }
366- }
367-
368- Ok ( ( ) )
369- }
370-
371- #[ cfg( unix) ]
372- fn make_symlink ( original : & Path , link : & Path ) -> Result < ( ) > {
373- std:: os:: unix:: fs:: symlink ( original, link)
374- . with_context ( || format ! ( "Failed to symlink {:?} -> {:?}" , original, link) )
375- }
376-
377- #[ cfg( windows) ]
378- fn make_symlink ( original : & Path , link : & Path ) -> Result < ( ) > {
379- // Windows treats file and directory symlinks differently.
380- // Since we only call this on files (checking is_file above),
381- // we use symlink_file.
382- std:: os:: windows:: fs:: symlink_file ( original, link)
383- . with_context ( || format ! ( "Failed to symlink {:?} -> {:?}" , original, link) )
384- }
0 commit comments