2019-07-21 17:45:31 +00:00
|
|
|
use std::env;
|
|
|
|
use std::fs::File;
|
2019-08-22 17:18:47 +00:00
|
|
|
use std::io::Read;
|
2019-07-21 17:45:31 +00:00
|
|
|
use std::io::Write;
|
|
|
|
use std::path::Path;
|
2019-08-22 17:18:47 +00:00
|
|
|
use std::path::PathBuf;
|
2019-07-21 17:45:31 +00:00
|
|
|
use std::process::Command;
|
|
|
|
|
|
|
|
fn main() {
|
2019-08-22 17:18:47 +00:00
|
|
|
// Get the current githash
|
2019-07-21 17:45:31 +00:00
|
|
|
match Command::new("git")
|
2019-10-18 13:32:26 +00:00
|
|
|
.args(&[
|
|
|
|
"log",
|
|
|
|
"-n",
|
|
|
|
"1",
|
2019-10-18 10:03:01 +00:00
|
|
|
"--pretty=format:%h/%cd",
|
2019-10-18 13:32:26 +00:00
|
|
|
"--date=format:%Y-%m-%d-%H:%M",
|
|
|
|
])
|
2019-07-21 17:45:31 +00:00
|
|
|
.output()
|
|
|
|
{
|
|
|
|
Ok(output) => match String::from_utf8(output.stdout) {
|
|
|
|
Ok(hash) => {
|
|
|
|
let mut target = File::create(
|
|
|
|
Path::new(
|
|
|
|
&env::var("OUT_DIR").expect("failed to query OUT_DIR environment variable"),
|
|
|
|
)
|
|
|
|
.join("githash"),
|
|
|
|
)
|
|
|
|
.expect("failed to create git hash file!");
|
|
|
|
target
|
|
|
|
.write_all(hash.trim().as_bytes())
|
|
|
|
.expect("failed to write to file!");
|
|
|
|
}
|
|
|
|
Err(e) => panic!("failed to convert git output to UTF-8: {}", e),
|
|
|
|
},
|
|
|
|
Err(e) => panic!("failed to retrieve current git commit hash: {}", e),
|
|
|
|
}
|
2019-08-22 17:18:47 +00:00
|
|
|
// Check if git-lfs is working
|
2019-10-05 08:33:18 +00:00
|
|
|
if std::env::var("DISABLE_GIT_LFS_CHECK").is_err() {
|
|
|
|
let asset_path: PathBuf = ["..", "assets", "voxygen", "background", "bg_main.png"]
|
|
|
|
.iter()
|
|
|
|
.collect();
|
|
|
|
let asset_file = match File::open(&asset_path) {
|
|
|
|
Ok(file) => file,
|
|
|
|
Err(e) => panic!(
|
|
|
|
"failed to open asset file {}: {}",
|
|
|
|
asset_path.to_str().unwrap(),
|
|
|
|
e
|
|
|
|
),
|
|
|
|
};
|
|
|
|
const LFS_MARKER: &[u8] = b"version https://git-lfs.github.com/spec/";
|
|
|
|
let mut buffer = Vec::new();
|
|
|
|
let bytes_read = asset_file
|
|
|
|
.take(LFS_MARKER.len() as u64)
|
|
|
|
.read_to_end(&mut buffer)
|
|
|
|
.expect("failed to read asset file");
|
2019-08-22 17:18:47 +00:00
|
|
|
|
2019-10-05 08:33:18 +00:00
|
|
|
if bytes_read == LFS_MARKER.len() && buffer == LFS_MARKER {
|
|
|
|
panic!(
|
|
|
|
"\n\nGit Large File Storage (git-lfs) has not been set up correctly.\n\
|
|
|
|
Most common reasons:\n\
|
|
|
|
\t- git-lfs was not installed before cloning this repository\n\
|
|
|
|
\t- this repository was not cloned from the primary gitlab mirror.\n\
|
|
|
|
\t The github mirror does not support lfs.\n\
|
|
|
|
See the book at https://book.veloren.net/ for details.\n\n"
|
|
|
|
);
|
|
|
|
}
|
2019-08-22 17:18:47 +00:00
|
|
|
}
|
2019-07-21 17:45:31 +00:00
|
|
|
}
|