diff --git a/CHANGELOG.md b/CHANGELOG.md index e7c4ec618c..8b501dec20 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ # UNRELEASED +### fix: set `CANISTER_CANDID_PATH_` properly for remote canisters + +In the remote canister declaration it is possible to set a candid file to use when the canister is remote on a specific network. +`dfx` now correctly sets the `CANISTER_CANDID_PATH_` environment variable during the build process on remote networks if the file exists. + ### feat: display schema for dfx metadata json `dfx schema --for dfx-metadata` to display JSON schema of the "dfx" metadata. diff --git a/e2e/assets/remote/envvar/dfx.json b/e2e/assets/remote/envvar/dfx.json index ec52f70e28..5530be1420 100644 --- a/e2e/assets/remote/envvar/dfx.json +++ b/e2e/assets/remote/envvar/dfx.json @@ -4,7 +4,7 @@ "type": "custom", "candid": "main.did", "wasm": "main.wasm", - "build": "bash -c 'echo \"CANISTER_ID_REMOTE: $CANISTER_ID_REMOTE\"'", + "build": "bash -c 'echo \"CANISTER_ID_REMOTE: $CANISTER_ID_REMOTE\nCANISTER_CANDID_PATH_REMOTE: $CANISTER_CANDID_PATH_REMOTE\"'", "dependencies": [ "remote" ] @@ -12,6 +12,7 @@ "remote": { "main": "remote.mo", "remote": { + "candid": "remotecandid.did", "id": { "actuallylocal": "qoctq-giaaa-aaaaa-aaaea-cai" } diff --git a/e2e/assets/remote/envvar/remotecandid.did b/e2e/assets/remote/envvar/remotecandid.did new file mode 100644 index 0000000000..c28255a393 --- /dev/null +++ b/e2e/assets/remote/envvar/remotecandid.did @@ -0,0 +1 @@ +service {} diff --git a/e2e/tests-dfx/remote.bash b/e2e/tests-dfx/remote.bash index bef462d540..390070157e 100644 --- a/e2e/tests-dfx/remote.bash +++ b/e2e/tests-dfx/remote.bash @@ -317,4 +317,5 @@ teardown() { assert_command dfx deploy --network actuallylocal -vv assert_match "CANISTER_ID_REMOTE: qoctq-giaaa-aaaaa-aaaea-cai" + assert_contains "CANISTER_CANDID_PATH_REMOTE: $(pwd -P)/remotecandid.did" } diff --git a/src/dfx/src/lib/builders/mod.rs b/src/dfx/src/lib/builders/mod.rs index 2d889e335f..866f7cd1ff 100644 --- a/src/dfx/src/lib/builders/mod.rs +++ b/src/dfx/src/lib/builders/mod.rs @@ -399,7 +399,15 @@ pub fn get_and_write_environment_variables<'a>( ]; for dep in dependencies { let canister = pool.get_canister(dep).unwrap(); - if let Some(output) = canister.get_build_output() { + if let Some(candid_path) = canister.get_info().get_remote_candid_if_remote() { + vars.push(( + Owned(format!( + "CANISTER_CANDID_PATH_{}", + canister.get_name().replace('-', "_").to_ascii_uppercase() + )), + Owned(candid_path.as_os_str().to_owned()), + )); + } else if let Some(output) = canister.get_build_output() { let candid_path = match &output.idl { IdlBuildOutput::File(p) => p.as_os_str(), }; diff --git a/src/dfx/src/lib/canister_info.rs b/src/dfx/src/lib/canister_info.rs index df7e04df57..ada2099d57 100644 --- a/src/dfx/src/lib/canister_info.rs +++ b/src/dfx/src/lib/canister_info.rs @@ -9,6 +9,7 @@ use dfx_core::config::model::dfinity::{ CanisterDeclarationsConfig, CanisterMetadataSection, CanisterTypeProperties, Config, Pullable, TechStack, WasmOptLevel, }; +use dfx_core::fs::canonicalize; use dfx_core::network::provider::get_network_context; use dfx_core::util; use fn_error_context::context; @@ -114,11 +115,11 @@ impl CanisterInfo { .as_ref() .and_then(|remote| remote.id.get(&network_name)) .copied(); - let remote_candid = canister_config - .remote - .as_ref() - .and_then(|r| r.candid.as_ref()) - .cloned(); + let remote_candid = canister_config.remote.as_ref().and_then(|r| { + r.candid + .as_ref() + .and_then(|candid| canonicalize(candid).ok()) + }); // Fill the default config values if None provided let declarations_config = CanisterDeclarationsConfig {