Skip to content

xtask: simplify env variables #1657

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

Merged
merged 1 commit into from
May 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion xtask/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition.workspace = true

[dependencies]
anyhow = "1.0.51"
clap = { version = "4.4.0", default-features = false, features = ["derive", "help", "usage", "std"] }
clap = { version = "4.4.0", default-features = false, features = ["derive", "help", "usage", "std", "env"] }
fatfs = { version = "0.3.6", default-features = false, features = ["alloc", "std"] }
fs-err = "3.0.0"
heck = "0.5.0"
Expand Down
6 changes: 3 additions & 3 deletions xtask/src/opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,15 @@ pub struct QemuOpt {
pub tpm: Option<TpmVersion>,

/// Path of an OVMF code file.
#[clap(long, action)]
#[clap(long, action, env)]
pub ovmf_code: Option<PathBuf>,

/// Path of an OVMF vars file.
#[clap(long, action)]
#[clap(long, action, env)]
pub ovmf_vars: Option<PathBuf>,

/// Path of an OVMF shell application.
#[clap(long, action)]
#[clap(long, action, env)]
pub ovmf_shell: Option<PathBuf>,

/// Run an example instead of the main binary.
Expand Down
35 changes: 5 additions & 30 deletions xtask/src/qemu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,6 @@ const OVMF_PREBUILT_SOURCE: Source = Source::EDK2_STABLE202502_R2;
/// Directory into which the prebuilts will be download (relative to the repo root).
const OVMF_PREBUILT_DIR: &str = "target/ovmf";

/// Environment variable for overriding the path of the OVMF code file.
const ENV_VAR_OVMF_CODE: &str = "OVMF_CODE";

/// Environment variable for overriding the path of the OVMF vars file.
const ENV_VAR_OVMF_VARS: &str = "OVMF_VARS";

/// Environment variable for overriding the path of the OVMF shell file.
const ENV_VAR_OVMF_SHELL: &str = "OVMF_SHELL";

impl From<UefiArch> for ovmf_prebuilt::Arch {
fn from(arch: UefiArch) -> Self {
match arch {
Expand All @@ -47,29 +38,13 @@ impl From<UefiArch> for ovmf_prebuilt::Arch {

/// Get a user-provided path for the given OVMF file type.
///
/// This uses the command-line arg if present, otherwise it falls back to an
/// environment variable. If neither is present, returns `None`.
/// This can come from an explicit CLI arg or an environment variable, depending
/// on how clap received and parsed the value.
fn get_user_provided_path(file_type: FileType, opt: &QemuOpt) -> Option<PathBuf> {
let opt_path;
let var_name;
match file_type {
FileType::Code => {
opt_path = &opt.ovmf_code;
var_name = ENV_VAR_OVMF_CODE;
}
FileType::Vars => {
opt_path = &opt.ovmf_vars;
var_name = ENV_VAR_OVMF_VARS;
}
FileType::Shell => {
opt_path = &opt.ovmf_shell;
var_name = ENV_VAR_OVMF_SHELL;
}
}
if let Some(path) = opt_path {
Some(path.clone())
} else {
env::var_os(var_name).map(PathBuf::from)
FileType::Code => opt.ovmf_code.clone(),
FileType::Vars => opt.ovmf_vars.clone(),
FileType::Shell => opt.ovmf_shell.clone(),
}
}

Expand Down
Loading