@@ -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