Skip to content
This repository has been archived by the owner on Jan 14, 2023. It is now read-only.

add git commit hash to version #116

Merged
merged 1 commit into from
Nov 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 57 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ gdb-server = { version = "0.9.0", git = "https://github.com/probe-rs/probe-rs"
probe-rs-cli-util = { version = "0.9.0", git = "https://github.com/probe-rs/probe-rs" }

structopt = "0.3.18"
git-version = "0.3.4"
indicatif = "0.15.0"
env_logger = "0.7.1"
log = { version = "0.4.0", features = ["serde"] }
Expand Down
14 changes: 14 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,14 @@ use probe_rs::{
use probe_rs_cli_util::build_artifact;
use probe_rs_rtt::{Rtt, ScanRegion};

const CARGO_NAME: &'static str = env!("CARGO_PKG_NAME");
Copy link
Member

Choose a reason for hiding this comment

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

Why not add those constants to the cli-util lib? :) I think that should work and then we can also add this to cargo-flash? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

does not seem to work for git_version

$ git status 
On branch version
nothing to commit, working tree clean

$ git rev-parse --short HEAD
e0104b6

$ cargo run - --version  
probe-rs-cli-util 0.9.0
git commit: v0.5.1-467-g7b33b4b-modified

I don't even see where 0.5.1 comes from :/ but both cargo env variable and git_version do the wrong thing or maybe phrased more accurately are used in a way they were not meant to be ;)

We can still add it to cargo flash as well though, just copy pasting :D

Copy link
Member

Choose a reason for hiding this comment

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

Yeah sounds good to me :) Do this now, possibly improve later :)

const CARGO_VERSION: &'static str = env!("CARGO_PKG_VERSION");
const GIT_VERSION: &'static str = git_version::git_version!();

#[derive(Debug, StructOpt)]
struct Opt {
#[structopt(short = "V", long = "version")]
pub version: bool,
#[structopt(name = "config")]
config: Option<String>,
#[structopt(name = "chip", long = "chip")]
Expand Down Expand Up @@ -120,6 +126,14 @@ fn main_try() -> Result<()> {
// Get commandline options.
let opt = Opt::from_iter(&args);

if opt.version {
println!(
"{} {}\ngit commit: {}",
CARGO_NAME, CARGO_VERSION, GIT_VERSION
);
return Ok(());
}

let work_dir = std::env::current_dir()?;

// Get the config.
Expand Down