refactor: Use feature flags to avoid building with fern and log (#351)

This commit is contained in:
Clement Tsang 2020-12-11 20:39:32 -05:00 committed by GitHub
parent 8c4ad90e67
commit 766fe25c55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 15 additions and 10 deletions

View File

@ -152,7 +152,7 @@ jobs:
uses: actions-rs/cargo@v1 uses: actions-rs/cargo@v1
with: with:
command: check command: check
args: --all-targets --verbose --target=${{ matrix.triple.target }} args: --all-targets --verbose --target=${{ matrix.triple.target }} --no-default-features
use-cross: ${{ matrix.triple.cross }} use-cross: ${{ matrix.triple.cross }}
tests: tests:

View File

@ -185,7 +185,7 @@ jobs:
uses: actions-rs/cargo@v1 uses: actions-rs/cargo@v1
with: with:
command: build command: build
args: --release --verbose --target=${{ matrix.triple.target }} args: --release --verbose --target=${{ matrix.triple.target }} --no-default-features
use-cross: ${{ matrix.triple.cross }} use-cross: ${{ matrix.triple.cross }}
- name: Move autocomplete to working directory - name: Move autocomplete to working directory

View File

@ -25,13 +25,16 @@ lto = true
opt-level = 3 opt-level = 3
codegen-units = 1 codegen-units = 1
[features]
default = ["fern", "log"]
[dependencies] [dependencies]
anyhow = "1.0.34" anyhow = "1.0.34"
backtrace = "0.3" backtrace = "0.3"
battery = "0.7.8" battery = "0.7.8"
chrono = "0.4.19" chrono = "0.4.19"
crossterm = "0.18.2" crossterm = "0.18.2"
ctrlc = {version = "3.1", features = ["termination"]} ctrlc = { version = "3.1", features = ["termination"] }
clap = "2.33" clap = "2.33"
dirs-next = "2.0.0" dirs-next = "2.0.0"
fnv = "1.0.7" fnv = "1.0.7"
@ -45,14 +48,14 @@ serde = {version = "1.0", features = ["derive"] }
sysinfo = "0.15.3" sysinfo = "0.15.3"
thiserror = "1.0.22" thiserror = "1.0.22"
toml = "0.5.7" toml = "0.5.7"
tui = {version = "0.13.0", features = ["crossterm"], default-features = false } tui = { version = "0.13.0", features = ["crossterm"], default-features = false }
typed-builder = "0.7.1" typed-builder = "0.7.1"
unicode-segmentation = "1.7.1" unicode-segmentation = "1.7.1"
unicode-width = "0.1" unicode-width = "0.1"
# For debugging only... # For debugging only...
fern = "0.6.0" fern = { version = "0.6.0", optional=true }
log = "0.4.11" log = { version="0.4.11", optional=true }
[target.'cfg(not(any(target_arch = "arm", target_arch = "aarch64")))'.dependencies] [target.'cfg(not(any(target_arch = "arm", target_arch = "aarch64")))'.dependencies]
heim = "0.0.11" heim = "0.0.11"

View File

@ -1,5 +1,6 @@
#![warn(rust_2018_idioms)] #![warn(rust_2018_idioms)]
#[allow(unused_imports)] #[allow(unused_imports)]
#[cfg(feature = "log")]
#[macro_use] #[macro_use]
extern crate log; extern crate log;
@ -33,7 +34,7 @@ fn main() -> Result<()> {
// tmp_dir.push("bottom_debug.log"); // tmp_dir.push("bottom_debug.log");
// utils::logging::init_logger(log::LevelFilter::Trace, tmp_dir.as_os_str())?; // utils::logging::init_logger(log::LevelFilter::Trace, tmp_dir.as_os_str())?;
// } else { // } else {
#[cfg(debug_assertions)] #[cfg(all(feature = "fern", debug_assertions))]
{ {
utils::logging::init_logger(log::LevelFilter::Debug, std::ffi::OsStr::new("debug.log"))?; utils::logging::init_logger(log::LevelFilter::Debug, std::ffi::OsStr::new("debug.log"))?;
} }

View File

@ -1,5 +1,6 @@
#![warn(rust_2018_idioms)] #![warn(rust_2018_idioms)]
#[allow(unused_imports)] #[allow(unused_imports)]
#[cfg(feature = "log")]
#[macro_use] #[macro_use]
extern crate log; extern crate log;

View File

@ -73,6 +73,7 @@ impl From<toml::de::Error> for BottomError {
} }
} }
#[cfg(feature = "fern")]
impl From<fern::InitError> for BottomError { impl From<fern::InitError> for BottomError {
fn from(err: fern::InitError) -> Self { fn from(err: fern::InitError) -> Self {
BottomError::FernError(err.to_string()) BottomError::FernError(err.to_string())

View File

@ -1,7 +1,6 @@
use std::ffi::OsStr; #[cfg(feature = "fern")]
pub fn init_logger( pub fn init_logger(
min_level: log::LevelFilter, debug_file_name: &OsStr, min_level: log::LevelFilter, debug_file_name: &std::ffi::OsStr,
) -> Result<(), fern::InitError> { ) -> Result<(), fern::InitError> {
fern::Dispatch::new() fern::Dispatch::new()
.format(|out, message, record| { .format(|out, message, record| {