Change build info format

This commit is contained in:
ChJR
2019-10-06 17:36:05 +09:00
parent 79e3700477
commit 85f51e55f9
3 changed files with 56 additions and 8 deletions

View File

@@ -15,7 +15,7 @@ fn git_hash() -> String {
}
fn git_timestamp() -> String {
git(&["log", "-1", "--format=%cd"])
git(&["log", "-1", "--format=%ct"])
}
fn git_tag() -> String {

View File

@@ -32,7 +32,8 @@ fn platform_python_compiler(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
fn platform_python_build(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
arg_check!(vm, args);
let (git_hash, git_timestamp) = version::get_build_info();
let git_hash = version::get_git_identifier();
let git_timestamp = version::get_git_datetime();
Ok(vm
.ctx
.new_tuple(vec![vm.new_str(git_hash), vm.new_str(git_timestamp)]))

View File

@@ -16,6 +16,10 @@ pub struct VersionInfo {
releaselevel: &'static str,
serial: usize,
}
extern crate chrono;
use chrono::prelude::DateTime;
use chrono::Local;
use std::time::{Duration, UNIX_EPOCH};
pub fn get_version() -> String {
format!(
@@ -45,13 +49,25 @@ pub fn get_compiler() -> String {
format!("rustc {}", rustc_version.semver)
}
pub fn get_build_info() -> (String, String) {
let git_hash = get_git_revision();
pub fn get_build_info() -> String {
// See: https://reproducible-builds.org/docs/timestamps/
let git_timestamp = option_env!("RUSTPYTHON_GIT_TIMESTAMP")
.unwrap_or("")
.to_string();
(git_hash, git_timestamp)
let git_revision = get_git_revision();
let separator = if git_revision.is_empty() { "" } else { ":" };
let git_identifier = get_git_identifier();
format!(
"{id}{sep}{revision}, {date:.20}, {time:.9}",
id = if git_identifier.is_empty() {
"default".to_string()
} else {
git_identifier
},
sep = separator,
revision = git_revision,
date = get_git_date(),
time = get_git_time(),
)
}
pub fn get_git_revision() -> String {
@@ -78,3 +94,34 @@ pub fn get_git_identifier() -> String {
git_tag
}
}
fn get_git_timestamp_datetime() -> DateTime<Local> {
let timestamp = option_env!("RUSTPYTHON_GIT_TIMESTAMP")
.unwrap_or("")
.to_string();
let timestamp = timestamp.parse::<u64>().unwrap_or(0);
let datetime = UNIX_EPOCH + Duration::from_secs(timestamp);
let datetime = DateTime::<Local>::from(datetime);
datetime
}
pub fn get_git_date() -> String {
let datetime = get_git_timestamp_datetime();
datetime.format("%b %e %Y").to_string()
}
pub fn get_git_time() -> String {
let datetime = get_git_timestamp_datetime();
datetime.format("%H:%M:%S").to_string()
}
pub fn get_git_datetime() -> String {
let date = get_git_date();
let time = get_git_time();
format!("{} {}", date, time)
}