Resolve environmental variables in bom file
This commit is contained in:
parent
53d1d0010d
commit
e47a0673e0
@ -408,6 +408,33 @@ impl TargetManagement {
|
||||
self.files_autodep.extend(files_autodep.into_iter());
|
||||
}
|
||||
|
||||
fn resolve_environmental_variables(&mut self) {
|
||||
self.dirs_to_make = self
|
||||
.dirs_to_make
|
||||
.iter()
|
||||
.map(|dir| resolve_envs(dir))
|
||||
.collect();
|
||||
self.links_to_create = self
|
||||
.links_to_create
|
||||
.iter()
|
||||
.map(|(src, linkname)| (resolve_envs(src), resolve_envs(linkname)))
|
||||
.collect();
|
||||
self.dirs_to_copy = self
|
||||
.dirs_to_copy
|
||||
.iter()
|
||||
.map(|(src, dest)| (resolve_envs(src), resolve_envs(dest)))
|
||||
.collect();
|
||||
self.files_to_copy = self
|
||||
.files_to_copy
|
||||
.iter()
|
||||
.map(|(src, dest)| (resolve_envs(src), resolve_envs(dest)))
|
||||
.collect();
|
||||
self.files_autodep = self
|
||||
.files_autodep
|
||||
.iter()
|
||||
.map(|file| resolve_envs(file))
|
||||
.collect();
|
||||
}
|
||||
}
|
||||
|
||||
/// This function will return all included bom files in the order to deal with.
|
||||
|
@ -80,3 +80,16 @@ pub fn find_included_bom_file(
|
||||
std::process::exit(FILE_NOT_EXISTS_ERROR);
|
||||
}
|
||||
|
||||
/// Try to resolve a path may contain environmental variables to a path without environmental variables
|
||||
/// This function relies on a third-party crate shellexpand.
|
||||
/// Known limitations: If the environmental variable points to an empty value, the conversion may fail.
|
||||
pub fn resolve_envs(path: &str) -> String {
|
||||
shellexpand::env(path).map_or_else(
|
||||
|_| {
|
||||
warn!("{} resolve fails.", path);
|
||||
path.to_string()
|
||||
},
|
||||
|res| res.to_string(),
|
||||
)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user