diff --git a/CHANGELOG.md b/CHANGELOG.md index 59cd161b1f..4e29a9d7ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -119,6 +119,8 @@ You can still disable the canister http feature through configuration: ### feat: custom canister `wasm` field can now specify a URL from which to download +- note that dfx will report an error if a custom canister's `wasm` field is a URL and the canister also has `build` steps. + ### feat: custom canister `candid` field can now specify a URL from which to download ### feat: deploy NNS canisters diff --git a/docs/dfx-json-schema.json b/docs/dfx-json-schema.json index 44b5593365..0b51632f62 100644 --- a/docs/dfx-json-schema.json +++ b/docs/dfx-json-schema.json @@ -183,7 +183,7 @@ "properties": { "build": { "title": "Build Commands", - "description": "Commands that are executed in order to produce this canister's WASM module. Expected to produce the WASM in the path specified by the 'wasm' field.", + "description": "Commands that are executed in order to produce this canister's WASM module. Expected to produce the WASM in the path specified by the 'wasm' field. No build commands are allowed if the `wasm` field is a URL.", "allOf": [ { "$ref": "#/definitions/SerdeVec_for_String" @@ -203,7 +203,7 @@ }, "wasm": { "title": "WASM Path", - "description": "Path to WASM to be installed. URLs to a WASM module are also acceptable.", + "description": "Path to WASM to be installed. URLs to a WASM module are also acceptable. A canister that has a URL to a WASM module can not also have `build` steps.", "type": "string" } } diff --git a/e2e/tests-dfx/build.bash b/e2e/tests-dfx/build.bash index 371c297026..fded1c79b8 100644 --- a/e2e/tests-dfx/build.bash +++ b/e2e/tests-dfx/build.bash @@ -38,6 +38,27 @@ teardown() { assert_match "$ID" } +@test "report an error if a canister defines both a wasm url and a build step" { + install_asset wasm/identity + mkdir -p www/wasm + mv main.wasm www/wasm/ + mv main.did www/wasm + start_webserver --directory www + dfx_start + + dfx_new + + jq '.canisters={}' dfx.json | sponge dfx.json + + jq '.canisters.e2e_project.candid="http://localhost:'"$E2E_WEB_SERVER_PORT"'/wasm/main.did"' dfx.json | sponge dfx.json + jq '.canisters.e2e_project.wasm="http://localhost:'"$E2E_WEB_SERVER_PORT"'/wasm/main.wasm"' dfx.json | sponge dfx.json + jq '.canisters.e2e_project.type="custom"' dfx.json | sponge dfx.json + jq '.canisters.e2e_project.build="echo nope"' dfx.json | sponge dfx.json + + assert_command_fail dfx deploy + assert_contains "Canister 'e2e_project' defines its wasm field as a URL, and has a build step." +} + @test "build uses default build args" { install_asset default_args dfx_start diff --git a/src/dfx/src/config/dfinity.rs b/src/dfx/src/config/dfinity.rs index 20c62c49db..1e30908633 100644 --- a/src/dfx/src/config/dfinity.rs +++ b/src/dfx/src/config/dfinity.rs @@ -138,6 +138,7 @@ pub enum CanisterTypeProperties { Custom { /// # WASM Path /// Path to WASM to be installed. URLs to a WASM module are also acceptable. + /// A canister that has a URL to a WASM module can not also have `build` steps. wasm: String, /// # Candid File @@ -147,6 +148,7 @@ pub enum CanisterTypeProperties { /// # Build Commands /// Commands that are executed in order to produce this canister's WASM module. /// Expected to produce the WASM in the path specified by the 'wasm' field. + /// No build commands are allowed if the `wasm` field is a URL. build: SerdeVec, }, /// # Motoko-Specific Properties diff --git a/src/dfx/src/lib/canister_info/custom.rs b/src/dfx/src/lib/canister_info/custom.rs index 5637243501..72c8a112ff 100644 --- a/src/dfx/src/lib/canister_info/custom.rs +++ b/src/dfx/src/lib/canister_info/custom.rs @@ -54,6 +54,12 @@ impl CanisterInfoFactory for CustomCanisterInfo { ) }; let (input_wasm_url, output_wasm_path) = if let Ok(input_wasm_url) = Url::parse(&wasm) { + if !build.is_empty() { + bail!( + "Canister '{}' defines its wasm field as a URL, and has a build step.", + info.name + ); + } let filename = input_wasm_url.path_segments().ok_or_else(|| { anyhow!( "unable to determine path segments for url {}",