-
Notifications
You must be signed in to change notification settings - Fork 34
/
build.rs
30 lines (26 loc) · 1014 Bytes
/
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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
use anyhow::Result;
use std::path::Path;
fn main() -> Result<()> {
// Copy hooks to appropriate location so that git will run them.
// In git worktrees, .git is a symlink and the following commands fail.
if Path::new(".git").is_dir() {
if !Path::new("./.git/hooks").exists() {
std::fs::create_dir_all("./.git/hooks")?;
}
std::fs::copy("./scripts/pre-commit", "./.git/hooks/pre-commit")?;
std::fs::copy("./scripts/pre-push", "./.git/hooks/pre-push")?;
}
// Supply information as compile-time environment variables.
#[cfg(feature = "opa-runtime")]
{
let output = std::process::Command::new("git")
.args(["rev-parse", "HEAD"])
.output()
.expect("`git rev-parse HEAD` failed.");
let git_hash = String::from_utf8(output.stdout).unwrap();
println!("cargo:rustc-env=GIT_HASH={}", git_hash);
}
Ok(())
}