Skip to content

Commit

Permalink
fix: set CANISTER_CANDID_PATH_ properly for remote canisters (#3701)
Browse files Browse the repository at this point in the history
  • Loading branch information
sesi200 authored Apr 16, 2024
1 parent bf5bb9d commit bbf9e9f
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

# UNRELEASED

### fix: set `CANISTER_CANDID_PATH_<canister name>` 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_<canister name>` 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.
Expand Down
3 changes: 2 additions & 1 deletion e2e/assets/remote/envvar/dfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
"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"
]
},
"remote": {
"main": "remote.mo",
"remote": {
"candid": "remotecandid.did",
"id": {
"actuallylocal": "qoctq-giaaa-aaaaa-aaaea-cai"
}
Expand Down
1 change: 1 addition & 0 deletions e2e/assets/remote/envvar/remotecandid.did
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
service {}
1 change: 1 addition & 0 deletions e2e/tests-dfx/remote.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
10 changes: 9 additions & 1 deletion src/dfx/src/lib/builders/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
};
Expand Down
11 changes: 6 additions & 5 deletions src/dfx/src/lib/canister_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit bbf9e9f

Please sign in to comment.