Skip to content

Commit

Permalink
Merge pull request multiversx#726 from ElrondNetwork/abi-git-version-…
Browse files Browse the repository at this point in the history
…in-house

abi - replaced git-version with meta post-processing
  • Loading branch information
andrei-marinica authored Nov 18, 2022
2 parents 4337847 + be60a75 commit e2b95c0
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"contractCrate": {
"name": "abi-tester",
"version": "0.0.0",
"git_version": "<git version here>"
"gitVersion": "<git version here>"
},
"framework": {
"name": "elrond-wasm",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"contractCrate": {
"name": "abi-tester",
"version": "0.0.0",
"git_version": "<git version here>"
"gitVersion": "<git version here>"
},
"framework": {
"name": "elrond-wasm",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"contractCrate": {
"name": "use-module",
"version": "0.0.0",
"git_version": "<git version here>"
"gitVersion": "<git version here>"
},
"framework": {
"name": "elrond-wasm",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"contractCrate": {
"name": "use-module",
"version": "0.0.0",
"git_version": "<git version here>"
"gitVersion": "<git version here>"
},
"framework": {
"name": "elrond-wasm",
Expand Down
1 change: 1 addition & 0 deletions elrond-wasm-debug/src/abi_json/build_info_abi_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ impl RustcAbiJson {
}

#[derive(Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ContractCrateBuildAbiJson {
pub name: String,
pub version: String,
Expand Down
44 changes: 40 additions & 4 deletions elrond-wasm-debug/src/meta/meta_abi.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
use std::{
fs::{create_dir_all, File},
io::Write,
process::{Command, Output},
};

use crate::abi_json::{serialize_abi_to_json, ContractAbiJson};

use super::meta_config::{ContractMetadata, MetaConfig};

fn write_contract_abi(contract_metadata: &ContractMetadata, output_path: &str) {
let abi_json = ContractAbiJson::from(&contract_metadata.abi);
fn write_contract_abi(contract_metadata: &ContractMetadata, git_version: &str, output_path: &str) {
let mut abi_json = ContractAbiJson::from(&contract_metadata.abi);
abi_json.build_info.contract_crate.git_version = git_version.to_string();
let abi_string = serialize_abi_to_json(&abi_json);

let abi_file_path = format!("{}/{}", output_path, contract_metadata.abi_output_name(),);
Expand All @@ -19,15 +21,49 @@ fn write_contract_abi(contract_metadata: &ContractMetadata, output_path: &str) {
impl MetaConfig {
pub fn write_abi(&self) {
create_dir_all(&self.output_dir).unwrap();
let git_version = self.git_describe();

if let Some(main_contract) = &self.main_contract {
write_contract_abi(main_contract, self.output_dir.as_str());
write_contract_abi(
main_contract,
git_version.as_str(),
self.output_dir.as_str(),
);
main_contract.create_dir_all();
}

if let Some(view_contract) = &self.view_contract {
write_contract_abi(view_contract, self.output_dir.as_str());
write_contract_abi(
view_contract,
git_version.as_str(),
self.output_dir.as_str(),
);
view_contract.create_dir_all();
}
}

fn git_describe(&self) -> String {
if !self.build_args.abi_git_version {
return String::new();
}

Command::new("git")
.args(["describe"])
.output()
.map(git_describe_process_output)
.unwrap_or_default()
}
}

fn git_describe_process_output(output: Output) -> String {
if output.status.success() {
let mut result = String::from_utf8(output.stdout).unwrap_or_default();
if result.ends_with('\n') {
// for some reason we get a trailing newline
let _ = result.pop();
}
result
} else {
String::new()
}
}
5 changes: 5 additions & 0 deletions elrond-wasm-debug/src/meta/meta_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub struct BuildArgs {
pub wasm_name_suffix: Option<String>,
pub wasm_opt: bool,
pub target_dir: Option<String>,
pub abi_git_version: bool,
}

impl Default for BuildArgs {
Expand All @@ -19,6 +20,7 @@ impl Default for BuildArgs {
wasm_name_suffix: None,
wasm_opt: true,
target_dir: None,
abi_git_version: true,
}
}
}
Expand Down Expand Up @@ -110,6 +112,9 @@ pub fn process_args(args: &[String]) -> BuildArgs {
.expect("argument `--target-dir` must be followed by argument");
result.target_dir = Some(arg.clone());
},
"--no-abi-git-version" => {
result.abi_git_version = false;
},
_ => {},
}
}
Expand Down
2 changes: 1 addition & 1 deletion elrond-wasm-derive/src/generate/abi_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ fn generate_abi_method_body(
contract_crate: elrond_wasm::abi::ContractCrateBuildAbi {
name: env!("CARGO_PKG_NAME"),
version: env!("CARGO_PKG_VERSION"),
git_version: elrond_wasm::abi::git_version!(fallback = ""),
git_version: "",
},
framework: elrond_wasm::abi::FrameworkBuildAbi::create(),
},
Expand Down
1 change: 0 additions & 1 deletion elrond-wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ wee_alloc = "0.4"
hashbrown = "0.11.2"
hex-literal = "0.3.1"
bitflags = "1.3.2"
git-version = "0.3.5"

[dependencies.num-traits]
version = "0.2"
Expand Down
3 changes: 0 additions & 3 deletions elrond-wasm/src/abi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,4 @@ pub use type_abi::*;
pub use type_description::*;
pub use type_description_container::*;

/// Used in generating the ABI.
pub use git_version::git_version;

pub type TypeName = alloc::string::String;

0 comments on commit e2b95c0

Please sign in to comment.