diff options
author | Aleksey Kladov <[email protected]> | 2021-05-07 19:46:25 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2021-05-07 19:46:25 +0100 |
commit | 189f785749e9e6921ae1db4338c3d65c9da102cf (patch) | |
tree | 3aec5f7ac38c5195c7b06ce75268f09a32e9e2b2 /crates | |
parent | a8da2ca3a189a3f9a422c38d0a26298dc0a9ce6f (diff) |
minor: standard snippet
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 | } |