-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add build-script-utils from Substrate (#422)
- Loading branch information
Showing
5 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ members = [ | |
"xtokens", | ||
"xcm-support", | ||
"unknown-tokens", | ||
"build-script-utils", | ||
] | ||
resolver = "2" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[package] | ||
name = "orml-build-script-utils" | ||
description = "Crate with utility functions for `build.rs` scripts." | ||
repository = "https://github.com/open-web3-stack/open-runtime-module-library/tree/master/build-script-utils" | ||
license = "Apache-2.0" | ||
version = "0.4.1-dev" | ||
authors = ["Parity Technologies <[email protected]>", "Laminar Developers <[email protected]>"] | ||
edition = "2018" | ||
|
||
[package.metadata.docs.rs] | ||
targets = ["x86_64-unknown-linux-gnu"] | ||
|
||
[dependencies] | ||
platforms = "1.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Crate with utility functions for `build.rs` scripts. | ||
|
||
License: Apache-2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
//! Crate with utility functions for `build.rs` scripts. | ||
|
||
mod version; | ||
|
||
pub use version::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use platforms::*; | ||
use std::process::Command; | ||
|
||
/// Generate the `cargo:` key output | ||
pub fn generate_cargo_keys() { | ||
println!( | ||
"cargo:rustc-env=SUBSTRATE_CLI_IMPL_VERSION={}", | ||
get_version(get_commit()) | ||
) | ||
} | ||
|
||
fn get_platform() -> String { | ||
let env_dash = if TARGET_ENV.is_some() { "-" } else { "" }; | ||
|
||
format!( | ||
"{}-{}{}{}", | ||
TARGET_ARCH.as_str(), | ||
TARGET_OS.as_str(), | ||
env_dash, | ||
TARGET_ENV.map(|x| x.as_str()).unwrap_or(""), | ||
) | ||
} | ||
|
||
fn get_version(impl_commit: String) -> String { | ||
let commit_dash = if impl_commit.is_empty() { "" } else { "-" }; | ||
|
||
format!( | ||
"{}{}{}-{}", | ||
std::env::var("CARGO_PKG_VERSION").unwrap_or_default(), | ||
commit_dash, | ||
impl_commit, | ||
get_platform(), | ||
) | ||
} | ||
|
||
fn get_commit() -> String { | ||
let commit = std::env::var("GIT_COMMIT").unwrap_or_default(); | ||
if !commit.is_empty() { | ||
return commit; | ||
} | ||
|
||
let output = Command::new("git").args(&["rev-parse", "--short", "HEAD"]).output(); | ||
|
||
match output { | ||
Ok(o) if o.status.success() => String::from_utf8_lossy(&o.stdout).trim().into(), | ||
Ok(o) => { | ||
println!("cargo:warning=Git command failed with status: {}", o.status); | ||
"unknown".into() | ||
} | ||
Err(err) => { | ||
println!("cargo:warning=Failed to execute git command: {}", err); | ||
"unknown".into() | ||
} | ||
} | ||
} |