Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
vporton committed Apr 15, 2024
1 parent a984e8a commit 4be4fa8
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions src/dfx/src/lib/builders/motoko.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,22 @@ impl MotokoBuilder {
})
}

fn obtain_canister_maps(pool: &CanisterPool) -> (BTreeMap<String, String>, BTreeMap<String, String>) {
// from name to principal:
let id_map = pool
.get_canister_list()
.iter()
.map(|c| (c.get_name().to_string(), c.canister_id().to_text()))
.collect();
// from principal to name:
let rev_id_map = pool
.get_canister_list()
.iter()
.map(|c| (c.canister_id().to_text(), c.get_name().to_string()))
.collect();
(id_map, rev_id_map)
}

/// Accomplish build given the already calculated canister dependencies
fn do_build(
&self,
Expand Down Expand Up @@ -315,29 +331,16 @@ impl CanisterBuilder for MotokoBuilder {
) -> DfxResult<BuildOutput> {
let motoko_info = canister_info.as_info::<MotokoCanisterInfo>()?;

// from name to principal:
let id_map = pool
.get_canister_list()
.iter()
.map(|c| (c.get_name().to_string(), c.canister_id().to_text()))
.collect();
// from principal to name:
let rev_id_map: BTreeMap<String, String> = pool
.get_canister_list()
.iter()
.map(|c| (c.canister_id().to_text(), c.get_name().to_string()))
.collect();

let cache = &self.cache;
get_imports(cache.as_ref(), &motoko_info, &mut *pool.imports.borrow_mut(), pool)?;
let (id_map, rev_id_map) = Self::obtain_canister_maps(pool);
get_imports(self.cache.as_ref(), &motoko_info, &mut *pool.imports.borrow_mut(), pool)?;

self.do_build(
pool,
canister_info,
config,
&id_map,
&rev_id_map,
cache.as_ref(),
self.cache.as_ref(),
)
}

Expand Down

0 comments on commit 4be4fa8

Please sign in to comment.