From babc9bdd4058bba788e8c5d1e5fefafb66486ae3 Mon Sep 17 00:00:00 2001 From: fzyzcjy Date: Fri, 1 Dec 2023 11:10:10 +0800 Subject: [PATCH] feat: update-goldens flag and exec --- .../codegen/parser/mod/generics/expect_ir.json | 15 ++++++++++----- .../codegen/parser/mod/methods/expect_ir.json | 9 ++++++--- .../parser/mod/multi_input_file/expect_ir.json | 6 ++++-- .../mod/non_qualified_names/expect_ir.json | 6 ++++-- .../parser/mod/qualified_names/expect_ir.json | 12 ++++++++---- .../codegen/parser/mod/simple/expect_ir.json | 3 ++- .../use_type_in_another_file/expect_ir.json | 3 ++- .../lib/src/makefile_dart/misc.dart | 3 +++ .../lib/src/makefile_dart/test.dart | 18 +++++++++++++----- .../lib/src/makefile_dart/test.g.dart | 16 ++++++++++++++++ 10 files changed, 68 insertions(+), 23 deletions(-) diff --git a/frb_codegen/test_fixtures/library/codegen/parser/mod/generics/expect_ir.json b/frb_codegen/test_fixtures/library/codegen/parser/mod/generics/expect_ir.json index 033b87c7df..d6c5a01d84 100644 --- a/frb_codegen/test_fixtures/library/codegen/parser/mod/generics/expect_ir.json +++ b/frb_codegen/test_fixtures/library/codegen/parser/mod/generics/expect_ir.json @@ -122,7 +122,8 @@ "safe_ident": "unit", "type": "Primitive" }, - "owner": "Function" + "owner": "Function", + "rust_async": false }, { "comments": [], @@ -160,7 +161,8 @@ "safe_ident": "unit", "type": "Primitive" }, - "owner": "Function" + "owner": "Function", + "rust_async": false }, { "comments": [], @@ -198,7 +200,8 @@ "safe_ident": "unit", "type": "Primitive" }, - "owner": "Function" + "owner": "Function", + "rust_async": false }, { "comments": [], @@ -236,7 +239,8 @@ "safe_ident": "unit", "type": "Primitive" }, - "owner": "Function" + "owner": "Function", + "rust_async": false }, { "comments": [], @@ -274,7 +278,8 @@ "safe_ident": "unit", "type": "Primitive" }, - "owner": "Function" + "owner": "Function", + "rust_async": false } ], "has_executor": false, diff --git a/frb_codegen/test_fixtures/library/codegen/parser/mod/methods/expect_ir.json b/frb_codegen/test_fixtures/library/codegen/parser/mod/methods/expect_ir.json index db47558cd2..3c9b87d38c 100644 --- a/frb_codegen/test_fixtures/library/codegen/parser/mod/methods/expect_ir.json +++ b/frb_codegen/test_fixtures/library/codegen/parser/mod/methods/expect_ir.json @@ -62,7 +62,8 @@ "enum_or_struct_name": "crate::api/MyEnum", "mode": "Instance" } - } + }, + "rust_async": false }, { "comments": [], @@ -81,7 +82,8 @@ "enum_or_struct_name": "crate::api/MyEnum", "mode": "Static" } - } + }, + "rust_async": false }, { "comments": [], @@ -125,7 +127,8 @@ "enum_or_struct_name": "crate::api/MyStruct", "mode": "Instance" } - } + }, + "rust_async": false } ], "has_executor": false, diff --git a/frb_codegen/test_fixtures/library/codegen/parser/mod/multi_input_file/expect_ir.json b/frb_codegen/test_fixtures/library/codegen/parser/mod/multi_input_file/expect_ir.json index 8f39ba5c1f..4b36f3644c 100644 --- a/frb_codegen/test_fixtures/library/codegen/parser/mod/multi_input_file/expect_ir.json +++ b/frb_codegen/test_fixtures/library/codegen/parser/mod/multi_input_file/expect_ir.json @@ -12,7 +12,8 @@ "safe_ident": "unit", "type": "Primitive" }, - "owner": "Function" + "owner": "Function", + "rust_async": false }, { "comments": [], @@ -25,7 +26,8 @@ "safe_ident": "unit", "type": "Primitive" }, - "owner": "Function" + "owner": "Function", + "rust_async": false } ], "has_executor": false, diff --git a/frb_codegen/test_fixtures/library/codegen/parser/mod/non_qualified_names/expect_ir.json b/frb_codegen/test_fixtures/library/codegen/parser/mod/non_qualified_names/expect_ir.json index c9357fd7f7..463adb7f44 100644 --- a/frb_codegen/test_fixtures/library/codegen/parser/mod/non_qualified_names/expect_ir.json +++ b/frb_codegen/test_fixtures/library/codegen/parser/mod/non_qualified_names/expect_ir.json @@ -43,7 +43,8 @@ "safe_ident": "unit", "type": "Primitive" }, - "owner": "Function" + "owner": "Function", + "rust_async": false }, { "comments": [], @@ -60,7 +61,8 @@ "safe_ident": "i_32", "type": "Primitive" }, - "owner": "Function" + "owner": "Function", + "rust_async": false } ], "has_executor": false, diff --git a/frb_codegen/test_fixtures/library/codegen/parser/mod/qualified_names/expect_ir.json b/frb_codegen/test_fixtures/library/codegen/parser/mod/qualified_names/expect_ir.json index fcd8a07186..0386f91fbf 100644 --- a/frb_codegen/test_fixtures/library/codegen/parser/mod/qualified_names/expect_ir.json +++ b/frb_codegen/test_fixtures/library/codegen/parser/mod/qualified_names/expect_ir.json @@ -43,7 +43,8 @@ "safe_ident": "unit", "type": "Primitive" }, - "owner": "Function" + "owner": "Function", + "rust_async": false }, { "comments": [], @@ -60,7 +61,8 @@ "safe_ident": "i_32", "type": "Primitive" }, - "owner": "Function" + "owner": "Function", + "rust_async": false }, { "comments": [], @@ -77,7 +79,8 @@ "safe_ident": "i_32", "type": "Primitive" }, - "owner": "Function" + "owner": "Function", + "rust_async": false }, { "comments": [], @@ -94,7 +97,8 @@ "safe_ident": "i_32", "type": "Primitive" }, - "owner": "Function" + "owner": "Function", + "rust_async": false } ], "has_executor": false, diff --git a/frb_codegen/test_fixtures/library/codegen/parser/mod/simple/expect_ir.json b/frb_codegen/test_fixtures/library/codegen/parser/mod/simple/expect_ir.json index 5ce3c17fe3..17ea8a5361 100644 --- a/frb_codegen/test_fixtures/library/codegen/parser/mod/simple/expect_ir.json +++ b/frb_codegen/test_fixtures/library/codegen/parser/mod/simple/expect_ir.json @@ -12,7 +12,8 @@ "safe_ident": "unit", "type": "Primitive" }, - "owner": "Function" + "owner": "Function", + "rust_async": false } ], "has_executor": false, diff --git a/frb_codegen/test_fixtures/library/codegen/parser/mod/use_type_in_another_file/expect_ir.json b/frb_codegen/test_fixtures/library/codegen/parser/mod/use_type_in_another_file/expect_ir.json index ea2c302ce8..00e5dbd5cc 100644 --- a/frb_codegen/test_fixtures/library/codegen/parser/mod/use_type_in_another_file/expect_ir.json +++ b/frb_codegen/test_fixtures/library/codegen/parser/mod/use_type_in_another_file/expect_ir.json @@ -74,7 +74,8 @@ "safe_ident": "unit", "type": "Primitive" }, - "owner": "Function" + "owner": "Function", + "rust_async": false } ], "has_executor": false, diff --git a/tools/frb_internal/lib/src/makefile_dart/misc.dart b/tools/frb_internal/lib/src/makefile_dart/misc.dart index 0025023521..43a39a5cdd 100644 --- a/tools/frb_internal/lib/src/makefile_dart/misc.dart +++ b/tools/frb_internal/lib/src/makefile_dart/misc.dart @@ -7,6 +7,7 @@ import 'package:build_cli_annotations/build_cli_annotations.dart'; import 'package:flutter_rust_bridge_internal/src/makefile_dart/consts.dart'; import 'package:flutter_rust_bridge_internal/src/makefile_dart/generate.dart'; import 'package:flutter_rust_bridge_internal/src/makefile_dart/lint.dart'; +import 'package:flutter_rust_bridge_internal/src/makefile_dart/test.dart'; import 'package:flutter_rust_bridge_internal/src/utils/makefile_dart_infra.dart'; part 'misc.g.dart'; @@ -61,6 +62,8 @@ Future precommit(PrecommitConfig config) async { await generateRunFrbCodegenCommandGenerate( GeneratePackageConfig(setExitIfChanged: false, package: package)); } + + await testRust(const TestRustConfig(updateGoldens: true)); } } diff --git a/tools/frb_internal/lib/src/makefile_dart/test.dart b/tools/frb_internal/lib/src/makefile_dart/test.dart index d54f35f8c2..0f76cb1cfe 100644 --- a/tools/frb_internal/lib/src/makefile_dart/test.dart +++ b/tools/frb_internal/lib/src/makefile_dart/test.dart @@ -9,8 +9,8 @@ part 'test.g.dart'; List> createCommands() { return [ - SimpleConfigCommand('test-rust', testRust, _$populateTestConfigParser, - _$parseTestConfigResult), + SimpleConfigCommand('test-rust', testRust, _$populateTestRustConfigParser, + _$parseTestRustConfigResult), SimpleConfigCommand('test-dart-native', testDartNative, _$populateTestDartConfigParser, _$parseTestDartConfigResult), SimpleConfigCommand('test-dart-web', testDartWeb, @@ -29,6 +29,13 @@ class TestConfig { const TestConfig(); } +@CliOptions() +class TestRustConfig { + final bool updateGoldens; + + const TestRustConfig({required this.updateGoldens}); +} + @CliOptions() class TestDartConfig { final String package; @@ -44,17 +51,18 @@ class TestFlutterConfig { const TestFlutterConfig({this.flutterTestArgs, required this.package}); } -Future testRust(TestConfig config) async { +Future testRust(TestRustConfig config) async { for (final package in kRustPackages) { - await testRustPackage(package); + await testRustPackage(config, package); } } -Future testRustPackage(String package) async { +Future testRustPackage(TestRustConfig config, String package) async { await exec('cargo build', relativePwd: package); await exec('cargo test', relativePwd: package, extraEnv: { // Because we have another CI to run the codegen and check outputs 'FRB_SKIP_GENERATE_FRB_EXAMPLE_TEST': '1', + if (config.updateGoldens) 'UPDATE_GOLDENS': '1', }); } diff --git a/tools/frb_internal/lib/src/makefile_dart/test.g.dart b/tools/frb_internal/lib/src/makefile_dart/test.g.dart index faca4f4280..22e456bb98 100644 --- a/tools/frb_internal/lib/src/makefile_dart/test.g.dart +++ b/tools/frb_internal/lib/src/makefile_dart/test.g.dart @@ -19,6 +19,22 @@ TestConfig parseTestConfig(List args) { return _$parseTestConfigResult(result); } +TestRustConfig _$parseTestRustConfigResult(ArgResults result) => TestRustConfig( + updateGoldens: result['update-goldens'] as bool, + ); + +ArgParser _$populateTestRustConfigParser(ArgParser parser) => parser + ..addFlag( + 'update-goldens', + ); + +final _$parserForTestRustConfig = _$populateTestRustConfigParser(ArgParser()); + +TestRustConfig parseTestRustConfig(List args) { + final result = _$parserForTestRustConfig.parse(args); + return _$parseTestRustConfigResult(result); +} + TestDartConfig _$parseTestDartConfigResult(ArgResults result) => TestDartConfig( package: result['package'] as String, );