Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions docs/cli-reference/dfx-envars.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion e2e/assets/post_install/dfx.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"version": 1,
"canisters": {
"postinstall": {
"post-install": {
"main": "main.mo",
"post_install": "echo hello-file"
},
Expand Down
6 changes: 3 additions & 3 deletions e2e/tests-dfx/install.bash
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ teardown() {
assert_command dfx canister create --all
assert_command dfx build

assert_command dfx canister install postinstall
assert_command dfx canister install post-install
assert_match 'hello-file'

assert_command dfx canister install postinstall_script
Expand Down Expand Up @@ -133,11 +133,11 @@ teardown() {
@test "post-install tasks discover dependencies" {
install_asset post_install
dfx_start
echo "echo hello \$CANISTER_ID_postinstall" >> postinstall.sh
echo "echo hello \$CANISTER_ID_post_install" >> postinstall.sh

assert_command dfx canister create --all
assert_command dfx build
id=$(dfx canister id postinstall)
id=$(dfx canister id post-install)

assert_command dfx canister install postinstall_script
assert_match "hello $id"
Expand Down
10 changes: 8 additions & 2 deletions src/dfx/src/lib/builders/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
));
}
Expand Down