-
-
Notifications
You must be signed in to change notification settings - Fork 86
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
make crates.io version not depend on the git
tool
#259
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,31 @@ | ||
use std::{env, error::Error, fs, path::PathBuf, process::Command}; | ||
use std::{ | ||
env, | ||
error::Error, | ||
fs, | ||
path::{Path, PathBuf}, | ||
process::Command, | ||
}; | ||
|
||
use semver::Version; | ||
|
||
fn main() -> Result<(), Box<dyn Error>> { | ||
let out = &PathBuf::from(env::var("OUT_DIR")?); | ||
let output = Command::new("git").args(&["rev-parse", "HEAD"]).output()?; | ||
let version = if output.status.success() { | ||
String::from_utf8(output.stdout).unwrap() | ||
let hash = Command::new("git") | ||
.args(&["rev-parse", "HEAD"]) | ||
.output() | ||
.ok() | ||
.and_then(|output| { | ||
if output.status.success() { | ||
String::from_utf8(output.stdout).ok() | ||
} else { | ||
None | ||
} | ||
}); | ||
let version = if let Some(hash) = hash { | ||
hash | ||
} else { | ||
assert!(!Path::new(".git").exists(), "you need to install the `git` command line tool to install the git version of `probe-run`"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you test that this is the right path? I'm not sure in which working directory build scripts are executed. If it's the Cargo workspace root this seems correct, but it seems like it might be the package root, which means that this would be wrong for the decoder. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, there's an old commit that removes a I guess I could also use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Either way seems fine to me |
||
|
||
// no git info -> assume crates.io | ||
let semver = Version::parse(&std::env::var("CARGO_PKG_VERSION")?)?; | ||
if semver.major == 0 { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
output()
call itself will fail if the program cannot be found, so I don't think the fix can use.map
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the original was not checking the .git path if git was not installed but the new version should