Skip to content

Update cross-util program name and version. #1052

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 3, 2022

Conversation

Alexhuszagh
Copy link
Contributor

@Alexhuszagh Alexhuszagh commented Oct 3, 2022

Updates to output of cross-util --version to use the program name cross-util, and in development builds, add the commit hash (so, for example, the output might be cross-util 0.2.4 (8d8d84b 2022-09-08)). The previous output would have been cross 0.2.4.

@Alexhuszagh Alexhuszagh added enhancement no changelog A valid PR without changelog (no-changelog) labels Oct 3, 2022
@Alexhuszagh Alexhuszagh requested a review from a team as a code owner October 3, 2022 13:25
@Alexhuszagh Alexhuszagh force-pushed the util_hash branch 2 times, most recently from 5365ed2 to 228b9c3 Compare October 3, 2022 14:23
@Emilgardis
Copy link
Member

diff --git a/Cargo.lock b/Cargo.lock
index 6615045..575a265 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -209,7 +209,6 @@ dependencies = [
  "ignore",
  "libc",
  "nix",
- "once_cell",
  "owo-colors",
  "regex",
  "rustc_version",
diff --git a/Cargo.toml b/Cargo.toml
index 8cfc50a..7535e37 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -47,7 +47,6 @@ walkdir = { version = "2", optional = true }
 tempfile = "3.3.0"
 owo-colors = { version = "3.5.0", features = ["supports-colors"] }
 semver = "1"
-once_cell = "1.15"
 
 [target.'cfg(not(windows))'.dependencies]
 nix = { version = "0.25", default-features = false, features = ["user"] }
diff --git a/src/bin/cross-util.rs b/src/bin/cross-util.rs
index a5092e1..cc90a68 100644
--- a/src/bin/cross-util.rs
+++ b/src/bin/cross-util.rs
@@ -3,24 +3,14 @@
 use clap::{CommandFactory, Parser, Subcommand};
 use cross::shell::MessageInfo;
 use cross::{docker, rustc::Toolchain};
-use once_cell::sync::OnceCell;
 
 mod commands;
 
 const APP_NAME: &str = "cross-util";
-static VERSION: OnceCell<String> = OnceCell::new();
-
-fn version() -> &'static str {
-    VERSION.get_or_init(|| {
-        format!(
-            concat!(env!("CARGO_PKG_VERSION"), "{}"),
-            cross::commit_info()
-        )
-    })
-}
+static VERSION: &str = concat!(env!("CARGO_PKG_VERSION"), cross::commit_info!());
 
 #[derive(Parser, Debug)]
-#[clap(about, long_about = None, name = APP_NAME, version = version())]
+#[clap(about, long_about = None, name = APP_NAME, version = VERSION)]
 struct Cli {
     /// Toolchain name/version to use (such as stable or 1.59.0).
     #[clap(value_parser = is_toolchain)]
diff --git a/src/lib.rs b/src/lib.rs
index a79452b..42b91a0 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -780,8 +780,15 @@ pub(crate) fn warn_host_version_mismatch(
     Ok(VersionMatch::Same)
 }
 
-pub fn commit_info() -> &'static str {
-    include_str!(concat!(env!("OUT_DIR"), "/commit-info.txt"))
+pub const fn commit_info() -> &'static str {
+    commit_info!()
+}
+
+#[macro_export]
+macro_rules! commit_info {
+    () => {
+        include_str!(concat!(env!("OUT_DIR"), "/commit-info.txt"))
+    };
 }
 
 /// Obtains the [`CrossToml`] from one of the possible locations

this works without any added deps

@Emilgardis
Copy link
Member

Even better, on clap 4.0, with the string feature enabled this is possible

#[clap(about, long_about = None, name = APP_NAME, version = format!(
    concat!(env!("CARGO_PKG_VERSION"), "{}"),
    cross::commit_info()
))]

@Alexhuszagh
Copy link
Contributor Author

Nice, the clap 4.0 migration will be very handy. I've updated it to move once_cell back to a dev dependency, removed the unnecessary format_args since we can just use concat! with commit_info! as a macro directly.

Copy link
Member

@Emilgardis Emilgardis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bors r+

@bors
Copy link
Contributor

bors bot commented Oct 3, 2022

Build succeeded:

@bors bors bot merged commit 596b223 into cross-rs:main Oct 3, 2022
@Emilgardis Emilgardis added this to the v0.3.0 milestone Mar 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement no changelog A valid PR without changelog (no-changelog)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants