Skip to content

Commit c794ec9

Browse files
committed
Merge branch 'master' into hc-get-lang-error-from-create-builder
2 parents f01b5ca + bf2de8f commit c794ec9

File tree

3 files changed

+49
-43
lines changed

3 files changed

+49
-43
lines changed

crates/e2e/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ ink = { version = "4.0.0-beta", path = "../ink" }
2121
ink_env = { version = "4.0.0-beta", path = "../env" }
2222
ink_primitives = { version = "4.0.0-beta", path = "../primitives" }
2323

24-
contract-metadata = { version = "2.0.0-beta" }
24+
contract-metadata = { version = "2.0.0-beta.1" }
2525
impl-serde = { version = "0.3.1", default-features = false }
2626
jsonrpsee = { version = "0.16.0", features = ["ws-client"] }
2727
serde = { version = "1.0.137", default-features = false, features = ["derive"] }

crates/e2e/macro/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ proc-macro = true
2121

2222
[dependencies]
2323
ink_ir = { version = "4.0.0-beta", path = "../../ink/ir" }
24+
contract-build = "2.0.0-beta.1"
2425
derive_more = "0.99.17"
2526
env_logger = "0.10.0"
2627
log = "0.4.17"
27-
serde_json = "1.0.85"
28+
serde_json = "1.0.89"
2829
syn = "1"
2930
proc-macro2 = "1"
3031
quote = "1"

crates/e2e/macro/src/codegen.rs

Lines changed: 46 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -174,47 +174,52 @@ impl InkE2ETest {
174174

175175
/// Builds the contract at `manifest_path`, returns the path to the contract
176176
/// bundle build artifact.
177-
fn build_contract(manifest_path: &str) -> String {
178-
use std::process::{
179-
Command,
180-
Stdio,
177+
fn build_contract(path_to_cargo_toml: &str) -> String {
178+
use contract_build::{
179+
BuildArtifacts,
180+
BuildMode,
181+
ExecuteArgs,
182+
Features,
183+
ManifestPath,
184+
Network,
185+
OptimizationPasses,
186+
OutputType,
187+
UnstableFlags,
188+
Verbosity,
189+
};
190+
191+
let manifest_path = ManifestPath::new(path_to_cargo_toml).unwrap_or_else(|err| {
192+
panic!("Invalid manifest path {}: {}", path_to_cargo_toml, err)
193+
});
194+
let args = ExecuteArgs {
195+
manifest_path,
196+
verbosity: Verbosity::Default,
197+
build_mode: BuildMode::Debug,
198+
features: Features::default(),
199+
network: Network::Online,
200+
build_artifact: BuildArtifacts::All,
201+
unstable_flags: UnstableFlags::default(),
202+
optimization_passes: Some(OptimizationPasses::default()),
203+
keep_debug_symbols: false,
204+
lint: false,
205+
output_type: OutputType::HumanReadable,
206+
skip_wasm_validation: false,
181207
};
182-
let output = Command::new("cargo")
183-
.args([
184-
"+stable",
185-
"contract",
186-
"build",
187-
"--output-json",
188-
&format!("--manifest-path={}", manifest_path),
189-
])
190-
.env("RUST_LOG", "")
191-
.stderr(Stdio::inherit())
192-
.output()
193-
.unwrap_or_else(|err| {
194-
panic!("failed to execute `cargo-contract` build process: {}", err)
195-
});
196-
197-
log::info!("`cargo-contract` returned status: {}", output.status);
198-
log::info!(
199-
"`cargo-contract` stdout: {}",
200-
String::from_utf8_lossy(&output.stdout)
201-
);
202-
if !output.status.success() {
203-
log::error!(
204-
"`cargo-contract` stderr: {}",
205-
String::from_utf8_lossy(&output.stderr)
206-
);
207-
}
208208

209-
assert!(
210-
output.status.success(),
211-
"contract build for {} failed",
212-
manifest_path
213-
);
214-
215-
let json = String::from_utf8_lossy(&output.stdout);
216-
let metadata: serde_json::Value = serde_json::from_str(&json)
217-
.unwrap_or_else(|err| panic!("cannot convert json to utf8: {}", err));
218-
let dest_metadata = metadata["metadata_result"]["dest_bundle"].to_string();
219-
dest_metadata.trim_matches('"').to_string()
209+
match contract_build::execute(args) {
210+
Ok(build_result) => {
211+
let metadata_result = build_result
212+
.metadata_result
213+
.expect("Metadata artifacts not generated");
214+
metadata_result
215+
.dest_bundle
216+
.canonicalize()
217+
.expect("Invalid dest bundle path")
218+
.to_string_lossy()
219+
.into()
220+
}
221+
Err(err) => {
222+
panic!("contract build for {} failed: {}", path_to_cargo_toml, err)
223+
}
224+
}
220225
}

0 commit comments

Comments
 (0)