diff --git a/frb_codegen/src/library/commands/cargo_expand/real.rs b/frb_codegen/src/library/commands/cargo_expand/real.rs index 6472d036bb..ab31421842 100644 --- a/frb_codegen/src/library/commands/cargo_expand/real.rs +++ b/frb_codegen/src/library/commands/cargo_expand/real.rs @@ -1,7 +1,7 @@ use crate::codegen::dumper::Dumper; use crate::codegen::ConfigDumpContent; use crate::command_args; -use crate::library::commands::command_runner::execute_command; +use crate::library::commands::command_runner::{execute_command, ExecuteCommandOptions}; use crate::utils::crate_name::CrateName; use anyhow::{bail, Context, Result}; use itertools::Itertools; @@ -92,8 +92,16 @@ fn run_raw( )] .into(); - let output = execute_command("cargo", &args, Some(rust_crate_dir), Some(extra_env)) - .with_context(|| format!("Could not expand rust code at path {rust_crate_dir:?}"))?; + let output = execute_command( + "cargo", + &args, + Some(rust_crate_dir), + Some(ExecuteCommandOptions { + envs: Some(extra_env), + ..Default::default() + }), + ) + .with_context(|| format!("Could not expand rust code at path {rust_crate_dir:?}"))?; let stdout = String::from_utf8(output.stdout)?; let stderr = String::from_utf8(output.stderr)?; diff --git a/frb_codegen/src/library/commands/command_runner.rs b/frb_codegen/src/library/commands/command_runner.rs index 09955b84f4..425dfa5bf2 100644 --- a/frb_codegen/src/library/commands/command_runner.rs +++ b/frb_codegen/src/library/commands/command_runner.rs @@ -25,12 +25,12 @@ macro_rules! command_run { let args = $crate::command_args!($($rest)*); $crate::library::commands::command_runner::execute_command($binary, args.iter(), None, None) }}; - ($binary:ident in $pwd:expr, envs = $envs:expr, $($rest:tt)*) => {{ + ($binary:ident in $pwd:expr, options = $options:expr, $($rest:tt)*) => {{ let args = $crate::command_args!($($rest)*); - $crate::library::commands::command_runner::execute_command($binary, args.iter(), $pwd, $envs) + $crate::library::commands::command_runner::execute_command($binary, args.iter(), $pwd, $options) }}; ($binary:ident in $pwd:expr, $($rest:tt)*) => {{ - $crate::command_run!($binary in $pwd, envs = None, $($rest)*) + $crate::command_run!($binary in $pwd, options = None, $($rest)*) }}; ($command:path $([ $($args:expr),* ])?, $($rest:tt)*) => {{ let args = $crate::command_args!($($rest)*); @@ -76,11 +76,11 @@ macro_rules! command_args { pub(crate) fn call_shell( cmd: &[PathBuf], pwd: Option<&Path>, - envs: Option>, + options: Option, ) -> anyhow::Result { let CommandInfo { program, args } = call_shell_info(cmd); let program = &program; - command_run!(program in pwd, envs = envs, *args) + command_run!(program in pwd, options = options, *args) } pub(crate) struct CommandInfo { @@ -108,12 +108,20 @@ pub(crate) fn call_shell_info(cmd: &[PathBuf]) -> CommandInfo { }; } +#[derive(Default)] +pub(crate) struct ExecuteCommandOptions { + pub envs: Option>, + pub log_when_error: Option, +} + pub(crate) fn execute_command<'a>( bin: &str, args: impl IntoIterator, current_dir: Option<&Path>, - envs: Option>, + options: Option, ) -> anyhow::Result { + let options = options.unwrap_or_default(); + let args = args.into_iter().collect_vec(); let args_display = args.iter().map(|path| path.to_string_lossy()).join(" "); let mut cmd = Command::new(bin); @@ -122,7 +130,7 @@ pub(crate) fn execute_command<'a>( if let Some(current_dir) = current_dir { cmd.current_dir(normalize_windows_unc_path(&path_to_string(current_dir)?)); } - if let Some(envs) = envs { + if let Some(envs) = options.envs { cmd.envs(envs); } @@ -149,7 +157,7 @@ pub(crate) fn execute_command<'a>( warn!("See keywords such as `error` in command output. Maybe there is a problem? command={:?} stdout={:?}", cmd, stdout); // frb-coverage:ignore-end } - } else { + } else if options.log_when_error.unwrap_or(true) { warn!( "command={:?} stdout={} stderr={}", cmd, diff --git a/frb_codegen/src/library/commands/dart_build_runner.rs b/frb_codegen/src/library/commands/dart_build_runner.rs index e419f5e5b0..017d2e9955 100644 --- a/frb_codegen/src/library/commands/dart_build_runner.rs +++ b/frb_codegen/src/library/commands/dart_build_runner.rs @@ -1,5 +1,6 @@ use crate::command_run; use crate::commands::command_runner::call_shell; +use crate::library::commands::command_runner::ExecuteCommandOptions; use crate::library::commands::fvm::command_arg_maybe_fvm; use crate::utils::dart_repository::dart_repo::DartRepository; use anyhow::bail; @@ -12,7 +13,10 @@ pub fn dart_build_runner(dart_root: &Path) -> anyhow::Result<()> { let repo = DartRepository::from_path(dart_root)?; let out = command_run!( - call_shell[Some(dart_root), Some(dart_run_extra_env())], + call_shell[Some(dart_root), Some(ExecuteCommandOptions { + envs: Some(dart_run_extra_env()), + ..Default::default() + })], ?command_arg_maybe_fvm(Some(dart_root)), *repo.toolchain.as_run_command(), *repo.command_extra_args(), diff --git a/frb_codegen/src/library/commands/ffigen.rs b/frb_codegen/src/library/commands/ffigen.rs index b165b7faee..8ac5be6811 100644 --- a/frb_codegen/src/library/commands/ffigen.rs +++ b/frb_codegen/src/library/commands/ffigen.rs @@ -1,6 +1,7 @@ use super::dart_build_runner::dart_run_extra_env; use crate::command_run; use crate::commands::command_runner::call_shell; +use crate::library::commands::command_runner::ExecuteCommandOptions; use crate::utils::dart_repository::dart_repo::DartRepository; use anyhow::bail; use itertools::Itertools; @@ -78,7 +79,10 @@ pub(crate) fn ffigen_raw(config: &FfigenCommandConfig, dart_root: &Path) -> anyh let repo = DartRepository::from_path(dart_root).unwrap(); let res = command_run!( - call_shell[Some(dart_root), Some(dart_run_extra_env())], + call_shell[Some(dart_root), Some(ExecuteCommandOptions { + envs: Some(dart_run_extra_env()), + ..Default::default() + })], *repo.toolchain.as_run_command(), *repo.command_extra_args(), "run", diff --git a/frb_codegen/src/library/commands/fvm.rs b/frb_codegen/src/library/commands/fvm.rs index 0151c2df20..cf9b976fe0 100644 --- a/frb_codegen/src/library/commands/fvm.rs +++ b/frb_codegen/src/library/commands/fvm.rs @@ -1,5 +1,5 @@ use crate::command_run; -use crate::library::commands::command_runner::call_shell; +use crate::library::commands::command_runner::{call_shell, ExecuteCommandOptions}; use std::path::Path; pub(crate) fn command_arg_maybe_fvm(pwd: Option<&Path>) -> Option { @@ -34,6 +34,6 @@ fn has_fvmrc(pwd: &Path) -> bool { #[allow(clippy::vec_init_then_push)] fn has_fvm_installation() -> bool { - command_run!(call_shell[None, None], "fvm", "--version") + command_run!(call_shell[None, Some(ExecuteCommandOptions { log_when_error: Some(false), ..Default::default() })], "fvm", "--version") .map_or(false, |res| res.status.success()) } diff --git a/website/docs/manual/troubleshooting.md b/website/docs/manual/troubleshooting.md index 591df67589..b8f0fb9e96 100644 --- a/website/docs/manual/troubleshooting.md +++ b/website/docs/manual/troubleshooting.md @@ -141,6 +141,10 @@ Try to uninstall the rust toolchain and install it again from the scratch: Check [the related issue on GitHub](https://github.com/fzyzcjy/flutter_rust_bridge/issues/2348) for the context. +## Warning: unexpected `cfg` condition name: `frb_expand` + +Please refer to [#2425](https://github.com/fzyzcjy/flutter_rust_bridge/issues/2425) for more details. + ## Other problems? Don't hesitate to [open an issue](https://github.com/fzyzcjy/flutter_rust_bridge/issues/new/choose)! I usually reply