This repository has been archived by the owner on Apr 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
executable file
·42 lines (36 loc) · 1.55 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// 🐻❄️🌧️ Noelware Telemetry: Telemetry project for Noelware, to capture anonymous data about the running products.
// Copyright 2022 Noelware <team@noelware.org>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use std::{ffi::OsStr, process::Command, time::SystemTime};
use chrono::{DateTime, Utc};
/// execute returns the standard output of the command specified.
fn execute<T: Into<String> + AsRef<OsStr>>(
command: T,
args: &[&str],
) -> Result<String, Box<dyn std::error::Error + 'static>> {
let res = Command::new(command).args(args).output().unwrap();
Ok(String::from_utf8(res.stdout)?)
}
fn main() {
println!("cargo:rerun-if-changed=build.rs");
// Generate the metadata variables
let commit_hash = execute("git", &["rev-parse", "--short=8", "HEAD"]).unwrap();
let now = SystemTime::now();
let now_in_utc: DateTime<Utc> = now.into();
println!("cargo:rustc-env=TELEMETRY_COMMIT_HASH={}", commit_hash);
println!(
"cargo:rustc-env=TELEMETRY_BUILD_DATE={}",
now_in_utc.to_rfc3339()
);
}