changelog shortlog graph tags branches changeset files revisions annotate raw help

Mercurial > core / rust/lib/util/src/bs/version.rs

changeset 698: 96958d3eb5b0
parent: 3d78bed56188
author: Richard Westhaver <ellis@rwest.io>
date: Fri, 04 Oct 2024 22:04:59 -0400
permissions: -rw-r--r--
description: fixes
1 use std::{borrow::Cow, process::Command};
2 
3 use platforms::*;
4 
5 /// Generate the `cargo:` key output
6 pub fn generate_cargo_keys() {
7  let output = Command::new("hg").args(["identify", "-i"]).output();
8 
9  let commit = match output {
10  Ok(o) if o.status.success() => {
11  let sha = String::from_utf8_lossy(&o.stdout).trim().to_owned();
12  Cow::from(sha)
13  }
14  Ok(o) => {
15  println!(
16  "cargo:warning=Mercurial command failed with status: {}",
17  o.status
18  );
19  Cow::from("unknown")
20  }
21  Err(err) => {
22  println!("cargo:warning=Failed to execute hg command: {}", err);
23  Cow::from("unknown")
24  }
25  };
26 
27  println!(
28  "cargo:rustc-env=CORE_VERSION={}",
29  get_version_short(&commit)
30  );
31 
32  println!("cargo:rustc-env=CORE_TARGET={}", get_platform());
33 }
34 
35 pub fn get_platform() -> String {
36  let env_dash = if TARGET_ENV.is_some() { "-" } else { "" };
37  format!(
38  "{}-{}{}{}",
39  TARGET_ARCH.as_str(),
40  TARGET_OS.as_str(),
41  env_dash,
42  TARGET_ENV.map(|x| x.as_str()).unwrap_or(""),
43  )
44 }
45 
46 pub fn get_version(impl_commit: &str) -> String {
47  let commit_dash = if impl_commit.is_empty() { "" } else { "-" };
48  format!(
49  "{}{}{}-{}",
50  std::env::var("CARGO_PKG_VERSION").unwrap_or_default(),
51  commit_dash,
52  impl_commit,
53  get_platform(),
54  )
55 }
56 
57 // TODO [2021-09-01 Wed 02:39] - reimpl this function via flag in `get_version`
58 fn get_version_short(impl_commit: &str) -> String {
59  let commit_dash = if impl_commit.is_empty() { "" } else { "-" };
60  format!(
61  "{}{}{}",
62  std::env::var("CARGO_PKG_VERSION").unwrap_or_default(),
63  commit_dash,
64  impl_commit,
65  )
66 }