chore(uv): more env var mappings (#8193)

## Summary

Small follow up to https://github.com/astral-sh/uv/pull/8151

## Test Plan

Existing tests
This commit is contained in:
samypr100 2024-10-15 11:59:03 +00:00 committed by GitHub
parent 7c5d94030d
commit 689611417b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 7 deletions

View file

@ -46,4 +46,5 @@ default = []
self-update = []
[build-dependencies]
uv-static = { workspace = true }
fs-err = { workspace = true }

View file

@ -5,10 +5,12 @@ use std::{
use fs_err as fs;
use uv_static::EnvVars;
fn main() {
// The workspace root directory is not available without walking up the tree
// https://github.com/rust-lang/cargo/issues/3946
let workspace_root = Path::new(&std::env::var("CARGO_MANIFEST_DIR").unwrap())
let workspace_root = Path::new(&std::env::var(EnvVars::CARGO_MANIFEST_DIR).unwrap())
.parent()
.expect("CARGO_MANIFEST_DIR should be nested in workspace")
.parent()
@ -18,7 +20,7 @@ fn main() {
commit_info(&workspace_root);
#[allow(clippy::disallowed_methods)]
let target = std::env::var("TARGET").unwrap();
let target = std::env::var(EnvVars::TARGET).unwrap();
println!("cargo:rustc-env=RUST_HOST_TARGET={target}");
}
@ -62,21 +64,27 @@ fn commit_info(workspace_root: &Path) {
let stdout = String::from_utf8(output.stdout).unwrap();
let mut parts = stdout.split_whitespace();
let mut next = || parts.next().unwrap();
println!("cargo:rustc-env=UV_COMMIT_HASH={}", next());
println!("cargo:rustc-env=UV_COMMIT_SHORT_HASH={}", next());
println!("cargo:rustc-env=UV_COMMIT_DATE={}", next());
println!("cargo:rustc-env={}={}", EnvVars::UV_COMMIT_HASH, next());
println!(
"cargo:rustc-env={}={}",
EnvVars::UV_COMMIT_SHORT_HASH,
next()
);
println!("cargo:rustc-env={}={}", EnvVars::UV_COMMIT_DATE, next());
// Describe can fail for some commits
// https://git-scm.com/docs/pretty-formats#Documentation/pretty-formats.txt-emdescribeoptionsem
if let Some(describe) = parts.next() {
let mut describe_parts = describe.split('-');
println!(
"cargo:rustc-env=UV_LAST_TAG={}",
"cargo:rustc-env={}={}",
EnvVars::UV_LAST_TAG,
describe_parts.next().unwrap()
);
// If this is the tagged commit, this component will be missing
println!(
"cargo:rustc-env=UV_LAST_TAG_DISTANCE={}",
"cargo:rustc-env={}={}",
EnvVars::UV_LAST_TAG_DISTANCE,
describe_parts.next().unwrap_or("0")
);
}