Skip to content

Commit

Permalink
Merge pull request #2478 from fzyzcjy/feat/2425
Browse files Browse the repository at this point in the history
Do not warn when fvm not found or for unexpected condition name
  • Loading branch information
fzyzcjy authored Jan 3, 2025
2 parents ca8dfe0 + 6f9f638 commit 5686b03
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 15 deletions.
14 changes: 11 additions & 3 deletions frb_codegen/src/library/commands/cargo_expand/real.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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)?;
Expand Down
24 changes: 16 additions & 8 deletions frb_codegen/src/library/commands/command_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)*);
Expand Down Expand Up @@ -76,11 +76,11 @@ macro_rules! command_args {
pub(crate) fn call_shell(
cmd: &[PathBuf],
pwd: Option<&Path>,
envs: Option<HashMap<String, String>>,
options: Option<ExecuteCommandOptions>,
) -> anyhow::Result<Output> {
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 {
Expand Down Expand Up @@ -108,12 +108,20 @@ pub(crate) fn call_shell_info(cmd: &[PathBuf]) -> CommandInfo {
};
}

#[derive(Default)]
pub(crate) struct ExecuteCommandOptions {
pub envs: Option<HashMap<String, String>>,
pub log_when_error: Option<bool>,
}

pub(crate) fn execute_command<'a>(
bin: &str,
args: impl IntoIterator<Item = &'a PathBuf>,
current_dir: Option<&Path>,
envs: Option<HashMap<String, String>>,
options: Option<ExecuteCommandOptions>,
) -> anyhow::Result<Output> {
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);
Expand All @@ -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);
}

Expand All @@ -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,
Expand Down
6 changes: 5 additions & 1 deletion frb_codegen/src/library/commands/dart_build_runner.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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(),
Expand Down
6 changes: 5 additions & 1 deletion frb_codegen/src/library/commands/ffigen.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions frb_codegen/src/library/commands/fvm.rs
Original file line number Diff line number Diff line change
@@ -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<String> {
Expand Down Expand Up @@ -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())
}
4 changes: 4 additions & 0 deletions website/docs/manual/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5686b03

Please sign in to comment.