From cb7aaeff67b0d7eae183edc8a6086e0dde7df127 Mon Sep 17 00:00:00 2001 From: wamynobe Date: Fri, 11 Oct 2024 17:10:09 +0700 Subject: [PATCH 1/7] allows swift generator to skip error class generation --- packages/pigeon/lib/pigeon_lib.dart | 1 + packages/pigeon/lib/swift_generator.dart | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/packages/pigeon/lib/pigeon_lib.dart b/packages/pigeon/lib/pigeon_lib.dart index 8b8a0506877b..075049d98298 100644 --- a/packages/pigeon/lib/pigeon_lib.dart +++ b/packages/pigeon/lib/pigeon_lib.dart @@ -745,6 +745,7 @@ class SwiftGeneratorAdapter implements GeneratorAdapter { path.posix.join(options.basePath ?? '', options.copyrightHeader)) : null, errorClassName: swiftOptions.errorClassName, + includeErrorClass: swiftOptions.includeErrorClass, )); const SwiftGenerator generator = SwiftGenerator(); generator.generate( diff --git a/packages/pigeon/lib/swift_generator.dart b/packages/pigeon/lib/swift_generator.dart index bda343b8b6ce..50dd42b1a5d7 100644 --- a/packages/pigeon/lib/swift_generator.dart +++ b/packages/pigeon/lib/swift_generator.dart @@ -28,6 +28,7 @@ class SwiftOptions { this.copyrightHeader, this.fileSpecificClassNameComponent, this.errorClassName, + this.includeErrorClass = true, }); /// A copyright header that will get prepended to generated code. @@ -39,6 +40,12 @@ class SwiftOptions { /// The name of the error class used for passing custom error parameters. final String? errorClassName; + /// Whether to include the error class in generation. + /// + /// This should only ever be set to false if you have another generated + /// Swift file in the same directory. + final bool includeErrorClass; + /// Creates a [SwiftOptions] from a Map representation where: /// `x = SwiftOptions.fromList(x.toMap())`. static SwiftOptions fromList(Map map) { @@ -47,6 +54,7 @@ class SwiftOptions { fileSpecificClassNameComponent: map['fileSpecificClassNameComponent'] as String?, errorClassName: map['errorClassName'] as String?, + includeErrorClass: map['includeErrorClass'] as bool? ?? true, ); } @@ -58,6 +66,7 @@ class SwiftOptions { if (fileSpecificClassNameComponent != null) 'fileSpecificClassNameComponent': fileSpecificClassNameComponent!, if (errorClassName != null) 'errorClassName': errorClassName!, + 'includeErrorClass': includeErrorClass, }; return result; } @@ -1304,6 +1313,9 @@ private func nilOrValue(_ value: Any?) -> T? { final bool hasProxyApi = root.apis.any((Api api) => api is AstProxyApi); _writePigeonError(generatorOptions, indent); + if (generatorOptions.includeErrorClass) { + _writePigeonError(generatorOptions, indent); + } if (hasHostApi || hasProxyApi) { _writeWrapResult(indent); From 5faea2268cd3ef2e0634c8b98d1019127ea9e050 Mon Sep 17 00:00:00 2001 From: wamynobe Date: Fri, 11 Oct 2024 18:20:54 +0700 Subject: [PATCH 2/7] update CHANGELOG.md --- packages/pigeon/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/pigeon/CHANGELOG.md b/packages/pigeon/CHANGELOG.md index ec8daa80804a..a19b24400009 100644 --- a/packages/pigeon/CHANGELOG.md +++ b/packages/pigeon/CHANGELOG.md @@ -1,3 +1,7 @@ +##NEXT + +* [swift] Adds `includeErrorClass` to `SwiftOptions`. + ## 22.5.0 * [swift] Adds implementation for `@ProxyApi`. From 79a54b0ac6d10539c997e4475b799fd04879209f Mon Sep 17 00:00:00 2001 From: wamynobe Date: Sat, 12 Oct 2024 22:01:13 +0700 Subject: [PATCH 3/7] Remove redundant code --- packages/pigeon/lib/swift_generator.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/pigeon/lib/swift_generator.dart b/packages/pigeon/lib/swift_generator.dart index 50dd42b1a5d7..289c50dbd887 100644 --- a/packages/pigeon/lib/swift_generator.dart +++ b/packages/pigeon/lib/swift_generator.dart @@ -1312,7 +1312,6 @@ private func nilOrValue(_ value: Any?) -> T? { .any((Api api) => api.methods.isNotEmpty); final bool hasProxyApi = root.apis.any((Api api) => api is AstProxyApi); - _writePigeonError(generatorOptions, indent); if (generatorOptions.includeErrorClass) { _writePigeonError(generatorOptions, indent); } From b50fd13cd002b1217b68a858dfb942a69edba615 Mon Sep 17 00:00:00 2001 From: wamynobe Date: Sat, 12 Oct 2024 22:11:02 +0700 Subject: [PATCH 4/7] Update CHANGELOG.md --- packages/pigeon/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/pigeon/CHANGELOG.md b/packages/pigeon/CHANGELOG.md index a19b24400009..1b8a674046d8 100644 --- a/packages/pigeon/CHANGELOG.md +++ b/packages/pigeon/CHANGELOG.md @@ -1,4 +1,4 @@ -##NEXT +## NEXT * [swift] Adds `includeErrorClass` to `SwiftOptions`. From e354fd659d69c9d22ac66836102da4e360d653d5 Mon Sep 17 00:00:00 2001 From: wamynobe Date: Thu, 17 Oct 2024 14:02:42 +0700 Subject: [PATCH 5/7] update CHANGELOG.md --- packages/pigeon/CHANGELOG.md | 2 +- packages/pigeon/lib/generator_tools.dart | 2 +- packages/pigeon/pubspec.yaml | 2 +- packages/pigeon/tool/shared/generation.dart | 3 +++ 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/pigeon/CHANGELOG.md b/packages/pigeon/CHANGELOG.md index 1b8a674046d8..50b7abc58596 100644 --- a/packages/pigeon/CHANGELOG.md +++ b/packages/pigeon/CHANGELOG.md @@ -1,4 +1,4 @@ -## NEXT +## 22.6.0 * [swift] Adds `includeErrorClass` to `SwiftOptions`. diff --git a/packages/pigeon/lib/generator_tools.dart b/packages/pigeon/lib/generator_tools.dart index 37bce3f64029..cbec3e8da6fc 100644 --- a/packages/pigeon/lib/generator_tools.dart +++ b/packages/pigeon/lib/generator_tools.dart @@ -14,7 +14,7 @@ import 'ast.dart'; /// The current version of pigeon. /// /// This must match the version in pubspec.yaml. -const String pigeonVersion = '22.5.0'; +const String pigeonVersion = '22.6.0'; /// Read all the content from [stdin] to a String. String readStdin() { diff --git a/packages/pigeon/pubspec.yaml b/packages/pigeon/pubspec.yaml index df2a2009fecb..cddaae515813 100644 --- a/packages/pigeon/pubspec.yaml +++ b/packages/pigeon/pubspec.yaml @@ -2,7 +2,7 @@ name: pigeon description: Code generator tool to make communication between Flutter and the host platform type-safe and easier. repository: https://github.com/flutter/packages/tree/main/packages/pigeon issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+pigeon%22 -version: 22.5.0 # This must match the version in lib/generator_tools.dart +version: 22.6.0 # This must match the version in lib/generator_tools.dart environment: sdk: ^3.3.0 diff --git a/packages/pigeon/tool/shared/generation.dart b/packages/pigeon/tool/shared/generation.dart index 695789fb6261..253ba31a289e 100644 --- a/packages/pigeon/tool/shared/generation.dart +++ b/packages/pigeon/tool/shared/generation.dart @@ -117,6 +117,7 @@ Future generateTestPigeons( ? null : '$outputBase/ios/Classes/$pascalCaseName.gen.swift', swiftErrorClassName: swiftErrorClassName, + swiftIncludeErrorClass: input != 'core_tests', // Linux gobjectHeaderOut: skipLanguages.contains(GeneratorLanguage.gobject) ? null @@ -212,6 +213,7 @@ Future runPigeon({ String? kotlinPackage, String? kotlinErrorClassName, bool kotlinIncludeErrorClass = true, + bool swiftIncludeErrorClass = true, String? swiftOut, String? swiftErrorClassName, String? cppHeaderOut, @@ -272,6 +274,7 @@ Future runPigeon({ swiftOut: swiftOut, swiftOptions: SwiftOptions( errorClassName: swiftErrorClassName, + includeErrorClass: swiftIncludeErrorClass, ), basePath: basePath, dartPackageName: dartPackageName, From 865a7d087dbf99b7f4508b5a8c77cb6e62a6fc93 Mon Sep 17 00:00:00 2001 From: wamynobe Date: Fri, 18 Oct 2024 09:38:02 +0700 Subject: [PATCH 6/7] Update test cases generation for swift --- packages/pigeon/tool/shared/generation.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/pigeon/tool/shared/generation.dart b/packages/pigeon/tool/shared/generation.dart index 253ba31a289e..61b6b9836bc6 100644 --- a/packages/pigeon/tool/shared/generation.dart +++ b/packages/pigeon/tool/shared/generation.dart @@ -91,7 +91,8 @@ Future generateTestPigeons( ? 'FlutterError' : '${pascalCaseName}Error'; - final bool swiftErrorUseDefaultErrorName = input == 'core_tests'; + final bool swiftErrorUseDefaultErrorName = + input == 'core_tests' || input == 'background_platform_channels'; final String? swiftErrorClassName = swiftErrorUseDefaultErrorName ? null : '${pascalCaseName}Error'; From 9c42c52e8b176f3bcac6738a23a1763df1169990 Mon Sep 17 00:00:00 2001 From: wamynobe Date: Fri, 18 Oct 2024 10:05:28 +0700 Subject: [PATCH 7/7] Update test cases generation for swift --- packages/pigeon/tool/shared/generation.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/pigeon/tool/shared/generation.dart b/packages/pigeon/tool/shared/generation.dart index 61b6b9836bc6..4cee0d4de568 100644 --- a/packages/pigeon/tool/shared/generation.dart +++ b/packages/pigeon/tool/shared/generation.dart @@ -150,6 +150,7 @@ Future generateTestPigeons( ? null : '$outputBase/macos/Classes/$pascalCaseName.gen.swift', swiftErrorClassName: swiftErrorClassName, + swiftIncludeErrorClass: input != 'core_tests', suppressVersion: true, dartPackageName: 'pigeon_integration_tests', injectOverflowTypes: includeOverflow && input == 'core_tests',