MCPcopy Create free account
hub / github.com/GraphiteEditor/Graphite / main

Function main

editor/build.rs:6–33  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4const GRAPHITE_RELEASE_SERIES: &str = "Alpha 4";
5
6fn main() {
7 // Instruct Cargo to rerun this build script if any of these environment variables change.
8 println!("cargo:rerun-if-env-changed=GRAPHITE_GIT_COMMIT_DATE");
9 println!("cargo:rerun-if-env-changed=GRAPHITE_GIT_COMMIT_HASH");
10 println!("cargo:rerun-if-env-changed=GRAPHITE_GIT_COMMIT_BRANCH");
11 println!("cargo:rerun-if-env-changed=GITHUB_HEAD_REF");
12
13 // Try to get the commit information from the environment (e.g. set by CI), otherwise fall back to Git commands.
14 let commit_date = env_or_else("GRAPHITE_GIT_COMMIT_DATE", || git_or_unknown(&["log", "-1", "--format=%cI"]));
15 let commit_hash = env_or_else("GRAPHITE_GIT_COMMIT_HASH", || git_or_unknown(&["rev-parse", "HEAD"]));
16 let commit_branch = env_or_else("GRAPHITE_GIT_COMMIT_BRANCH", || {
17 let gh = env::var("GITHUB_HEAD_REF").unwrap_or_default();
18 if !gh.trim().is_empty() {
19 gh.trim().to_string()
20 } else {
21 git(&["rev-parse", "--abbrev-ref", "HEAD"]).unwrap_or_default()
22 }
23 });
24
25 // Instruct Cargo to set environment variables for compile time.
26 // They are accessed with the `env!("GRAPHITE_*")` macro in the codebase.
27 println!("cargo:rustc-env=GRAPHITE_RELEASE_SERIES={GRAPHITE_RELEASE_SERIES}");
28 if !commit_branch.is_empty() {
29 println!("cargo:rustc-env=GRAPHITE_GIT_COMMIT_BRANCH={commit_branch}");
30 }
31 println!("cargo:rustc-env=GRAPHITE_GIT_COMMIT_HASH={commit_hash}");
32 println!("cargo:rustc-env=GRAPHITE_GIT_COMMIT_DATE={commit_date}");
33}
34
35/// Get an environment variable, or if it is not set or empty, use the provided fallback function. Returns a string with trimmed whitespace.
36fn env_or_else(key: &str, fallback: impl FnOnce() -> String) -> String {

Callers

nothing calls this directly

Calls 4

env_or_elseFunction · 0.85
git_or_unknownFunction · 0.85
gitFunction · 0.85
is_emptyMethod · 0.45

Tested by

no test coverage detected