From 5061daea3c6428ccadaafe876b6af046bfd275ea Mon Sep 17 00:00:00 2001 From: GChanathip Date: Fri, 22 Nov 2024 18:24:09 +0700 Subject: [PATCH 1/6] Add flavor to dartDefines android. --- .../lib/src/crossplatform/app_options.dart | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/packages/patrol_cli/lib/src/crossplatform/app_options.dart b/packages/patrol_cli/lib/src/crossplatform/app_options.dart index dfbc7e6ca..324cae03f 100644 --- a/packages/patrol_cli/lib/src/crossplatform/app_options.dart +++ b/packages/patrol_cli/lib/src/crossplatform/app_options.dart @@ -115,14 +115,22 @@ class AndroidAppOptions { final target = '-Ptarget=${flutter.target}'; cmd.add(target); + // Create modifiable Map + final effectiveDartDefines = Map.of(flutter.dartDefines); + + // Add flavor to dart defines + if (flutter.flavor != null) { + effectiveDartDefines['FLUTTER_APP_FLAVOR'] = flutter.flavor!; + } + // Add Dart defines encoded in base64 - if (flutter.dartDefines.isNotEmpty) { + if (effectiveDartDefines.isNotEmpty) { final dartDefinesString = StringBuffer(); - for (var i = 0; i < flutter.dartDefines.length; i++) { - final entry = flutter.dartDefines.entries.elementAt(i); + for (var i = 0; i < effectiveDartDefines.length; i++) { + final entry = effectiveDartDefines.entries.elementAt(i); final pair = utf8.encode('${entry.key}=${entry.value}'); dartDefinesString.write(base64Encode(pair)); - if (i != flutter.dartDefines.length - 1) { + if (i != effectiveDartDefines.length - 1) { dartDefinesString.write(','); } } @@ -210,8 +218,7 @@ class IOSAppOptions { '-quiet', ...['-derivedDataPath', '../build/ios_integ'], r'OTHER_SWIFT_FLAGS=$(inherited) -D PATROL_ENABLED', - if (clearPermissions) - r'GCC_PREPROCESSOR_DEFINITIONS=$(inherited) CLEAR_PERMISSIONS=1', + if (clearPermissions) r'GCC_PREPROCESSOR_DEFINITIONS=$(inherited) CLEAR_PERMISSIONS=1', ]; return cmd; From 206326c5aaa5466e0ec11b47d6f886969893caa3 Mon Sep 17 00:00:00 2001 From: GChanathip Date: Fri, 22 Nov 2024 18:50:15 +0700 Subject: [PATCH 2/6] update test case --- .../test/crossplatform/app_options_test.dart | 24 +++++++------------ 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/packages/patrol_cli/test/crossplatform/app_options_test.dart b/packages/patrol_cli/test/crossplatform/app_options_test.dart index f30376a58..d84f6cf18 100644 --- a/packages/patrol_cli/test/crossplatform/app_options_test.dart +++ b/packages/patrol_cli/test/crossplatform/app_options_test.dart @@ -27,8 +27,7 @@ void main() { testServerPort: 2, ); - final invocation = - options.toGradleAssembleTestInvocation(isWindows: true); + final invocation = options.toGradleAssembleTestInvocation(isWindows: true); expect( invocation, equals([ @@ -56,8 +55,7 @@ void main() { testServerPort: 2, ); - final invocation = - options.toGradleAssembleTestInvocation(isWindows: false); + final invocation = options.toGradleAssembleTestInvocation(isWindows: false); expect( invocation, equals([ @@ -93,15 +91,14 @@ void main() { testServerPort: 2, ); - final invocation = - options.toGradleAssembleTestInvocation(isWindows: true); + final invocation = options.toGradleAssembleTestInvocation(isWindows: true); expect( invocation, equals([ r'.\gradlew.bat', ':app:assembleDevReleaseAndroidTest', r'-Ptarget=C:\Users\john\app\integration_test\app_test.dart', - '-Pdart-defines=RU1BSUw9dXNlckBleGFtcGxlLmNvbQ==,UEFTU1dPUkQ9bnk0bmNhdA==,Zm9vPWJhcg==', + '-Pdart-defines=RU1BSUw9dXNlckBleGFtcGxlLmNvbQ==,UEFTU1dPUkQ9bnk0bmNhdA==,Zm9vPWJhcg==,RkxVVFRFUl9BUFBfRkxBVk9SPWRldg==', '-Papp-server-port=1', '-Ptest-server-port=2', ]), @@ -123,15 +120,14 @@ void main() { testServerPort: 2, ); - final invocation = - options.toGradleAssembleTestInvocation(isWindows: false); + final invocation = options.toGradleAssembleTestInvocation(isWindows: false); expect( invocation, equals([ './gradlew', ':app:assembleDevDebugAndroidTest', '-Ptarget=/Users/john/app/integration_test/app_test.dart', - '-Pdart-defines=RU1BSUw9dXNlckBleGFtcGxlLmNvbQ==,UEFTU1dPUkQ9bnk0bmNhdA==,Zm9vPWJhcg==', + '-Pdart-defines=RU1BSUw9dXNlckBleGFtcGxlLmNvbQ==,UEFTU1dPUkQ9bnk0bmNhdA==,Zm9vPWJhcg==,RkxVVFRFUl9BUFBfRkxBVk9SPWRldg==', '-Papp-server-port=1', '-Ptest-server-port=2', ]), @@ -143,9 +139,7 @@ void main() { group('IOSAppOptions', () { late IOSAppOptions options; - group( - 'correctly encodes default xcodebuild invocation for simulator with dartDefineFromFile path', - () { + group('correctly encodes default xcodebuild invocation for simulator with dartDefineFromFile path', () { const flutterOpts = FlutterAppOptions( command: flutterCommand, target: 'integration_test/app_test.dart', @@ -226,9 +220,7 @@ void main() { }); }); - group( - 'correctly encodes default xcodebuild invocation for simulator without dartDefineFromFile path', - () { + group('correctly encodes default xcodebuild invocation for simulator without dartDefineFromFile path', () { const flutterOpts = FlutterAppOptions( command: flutterCommand, target: 'integration_test/app_test.dart', From bc67b83dc1ffe02f6d07fa592b66314f873c2360 Mon Sep 17 00:00:00 2001 From: GChanathip Date: Fri, 22 Nov 2024 18:55:58 +0700 Subject: [PATCH 3/6] format --- .../lib/src/crossplatform/app_options.dart | 3 ++- .../test/crossplatform/app_options_test.dart | 20 +++++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/packages/patrol_cli/lib/src/crossplatform/app_options.dart b/packages/patrol_cli/lib/src/crossplatform/app_options.dart index 324cae03f..b8f0e68e3 100644 --- a/packages/patrol_cli/lib/src/crossplatform/app_options.dart +++ b/packages/patrol_cli/lib/src/crossplatform/app_options.dart @@ -218,7 +218,8 @@ class IOSAppOptions { '-quiet', ...['-derivedDataPath', '../build/ios_integ'], r'OTHER_SWIFT_FLAGS=$(inherited) -D PATROL_ENABLED', - if (clearPermissions) r'GCC_PREPROCESSOR_DEFINITIONS=$(inherited) CLEAR_PERMISSIONS=1', + if (clearPermissions) + r'GCC_PREPROCESSOR_DEFINITIONS=$(inherited) CLEAR_PERMISSIONS=1', ]; return cmd; diff --git a/packages/patrol_cli/test/crossplatform/app_options_test.dart b/packages/patrol_cli/test/crossplatform/app_options_test.dart index d84f6cf18..377753ce3 100644 --- a/packages/patrol_cli/test/crossplatform/app_options_test.dart +++ b/packages/patrol_cli/test/crossplatform/app_options_test.dart @@ -27,7 +27,8 @@ void main() { testServerPort: 2, ); - final invocation = options.toGradleAssembleTestInvocation(isWindows: true); + final invocation = + options.toGradleAssembleTestInvocation(isWindows: true); expect( invocation, equals([ @@ -55,7 +56,8 @@ void main() { testServerPort: 2, ); - final invocation = options.toGradleAssembleTestInvocation(isWindows: false); + final invocation = + options.toGradleAssembleTestInvocation(isWindows: false); expect( invocation, equals([ @@ -91,7 +93,8 @@ void main() { testServerPort: 2, ); - final invocation = options.toGradleAssembleTestInvocation(isWindows: true); + final invocation = + options.toGradleAssembleTestInvocation(isWindows: true); expect( invocation, equals([ @@ -120,7 +123,8 @@ void main() { testServerPort: 2, ); - final invocation = options.toGradleAssembleTestInvocation(isWindows: false); + final invocation = + options.toGradleAssembleTestInvocation(isWindows: false); expect( invocation, equals([ @@ -139,7 +143,9 @@ void main() { group('IOSAppOptions', () { late IOSAppOptions options; - group('correctly encodes default xcodebuild invocation for simulator with dartDefineFromFile path', () { + group( + 'correctly encodes default xcodebuild invocation for simulator with dartDefineFromFile path', + () { const flutterOpts = FlutterAppOptions( command: flutterCommand, target: 'integration_test/app_test.dart', @@ -220,7 +226,9 @@ void main() { }); }); - group('correctly encodes default xcodebuild invocation for simulator without dartDefineFromFile path', () { + group( + 'correctly encodes default xcodebuild invocation for simulator without dartDefineFromFile path', + () { const flutterOpts = FlutterAppOptions( command: flutterCommand, target: 'integration_test/app_test.dart', From b4edb5299a96411882deb8c8e60e3ed95e169d1b Mon Sep 17 00:00:00 2001 From: GChanathip <68949592+GChanathip@users.noreply.github.com> Date: Tue, 26 Nov 2024 10:43:07 +0700 Subject: [PATCH 4/6] Update packages/patrol_cli/lib/src/crossplatform/app_options.dart Co-authored-by: Piotr Maszota <37781044+piotruela@users.noreply.github.com> --- packages/patrol_cli/lib/src/crossplatform/app_options.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/patrol_cli/lib/src/crossplatform/app_options.dart b/packages/patrol_cli/lib/src/crossplatform/app_options.dart index b8f0e68e3..342ecaac7 100644 --- a/packages/patrol_cli/lib/src/crossplatform/app_options.dart +++ b/packages/patrol_cli/lib/src/crossplatform/app_options.dart @@ -119,8 +119,8 @@ class AndroidAppOptions { final effectiveDartDefines = Map.of(flutter.dartDefines); // Add flavor to dart defines - if (flutter.flavor != null) { - effectiveDartDefines['FLUTTER_APP_FLAVOR'] = flutter.flavor!; + if (flutter.flavor case final flavor?) { + effectiveDartDefines['FLUTTER_APP_FLAVOR'] = flavor; } // Add Dart defines encoded in base64 From 3a2cc2477a7c9da1146cfa179214bfb89739e190 Mon Sep 17 00:00:00 2001 From: GChanathip Date: Tue, 26 Nov 2024 11:01:57 +0700 Subject: [PATCH 5/6] update changelog --- packages/patrol_cli/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/patrol_cli/CHANGELOG.md b/packages/patrol_cli/CHANGELOG.md index d199264df..9a0bb533a 100644 --- a/packages/patrol_cli/CHANGELOG.md +++ b/packages/patrol_cli/CHANGELOG.md @@ -1,3 +1,7 @@ +## 3.5.0 + +- Add android product flavor to dart-define. (#2425) + ## 3.4.0 - Add support for the `patrol_log` package. (#2387) From 2df71f3357b89edf369403aa670bf68acf923834 Mon Sep 17 00:00:00 2001 From: GChanathip Date: Tue, 26 Nov 2024 15:17:45 +0700 Subject: [PATCH 6/6] remove versioning from changelog --- packages/patrol_cli/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/patrol_cli/CHANGELOG.md b/packages/patrol_cli/CHANGELOG.md index 9a0bb533a..8072712a5 100644 --- a/packages/patrol_cli/CHANGELOG.md +++ b/packages/patrol_cli/CHANGELOG.md @@ -1,4 +1,4 @@ -## 3.5.0 +## Unreleased - Add android product flavor to dart-define. (#2425)