-
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More debug info, fix bad path context
- Loading branch information
Showing
3 changed files
with
55 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,45 @@ | ||
use std::env; | ||
use std::fs::File; | ||
use std::io::Read; | ||
use std::path::Path; | ||
|
||
#[cfg(windows)] | ||
extern crate winres; | ||
|
||
#[cfg(windows)] | ||
fn main() { | ||
get_commit(); | ||
let mut res = winres::WindowsResource::new(); | ||
res.set_icon("assets\\icon.ico"); | ||
res.compile().unwrap(); | ||
} | ||
|
||
#[cfg(unix)] | ||
#[cfg(not(windows))] | ||
fn main() { | ||
get_commit(); | ||
} | ||
|
||
//Save commit to enviromnent variable | ||
fn get_commit() { | ||
//Github Actions commit | ||
let mut commit = if let Ok(commit) = env::var("GITHUB_SHA") { | ||
commit | ||
} else { | ||
//Local commit | ||
if let Ok(mut f) = File::open(Path::new(".git").join("refs").join("heads").join("master")) { | ||
let mut buf = String::new(); | ||
f.read_to_string(&mut buf).ok(); | ||
buf | ||
} else { | ||
String::new() | ||
} | ||
}; | ||
// Trim | ||
if commit.len() > 8 { | ||
commit = commit[..8].to_string() | ||
} | ||
if commit.is_empty() { | ||
commit = "unknown".to_string(); | ||
} | ||
println!("cargo:rustc-env=COMMIT={}", commit); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters