#[macro_export]
macro_rules! init_proxy_build {
() => {
use $crate::GitInfo;
let cargo_manifest_dir = env!("CARGO_MANIFEST_DIR");
fn output_none() {
println!("cargo:rustc-env=PACKAGEVERSION_GITVERSION_IS_KNOWN=false");
println!("cargo:rustc-env=PACKAGEVERSION_GITVERSION_HAS_TAG=false");
println!("cargo:rustc-env=PACKAGEVERSION_GITVERSION_TAG=");
println!("cargo:rustc-env=PACKAGEVERSION_GITVERSION_COMMITS_SINCE_TAG=");
println!("cargo:rustc-env=PACKAGEVERSION_GITVERSION_COMMIT_ID=");
println!("cargo:rustc-env=PACKAGEVERSION_GITVERSION_MODIFIED=");
}
let repo = match $crate::git2::Repository::discover(cargo_manifest_dir) {
Ok(repo) => Some(repo),
Err(err) => {
println!("cargo:warning=Error getting version info from git, didn't find git repository: {}", err);
None
}
};
let repository_version = repo.as_ref().and_then(|repo|
match $crate::get_git_info(&repo) {
Ok(git_info) => Some(git_info),
Err(err) => {
println!("cargo:warning=Error getting version info from git: {}", err);
None
}
}
);
if let Some(repository_version) = repository_version {
println!("cargo:rustc-env=PACKAGEVERSION_GITVERSION_IS_KNOWN=true");
if let Some(tag_info) = repository_version.tag_info {
println!(
"cargo:rustc-env=PACKAGEVERSION_GITVERSION_HAS_TAG=true"
);
println!(
"cargo:rustc-env=PACKAGEVERSION_GITVERSION_TAG={}",
tag_info.tag
);
println!(
"cargo:rustc-env=PACKAGEVERSION_GITVERSION_COMMITS_SINCE_TAG={}",
tag_info.commits_since_tag
);
} else {
println!(
"cargo:rustc-env=PACKAGEVERSION_GITVERSION_HAS_TAG=false",
);
println!(
"cargo:rustc-env=PACKAGEVERSION_GITVERSION_TAG=",
);
println!(
"cargo:rustc-env=PACKAGEVERSION_GITVERSION_COMMITS_SINCE_TAG=",
);
}
println!(
"cargo:rustc-env=PACKAGEVERSION_GITVERSION_COMMIT_ID={}",
repository_version.commit_id
);
println!(
"cargo:rustc-env=PACKAGEVERSION_GITVERSION_MODIFIED={}",
repository_version.modified
);
} else {
output_none();
}
if let Some(repo) = repo {
println!(
"cargo:rerun-if-changed={repo_workspace_path}",
repo_workspace_path = repo.workdir().unwrap().display()
);
println!(
"cargo:rerun-if-changed={repo_path}",
repo_path = repo.path().display()
);
} else {
println!(
"cargo:rerun-if-changed={cargo_manifest_dir}",
);
}
};
}
#[macro_export]
macro_rules! init_proxy_lib {
() => {
pub use $crate::*;
pub const GITINFO: Option<$crate::GitInfo> = if $crate::konst::result::unwrap!(
$crate::konst::primitive::parse_bool(env!("PACKAGEVERSION_GITVERSION_IS_KNOWN"))
) {
Some($crate::GitInfo {
tag_info: if $crate::konst::result::unwrap!($crate::konst::primitive::parse_bool(
env!("PACKAGEVERSION_GITVERSION_HAS_TAG")
)) {
Some($crate::TagInfo {
tag: env!("PACKAGEVERSION_GITVERSION_TAG"),
commits_since_tag: $crate::konst::result::unwrap!({
let mut parser = $crate::konst::parsing::Parser::new(env!(
"PACKAGEVERSION_GITVERSION_COMMITS_SINCE_TAG"
));
parser.parse_u32()
}),
})
} else {
None
},
commit_id: env!("PACKAGEVERSION_GITVERSION_COMMIT_ID"),
modified: $crate::konst::result::unwrap!($crate::konst::primitive::parse_bool(
env!("PACKAGEVERSION_GITVERSION_MODIFIED")
)),
})
} else {
None
};
};
}