Skip to content

Commit

Permalink
xtask: Install a simple logger
Browse files Browse the repository at this point in the history
This currently doesn't do anything, but in the next commit ovmf-prebuilt will be
used to download OVMF files, and that library uses the logger.
  • Loading branch information
nicholasbishop committed Nov 4, 2024
1 parent 92275d1 commit 92a7058
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion xtask/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ fatfs = { version = "0.3.6", default-features = false, features = ["alloc", "std
fs-err = "3.0.0"
heck = "0.5.0"
itertools = "0.13.0"
log.workspace = true
lzma-rs = "0.3.0"
mbrman = "0.5.1"
nix = { version = "0.29.0", default-features = false, features = ["fs"] }
Expand All @@ -24,5 +25,5 @@ sha2 = "0.10.6"
syn = { version = "2.0.0", features = ["full"] }
tar = "0.4.38"
tempfile = "3.6.0"
walkdir = "2.4.0"
ureq = "2.8.0"
walkdir = "2.4.0"
25 changes: 25 additions & 0 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use arch::UefiArch;
use cargo::{Cargo, CargoAction, Feature, Package, TargetTypes};
use clap::Parser;
use itertools::Itertools;
use log::{LevelFilter, Metadata, Record};
use opt::{Action, BuildOpt, ClippyOpt, CovOpt, DocOpt, Opt, QemuOpt, TpmVersion};
use std::process::Command;
use util::run_cmd;
Expand Down Expand Up @@ -322,9 +323,33 @@ fn has_cmd(target_cmd: &str) -> bool {
run_cmd(cmd).is_ok()
}

fn install_logger() {
struct Logger;

impl log::Log for Logger {
fn enabled(&self, _: &Metadata) -> bool {
true
}

fn log(&self, record: &Record) {
println!("[{}] {}", record.level(), record.args());
}

fn flush(&self) {}
}

static LOGGER: Logger = Logger;

log::set_logger(&LOGGER)
.map(|()| log::set_max_level(LevelFilter::Info))
.unwrap();
}

fn main() -> Result<()> {
let opt = Opt::parse();

install_logger();

match &opt.action {
Action::Build(build_opt) => build(build_opt),
Action::CheckRaw(_) => check_raw::check_raw(),
Expand Down

0 comments on commit 92a7058

Please sign in to comment.