From 1a1d679fae2b00a68a3add551318b1d552bbae58 Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Thu, 18 Feb 2021 13:16:49 +0100 Subject: [PATCH 01/20] Revert "Revert me: Remove `--all-features` (#114)" This reverts commit 4a0d352bf09556461dc2eddf79bc8e896e7981f4. --- .gitlab-ci.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6f20beeb..4ea682d3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -79,9 +79,7 @@ test: stage: test <<: *docker-env script: - # We are temporarily removing `--all-features` here for the build to succeed - # until our substrate dependencies are released in newer versions. - - cargo test --verbose --workspace + - cargo test --verbose --workspace --all-features #### stage: build (default features) -- GitLab From 2926b4de4d54ca7339b039799aea037475797d18 Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Thu, 18 Feb 2021 09:42:58 +0100 Subject: [PATCH 02/20] Pass verbosity flag --- src/cmd/build.rs | 6 +++--- src/cmd/metadata.rs | 7 ++----- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/cmd/build.rs b/src/cmd/build.rs index 98060919..98f929db 100644 --- a/src/cmd/build.rs +++ b/src/cmd/build.rs @@ -439,7 +439,7 @@ pub(crate) fn execute_with_crate_metadata( #[cfg(feature = "test-ci-only")] #[cfg(test)] mod tests_ci_only { - use crate::{cmd, util::tests::with_tmp_dir, BuildArtifacts, ManifestPath, UnstableFlags}; + use crate::{cmd, util::tests::with_tmp_dir, BuildArtifacts, ManifestPath, UnstableFlags, Verbosity}; #[test] fn build_template() { @@ -449,7 +449,7 @@ mod tests_ci_only { ManifestPath::new(&path.join("new_project").join("Cargo.toml")).unwrap(); let res = super::execute( &manifest_path, - None, + Verbosity::Default, true, BuildArtifacts::All, UnstableFlags::default(), @@ -477,7 +477,7 @@ mod tests_ci_only { // when super::execute( &manifest_path, - None, + Verbosity::Default, true, BuildArtifacts::CheckOnly, UnstableFlags::default(), diff --git a/src/cmd/metadata.rs b/src/cmd/metadata.rs index 0197c2f1..eeae488e 100644 --- a/src/cmd/metadata.rs +++ b/src/cmd/metadata.rs @@ -281,10 +281,7 @@ pub(crate) fn execute( #[cfg(test)] mod tests { use crate::cmd::metadata::blake2_hash; - use crate::{ - cmd, crate_metadata::CrateMetadata, util::tests::with_tmp_dir, BuildArtifacts, - ManifestPath, UnstableFlags, - }; + use crate::{cmd, crate_metadata::CrateMetadata, util::tests::with_tmp_dir, BuildArtifacts, ManifestPath, UnstableFlags, Verbosity}; use contract_metadata::*; use serde_json::{Map, Value}; use std::{fmt::Write, fs}; @@ -379,7 +376,7 @@ mod tests { let crate_metadata = CrateMetadata::collect(&test_manifest.manifest_path)?; let dest_bundle = cmd::metadata::execute( &test_manifest.manifest_path, - None, + Verbosity::Default, BuildArtifacts::All, UnstableFlags::default(), )? -- GitLab From 271696e766375d00234ba7ae3e2e40d2a3f60d75 Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Thu, 18 Feb 2021 12:44:17 +0100 Subject: [PATCH 03/20] Format use --- src/cmd/build.rs | 4 +++- src/cmd/metadata.rs | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/cmd/build.rs b/src/cmd/build.rs index 98f929db..63a3684a 100644 --- a/src/cmd/build.rs +++ b/src/cmd/build.rs @@ -439,7 +439,9 @@ pub(crate) fn execute_with_crate_metadata( #[cfg(feature = "test-ci-only")] #[cfg(test)] mod tests_ci_only { - use crate::{cmd, util::tests::with_tmp_dir, BuildArtifacts, ManifestPath, UnstableFlags, Verbosity}; + use crate::{ + cmd, util::tests::with_tmp_dir, BuildArtifacts, ManifestPath, UnstableFlags, Verbosity, + }; #[test] fn build_template() { diff --git a/src/cmd/metadata.rs b/src/cmd/metadata.rs index eeae488e..8e4ba630 100644 --- a/src/cmd/metadata.rs +++ b/src/cmd/metadata.rs @@ -281,7 +281,10 @@ pub(crate) fn execute( #[cfg(test)] mod tests { use crate::cmd::metadata::blake2_hash; - use crate::{cmd, crate_metadata::CrateMetadata, util::tests::with_tmp_dir, BuildArtifacts, ManifestPath, UnstableFlags, Verbosity}; + use crate::{ + cmd, crate_metadata::CrateMetadata, util::tests::with_tmp_dir, BuildArtifacts, + ManifestPath, UnstableFlags, Verbosity, + }; use contract_metadata::*; use serde_json::{Map, Value}; use std::{fmt::Write, fs}; -- GitLab From 0c36a1202fb37a2337bd66372fe47766f7ffd607 Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Thu, 18 Feb 2021 14:14:14 +0100 Subject: [PATCH 04/20] Run tests without `binaryen-as-dependency` --- .gitlab-ci.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4ea682d3..e700f3ab 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -81,6 +81,11 @@ test: script: - cargo test --verbose --workspace --all-features + # we also run the tests with the feature `binaryen-as-dependency` disabled + # in order to test that everything also works with a `binaryen` provided + # by the system. + - cargo test --verbose --workspace --features=test-ci-only + #### stage: build (default features) build: -- GitLab From 1b2cb32d42deb997bca451c1d43d80150141b22c Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Thu, 18 Feb 2021 14:15:38 +0100 Subject: [PATCH 05/20] Update to `scale-info` 0.6 --- templates/new/_Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/new/_Cargo.toml b/templates/new/_Cargo.toml index 9c06a6c4..5c36a7f3 100644 --- a/templates/new/_Cargo.toml +++ b/templates/new/_Cargo.toml @@ -12,7 +12,7 @@ ink_storage = { version = "3.0.0-rc2", default-features = false } ink_lang = { version = "3.0.0-rc2", default-features = false } scale = { package = "parity-scale-codec", version = "2.0", default-features = false, features = ["derive"] } -scale-info = { version = "0.5.0", default-features = false, features = ["derive"], optional = true } +scale-info = { version = "0.6", default-features = false, features = ["derive"], optional = true } [lib] name = "{{name}}" -- GitLab From 464362745ee6b920fb8482a7ab38158292b4a834 Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Tue, 2 Mar 2021 17:55:04 +0100 Subject: [PATCH 06/20] Fix `value used after move` --- src/cmd/build.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/cmd/build.rs b/src/cmd/build.rs index f800b752..e5ffa9f8 100644 --- a/src/cmd/build.rs +++ b/src/cmd/build.rs @@ -481,10 +481,12 @@ mod tests_ci_only { // the path can never be e.g. `foo_target/ink` -- the assert // would fail for that. assert!(res.target_directory.ends_with("target/ink")); - assert!(res.optimization_result.unwrap().optimized_size > 0.0); + + let optimized_size = res.optimization_result.unwrap().optimized_size; + assert!(optimized_size > 0.0); // our optimized contract template should always be below 3k. - assert!(res.optimization_result.unwrap().optimized_size < 3.0); + assert!(optimized_size < 3.0); Ok(()) }) -- GitLab From 9254d0d2e54d95e01ffb63690f1c6b1a81d7e94a Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Fri, 5 Mar 2021 06:22:36 +0100 Subject: [PATCH 07/20] Do not continue processing wasm on `check` Results in `No such file` otherwise, since no *.wasm is generated on `check`. --- src/cmd/build.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/cmd/build.rs b/src/cmd/build.rs index e5ffa9f8..06347320 100644 --- a/src/cmd/build.rs +++ b/src/cmd/build.rs @@ -430,6 +430,9 @@ pub(crate) fn execute_with_crate_metadata( "Building cargo project".bright_green().bold() ); build_cargo_project(&crate_metadata, build_artifact, verbosity, unstable_flags)?; + if build_artifact == BuildArtifacts::CheckOnly { + return Ok((None, None)); + } maybe_println!( verbosity, " {} {}", -- GitLab From 16a3f386bb926ce9af7fa6fd489802cb7472ffd8 Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Fri, 5 Mar 2021 06:24:31 +0100 Subject: [PATCH 08/20] Make casing consistent for `log` messages --- src/util.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util.rs b/src/util.rs index ece7a0c0..c701f0ab 100644 --- a/src/util.rs +++ b/src/util.rs @@ -64,7 +64,7 @@ where Verbosity::Default => &mut cmd, }; - log::info!("invoking cargo: {:?}", cmd); + log::info!("Invoking cargo: {:?}", cmd); let child = cmd // capture the stdout to return from this function as bytes -- GitLab From 67d11017763e5131c99826d102f0d0b9c066c188 Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Fri, 5 Mar 2021 06:23:40 +0100 Subject: [PATCH 09/20] Clarify behavior of `check` --- src/cmd/build.rs | 10 +++++++--- src/main.rs | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/cmd/build.rs b/src/cmd/build.rs index 06347320..87447144 100644 --- a/src/cmd/build.rs +++ b/src/cmd/build.rs @@ -496,7 +496,7 @@ mod tests_ci_only { } #[test] - fn check_must_not_create_target_in_project_dir() { + fn check_must_not_output_contract_artifacts_in_project_dir() { with_tmp_dir(|path| { // given cmd::new::execute("new_project", Some(path)).expect("new project creation failed"); @@ -515,8 +515,12 @@ mod tests_ci_only { // then assert!( - !project_dir.join("target").exists(), - "found target folder in project directory!" + !project_dir.join("target/ink/new_project.contract").exists(), + "found contract artifact in project directory!" + ); + assert!( + !project_dir.join("target/ink/new_project.wasm").exists(), + "found wasm artifact in project directory!" ); Ok(()) }) diff --git a/src/main.rs b/src/main.rs index 445d4886..34188abc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -315,7 +315,7 @@ enum Command { /// Command has been deprecated, use `cargo contract build` instead #[structopt(name = "generate-metadata")] GenerateMetadata {}, - /// Check that the code builds as Wasm; does not output any build artifact to the top level `target/` directory + /// Check that the code builds as Wasm; does not output any `.contract` artifact to the `target/` directory #[structopt(name = "check")] Check(CheckCommand), /// Test the smart contract off-chain -- GitLab From d2bf1dd9e7dc9f8ca7c82e7abd18ee762844eb31 Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Fri, 5 Mar 2021 06:39:13 +0100 Subject: [PATCH 10/20] Revert me: add debug output --- src/cmd/build.rs | 1 + src/util.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/src/cmd/build.rs b/src/cmd/build.rs index 87447144..2a9be09c 100644 --- a/src/cmd/build.rs +++ b/src/cmd/build.rs @@ -483,6 +483,7 @@ mod tests_ci_only { // always matches whole path components we can be sure // the path can never be e.g. `foo_target/ink` -- the assert // would fail for that. + eprintln!("{:?}", res.target_directory); assert!(res.target_directory.ends_with("target/ink")); let optimized_size = res.optimization_result.unwrap().optimized_size; diff --git a/src/util.rs b/src/util.rs index c701f0ab..538de424 100644 --- a/src/util.rs +++ b/src/util.rs @@ -64,6 +64,7 @@ where Verbosity::Default => &mut cmd, }; + eprintln!("Invoking cargo: {:?}", cmd); log::info!("Invoking cargo: {:?}", cmd); let child = cmd -- GitLab From 723c9b294dabadf31a4c3fa39dddfc8356f83ccf Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Fri, 5 Mar 2021 06:56:47 +0100 Subject: [PATCH 11/20] Upgrade `cargo_metadata` to 0.13.1 --- Cargo.lock | 14 ++++++++++++-- Cargo.toml | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 945c9d7f..743c2de9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -478,6 +478,15 @@ version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "631ae5198c9be5e753e5cc215e1bd73c2b466a3565173db433f52bb9d3e66dba" +[[package]] +name = "camino" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd065703998b183ed0b348a22555691373a9345a1431141e5778b48bb17e4703" +dependencies = [ + "serde", +] + [[package]] name = "cargo-contract" version = "0.10.0" @@ -528,10 +537,11 @@ dependencies = [ [[package]] name = "cargo_metadata" -version = "0.12.3" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7714a157da7991e23d90686b9524b9e12e0407a108647f52e9328f4b3d51ac7f" +checksum = "081e3f0755c1f380c2d010481b6fa2e02973586d5f2b24eebb7a2a1d98b143d8" dependencies = [ + "camino", "cargo-platform", "semver 0.11.0", "semver-parser 0.10.2", diff --git a/Cargo.toml b/Cargo.toml index 5b83e1d7..e83a12f0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,7 @@ heck = "0.3.2" zip = { version = "0.5.11", default-features = false } pwasm-utils = "0.17.0" parity-wasm = "0.42.1" -cargo_metadata = "0.12.3" +cargo_metadata = "0.13.1" codec = { package = "parity-scale-codec", version = "2.0.0", features = ["derive"] } which = "4.0.2" colored = "2.0.0" -- GitLab From 6257e49ff6bec7995806206e8a77d895c5bc5e96 Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Fri, 5 Mar 2021 07:03:08 +0100 Subject: [PATCH 12/20] Fix assert for target path `target/ink` --- src/cmd/build.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/cmd/build.rs b/src/cmd/build.rs index 2a9be09c..b5fe972b 100644 --- a/src/cmd/build.rs +++ b/src/cmd/build.rs @@ -478,13 +478,13 @@ mod tests_ci_only { ) .expect("build failed"); - // we can't use `/target/ink` here, since this would match - // for `/target` being the root path. but since `ends_with` - // always matches whole path components we can be sure - // the path can never be e.g. `foo_target/ink` -- the assert - // would fail for that. - eprintln!("{:?}", res.target_directory); - assert!(res.target_directory.ends_with("target/ink")); + // our ci has set `CARGO_TARGET_DIR` to cache artifacts. + // this dir does not include `/target/` as a path, hence + // we can't match for e.g. `foo_project/target/ink`. + // + // we also can't match for `/ink` here, since this would match + // for `/ink` being the root path. + assert!(res.target_directory.ends_with("ink")); let optimized_size = res.optimization_result.unwrap().optimized_size; assert!(optimized_size > 0.0); -- GitLab From cc82610261391678a52d1505c68fe99c03f82c87 Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Fri, 5 Mar 2021 07:03:49 +0100 Subject: [PATCH 13/20] Revert "Revert me: add debug output" This reverts commit d2bf1dd9e7dc9f8ca7c82e7abd18ee762844eb31. --- src/util.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/util.rs b/src/util.rs index 538de424..c701f0ab 100644 --- a/src/util.rs +++ b/src/util.rs @@ -64,7 +64,6 @@ where Verbosity::Default => &mut cmd, }; - eprintln!("Invoking cargo: {:?}", cmd); log::info!("Invoking cargo: {:?}", cmd); let child = cmd -- GitLab From 7e378be274066cda957cc3156f388d8ecdb6fa2d Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Fri, 5 Mar 2021 07:09:25 +0100 Subject: [PATCH 14/20] Revert "Upgrade `cargo_metadata` to 0.13.1" This reverts commit 723c9b294dabadf31a4c3fa39dddfc8356f83ccf. --- Cargo.lock | 14 ++------------ Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 743c2de9..945c9d7f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -478,15 +478,6 @@ version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "631ae5198c9be5e753e5cc215e1bd73c2b466a3565173db433f52bb9d3e66dba" -[[package]] -name = "camino" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd065703998b183ed0b348a22555691373a9345a1431141e5778b48bb17e4703" -dependencies = [ - "serde", -] - [[package]] name = "cargo-contract" version = "0.10.0" @@ -537,11 +528,10 @@ dependencies = [ [[package]] name = "cargo_metadata" -version = "0.13.1" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "081e3f0755c1f380c2d010481b6fa2e02973586d5f2b24eebb7a2a1d98b143d8" +checksum = "7714a157da7991e23d90686b9524b9e12e0407a108647f52e9328f4b3d51ac7f" dependencies = [ - "camino", "cargo-platform", "semver 0.11.0", "semver-parser 0.10.2", diff --git a/Cargo.toml b/Cargo.toml index e83a12f0..5b83e1d7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,7 @@ heck = "0.3.2" zip = { version = "0.5.11", default-features = false } pwasm-utils = "0.17.0" parity-wasm = "0.42.1" -cargo_metadata = "0.13.1" +cargo_metadata = "0.12.3" codec = { package = "parity-scale-codec", version = "2.0.0", features = ["derive"] } which = "4.0.2" colored = "2.0.0" -- GitLab From 49319f864fae8bee3bd8b6bf246fa3654f846253 Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Wed, 10 Mar 2021 10:14:57 +0100 Subject: [PATCH 15/20] Run tests only with `binaryen-as-dependency` --- .gitlab-ci.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e700f3ab..4ea682d3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -81,11 +81,6 @@ test: script: - cargo test --verbose --workspace --all-features - # we also run the tests with the feature `binaryen-as-dependency` disabled - # in order to test that everything also works with a `binaryen` provided - # by the system. - - cargo test --verbose --workspace --features=test-ci-only - #### stage: build (default features) build: -- GitLab From 02bc6f85086392f6b9b45e0bfebe557ee4f40536 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Tue, 9 Mar 2021 15:46:03 +0000 Subject: [PATCH 16/20] Upgrade cargo-metadata and fix usages (#210) --- Cargo.lock | 26 ++++++++++++++++++-------- Cargo.toml | 6 +++--- src/crate_metadata.rs | 6 +++--- src/workspace/manifest.rs | 16 ++-------------- src/workspace/mod.rs | 5 +++-- 5 files changed, 29 insertions(+), 30 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index efde35bd..8be9f3dc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -478,6 +478,15 @@ version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "631ae5198c9be5e753e5cc215e1bd73c2b466a3565173db433f52bb9d3e66dba" +[[package]] +name = "camino" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd065703998b183ed0b348a22555691373a9345a1431141e5778b48bb17e4703" +dependencies = [ + "serde", +] + [[package]] name = "cargo-contract" version = "0.10.0" @@ -497,7 +506,7 @@ dependencies = [ "hex", "impl-serde", "log", - "parity-scale-codec 2.0.0", + "parity-scale-codec 2.0.1", "parity-wasm 0.42.1", "pretty_assertions", "pwasm-utils", @@ -528,10 +537,11 @@ dependencies = [ [[package]] name = "cargo_metadata" -version = "0.12.3" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7714a157da7991e23d90686b9524b9e12e0407a108647f52e9328f4b3d51ac7f" +checksum = "081e3f0755c1f380c2d010481b6fa2e02973586d5f2b24eebb7a2a1d98b143d8" dependencies = [ + "camino", "cargo-platform", "semver 0.11.0", "semver-parser 0.10.2", @@ -2021,14 +2031,14 @@ dependencies = [ [[package]] name = "parity-scale-codec" -version = "2.0.0" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75c823fdae1bb5ff5708ee61a62697e6296175dc671710876871c853f48592b3" +checksum = "0cd3dab59b5cf4bc81069ade0fc470341a1ef3ad5fa73e5a8943bed2ec12b2e8" dependencies = [ "arrayvec 0.5.2", "bitvec 0.20.1", "byte-slice-cast 1.0.0", - "parity-scale-codec-derive 2.0.0", + "parity-scale-codec-derive 2.0.1", "serde", ] @@ -2046,9 +2056,9 @@ dependencies = [ [[package]] name = "parity-scale-codec-derive" -version = "2.0.0" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9029e65297c7fd6d7013f0579e193ec2b34ae78eabca854c9417504ad8a2d214" +checksum = "fa04976a81fde04924b40cc4036c4d12841e8bb04325a5cf2ada75731a150a7d" dependencies = [ "proc-macro-crate", "proc-macro2", diff --git a/Cargo.toml b/Cargo.toml index 31ca14b2..6be643ba 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,14 +21,14 @@ include = ["Cargo.toml", "src/**/*.rs", "README.md", "LICENSE", "build.rs", "tem [dependencies] env_logger = "0.8.3" anyhow = "1.0.38" -structopt = "0.3.20" +structopt = "0.3.21" log = "0.4.14" heck = "0.3.2" zip = { version = "0.5.11", default-features = false } pwasm-utils = "0.17.0" parity-wasm = "0.42.1" -cargo_metadata = "0.12.3" -codec = { package = "parity-scale-codec", version = "2.0.0", features = ["derive"] } +cargo_metadata = "0.13.1" +codec = { package = "parity-scale-codec", version = "2.0.1", features = ["derive"] } which = "4.0.2" colored = "2.0.0" toml = "0.5.8" diff --git a/src/crate_metadata.rs b/src/crate_metadata.rs index 95e11d13..26bf7f5f 100644 --- a/src/crate_metadata.rs +++ b/src/crate_metadata.rs @@ -92,13 +92,13 @@ impl CrateMetadata { cargo_meta: metadata, root_package, package_name, - original_wasm, - dest_wasm, + original_wasm: original_wasm.into(), + dest_wasm: dest_wasm.into(), ink_version, documentation, homepage, user, - target_directory, + target_directory: target_directory.into(), }; Ok(crate_metadata) } diff --git a/src/workspace/manifest.rs b/src/workspace/manifest.rs index 69d9a272..dc1699bb 100644 --- a/src/workspace/manifest.rs +++ b/src/workspace/manifest.rs @@ -17,7 +17,7 @@ use anyhow::{Context, Result}; use super::{metadata, Profile}; -use std::convert::{TryFrom, TryInto}; +use std::convert::TryFrom; use std::{ collections::HashSet, fs, @@ -77,14 +77,6 @@ impl ManifestPath { } } -impl TryFrom<&PathBuf> for ManifestPath { - type Error = anyhow::Error; - - fn try_from(value: &PathBuf) -> Result { - ManifestPath::new(value) - } -} - impl

TryFrom> for ManifestPath where P: AsRef, @@ -126,11 +118,7 @@ impl Manifest { /// Create new Manifest for the given manifest path. /// /// The path *must* be to a `Cargo.toml`. - pub fn new

(path: P) -> Result - where - P: TryInto, - { - let manifest_path = path.try_into()?; + pub fn new(manifest_path: ManifestPath) -> Result { let toml = fs::read_to_string(&manifest_path).context("Loading Cargo.toml")?; let toml: value::Table = toml::from_str(&toml)?; diff --git a/src/workspace/mod.rs b/src/workspace/mod.rs index bc461d0d..7f242d2a 100644 --- a/src/workspace/mod.rs +++ b/src/workspace/mod.rs @@ -58,7 +58,8 @@ impl Workspace { package_id ) }); - let manifest = Manifest::new(&package.manifest_path)?; + let manifest_path = ManifestPath::new(&package.manifest_path)?; + let manifest = Manifest::new(manifest_path)?; Ok((package_id.clone(), (package.clone(), manifest))) }; @@ -73,7 +74,7 @@ impl Workspace { } Ok(Workspace { - workspace_root: metadata.workspace_root.clone(), + workspace_root: metadata.workspace_root.clone().into(), root_package: root_package.clone(), members, }) -- GitLab From c00e7c66cad25e912ccafebbb9895c2b6e9a00b8 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Tue, 9 Mar 2021 15:46:22 +0000 Subject: [PATCH 17/20] Only allow new contract names beginning with an alphabetic character (#219) * Only allow contract names beginning with an alphabetic character * Add test for contract name beginning with a number * Add test for contract name beginning with a number --- src/cmd/new.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/cmd/new.rs b/src/cmd/new.rs index 5c23574b..3c88c5b2 100644 --- a/src/cmd/new.rs +++ b/src/cmd/new.rs @@ -31,6 +31,15 @@ where anyhow::bail!("Contract names can only contain alphanumeric characters and underscores"); } + if !name + .chars() + .next() + .map(|c| c.is_alphabetic()) + .unwrap_or(false) + { + anyhow::bail!("Contract names must begin with an alphabetic character"); + } + let out_dir = dir .map_or(env::current_dir()?, |p| p.as_ref().to_path_buf()) .join(name); @@ -127,6 +136,19 @@ mod tests { }) } + #[test] + fn rejects_name_beginning_with_number() { + with_tmp_dir(|path| { + let result = execute("1xxx", Some(path)); + assert!(result.is_err(), "Should fail"); + assert_eq!( + result.err().unwrap().to_string(), + "Contract names must begin with an alphabetic character" + ); + Ok(()) + }) + } + #[test] fn contract_cargo_project_already_exists() { with_tmp_dir(|path| { -- GitLab From d8827bc2a2cbd61595ddfc101ea9db7d0e96edeb Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Wed, 10 Mar 2021 10:14:57 +0100 Subject: [PATCH 18/20] Run tests only with `binaryen-as-dependency` --- .gitlab-ci.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e700f3ab..4ea682d3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -81,11 +81,6 @@ test: script: - cargo test --verbose --workspace --all-features - # we also run the tests with the feature `binaryen-as-dependency` disabled - # in order to test that everything also works with a `binaryen` provided - # by the system. - - cargo test --verbose --workspace --features=test-ci-only - #### stage: build (default features) build: -- GitLab From defe20db97bdcd42809e29e67a748511131a9e42 Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Wed, 10 Mar 2021 15:22:13 +0100 Subject: [PATCH 19/20] Refactor --- src/cmd/build.rs | 43 ++++++++++++++++++++++++++++++------------- src/cmd/metadata.rs | 13 ++++++++----- 2 files changed, 38 insertions(+), 18 deletions(-) diff --git a/src/cmd/build.rs b/src/cmd/build.rs index b5fe972b..2b1a1c04 100644 --- a/src/cmd/build.rs +++ b/src/cmd/build.rs @@ -40,6 +40,12 @@ use structopt::StructOpt; /// This is the maximum number of pages available for a contract to allocate. const MAX_MEMORY_PAGES: u32 = 16; +/// Result of executing the build. +pub struct ExecutionResult { + pub dest_wasm: PathBuf, + pub optimization_result: OptimizationResult, +} + /// Executes build of the smart-contract which produces a wasm binary that is ready for deploying. /// /// It does so by invoking `cargo build` and then post processing the final binary. @@ -114,6 +120,8 @@ impl CheckCommand { /// Builds the project in the specified directory, defaults to the current directory. /// +/// Returns the path to the generated contract artifact, if one was generated. +/// /// Uses the unstable cargo feature [`build-std`](https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#build-std) /// to build the standard library with [`panic_immediate_abort`](https://github.com/johnthagen/min-sized-rust#remove-panic-string-formatting-with-panic_immediate_abort) /// which reduces the size of the Wasm binary by not including panic strings and formatting code. @@ -132,7 +140,7 @@ fn build_cargo_project( build_artifact: BuildArtifacts, verbosity: Verbosity, unstable_flags: UnstableFlags, -) -> Result<()> { +) -> Result> { util::assert_channel()?; // set linker args via RUSTFLAGS. @@ -184,7 +192,11 @@ fn build_cargo_project( // clear RUSTFLAGS std::env::remove_var("RUSTFLAGS"); - Ok(()) + if build_artifact == BuildArtifacts::CheckOnly { + Ok(Some(crate_metadata.dest_wasm.clone())) + } else { + Ok(None) + } } /// Ensures the wasm memory import of a given module has the maximum number of pages. @@ -384,13 +396,19 @@ fn execute( ) -> Result { if build_artifact == BuildArtifacts::CodeOnly || build_artifact == BuildArtifacts::CheckOnly { let crate_metadata = CrateMetadata::collect(manifest_path)?; - let (maybe_dest_wasm, maybe_optimization_result) = execute_with_crate_metadata( + let maybe_execution_result = execute_with_crate_metadata( &crate_metadata, verbosity, optimize_contract, build_artifact, unstable_flags, )?; + + let (maybe_dest_wasm, maybe_optimization_result) = maybe_execution_result + .map_or((None, None), |r| { + (Some(r.dest_wasm), Some(r.optimization_result)) + }); + let res = BuildResult { dest_wasm: maybe_dest_wasm, dest_metadata: None, @@ -415,23 +433,22 @@ fn execute( /// /// Uses the supplied `CrateMetadata`. If an instance is not available use [`execute_build`] /// -/// Returns a tuple of `(maybe_optimized_wasm_path, maybe_optimization_result)`. +/// Returns an `ExecutionResult` if the build resulted in any artifacts. pub(crate) fn execute_with_crate_metadata( crate_metadata: &CrateMetadata, verbosity: Verbosity, optimize_contract: bool, build_artifact: BuildArtifacts, unstable_flags: UnstableFlags, -) -> Result<(Option, Option)> { +) -> Result> { maybe_println!( verbosity, " {} {}", format!("[1/{}]", build_artifact.steps()).bold(), "Building cargo project".bright_green().bold() ); - build_cargo_project(&crate_metadata, build_artifact, verbosity, unstable_flags)?; - if build_artifact == BuildArtifacts::CheckOnly { - return Ok((None, None)); + if build_cargo_project(&crate_metadata, build_artifact, verbosity, unstable_flags)?.is_none() { + return Ok(None); } maybe_println!( verbosity, @@ -441,7 +458,7 @@ pub(crate) fn execute_with_crate_metadata( ); post_process_wasm(&crate_metadata)?; if !optimize_contract { - return Ok((None, None)); + return Ok(None); } maybe_println!( verbosity, @@ -450,10 +467,10 @@ pub(crate) fn execute_with_crate_metadata( "Optimizing wasm file".bright_green().bold() ); let optimization_result = optimize_wasm(&crate_metadata)?; - Ok(( - Some(crate_metadata.dest_wasm.clone()), - Some(optimization_result), - )) + Ok(Some(ExecutionResult { + dest_wasm: crate_metadata.dest_wasm.clone(), + optimization_result, + })) } #[cfg(feature = "test-ci-only")] diff --git a/src/cmd/metadata.rs b/src/cmd/metadata.rs index 18135149..06a1d66e 100644 --- a/src/cmd/metadata.rs +++ b/src/cmd/metadata.rs @@ -233,18 +233,21 @@ impl GenerateMetadataCommand { /// /// Return a tuple of `(dest_wasm, hash, optimization_result)`. fn wasm_hash(&self) -> Result<(PathBuf, CodeHash, OptimizationResult)> { - let (maybe_dest_wasm, maybe_optimization_res) = super::build::execute_with_crate_metadata( + let res = super::build::execute_with_crate_metadata( &self.crate_metadata, self.verbosity, true, // for the hash we always use the optimized version of the contract self.build_artifact, self.unstable_options.clone(), - )?; + )? + .expect("result must exist"); let wasm = fs::read(&self.crate_metadata.dest_wasm)?; - let dest_wasm = maybe_dest_wasm.expect("dest wasm must exist"); - let optimization_res = maybe_optimization_res.expect("optimization result must exist"); - Ok((dest_wasm, blake2_hash(wasm.as_slice()), optimization_res)) + Ok(( + res.dest_wasm, + blake2_hash(wasm.as_slice()), + res.optimization_result, + )) } } -- GitLab From 81bdd0ab17633d5cd413ab32fd31071a0f5b202a Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Wed, 10 Mar 2021 16:10:37 +0100 Subject: [PATCH 20/20] Revert "Refactor" This reverts commit defe20db97bdcd42809e29e67a748511131a9e42. --- src/cmd/build.rs | 43 +++++++++++++------------------------------ src/cmd/metadata.rs | 13 +++++-------- 2 files changed, 18 insertions(+), 38 deletions(-) diff --git a/src/cmd/build.rs b/src/cmd/build.rs index 2b1a1c04..b5fe972b 100644 --- a/src/cmd/build.rs +++ b/src/cmd/build.rs @@ -40,12 +40,6 @@ use structopt::StructOpt; /// This is the maximum number of pages available for a contract to allocate. const MAX_MEMORY_PAGES: u32 = 16; -/// Result of executing the build. -pub struct ExecutionResult { - pub dest_wasm: PathBuf, - pub optimization_result: OptimizationResult, -} - /// Executes build of the smart-contract which produces a wasm binary that is ready for deploying. /// /// It does so by invoking `cargo build` and then post processing the final binary. @@ -120,8 +114,6 @@ impl CheckCommand { /// Builds the project in the specified directory, defaults to the current directory. /// -/// Returns the path to the generated contract artifact, if one was generated. -/// /// Uses the unstable cargo feature [`build-std`](https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#build-std) /// to build the standard library with [`panic_immediate_abort`](https://github.com/johnthagen/min-sized-rust#remove-panic-string-formatting-with-panic_immediate_abort) /// which reduces the size of the Wasm binary by not including panic strings and formatting code. @@ -140,7 +132,7 @@ fn build_cargo_project( build_artifact: BuildArtifacts, verbosity: Verbosity, unstable_flags: UnstableFlags, -) -> Result> { +) -> Result<()> { util::assert_channel()?; // set linker args via RUSTFLAGS. @@ -192,11 +184,7 @@ fn build_cargo_project( // clear RUSTFLAGS std::env::remove_var("RUSTFLAGS"); - if build_artifact == BuildArtifacts::CheckOnly { - Ok(Some(crate_metadata.dest_wasm.clone())) - } else { - Ok(None) - } + Ok(()) } /// Ensures the wasm memory import of a given module has the maximum number of pages. @@ -396,19 +384,13 @@ fn execute( ) -> Result { if build_artifact == BuildArtifacts::CodeOnly || build_artifact == BuildArtifacts::CheckOnly { let crate_metadata = CrateMetadata::collect(manifest_path)?; - let maybe_execution_result = execute_with_crate_metadata( + let (maybe_dest_wasm, maybe_optimization_result) = execute_with_crate_metadata( &crate_metadata, verbosity, optimize_contract, build_artifact, unstable_flags, )?; - - let (maybe_dest_wasm, maybe_optimization_result) = maybe_execution_result - .map_or((None, None), |r| { - (Some(r.dest_wasm), Some(r.optimization_result)) - }); - let res = BuildResult { dest_wasm: maybe_dest_wasm, dest_metadata: None, @@ -433,22 +415,23 @@ fn execute( /// /// Uses the supplied `CrateMetadata`. If an instance is not available use [`execute_build`] /// -/// Returns an `ExecutionResult` if the build resulted in any artifacts. +/// Returns a tuple of `(maybe_optimized_wasm_path, maybe_optimization_result)`. pub(crate) fn execute_with_crate_metadata( crate_metadata: &CrateMetadata, verbosity: Verbosity, optimize_contract: bool, build_artifact: BuildArtifacts, unstable_flags: UnstableFlags, -) -> Result> { +) -> Result<(Option, Option)> { maybe_println!( verbosity, " {} {}", format!("[1/{}]", build_artifact.steps()).bold(), "Building cargo project".bright_green().bold() ); - if build_cargo_project(&crate_metadata, build_artifact, verbosity, unstable_flags)?.is_none() { - return Ok(None); + build_cargo_project(&crate_metadata, build_artifact, verbosity, unstable_flags)?; + if build_artifact == BuildArtifacts::CheckOnly { + return Ok((None, None)); } maybe_println!( verbosity, @@ -458,7 +441,7 @@ pub(crate) fn execute_with_crate_metadata( ); post_process_wasm(&crate_metadata)?; if !optimize_contract { - return Ok(None); + return Ok((None, None)); } maybe_println!( verbosity, @@ -467,10 +450,10 @@ pub(crate) fn execute_with_crate_metadata( "Optimizing wasm file".bright_green().bold() ); let optimization_result = optimize_wasm(&crate_metadata)?; - Ok(Some(ExecutionResult { - dest_wasm: crate_metadata.dest_wasm.clone(), - optimization_result, - })) + Ok(( + Some(crate_metadata.dest_wasm.clone()), + Some(optimization_result), + )) } #[cfg(feature = "test-ci-only")] diff --git a/src/cmd/metadata.rs b/src/cmd/metadata.rs index 06a1d66e..18135149 100644 --- a/src/cmd/metadata.rs +++ b/src/cmd/metadata.rs @@ -233,21 +233,18 @@ impl GenerateMetadataCommand { /// /// Return a tuple of `(dest_wasm, hash, optimization_result)`. fn wasm_hash(&self) -> Result<(PathBuf, CodeHash, OptimizationResult)> { - let res = super::build::execute_with_crate_metadata( + let (maybe_dest_wasm, maybe_optimization_res) = super::build::execute_with_crate_metadata( &self.crate_metadata, self.verbosity, true, // for the hash we always use the optimized version of the contract self.build_artifact, self.unstable_options.clone(), - )? - .expect("result must exist"); + )?; let wasm = fs::read(&self.crate_metadata.dest_wasm)?; - Ok(( - res.dest_wasm, - blake2_hash(wasm.as_slice()), - res.optimization_result, - )) + let dest_wasm = maybe_dest_wasm.expect("dest wasm must exist"); + let optimization_res = maybe_optimization_res.expect("optimization result must exist"); + Ok((dest_wasm, blake2_hash(wasm.as_slice()), optimization_res)) } } -- GitLab