-
-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to specify fallback value for git sha #174
Comments
That is the correct method to override the output. Seems like a bug. I'll take a look. |
I wrote a little stand alone test and was able to generate the override successfully (build.rs below):
Here was the output when running
If possible, could you run |
I should also mention that any failures are silently suppressed by default so |
This was run after cargo clean, in a directory where I had deleted the My code in use anyhow::Result;
use vergen::EmitBuilder;
fn main() -> Result<()> {
println!("cargo:rustc-env=VERGEN_GIT_SHA=unknown");
std::env::set_var("VERGEN_GIT_SHA", "0xdeadbob");
EmitBuilder::builder()
.git_sha(true)
.emit()
} The relevant section of [youki 0.0.4] cargo:rustc-env=VERGEN_GIT_SHA=unknown
[youki 0.0.4] cargo:rustc-env=VERGEN_GIT_SHA=VERGEN_IDEMPOTENT_OUTPUT
[youki 0.0.4] cargo:warning=not within a suitable 'git' worktree!
[youki 0.0.4] cargo:warning=VERGEN_GIT_SHA set to default
[youki 0.0.4] cargo:rerun-if-changed=build.rs
[youki 0.0.4] cargo:rerun-if-env-changed=VERGEN_IDEMPOTENT
[youki 0.0.4] cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH
warning: not within a suitable 'git' worktree!
warning: VERGEN_GIT_SHA set to default The o/p after removing my custom fallback (first println) is Running `/tmp/youki/target/debug/build/youki-742bbcccb9a2924c/build-script-build`
[youki 0.0.4] cargo:rustc-env=VERGEN_GIT_SHA=VERGEN_IDEMPOTENT_OUTPUT
[youki 0.0.4] cargo:warning=not within a suitable 'git' worktree!
[youki 0.0.4] cargo:warning=VERGEN_GIT_SHA set to default
[youki 0.0.4] cargo:rerun-if-changed=build.rs
[youki 0.0.4] cargo:rerun-if-env-changed=VERGEN_IDEMPOTENT
[youki 0.0.4] cargo:rerun-if-env-changed=SOURCE_DATE_EPOCH
warning: not within a suitable 'git' worktree!
warning: VERGEN_GIT_SHA set to default |
The current logic only applies override values in place of otherwise successful generation. In this particular case, an error is occurring and causing the defaults to be used, completely skipping the override check. I could see where you would still want the overrides even if errors have happened. I'll get that logic added. |
Hey, thanks for the info. |
Hey @CraZySacX Can you take a look at my comment above and let me know if there is any way I can conditionally override the GIT_SHA when it is not available and let it take its proper value otherwise? |
Currently that is not possible. This requires some thought regarding implementation. Any errors are propagated back up to the emitter and overrides/idempotent is used to fill in the variables. I think in your particular case, you could turn on the
|
Thanks, that works! |
I want to emit "unknown" in place of git sha if while compiling git info is unavailable. In previous versions, I used to add
println!("cargo:rustc-env=VERGEN_GIT_SHA_SHORT=unknown");
before thevergen(config)
call, so if vergen does not emit, there is a placeholder to fall back to.In 8.0, the config is removed, and we have to use the builder pattern, which I have used as follows :
But when git version is not present, this emits
VERGEN_IDEMPOTENT_OUTPUT
as the value. I saw in the documentation it is mentioned that if we specify certain env vars, vergen will take their values, so I addedBefore the emit call, but that still outputs the same (
VERGEN_IDEMPOTENT_OUTPUT
). Also if I'm not mistake this will be an unconditional override.Is there any way with which we can define a fallback value for a certain param?
Thanks!
The text was updated successfully, but these errors were encountered: