diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-05-07 19:47:05 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2021-05-07 19:47:05 +0100 |
commit | 1ec82d4bdf47fa5ec1f8599757bbadae274d4f5a (patch) | |
tree | 30b598248fe8d2f7ecfcc302d71ab96350c11934 /crates | |
parent | 0bc85ac7986347d50d2eb8403084d61ac33447a4 (diff) | |
parent | 189f785749e9e6921ae1db4338c3d65c9da102cf (diff) |
Merge #8751
8751: minor: standard snippet r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r-- | crates/rust-analyzer/build.rs | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/crates/rust-analyzer/build.rs b/crates/rust-analyzer/build.rs index bca6611d6..aceab82d9 100644 --- a/crates/rust-analyzer/build.rs +++ b/crates/rust-analyzer/build.rs | |||
@@ -51,16 +51,23 @@ fn rev() -> String { | |||
51 | } | 51 | } |
52 | 52 | ||
53 | fn commit_hash() -> Option<String> { | 53 | fn commit_hash() -> Option<String> { |
54 | output_to_string("git rev-parse --short HEAD") | 54 | exec("git rev-parse --short HEAD").ok() |
55 | } | 55 | } |
56 | 56 | ||
57 | fn build_date() -> Option<String> { | 57 | fn build_date() -> Option<String> { |
58 | output_to_string("date -u +%Y-%m-%d") | 58 | exec("date -u +%Y-%m-%d").ok() |
59 | } | 59 | } |
60 | 60 | ||
61 | fn output_to_string(command: &str) -> Option<String> { | 61 | fn exec(command: &str) -> std::io::Result<String> { |
62 | let args = command.split_ascii_whitespace().collect::<Vec<_>>(); | 62 | let args = command.split_ascii_whitespace().collect::<Vec<_>>(); |
63 | let output = Command::new(args[0]).args(&args[1..]).output().ok()?; | 63 | let output = Command::new(args[0]).args(&args[1..]).output()?; |
64 | let stdout = String::from_utf8(output.stdout).ok()?; | 64 | if !output.status.success() { |
65 | Some(stdout.trim().to_string()) | 65 | return Err(std::io::Error::new( |
66 | std::io::ErrorKind::InvalidData, | ||
67 | format!("command {:?} returned non-zero code", command,), | ||
68 | )); | ||
69 | } | ||
70 | let stdout = String::from_utf8(output.stdout) | ||
71 | .map_err(|err| std::io::Error::new(std::io::ErrorKind::InvalidData, err))?; | ||
72 | Ok(stdout.trim().to_string()) | ||
66 | } | 73 | } |