summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--mullvad-daemon/Cargo.toml1
-rw-r--r--mullvad-daemon/build.rs50
-rw-r--r--mullvad-daemon/src/main.rs10
3 files changed, 61 insertions, 0 deletions
diff --git a/mullvad-daemon/Cargo.toml b/mullvad-daemon/Cargo.toml
index 4cdccc1c8a..5f4d48ee58 100644
--- a/mullvad-daemon/Cargo.toml
+++ b/mullvad-daemon/Cargo.toml
@@ -4,6 +4,7 @@ version = "0.1.0"
authors = ["Mullvad VPN <admin@mullvad.net>", "Linus Färnstrand <linus@mullvad.net>", "Erik Larkö <erik@mullvad.net>", "Andrej Mihajlov <and@mullvad.net>"]
description = "Mullvad VPN backend daemon. Runs and controls the VPN tunnels."
license = "GPL-3.0"
+build = "build.rs"
[[bin]]
name = "mullvadd"
diff --git a/mullvad-daemon/build.rs b/mullvad-daemon/build.rs
new file mode 100644
index 0000000000..c810fe395a
--- /dev/null
+++ b/mullvad-daemon/build.rs
@@ -0,0 +1,50 @@
+// 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;
+use std::path::PathBuf;
+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"))
+ .unwrap()
+ .write_all(commit_info().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_hash(), commit_date()) {
+ (Some(hash), Some(date)) => format!("({} {})", hash.trim(), date),
+ _ => String::new(),
+ }
+}
+
+fn commit_hash() -> Option<String> {
+ Command::new("git")
+ .args(&["rev-parse", "--short", "HEAD"])
+ .output()
+ .ok()
+ .and_then(|out| String::from_utf8(out.stdout).ok())
+}
+
+fn commit_date() -> Option<String> {
+ Command::new("git")
+ .args(&["log", "-1", "--date=short", "--pretty=format:%cd"])
+ .output()
+ .ok()
+ .and_then(|out| String::from_utf8(out.stdout).ok())
+}
diff --git a/mullvad-daemon/src/main.rs b/mullvad-daemon/src/main.rs
index 017c428fc2..ca189652c4 100644
--- a/mullvad-daemon/src/main.rs
+++ b/mullvad-daemon/src/main.rs
@@ -612,6 +612,7 @@ quick_main!(run);
fn run() -> Result<()> {
let config = cli::get_config();
init_logger(config.log_level, config.log_file.as_ref())?;
+ log_version();
let daemon = Daemon::new().chain_err(|| "Unable to initialize daemon")?;
@@ -658,3 +659,12 @@ fn init_logger(log_level: log::LogLevelFilter, log_file: Option<&PathBuf>) -> Re
.apply()
.chain_err(|| "Failed to bootstrap logging system")
}
+
+fn log_version() {
+ info!(
+ "Starting {} v{} {}",
+ env!("CARGO_PKG_NAME"),
+ env!("CARGO_PKG_VERSION"),
+ include_str!(concat!(env!("OUT_DIR"), "/git-commit-info.txt"))
+ )
+}