Respond to the cargo metadata package ID change in comp-sys

This commit is contained in:
Zhang Junyang
2024-06-20 16:10:47 +00:00
committed by Tate, Hongliang Tian
parent 952fbacaf1
commit 18a0490e23

View File

@ -76,29 +76,29 @@ pub fn component_generate() -> Vec<ComponentInfo> {
// priority calculation complete // priority calculation complete
let mut components_info = Vec::new(); let mut components_info = Vec::new();
for package in component_packages { for package in component_packages {
let temp_id = package["id"].as_str().unwrap();
// extract path, let's take `(path+file:///path/to/comps/pci)` as an example
let path = { let path = {
// use the last element, `pci)` // Parse the package ID <https://doc.rust-lang.org/cargo/reference/pkgid-spec.html>
let mut paths: Vec<&str> = temp_id.split(&workspace_root).collect(); // and extract the path. Let's take `path+file:///path/to/comps/pci#aster-pci@0.1.0`
// remove the last character // as an example package ID.
let mut path1 = paths.pop().unwrap().to_string(); let id = package["id"].as_str().unwrap();
path1.pop(); // Remove the prefix `path+file://`.
if path1.starts_with('/') { assert!(id.starts_with("path+file://"));
path1.remove(0); let id = id.trim_start_matches("path+file://");
} // Remove the fragment part `#aster-pci@0.1.0`. Note that the package name part
path1 // may be missing if the directory name is the same as the package name.
id.split(['#', '@']).next().unwrap()
}; };
let component_info = ComponentInfo { let component_info = {
name: package["name"].as_str().unwrap().to_string(), let package_name = package["name"].as_str().unwrap().to_string();
path: PathBuf::from(&workspace_root) ComponentInfo {
.join(path) name: package_name.clone(),
.to_str() path: PathBuf::from(&workspace_root)
.unwrap() .join(path)
.to_string(), .to_str()
priority: *mapping .unwrap()
.get(&package["name"].as_str().unwrap().to_string()) .to_string(),
.unwrap(), priority: *mapping.get(&package_name).unwrap(),
}
}; };
components_info.push(component_info) components_info.push(component_info)
} }