summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorLinus Färnstrand <linus@mullvad.net>2018-02-02 11:21:17 +0100
committerLinus Färnstrand <linus@mullvad.net>2018-02-07 09:48:25 +0100
commit6e43ce3b049aabcd04fb144c2ea33af98ce0e0f4 (patch)
tree7d82b0dfacd777ef061356bf2013f47148d29c09
parent51e2cf9d6e872588b8519b3756c46be8f1045312 (diff)
downloadmullvadvpn-6e43ce3b049aabcd04fb144c2ea33af98ce0e0f4.tar.xz
mullvadvpn-6e43ce3b049aabcd04fb144c2ea33af98ce0e0f4.zip
Make the daemon version be the git description
-rw-r--r--mullvad-daemon/build.rs49
-rw-r--r--mullvad-daemon/src/bin/problem-report.rs9
-rw-r--r--mullvad-daemon/src/cli.rs5
-rw-r--r--mullvad-daemon/src/main.rs5
4 files changed, 32 insertions, 36 deletions
diff --git a/mullvad-daemon/build.rs b/mullvad-daemon/build.rs
index 14320da319..9e6c57fc96 100644
--- a/mullvad-daemon/build.rs
+++ b/mullvad-daemon/build.rs
@@ -1,13 +1,3 @@
-// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
use std::env;
use std::fs::File;
use std::io::Write;
@@ -18,33 +8,34 @@ use std::process::Command;
fn main() {
let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
- File::create(out_dir.join("git-commit-info.txt"))
+ File::create(out_dir.join("git-commit-desc.txt"))
.unwrap()
- .write_all(commit_info().as_bytes())
+ .write_all(commit_description().as_bytes())
+ .unwrap();
+ File::create(out_dir.join("git-commit-date.txt"))
+ .unwrap()
+ .write_all(commit_date().as_bytes())
.unwrap();
}
-// Implementation borrowed from rustfmt. Returns a string containing commit hash and commit date
-// if it was able to obtain it, otherwise an empty string.
-fn commit_info() -> String {
- match (commit_description(), commit_date()) {
- (Some(hash), Some(date)) => format!("{} {}", hash.trim(), date),
- _ => String::new(),
- }
-}
-
-fn commit_description() -> Option<String> {
- Command::new("git")
+fn commit_description() -> String {
+ let output = Command::new("git")
.args(&["describe", "--dirty"])
.output()
- .ok()
- .and_then(|out| String::from_utf8(out.stdout).ok())
+ .expect("Unable to get git commit description");
+ ::std::str::from_utf8(&output.stdout)
+ .unwrap()
+ .trim()
+ .to_owned()
}
-fn commit_date() -> Option<String> {
- Command::new("git")
+fn commit_date() -> String {
+ let output = Command::new("git")
.args(&["log", "-1", "--date=short", "--pretty=format:%cd"])
.output()
- .ok()
- .and_then(|out| String::from_utf8(out.stdout).ok())
+ .expect("Unable to get git commit date");
+ ::std::str::from_utf8(&output.stdout)
+ .unwrap()
+ .trim()
+ .to_owned()
}
diff --git a/mullvad-daemon/src/bin/problem-report.rs b/mullvad-daemon/src/bin/problem-report.rs
index 0365771f14..51c10ca20d 100644
--- a/mullvad-daemon/src/bin/problem-report.rs
+++ b/mullvad-daemon/src/bin/problem-report.rs
@@ -334,10 +334,11 @@ fn collect_metadata() -> HashMap<String, String> {
}
fn daemon_version() -> String {
- String::from(include_str!(concat!(
- env!("OUT_DIR"),
- "/git-commit-info.txt"
- )))
+ format!(
+ "{} {}",
+ include_str!(concat!(env!("OUT_DIR"), "/git-commit-desc.txt")),
+ include_str!(concat!(env!("OUT_DIR"), "/git-commit-date.txt"))
+ )
}
#[cfg(target_os = "linux")]
diff --git a/mullvad-daemon/src/cli.rs b/mullvad-daemon/src/cli.rs
index 676337bcb3..17af99f266 100644
--- a/mullvad-daemon/src/cli.rs
+++ b/mullvad-daemon/src/cli.rs
@@ -33,7 +33,10 @@ pub fn get_config() -> Config {
fn create_app() -> App<'static, 'static> {
App::new(crate_name!())
- .version(crate_version!())
+ .version(include_str!(concat!(
+ env!("OUT_DIR"),
+ "/git-commit-desc.txt"
+ )))
.author(crate_authors!())
.about(crate_description!())
.arg(
diff --git a/mullvad-daemon/src/main.rs b/mullvad-daemon/src/main.rs
index 561c0c0b52..4249714d47 100644
--- a/mullvad-daemon/src/main.rs
+++ b/mullvad-daemon/src/main.rs
@@ -803,9 +803,10 @@ fn init_logger(log_level: log::LogLevelFilter, log_file: Option<&PathBuf>) -> Re
fn log_version() {
info!(
- "Starting {} {}",
+ "Starting {} - {} {}",
env!("CARGO_PKG_NAME"),
- include_str!(concat!(env!("OUT_DIR"), "/git-commit-info.txt"))
+ include_str!(concat!(env!("OUT_DIR"), "/git-commit-desc.txt")),
+ include_str!(concat!(env!("OUT_DIR"), "/git-commit-date.txt"))
)
}