Skip to content

Commit

Permalink
Merge pull request fzyzcjy#1809 from fzyzcjy/feat/1807
Browse files Browse the repository at this point in the history
Fix error when using build.rs instead of standard way to trigger code generation
  • Loading branch information
fzyzcjy authored Mar 10, 2024
2 parents db1de32 + fbfbe58 commit 7e9e0a2
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 15 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 2.0.0-dev.28

* Please refer to https://fzyzcjy.github.io/flutter_rust_bridge/guides/miscellaneous/whats-new for what's changed in V2.
* Fix error when using build.rs instead of standard way to trigger code generation #1809

## 2.0.0-dev.27

* Please refer to https://fzyzcjy.github.io/flutter_rust_bridge/guides/miscellaneous/whats-new for what's changed in V2.
Expand Down
9 changes: 8 additions & 1 deletion frb_codegen/src/library/codegen/parser/attribute_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl FrbAttributes {
attrs
.iter()
.filter(|attr| {
attr.path().is_ident(METADATA_IDENT)
attr.path().segments.last().unwrap().ident == METADATA_IDENT
// exclude the `#[frb]` case
&& !matches!(attr.meta, Meta::Path(_))
})
Expand Down Expand Up @@ -449,6 +449,13 @@ mod tests {
Ok(())
}

#[test]
fn test_double_colon() -> anyhow::Result<()> {
let parsed = parse("#[flutter_rust_bridge::frb(sync)]")?;
assert_eq!(parsed.0, vec![FrbAttribute::Sync]);
Ok(())
}

#[test]
fn test_multiple_via_comma() -> anyhow::Result<()> {
let parsed = parse("#[frb(sync, non_final)]")?;
Expand Down
18 changes: 13 additions & 5 deletions tools/frb_internal/lib/src/makefile_dart/generate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -397,16 +397,24 @@ Future<void> _renameDirIfExists(String src, String dst) async {
Future<void> _wrapMaybeSetExitIfChanged(
GenerateConfig config, Future<void> Function() inner,
{String? extraArgs}) async {
await wrapMaybeSetExitIfChangedRaw(config.setExitIfChanged, inner,
extraArgs: extraArgs);
}

Future<void> wrapMaybeSetExitIfChangedRaw(
bool enable,
Future<void> Function() inner, {
String? extraArgs,
}) async {
// Before actually executing anything, check whether git repository is already dirty
await _maybeSetExitIfChanged(config, extraArgs: extraArgs);
await _maybeSetExitIfChanged(enable, extraArgs: extraArgs);
await inner();
// The real check
await _maybeSetExitIfChanged(config, extraArgs: extraArgs);
await _maybeSetExitIfChanged(enable, extraArgs: extraArgs);
}

Future<void> _maybeSetExitIfChanged(GenerateConfig config,
{String? extraArgs}) async {
if (config.setExitIfChanged) {
Future<void> _maybeSetExitIfChanged(bool enable, {String? extraArgs}) async {
if (enable) {
await exec('git diff --exit-code ${extraArgs ?? ""}');
}
}
Expand Down
21 changes: 12 additions & 9 deletions tools/frb_internal/lib/src/makefile_dart/test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -354,15 +354,18 @@ Future<void> testDartNative(TestDartNativeConfig config) async {
extraFlags += '--enable-vm-service ';
}

await exec(
'${dartMode.name} $extraFlags test ${config.coverage ? ' --coverage="coverage"' : ""}',
relativePwd: config.package,
extraEnv: {
// Deliberately do not provide backtrace env to see whether the test_utils work
// ...kEnvEnableRustBacktrace,
...rustEnvMap,
},
);
// extra check for e.g. #1807
await wrapMaybeSetExitIfChangedRaw(true, () async {
await exec(
'${dartMode.name} $extraFlags test ${config.coverage ? ' --coverage="coverage"' : ""}',
relativePwd: config.package,
extraEnv: {
// Deliberately do not provide backtrace env to see whether the test_utils work
// ...kEnvEnableRustBacktrace,
...rustEnvMap,
},
);
});
},
);

Expand Down

0 comments on commit 7e9e0a2

Please sign in to comment.