mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2026-11-17 13:46:27 -05:00
Main changes: - Refactor connect/auth flows around a single OS profile and host identity model, including gateway fallback and cookie-on-stdin handling. - Align request parameters, HIP host-id propagation, SAML webview user-agent behavior, and portal default-browser handling with observed official client behavior. - Add opt-in cookie cache support and Microsoft Defender HIP reporting while keeping host-id validation explicit. - Add BSD build, packaging, release artifact, and provenance support with FreeBSD/OpenBSD path and dependency cleanup. - Update NixOS install documentation and dependency compatibility fixes.
61 lines
1.7 KiB
Rust
61 lines
1.7 KiB
Rust
use std::{env, fs, path::PathBuf, process::Command};
|
|
|
|
const UNKNOWN_COMMIT: &str = "unknown";
|
|
const DISPLAY_COMMIT_LEN: usize = 9;
|
|
|
|
fn main() {
|
|
println!("cargo:rerun-if-env-changed=GPSERVICE_GIT_COMMIT");
|
|
println!("cargo:rerun-if-env-changed=SOURCE_GIT_COMMIT");
|
|
println!("cargo:rerun-if-env-changed=GITHUB_SHA");
|
|
|
|
let repo_root = PathBuf::from(env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR is set")).join("../..");
|
|
let source_commit = repo_root.join("SOURCE_COMMIT");
|
|
println!("cargo:rerun-if-changed={}", source_commit.display());
|
|
println!(
|
|
"cargo:rustc-env=GPSERVICE_GIT_COMMIT={}",
|
|
resolve_commit(&repo_root, &source_commit)
|
|
);
|
|
}
|
|
|
|
fn resolve_commit(repo_root: &PathBuf, source_commit: &PathBuf) -> String {
|
|
env_commit("GPSERVICE_GIT_COMMIT")
|
|
.or_else(|| env_commit("SOURCE_GIT_COMMIT"))
|
|
.or_else(|| env_commit("GITHUB_SHA"))
|
|
.or_else(|| file_commit(source_commit))
|
|
.or_else(|| git_commit(repo_root))
|
|
.unwrap_or_else(|| UNKNOWN_COMMIT.to_string())
|
|
}
|
|
|
|
fn env_commit(key: &str) -> Option<String> {
|
|
env::var(key).ok().and_then(|value| normalize_commit(&value))
|
|
}
|
|
|
|
fn file_commit(path: &PathBuf) -> Option<String> {
|
|
fs::read_to_string(path).ok().and_then(|value| normalize_commit(&value))
|
|
}
|
|
|
|
fn git_commit(repo_root: &PathBuf) -> Option<String> {
|
|
let output = Command::new("git")
|
|
.args(["rev-parse", "--short=9", "HEAD"])
|
|
.current_dir(repo_root)
|
|
.output()
|
|
.ok()?;
|
|
|
|
if !output.status.success() {
|
|
return None;
|
|
}
|
|
|
|
String::from_utf8(output.stdout)
|
|
.ok()
|
|
.and_then(|value| normalize_commit(&value))
|
|
}
|
|
|
|
fn normalize_commit(value: &str) -> Option<String> {
|
|
let value = value.trim();
|
|
if value.is_empty() {
|
|
return None;
|
|
}
|
|
|
|
Some(value.chars().take(DISPLAY_COMMIT_LEN).collect())
|
|
}
|