Skip to content

Commit

Permalink
refactor: use logfroth EnvFilter and improve incremental build (#155)
Browse files Browse the repository at this point in the history
Signed-off-by: tison <[email protected]>
  • Loading branch information
tisonkun authored Aug 22, 2024
1 parent 14134c0 commit 42ef5d6
Show file tree
Hide file tree
Showing 4 changed files with 163 additions and 36 deletions.
171 changes: 140 additions & 31 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 cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ clap = { workspace = true }
const_format = { workspace = true }
hawkeye-fmt = { workspace = true }
log = { workspace = true }
env_logger = "0.11"
logforth = { version = "0.11", features = ["env-filter"] }
shadow-rs = { workspace = true }

[build-dependencies]
build-data = { workspace = true }
shadow-rs = { workspace = true }
gix-discover = "0.33"
9 changes: 7 additions & 2 deletions cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,21 @@

use std::collections::BTreeSet;
use std::env;
use std::path::Path;

use build_data::format_timestamp;
use build_data::get_source_time;
use shadow_rs::CARGO_METADATA;
use shadow_rs::CARGO_TREE;

fn main() -> shadow_rs::SdResult<()> {
println!("cargo:rerun-if-changed=.git/refs/heads");
if let Ok((dir, _)) = gix_discover::upwards(Path::new(env!("CARGO_MANIFEST_DIR"))) {
let git_refs_heads = dir.as_ref().join(".git/refs/heads");
println!("cargo::rerun-if-changed={}", git_refs_heads.display());
}

println!(
"cargo:rustc-env=SOURCE_TIMESTAMP={}",
"cargo::rustc-env=SOURCE_TIMESTAMP={}",
if let Ok(t) = get_source_time() {
format_timestamp(t)
} else {
Expand Down
16 changes: 14 additions & 2 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,27 @@

use clap::FromArgMatches;
use clap::Subcommand;
use env_logger::Env;
use logforth::append;
use logforth::filter::EnvFilter;
use logforth::layout::TextLayout;
use logforth::Dispatch;
use logforth::Logger;

use crate::subcommand::SubCommand;

pub mod subcommand;
pub mod version;

fn main() {
env_logger::init_from_env(Env::new().default_filter_or("info"));
Logger::new()
.dispatch(
Dispatch::new()
.filter(EnvFilter::from_default_env_or("info"))
.layout(TextLayout::default())
.append(append::Stderr),
)
.apply()
.unwrap();

let build_info = version::build_info();
let command = clap::Command::new("hawkeye")
Expand Down

0 comments on commit 42ef5d6

Please sign in to comment.