/// Launches a nested component manager which will run the created realm (along with any local
/// components in the realm). This component manager _must_ be referenced by a relative URL.
///
/// Note that any routes with a source of `parent` in the root realm will need to also be used
/// in component manager's manifest and listed as a namespace capability in its config.
///
/// Note that any routes with a target of `parent` from the root realm will result in exposing
/// the capability to component manager, which is rather useless by itself. Component manager
/// does expose the hub though, which could be traversed to find an exposed capability.
Launches a nested component manager which will run the created realm (along with any local
components in the realm). This component manager _must_ be referenced by a relative URL.

Note that any routes with a source of `parent` in the root realm will need to also be used
in component manager's manifest and listed as a namespace capability in its config.

Note that any routes with a target of `parent` from the root realm will result in exposing
the capability to component manager, which is rather useless by itself. Component manager
does expose the hub though, which could be traversed to find an exposed capability.
Launches a nested component manager which will run the created realm ( along with any local components in the realm ) . This component manager _must_ be referenced by a relative URL . Note that any routes with a source of ` parent ` in the root realm will need to also be used in component manager ' s manifest and listed as a namespace capability in its config . Note that any routes with a target of ` parent ` from the root realm will result in exposing the capability to component manager which is rather useless by itself . Component manager does expose the hub though which could be traversed to find an exposed capability .
pub async fn build_in_nested_component_manager(
        self,
        component_manager_relative_url: &str,
    ) -> Result<RealmInstance, Error> {
        if *self.root_realm.has_legacy_children.lock().await {
            return Err(Error::LegacyChildrenUnsupportedInNestedComponentManager);
        }
        let collection_name = self.collection_name.clone();
        let (root_url, local_component_runner_task) = self.initialize().await?;
        // We now have a root URL we could create in a collection, but instead we want to launch a
        // component manager and give that component manager this root URL. That flag is set with
        // command line arguments, so we can't just launch an unmodified component manager.
        //
        // Open a new connection to the realm builder server to begin creating a new realm. This
        // new realm will hold a single component: component manager. We will modify its manifest
        // such that the root component URL is set to the root_url we just obtained, and the nested
        // component manager will then fetch the manifest from realm builder itself.
        //
        // Note this presumes that component manager is pointed to a config with the following line:
        //
        //     realm_builder_resolver_and_runner: "namespace",
        let component_manager_realm = RealmBuilder::new().await?;
        component_manager_realm
            .add_child(
                "component_manager",
                component_manager_relative_url,
                ChildOptions::new().eager(),
            )
            .await?;
        let mut component_manager_decl =
            component_manager_realm.get_component_decl("component_manager").await?;
        match **component_manager_decl
            .program
            .as_mut()
            .expect("component manager's manifest is lacking a program section")
            .info
            .entries
            .get_or_insert(vec![])
            .iter_mut()
            .find(|e| e.key == "args")
            .expect("component manager's manifest doesn't specify a config")
            .value
            .as_mut()
            .expect("component manager's manifest has a malformed 'args' section") {
                fdata::DictionaryValue::StrVec(ref mut v) => v.push(root_url),
                _ => panic!("component manager's manifest has a single value for 'args', but we were expecting a vector"),
        }
        component_manager_realm
            .replace_component_decl("component_manager", component_manager_decl)
            .await?;
        component_manager_realm
            .add_route(
                Route::new()
                    .capability(Capability::protocol_by_name(
                        "fuchsia.component.resolver.RealmBuilder",
                    ))
                    .capability(Capability::protocol_by_name(
                        "fuchsia.component.runner.RealmBuilder",
                    ))
                    .capability(Capability::protocol_by_name("fuchsia.logger.LogSink"))
                    .capability(Capability::protocol_by_name("fuchsia.process.Launcher"))
                    .capability(Capability::protocol_by_name("fuchsia.sys.Loader"))
                    .capability(Capability::protocol_by_name("fuchsia.tracing.provider.Registry"))
                    .from(Ref::parent())
                    .to(Ref::child("component_manager")),
            )
            .await?;
        component_manager_realm
            .add_route(
                Route::new()
                    .capability(Capability::directory("hub").path("/hub").rights(fio::RW_STAR_DIR))
                    .capability(Capability::protocol_by_name("fuchsia.sys2.EventSource"))
                    .from(Ref::child("component_manager"))
                    .to(Ref::parent()),
            )
            .await?;
        let (component_manager_url, _) = component_manager_realm.initialize().await?;
        let root = ScopedInstance::new(collection_name, component_manager_url)
            .await
            .map_err(Error::FailedToCreateChild)?;
        root.connect_to_binder().map_err(Error::FailedToBind)?;
        Ok(RealmInstance { root, local_component_runner_task: Some(local_component_runner_task) })
    }
pub async fn build_in_nested_component_manager ( self , component_manager_relative_url : & str , ) -> Result < RealmInstance , Error > { if * self . root_realm . has_legacy_children . lock ( ) . await { return Err ( Error :: LegacyChildrenUnsupportedInNestedComponentManager ) ; } let collection_name = self . collection_name . clone ( ) ; let ( root_url , local_component_runner_task ) = self . initialize ( ) . await ? ; // We now have a root URL we could create in a collection, but instead we want to launch a // component manager and give that component manager this root URL. That flag is set with // command line arguments, so we can't just launch an unmodified component manager. // // Open a new connection to the realm builder server to begin creating a new realm. This // new realm will hold a single component: component manager. We will modify its manifest // such that the root component URL is set to the root_url we just obtained, and the nested // component manager will then fetch the manifest from realm builder itself. // // Note this presumes that component manager is pointed to a config with the following line: // //     realm_builder_resolver_and_runner: "namespace", let component_manager_realm = RealmBuilder :: new ( ) . await ? ; component_manager_realm . add_child ( " " , component_manager_relative_url , ChildOptions :: new ( ) . eager ( ) , ) . await ? ; let mut component_manager_decl = component_manager_realm . get_component_decl ( " " ) . await ? ; match * * component_manager_decl . program . as_mut ( ) . expect ( " " ) . info . entries . get_or_insert ( vec ! [ ] ) . iter_mut ( ) . find ( | e | e . key == " " ) . expect ( " " ) . value . as_mut ( ) . expect ( " " ) { fdata :: DictionaryValue :: StrVec ( ref mut v ) => v . push ( root_url ) , _ => panic ! ( " " ) , } component_manager_realm . replace_component_decl ( " " , component_manager_decl ) . await ? ; component_manager_realm . add_route ( Route :: new ( ) . capability ( Capability :: protocol_by_name ( " " , ) ) . capability ( Capability :: protocol_by_name ( " " , ) ) . capability ( Capability :: protocol_by_name ( " " ) ) . capability ( Capability :: protocol_by_name ( " " ) ) . capability ( Capability :: protocol_by_name ( " " ) ) . capability ( Capability :: protocol_by_name ( " " ) ) . from ( Ref :: parent ( ) ) . to ( Ref :: child ( " " ) ) , ) . await ? ; component_manager_realm . add_route ( Route :: new ( ) . capability ( Capability :: directory ( " " ) . path ( " " ) . rights ( fio :: RW_STAR_DIR ) ) . capability ( Capability :: protocol_by_name ( " " ) ) . from ( Ref :: child ( " " ) ) . to ( Ref :: parent ( ) ) , ) . await ? ; let ( component_manager_url , _ ) = component_manager_realm . initialize ( ) . await ? ; let root = ScopedInstance :: new ( collection_name , component_manager_url ) . await . map_err ( Error :: FailedToCreateChild ) ? ; root . connect_to_binder ( ) . map_err ( Error :: FailedToBind ) ? ; Ok ( RealmInstance { root , local_component_runner_task : Some ( local_component_runner_task ) } ) }
Launches a nested component manager which will run the created realm (along with any local
components in the realm).
Launches a nested component manager which will run the created realm ( along with any local components in the realm ) .
self
component_manager_relative_url
&str