@@ -122,9 +122,16 @@ pub enum Edition {
122
122
Edition2015 ,
123
123
}
124
124
125
+ #[ derive( Debug , Clone , Copy , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
126
+ pub struct ExternSourceId ( pub u32 ) ;
127
+
125
128
#[ derive( Default , Debug , Clone , PartialEq , Eq ) ]
126
129
pub struct Env {
127
130
entries : FxHashMap < String , String > ,
131
+
132
+ // Note: Some env variables (e.g. OUT_DIR) are located outside of the
133
+ // crate. We store a map to allow remap it to ExternSourceId
134
+ extern_paths : FxHashMap < String , ExternSourceId > ,
128
135
}
129
136
130
137
#[ derive( Debug , Clone , PartialEq , Eq ) ]
@@ -269,6 +276,26 @@ impl Env {
269
276
pub fn get ( & self , env : & str ) -> Option < String > {
270
277
self . entries . get ( env) . cloned ( )
271
278
}
279
+
280
+ pub fn extern_path ( & self , path : & str ) -> Option < ( ExternSourceId , RelativePathBuf ) > {
281
+ self . extern_paths . iter ( ) . find_map ( |( root_path, id) | {
282
+ if path. starts_with ( root_path) {
283
+ let mut rel_path = & path[ root_path. len ( ) ..] ;
284
+ if rel_path. starts_with ( "/" ) {
285
+ rel_path = & rel_path[ 1 ..] ;
286
+ }
287
+ let rel_path = RelativePathBuf :: from_path ( rel_path) . ok ( ) ?;
288
+ Some ( ( id. clone ( ) , rel_path) )
289
+ } else {
290
+ None
291
+ }
292
+ } )
293
+ }
294
+
295
+ pub fn set_extern_path ( & mut self , env : & str , root_path : & str , root : ExternSourceId ) {
296
+ self . entries . insert ( env. to_owned ( ) , root_path. to_owned ( ) ) ;
297
+ self . extern_paths . insert ( root_path. to_owned ( ) , root) ;
298
+ }
272
299
}
273
300
274
301
#[ derive( Debug ) ]
0 commit comments