summaryrefslogtreecommitdiffstats
path: root/build.rs
diff options
context:
space:
mode:
authorClement Tsang <34804052+ClementTsang@users.noreply.github.com>2023-01-02 15:18:05 -0500
committerGitHub <noreply@github.com>2023-01-02 15:18:05 -0500
commit7c53f088c3933812847b7359c50cad8c0fa315a4 (patch)
tree20bc95fc687b6ffa42fda53f0b795f1f69762f07 /build.rs
parenta56e7f6cc9c0515d15576c7b06392c0b0c79b288 (diff)
ci: add build hash to nightly builds for version (#951)
This adds the build hash to the btm -V output for nightly builds, making it easier to troubleshoot when someone might have obtained a nightly build, and what commit it corresponds to.
Diffstat (limited to 'build.rs')
-rw-r--r--build.rs50
1 files changed, 42 insertions, 8 deletions
diff --git a/build.rs b/build.rs
index 4bf02504..d7c06782 100644
--- a/build.rs
+++ b/build.rs
@@ -1,6 +1,5 @@
use std::{
- env, fs,
- io::Result,
+ env, fs, io,
path::{Path, PathBuf},
};
@@ -8,7 +7,7 @@ use clap_complete::{generate_to, shells::Shell};
include!("src/clap.rs");
-fn create_dir(dir: &Path) -> Result<()> {
+fn create_dir(dir: &Path) -> io::Result<()> {
let res = fs::create_dir_all(dir);
match &res {
Ok(()) => {}
@@ -23,12 +22,14 @@ fn create_dir(dir: &Path) -> Result<()> {
res
}
-fn main() -> Result<()> {
- const COMPLETION_DIR: &str = "./target/tmp/bottom/completion/";
- const MANPAGE_DIR: &str = "./target/tmp/bottom/manpage/";
+fn btm_generate() -> io::Result<()> {
+ const ENV_KEY: &str = "BTM_GENERATE";
- match env::var_os("BTM_GENERATE") {
+ match env::var_os(ENV_KEY) {
Some(var) if !var.is_empty() => {
+ const COMPLETION_DIR: &str = "./target/tmp/bottom/completion/";
+ const MANPAGE_DIR: &str = "./target/tmp/bottom/manpage/";
+
let completion_out_dir = PathBuf::from(COMPLETION_DIR);
let manpage_out_dir = PathBuf::from(MANPAGE_DIR);
@@ -53,7 +54,40 @@ fn main() -> Result<()> {
_ => {}
}
- println!("cargo:rerun-if-env-changed=BTM_GENERATE");
+ println!("cargo:rerun-if-env-changed={ENV_KEY}");
+
+ Ok(())
+}
+
+fn nightly_version() {
+ const ENV_KEY: &str = "BTM_BUILD_RELEASE_CALLER";
+
+ match env::var_os(ENV_KEY) {
+ Some(var) if !var.is_empty() && var == "nightly" => {
+ let version = env!("CARGO_PKG_VERSION");
+
+ if let Some(git_hash) = option_env!("CIRRUS_CHANGE_IN_REPO")
+ .and_then(|cirrus_sha: &str| cirrus_sha.get(0..8))
+ {
+ println!("cargo:rustc-env=NIGHTLY_VERSION={version}-nightly-{git_hash}");
+ } else if let Ok(output) = std::process::Command::new("git")
+ .args(["rev-parse", "--short", "HEAD"])
+ .output()
+ {
+ let git_hash = String::from_utf8(output.stdout).unwrap();
+ println!("cargo:rustc-env=NIGHTLY_VERSION={version}-nightly-{git_hash}");
+ }
+ }
+ _ => {}
+ }
+
+ println!("cargo:rerun-if-env-changed={ENV_KEY}");
+ println!("cargo:rerun-if-env-changed=CIRRUS_CHANGE_IN_REPO");
+}
+
+fn main() -> Result<()> {
+ btm_generate()?;
+ nightly_version();
Ok(())
}