diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f2d752ab5..0eeb87cfaa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,10 @@ If you want to disable this behavior, you can config it in dfx.json: } } +### fix: Valid canister-based env vars + +Hyphens are not valid in shell environment variables, but do occur in canister names such as `smiley-dapp`. This poses a problem for vars with names such as `CANISTER_ID_${CANISTER_NAME}`. With this change, hyphens are replaced with underscores in environment variables. The canister id of `smiley-dapp` will be available as `CANISTER_ID_smiley_dapp`. Other environment variables are unaffected. + ### feat: Add dfx sns deploy This allows users to deploy a set of SNS canisters. diff --git a/docs/cli-reference/dfx-envars.md b/docs/cli-reference/dfx-envars.md index e8d35dbd40..edf0f37a13 100644 --- a/docs/cli-reference/dfx-envars.md +++ b/docs/cli-reference/dfx-envars.md @@ -16,9 +16,9 @@ For example, if you have a `whoami_frontend` canister that lists `whoami` under ## CANISTER_ID\_{canister.name} -Use environment variables with the `CANISTER_ID` prefix to reference the canister identifier for each canister in the `dfx.json` file for your project. +Use environment variables with the `CANISTER_ID` prefix to reference the canister identifier for each canister in the `dfx.json` file for your project. Hyphens are invalid in environment variables and are replaced by underscores. -For example, if you have a `linkedup` project that consists of the `linkedup` and `connectd` canisters, you could use the `CANISTER_ID_linkedup` and `CANISTER_ID_connectd` environment variables to refer to the canister identifiers—for example `ryjl3-tyaaa-aaaaa-aaaba-cai` and `rrkah-fqaaa-aaaaa-aaaaq-cai`—created for your project. +For example, if you have a `linkedup` project that consists of the `linkedup` and `connect-d` canisters, you could use the `CANISTER_ID_linkedup` and `CANISTER_ID_connect_d` environment variables to refer to the canister identifiers—for example `ryjl3-tyaaa-aaaaa-aaaba-cai` and `rrkah-fqaaa-aaaaa-aaaaq-cai`—created for your project. ## DFX_CONFIG_ROOT diff --git a/src/dfx/src/lib/builders/mod.rs b/src/dfx/src/lib/builders/mod.rs index a45bd71a70..da19322364 100644 --- a/src/dfx/src/lib/builders/mod.rs +++ b/src/dfx/src/lib/builders/mod.rs @@ -316,14 +316,20 @@ pub fn environment_variables<'a>( }; vars.push(( - Owned(format!("CANISTER_CANDID_PATH_{}", canister.get_name())), + Owned(format!( + "CANISTER_CANDID_PATH_{}", + canister.get_name().replace('-', "_") + )), Borrowed(candid_path), )); } } for canister in pool.get_canister_list() { vars.push(( - Owned(format!("CANISTER_ID_{}", canister.get_name())), + Owned(format!( + "CANISTER_ID_{}", + canister.get_name().replace('-', "_") + )), Owned(canister.canister_id().to_text().into()), )); }