Newer
Older
// Copyright 2018-2019 Parity Technologies (UK) Ltd.
// This file is part of ink!.
//
// ink! is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ink! is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with ink!. If not, see <http://www.gnu.org/licenses/>.
Andrew Jones
committed
use crate::{
util,
workspace::{ManifestPath, Workspace},
Verbosity,
Andrew Jones
committed
};
use anyhow::Result;
Andrew Jones
committed
const METADATA_FILE: &str = "metadata.json";
/// Executes build of the smart-contract which produces a wasm binary that is ready for deploying.
///
/// It does so by invoking build by cargo and then post processing the final binary.
Andrew Jones
committed
pub(crate) fn execute_generate_metadata(
manifest_path: ManifestPath,
verbosity: Option<Verbosity>,
Andrew Jones
committed
) -> Result<String> {
util::assert_channel()?;
println!(" Generating metadata");
Andrew Jones
committed
let (metadata, root_package_id) = crate::util::get_cargo_metadata(&manifest_path)?;
Andrew Jones
committed
let out_path = metadata.target_directory.join(METADATA_FILE);
let out_path_display = format!("{}", out_path.display());
let target_dir = metadata.target_directory.clone();
let generate_metadata = move |manifest_path: &ManifestPath| -> Result<()> {
Andrew Jones
committed
let target_dir_arg = format!("--target-dir={}", target_dir.to_string_lossy());
util::invoke_cargo(
"run",
&[
"--package",
"abi-gen",
Andrew Jones
committed
&target_dir_arg,
"--release",
// "--no-default-features", // Breaks builds for MacOS (linker errors), we should investigate this issue asap!
],
manifest_path.directory(),
verbosity,
)
};
if unstable_options.original_manifest {
generate_metadata(&manifest_path)?;
} else {
Workspace::new(&metadata, &root_package_id)?
.with_root_package_manifest(|manifest| {
manifest
.with_added_crate_type("rlib")?
.with_profile_release_lto(false)?;
Ok(())
})?
.using_temp(generate_metadata)?;
}
"Your metadata file is ready.\nYou can find it here:\n{}",
Andrew Jones
committed
out_path_display
#[cfg(feature = "test-ci-only")]
Andrew Jones
committed
use crate::{
cmd::{execute_generate_metadata, execute_new},
util::tests::with_tmp_dir,
workspace::ManifestPath,
Andrew Jones
committed
};
fn generate_metadata() {
Andrew Jones
committed
env_logger::try_init().ok();
execute_new("new_project", Some(path)).expect("new project creation failed");
let working_dir = path.join("new_project");
Andrew Jones
committed
let manifest_path = ManifestPath::new(working_dir.join("Cargo.toml")).unwrap();
let message =
execute_generate_metadata(manifest_path, None, UnstableFlags::default()).expect("generate metadata failed");
Andrew Jones
committed
println!("{}", message);
abi_file.push("metadata.json");
Andrew Jones
committed
assert!(
abi_file.exists(),
format!("Missing metadata file '{}'", abi_file.display())
)