Skip to content

Commit d24e96c

Browse files
Merge pull request #1657 from rust-osdev/xtask
xtask: simplify env variables
2 parents d72702d + e3acd45 commit d24e96c

File tree

3 files changed

+9
-34
lines changed

3 files changed

+9
-34
lines changed

xtask/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ edition.workspace = true
77

88
[dependencies]
99
anyhow = "1.0.51"
10-
clap = { version = "4.4.0", default-features = false, features = ["derive", "help", "usage", "std"] }
10+
clap = { version = "4.4.0", default-features = false, features = ["derive", "help", "usage", "std", "env"] }
1111
fatfs = { version = "0.3.6", default-features = false, features = ["alloc", "std"] }
1212
fs-err = "3.0.0"
1313
heck = "0.5.0"

xtask/src/opt.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -187,15 +187,15 @@ pub struct QemuOpt {
187187
pub tpm: Option<TpmVersion>,
188188

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

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

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

201201
/// Run an example instead of the main binary.

xtask/src/qemu.rs

+5-30
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,6 @@ const OVMF_PREBUILT_SOURCE: Source = Source::EDK2_STABLE202502_R2;
2626
/// Directory into which the prebuilts will be download (relative to the repo root).
2727
const OVMF_PREBUILT_DIR: &str = "target/ovmf";
2828

29-
/// Environment variable for overriding the path of the OVMF code file.
30-
const ENV_VAR_OVMF_CODE: &str = "OVMF_CODE";
31-
32-
/// Environment variable for overriding the path of the OVMF vars file.
33-
const ENV_VAR_OVMF_VARS: &str = "OVMF_VARS";
34-
35-
/// Environment variable for overriding the path of the OVMF shell file.
36-
const ENV_VAR_OVMF_SHELL: &str = "OVMF_SHELL";
37-
3829
impl From<UefiArch> for ovmf_prebuilt::Arch {
3930
fn from(arch: UefiArch) -> Self {
4031
match arch {
@@ -47,29 +38,13 @@ impl From<UefiArch> for ovmf_prebuilt::Arch {
4738

4839
/// Get a user-provided path for the given OVMF file type.
4940
///
50-
/// This uses the command-line arg if present, otherwise it falls back to an
51-
/// environment variable. If neither is present, returns `None`.
41+
/// This can come from an explicit CLI arg or an environment variable, depending
42+
/// on how clap received and parsed the value.
5243
fn get_user_provided_path(file_type: FileType, opt: &QemuOpt) -> Option<PathBuf> {
53-
let opt_path;
54-
let var_name;
5544
match file_type {
56-
FileType::Code => {
57-
opt_path = &opt.ovmf_code;
58-
var_name = ENV_VAR_OVMF_CODE;
59-
}
60-
FileType::Vars => {
61-
opt_path = &opt.ovmf_vars;
62-
var_name = ENV_VAR_OVMF_VARS;
63-
}
64-
FileType::Shell => {
65-
opt_path = &opt.ovmf_shell;
66-
var_name = ENV_VAR_OVMF_SHELL;
67-
}
68-
}
69-
if let Some(path) = opt_path {
70-
Some(path.clone())
71-
} else {
72-
env::var_os(var_name).map(PathBuf::from)
45+
FileType::Code => opt.ovmf_code.clone(),
46+
FileType::Vars => opt.ovmf_vars.clone(),
47+
FileType::Shell => opt.ovmf_shell.clone(),
7348
}
7449
}
7550

0 commit comments

Comments
 (0)