Skip to content

Commit

Permalink
Rename option to --wasm-log-level; small refactoring (#4060)
Browse files Browse the repository at this point in the history
Rename the CLI option to set the WASM log level; applied some suggested simplifications, to `LogLevel` and to the type it was based on.

# Important Notes
This addresses review of #4017.
  • Loading branch information
kazcw committed Jan 19, 2023
1 parent 246755d commit f39070a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 68 deletions.
43 changes: 29 additions & 14 deletions build/build/src/project/wasm.rs
Expand Up @@ -49,7 +49,17 @@ pub const WASM_ARTIFACT_NAME: &str = "gui_wasm";

pub const DEFAULT_TARGET_CRATE: &str = "app/gui";

#[derive(Clone, Copy, Debug, Default, strum::Display, strum::EnumString, PartialEq, Eq)]
#[derive(
clap::ArgEnum,
Clone,
Copy,
Debug,
Default,
strum::Display,
strum::EnumString,
PartialEq,
Eq
)]
#[strum(serialize_all = "kebab-case")]
pub enum ProfilingLevel {
#[default]
Expand All @@ -59,7 +69,17 @@ pub enum ProfilingLevel {
Debug,
}

#[derive(Clone, Copy, Debug, Default, strum::Display, strum::EnumString, PartialEq, Eq)]
#[derive(
clap::ArgEnum,
Clone,
Copy,
Debug,
Default,
strum::Display,
strum::EnumString,
PartialEq,
Eq
)]
#[strum(serialize_all = "kebab-case")]
pub enum LogLevel {
Error,
Expand Down Expand Up @@ -129,8 +149,8 @@ pub struct BuildInput {
pub extra_cargo_options: Vec<String>,
pub profile: Profile,
pub profiling_level: Option<ProfilingLevel>,
pub log_level: Option<LogLevel>,
pub uncollapsed_log_level: Option<LogLevel>,
pub log_level: LogLevel,
pub uncollapsed_log_level: LogLevel,
pub wasm_size_limit: Option<byte_unit::Byte>,
}

Expand Down Expand Up @@ -234,11 +254,8 @@ impl IsTarget for Wasm {
if let Some(profiling_level) = profiling_level {
command.set_env(env::ENSO_MAX_PROFILING_LEVEL, &profiling_level)?;
}
command.set_env(env::ENSO_MAX_LOG_LEVEL, &log_level.unwrap_or_default())?;
command.set_env(
env::ENSO_MAX_UNCOLLAPSED_LOG_LEVEL,
&uncollapsed_log_level.unwrap_or_default(),
)?;
command.set_env(env::ENSO_MAX_LOG_LEVEL, &log_level)?;
command.set_env(env::ENSO_MAX_UNCOLLAPSED_LOG_LEVEL, &uncollapsed_log_level)?;
command.run_ok().await?;

Self::finalize_wasm(wasm_opt_options, *skip_wasm_opt, *profile, &temp_dist).await?;
Expand Down Expand Up @@ -343,11 +360,9 @@ impl IsWatchable for Wasm {
if let Some(profiling_level) = profiling_level {
watch_cmd.args(["--profiling-level", profiling_level.to_string().as_str()]);
}
watch_cmd.args(["--log-level", log_level.unwrap_or_default().to_string().as_str()]);
watch_cmd.args([
"--uncollapsed-log-level",
uncollapsed_log_level.unwrap_or_default().to_string().as_str(),
]);
watch_cmd.args(["--wasm-log-level", log_level.to_string().as_str()]);
watch_cmd
.args(["--wasm-uncollapsed-log-level", uncollapsed_log_level.to_string().as_str()]);
for wasm_opt_option in wasm_opt_options {
watch_cmd.args(["--wasm-opt-option", &wasm_opt_option]);
}
Expand Down
57 changes: 8 additions & 49 deletions build/cli/src/arg/wasm.rs
Expand Up @@ -7,7 +7,6 @@ use crate::source_args_hlp;
use crate::BuildJob;
use crate::IsWatchableSource;

use clap::ArgEnum;
use clap::Args;
use clap::Subcommand;
use enso_build::project::wasm::test::Browser;
Expand All @@ -19,7 +18,9 @@ use std::sync::OnceLock;
// === Export ===
// ==============

pub use enso_build::project::wasm::LogLevel;
pub use enso_build::project::wasm::Profile;
pub use enso_build::project::wasm::ProfilingLevel;



Expand All @@ -37,48 +38,6 @@ pub fn initialize_default_wasm_size_limit(limit: byte_unit::Byte) -> Result {
.map_err(|e| anyhow!("WASM size limit was already set to {e}."))
}

// Follows hierarchy defined in lib/rust/profiler/src/lib.rs
#[derive(ArgEnum, Clone, Copy, Debug, PartialEq, Eq)]
pub enum ProfilingLevel {
Objective,
Task,
Detail,
Debug,
}

impl From<ProfilingLevel> for enso_build::project::wasm::ProfilingLevel {
fn from(profile: ProfilingLevel) -> Self {
match profile {
ProfilingLevel::Objective => Self::Objective,
ProfilingLevel::Task => Self::Task,
ProfilingLevel::Detail => Self::Detail,
ProfilingLevel::Debug => Self::Debug,
}
}
}

// Follows hierarchy defined in lib/rust/logging/src/lib.rs
#[derive(ArgEnum, Clone, Copy, Debug, PartialEq, Eq)]
pub enum LogLevel {
Error,
Warn,
Info,
Debug,
Trace,
}

impl From<LogLevel> for enso_build::project::wasm::LogLevel {
fn from(level: LogLevel) -> Self {
match level {
LogLevel::Error => Self::Error,
LogLevel::Warn => Self::Warn,
LogLevel::Info => Self::Info,
LogLevel::Debug => Self::Debug,
LogLevel::Trace => Self::Trace,
}
}
}

#[derive(Args, Clone, Debug, PartialEq, Eq)]
pub struct BuildInput {
/// Which crate should be treated as a WASM entry point. Relative path from source root.
Expand Down Expand Up @@ -106,13 +65,13 @@ pub struct BuildInput {
#[clap(long, arg_enum, enso_env())]
pub profiling_level: Option<ProfilingLevel>,

/// Compiles Enso with given log level. If not set, defaults to [`warn`].
#[clap(long, arg_enum, enso_env())]
pub log_level: Option<LogLevel>,
/// Compiles Enso with given log level.
#[clap(long, arg_enum, enso_env(), default_value_t)]
pub wasm_log_level: LogLevel,

/// Compiles Enso with given uncollapsed log level. If not set, defaults to [`warn`].
#[clap(long, arg_enum, enso_env())]
pub uncollapsed_log_level: Option<LogLevel>,
/// Compiles Enso with given uncollapsed log level.
#[clap(long, arg_enum, enso_env(), default_value_t)]
pub wasm_uncollapsed_log_level: LogLevel,

/// Fail the build if compressed WASM exceeds the specified size. Supports format like
/// "4.06MiB". Pass "0" to disable check.
Expand Down
10 changes: 5 additions & 5 deletions build/cli/src/lib.rs
Expand Up @@ -620,8 +620,8 @@ impl Resolvable for Wasm {
wasm_opt_option: wasm_opt_options,
cargo_options,
profiling_level,
log_level,
uncollapsed_log_level,
wasm_log_level,
wasm_uncollapsed_log_level,
wasm_size_limit,
skip_wasm_opt,
} = from;
Expand All @@ -631,9 +631,9 @@ impl Resolvable for Wasm {
skip_wasm_opt,
extra_cargo_options: cargo_options,
profile: wasm_profile,
profiling_level: profiling_level.map(into),
log_level: log_level.map(into),
uncollapsed_log_level: uncollapsed_log_level.map(into),
profiling_level,
log_level: wasm_log_level,
uncollapsed_log_level: wasm_uncollapsed_log_level,
wasm_size_limit: wasm_size_limit.filter(|size_limit| size_limit.get_bytes() > 0),
})
}
Expand Down

0 comments on commit f39070a

Please sign in to comment.