@@ -15,17 +15,14 @@ use dfx_core::network::provider::get_network_context;
1515use dfx_core:: util;
1616use fn_error_context:: context;
1717use std:: path:: { Path , PathBuf } ;
18+ use url:: Url ;
1819
1920pub mod assets;
2021pub mod custom;
2122pub mod motoko;
2223pub mod pull;
2324pub mod rust;
24- use self :: pull:: PullCanisterInfo ;
25- use assets:: AssetsCanisterInfo ;
26- use custom:: CustomCanisterInfo ;
27- use motoko:: MotokoCanisterInfo ;
28- use rust:: RustCanisterInfo ;
25+ use crate :: lib:: deps:: get_candid_path_in_project;
2926
3027pub trait CanisterInfoFactory {
3128 fn create ( info : & CanisterInfo ) -> DfxResult < Self >
@@ -63,6 +60,7 @@ pub struct CanisterInfo {
6360 gzip : bool ,
6461 init_arg : Option < String > ,
6562 init_arg_file : Option < String > ,
63+ output_idl_path : PathBuf ,
6664}
6765
6866impl CanisterInfo {
@@ -137,6 +135,32 @@ impl CanisterInfo {
137135
138136 let output_root = build_root. join ( name) ;
139137
138+ let output_idl_path: PathBuf = if let ( Some ( _id) , Some ( candid) ) =
139+ ( & remote_id, & remote_candid)
140+ {
141+ workspace_root. join ( candid)
142+ } else {
143+ match & canister_config. type_specific {
144+ CanisterTypeProperties :: Rust { package : _, candid } => workspace_root. join ( candid) ,
145+ CanisterTypeProperties :: Assets { .. } => output_root. join ( "assetstorage.did" ) ,
146+ CanisterTypeProperties :: Custom {
147+ wasm : _,
148+ candid,
149+ build : _,
150+ } => {
151+ if Url :: parse ( candid) . is_ok ( ) {
152+ output_root. join ( name) . with_extension ( "did" )
153+ } else {
154+ workspace_root. join ( candid)
155+ }
156+ }
157+ CanisterTypeProperties :: Motoko => output_root. join ( name) . with_extension ( "did" ) ,
158+ CanisterTypeProperties :: Pull { id } => {
159+ get_candid_path_in_project ( workspace_root, id)
160+ }
161+ }
162+ } ;
163+
140164 let type_specific = canister_config. type_specific . clone ( ) ;
141165
142166 let args = match & canister_config. args {
@@ -174,6 +198,7 @@ impl CanisterInfo {
174198 gzip,
175199 init_arg,
176200 init_arg_file,
201+ output_idl_path,
177202 } ;
178203
179204 Ok ( canister_info)
@@ -300,26 +325,8 @@ impl CanisterInfo {
300325 /// Path to the candid file from canister builder which should contain init types.
301326 ///
302327 /// To be separated into service.did and init_args.
303- pub fn get_output_idl_path ( & self ) -> Option < PathBuf > {
304- match & self . type_specific {
305- CanisterTypeProperties :: Motoko { .. } => self
306- . as_info :: < MotokoCanisterInfo > ( )
307- . map ( |x| x. get_output_idl_path ( ) . to_path_buf ( ) ) ,
308- CanisterTypeProperties :: Custom { .. } => self
309- . as_info :: < CustomCanisterInfo > ( )
310- . map ( |x| x. get_output_idl_path ( ) . to_path_buf ( ) ) ,
311- CanisterTypeProperties :: Assets { .. } => self
312- . as_info :: < AssetsCanisterInfo > ( )
313- . map ( |x| x. get_output_idl_path ( ) . to_path_buf ( ) ) ,
314- CanisterTypeProperties :: Rust { .. } => self
315- . as_info :: < RustCanisterInfo > ( )
316- . map ( |x| x. get_output_idl_path ( ) . to_path_buf ( ) ) ,
317- CanisterTypeProperties :: Pull { .. } => self
318- . as_info :: < PullCanisterInfo > ( )
319- . map ( |x| x. get_output_idl_path ( ) . to_path_buf ( ) ) ,
320- }
321- . ok ( )
322- . or_else ( || self . remote_candid . clone ( ) )
328+ pub fn get_output_idl_path ( & self ) -> & Path {
329+ self . output_idl_path . as_path ( )
323330 }
324331
325332 #[ context( "Failed to create <Type>CanisterInfo for canister '{}'." , self . name, ) ]
0 commit comments