Skip to content

Commit ec3a178

Browse files
Fix version calculation
1 parent ea338e0 commit ec3a178

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

xpd-common/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ license = "EUPL-1.2"
88
readme = "README.txt"
99
categories = ["games"]
1010
keywords = ["discord-bot", "mee6"]
11+
build = "build.rs"
1112

1213
[dependencies]
1314
# twilight

xpd-common/build.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::{
2-
process::{Command, ExitStatus},
2+
process::{Command, ExitStatus, Stdio},
33
string::FromUtf8Error,
44
};
55

@@ -12,19 +12,25 @@ fn main() {
1212
}
1313
};
1414

15-
println!("cargo:rustc-env=GIT_HASH_EXPERIENCED={}", commit_msg);
15+
println!("cargo::rustc-env=GIT_HASH_EXPERIENCED={}", commit_msg);
1616
}
1717

1818
fn get_sha() -> Result<String, Error> {
1919
let output = Command::new("git")
2020
.arg("rev-parse")
2121
.arg("HEAD")
22+
.stdout(Stdio::piped())
23+
.stderr(Stdio::piped())
24+
.stdin(Stdio::null())
2225
.spawn()?
2326
.wait_with_output()?;
2427
if !output.status.success() {
2528
return Err(Error::BadStatus(output.status));
2629
}
2730
let output = String::from_utf8(output.stdout)?.trim().to_string();
31+
if output.is_empty() {
32+
return Err(Error::NoOutput);
33+
}
2834
Ok(output)
2935
}
3036

@@ -33,17 +39,19 @@ enum Error {
3339
TryFromString,
3440
BadStatus(ExitStatus),
3541
Io(std::io::Error),
42+
NoOutput,
3643
}
3744

3845
impl std::fmt::Display for Error {
3946
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4047
match self {
41-
Error::TryFromString => write!(f, "Invalid UTF-8 in `git rev-parse HEAD` output")?,
42-
Error::BadStatus(exit_status) => write!(
48+
Self::TryFromString => write!(f, "Invalid UTF-8 in `git rev-parse HEAD` output")?,
49+
Self::BadStatus(exit_status) => write!(
4350
f,
4451
"`git rev-parse HEAD` exited with non-zero status {exit_status}"
4552
)?,
46-
Error::Io(error) => write!(f, "I/O error trying to run `git rev-parse HEAD`: {error}")?,
53+
Self::Io(error) => write!(f, "I/O error trying to run `git rev-parse HEAD`: {error}")?,
54+
Self::NoOutput => write!(f, "No output from git-rev-parse")?,
4755
}
4856
Ok(())
4957
}

0 commit comments

Comments
 (0)