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
with:
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 }}
tests:

View File

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

View File

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

View File

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

View File

@ -1,5 +1,6 @@
#![warn(rust_2018_idioms)]
#[allow(unused_imports)]
#[cfg(feature = "log")]
#[macro_use]
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 {
fn from(err: fern::InitError) -> Self {
BottomError::FernError(err.to_string())

View File

@ -1,7 +1,6 @@
use std::ffi::OsStr;
#[cfg(feature = "fern")]
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> {
fern::Dispatch::new()
.format(|out, message, record| {