fn extract_package_data<'a>(
        component_id: &mut i32,
        service_map: &mut ServiceMapping,
        components: &mut HashMap<String, Component>,
        manifests: &mut Vec<Manifest>,
        pkg: &PackageDefinition,
        static_pkgs: &'a Option<Vec<StaticPackageDescription<'a>>>,
    ) -> Result<()> {
        let source = Self::get_pkg_source(pkg, static_pkgs);
        // Extract V1 and V2 components from the packages.
        for (path, cm) in &pkg.cms {
            // Component Framework Version 2.
            if path.starts_with("meta/") && path.ends_with(".cm") {
                *component_id += 1;
                let url = format!("{}#{}", pkg.url, path);
                components.insert(
                    url.clone(),
                    Component {
                        id: *component_id,
                        url: url.clone(),
                        version: 2,
                        source: source.clone(),
                    },
                );

                let cf2_manifest = {
                    if let ComponentManifest::Version2(decl_bytes) = &cm {
                        let mut cap_uses = Vec::new();
                        let base64_bytes = base64::encode(&decl_bytes);

                        if let Ok(cm_decl) = decode_persistent::<fsys::ComponentDecl>(&decl_bytes) {
                            if let Err(err) = cm_fidl_validator::validate(&cm_decl) {
                                warn!("Invalid cm {} {}", url, err);
                            } else {
                                if let Some(uses) = cm_decl.uses {
                                    for use_ in uses {
                                        match &use_ {
                                            fsys::UseDecl::Protocol(protocol) => {
                                                if let Some(source_name) = &protocol.source_name {
                                                    cap_uses.push(Capability::Protocol(
                                                        ProtocolCapability::new(
                                                            source_name.clone(),
                                                        ),
                                                    ));
                                                }
                                            }
                                            _ => {}
                                        }
                                    }
                                }
                                if let Some(exposes) = cm_decl.exposes {
                                    for expose in exposes {
                                        match &expose {
                                            fsys::ExposeDecl::Protocol(protocol) => {
                                                if let Some(source_name) = &protocol.source_name {
                                                    if let Some(fsys::Ref::Self_(_)) =
                                                        &protocol.source
                                                    {
                                                        service_map.insert(
                                                            source_name.clone(),
                                                            url.clone(),
                                                        );
                                                    }
                                                }
                                            }
                                            _ => {}
                                        }
                                    }
                                }
                            }
                        } else {
                            warn!("cm failed to be decoded {}", url);
                        }
                        Manifest {
                            component_id: *component_id,
                            manifest: ManifestData::Version2(base64_bytes),
                            uses: cap_uses,
                        }
                    } else {
                        Manifest {
                            component_id: *component_id,
                            manifest: ManifestData::Version2(String::from("")),
                            uses: Vec::new(),
                        }
                    }
                };
                manifests.push(cf2_manifest);
            // Component Framework Version 1.
            } else if path.starts_with("meta/") && path.ends_with(".cmx") {
                *component_id += 1;
                let url = format!("{}#{}", pkg.url, path);
                components.insert(
                    url.clone(),
                    Component {
                        id: *component_id,
                        url: url.clone(),
                        version: 1,
                        source: source.clone(),
                    },
                );

                let cf1_manifest = {
                    if let ComponentManifest::Version1(sandbox) = &cm {
                        Manifest {
                            component_id: *component_id,
                            manifest: ManifestData::Version1(serde_json::to_string(&sandbox)?),
                            uses: {
                                match sandbox.services.as_ref() {
                                    Some(svcs) => svcs
                                        .into_iter()
                                        .map(|e| {
                                            Capability::Protocol(ProtocolCapability::new(e.clone()))
                                        })
                                        .collect(),
                                    None => Vec::new(),
                                }
                            },
                        }
                    } else {
                        Manifest {
                            component_id: *component_id,
                            manifest: ManifestData::Version1(String::from("")),
                            uses: Vec::new(),
                        }
                    }
                };
                manifests.push(cf1_manifest);
            }
        }
        Ok(())
    }
/// Extracts all of the components and manifests from a package.
Extracts all of the components and manifests from a package.
Extracts all of the components and manifests from a package .
fn extract_package_data<'a>(
        component_id: &mut i32,
        service_map: &mut ServiceMapping,
        components: &mut HashMap<String, Component>,
        manifests: &mut Vec<Manifest>,
        pkg: &PackageDefinition,
        static_pkgs: &'a Option<Vec<StaticPackageDescription<'a>>>,
    ) -> Result<()> {
        let source = Self::get_pkg_source(pkg, static_pkgs);
        // Extract V1 and V2 components from the packages.
        for (path, cm) in &pkg.cms {
            // Component Framework Version 2.
            if path.starts_with("meta/") && path.ends_with(".cm") {
                *component_id += 1;
                let url = format!("{}#{}", pkg.url, path);
                components.insert(
                    url.clone(),
                    Component {
                        id: *component_id,
                        url: url.clone(),
                        version: 2,
                        source: source.clone(),
                    },
                );
                let cf2_manifest = {
                    if let ComponentManifest::Version2(decl_bytes) = &cm {
                        let mut cap_uses = Vec::new();
                        let base64_bytes = base64::encode(&decl_bytes);
                        if let Ok(cm_decl) = decode_persistent::<fsys::ComponentDecl>(&decl_bytes) {
                            if let Err(err) = cm_fidl_validator::validate(&cm_decl) {
                                warn!("Invalid cm {} {}", url, err);
                            } else {
                                if let Some(uses) = cm_decl.uses {
                                    for use_ in uses {
                                        match &use_ {
                                            fsys::UseDecl::Protocol(protocol) => {
                                                if let Some(source_name) = &protocol.source_name {
                                                    cap_uses.push(Capability::Protocol(
                                                        ProtocolCapability::new(
                                                            source_name.clone(),
                                                        ),
                                                    ));
                                                }
                                            }
                                            _ => {}
                                        }
                                    }
                                }
                                if let Some(exposes) = cm_decl.exposes {
                                    for expose in exposes {
                                        match &expose {
                                            fsys::ExposeDecl::Protocol(protocol) => {
                                                if let Some(source_name) = &protocol.source_name {
                                                    if let Some(fsys::Ref::Self_(_)) =
                                                        &protocol.source
                                                    {
                                                        service_map.insert(
                                                            source_name.clone(),
                                                            url.clone(),
                                                        );
                                                    }
                                                }
                                            }
                                            _ => {}
                                        }
                                    }
                                }
                            }
                        } else {
                            warn!("cm failed to be decoded {}", url);
                        }
                        Manifest {
                            component_id: *component_id,
                            manifest: ManifestData::Version2(base64_bytes),
                            uses: cap_uses,
                        }
                    } else {
                        Manifest {
                            component_id: *component_id,
                            manifest: ManifestData::Version2(String::from("")),
                            uses: Vec::new(),
                        }
                    }
                };
                manifests.push(cf2_manifest);
            // Component Framework Version 1.
            } else if path.starts_with("meta/") && path.ends_with(".cmx") {
                *component_id += 1;
                let url = format!("{}#{}", pkg.url, path);
                components.insert(
                    url.clone(),
                    Component {
                        id: *component_id,
                        url: url.clone(),
                        version: 1,
                        source: source.clone(),
                    },
                );
                let cf1_manifest = {
                    if let ComponentManifest::Version1(sandbox) = &cm {
                        Manifest {
                            component_id: *component_id,
                            manifest: ManifestData::Version1(serde_json::to_string(&sandbox)?),
                            uses: {
                                match sandbox.services.as_ref() {
                                    Some(svcs) => svcs
                                        .into_iter()
                                        .map(|e| {
                                            Capability::Protocol(ProtocolCapability::new(e.clone()))
                                        })
                                        .collect(),
                                    None => Vec::new(),
                                }
                            },
                        }
                    } else {
                        Manifest {
                            component_id: *component_id,
                            manifest: ManifestData::Version1(String::from("")),
                            uses: Vec::new(),
                        }
                    }
                };
                manifests.push(cf1_manifest);
            }
        }
        Ok(())
    }
fn extract_package_data < ' a > ( component_id : & mut i32 , service_map : & mut ServiceMapping , components : & mut HashMap < String , Component > , manifests : & mut Vec < Manifest > , pkg : & PackageDefinition , static_pkgs : & ' a Option < Vec < StaticPackageDescription < ' a > > > , ) -> Result < ( ) > { let source = Self :: get_pkg_source ( pkg , static_pkgs ) ; // Extract V1 and V2 components from the packages. for ( path , cm ) in & pkg . cms { // Component Framework Version 2. if path . starts_with ( " " ) && path . ends_with ( " " ) { * component_id += 1 ; let url = format ! ( " " pkg url path ) ; components . insert ( url . clone ( ) , Component { id : * component_id , url : url . clone ( ) , version : 2 , source : source . clone ( ) , } , ) ; let cf2_manifest = { if let ComponentManifest :: Version2 ( decl_bytes ) = & cm { let mut cap_uses = Vec :: new ( ) ; let base64_bytes = base64 :: encode ( & decl_bytes ) ; if let Ok ( cm_decl ) = decode_persistent :: < fsys :: ComponentDecl > ( & decl_bytes ) { if let Err ( err ) = cm_fidl_validator :: validate ( & cm_decl ) { warn ! ( " " url err ) ; } else { if let Some ( uses ) = cm_decl . uses { for use_ in uses { match & use_ { fsys :: UseDecl :: Protocol ( protocol ) => { if let Some ( source_name ) = & protocol . source_name { cap_uses . push ( Capability :: Protocol ( ProtocolCapability :: new ( source_name . clone ( ) , ) , ) ) ; } } _ => { } } } } if let Some ( exposes ) = cm_decl . exposes { for expose in exposes { match & expose { fsys :: ExposeDecl :: Protocol ( protocol ) => { if let Some ( source_name ) = & protocol . source_name { if let Some ( fsys :: Ref :: Self_ ( _ ) ) = & protocol . source { service_map . insert ( source_name . clone ( ) , url . clone ( ) , ) ; } } } _ => { } } } } } } else { warn ! ( " " url ) ; } Manifest { component_id : * component_id , manifest : ManifestData :: Version2 ( base64_bytes ) , uses : cap_uses , } } else { Manifest { component_id : * component_id , manifest : ManifestData :: Version2 ( String :: from ( " " ) ) , uses : Vec :: new ( ) , } } } ; manifests . push ( cf2_manifest ) ; // Component Framework Version 1. } else if path . starts_with ( " " ) && path . ends_with ( " " ) { * component_id += 1 ; let url = format ! ( " " pkg url path ) ; components . insert ( url . clone ( ) , Component { id : * component_id , url : url . clone ( ) , version : 1 , source : source . clone ( ) , } , ) ; let cf1_manifest = { if let ComponentManifest :: Version1 ( sandbox ) = & cm { Manifest { component_id : * component_id , manifest : ManifestData :: Version1 ( serde_json :: to_string ( & sandbox ) ? ) , uses : { match sandbox . services . as_ref ( ) { Some ( svcs ) => svcs . into_iter ( ) . map ( | e | { Capability :: Protocol ( ProtocolCapability :: new ( e . clone ( ) ) ) } ) . collect ( ) , None => Vec :: new ( ) , } } , } } else { Manifest { component_id : * component_id , manifest : ManifestData :: Version1 ( String :: from ( " " ) ) , uses : Vec :: new ( ) , } } } ; manifests . push ( cf1_manifest ) ; } } Ok ( ( ) ) }
Extracts all of the components and manifests from a package.
Extracts all of the components and manifests from a package .
component_id
&mut i32
service_map
&mut ServiceMapping
components
&mut HashMap<String, Component>
manifests
&mut Vec<Manifest>
pkg
&PackageDefinition
static_pkgs
&'a Option<Vec<StaticPackageDescription<'a>>>
component_id
&mut i32
service_map
&mut ServiceMapping
components
&mut HashMap<String, Component>
manifests
&mut Vec<Manifest>
pkg
&PackageDefinition
static_pkgs
&'a Option<Vec<StaticPackageDescription<'a>>>