diff --git a/dev/devicelab/bin/tasks/plugin_test_ios.dart b/dev/devicelab/bin/tasks/plugin_test_ios.dart index f48d291325..0a82eb6231 100644 --- a/dev/devicelab/bin/tasks/plugin_test_ios.dart +++ b/dev/devicelab/bin/tasks/plugin_test_ios.dart @@ -9,5 +9,6 @@ Future main() async { await task(combine([ PluginTest('ios', ['-i', 'objc', '--platforms=ios']), PluginTest('ios', ['-i', 'swift', '--platforms=ios']), + PluginTest('macos', ['--platforms=macos']), ])); } diff --git a/dev/devicelab/lib/tasks/plugin_tests.dart b/dev/devicelab/lib/tasks/plugin_tests.dart index 7f9f7ff8ef..d85c30c817 100644 --- a/dev/devicelab/lib/tasks/plugin_tests.dart +++ b/dev/devicelab/lib/tasks/plugin_tests.dart @@ -117,27 +117,31 @@ class _FlutterProject { }); final _FlutterProject project = _FlutterProject(directory, name); - if (template == 'plugin' && target == 'ios') { - project._reduceIOSPluginMinimumVersion(name); + if (template == 'plugin' && (target == 'ios' || target == 'macos')) { + project._reduceDarwinPluginMinimumVersion(name, target); } return project; } // Make the platform version artificially low to test that the "deployment // version too low" warning is never emitted. - void _reduceIOSPluginMinimumVersion(String plugin) { - final File podspec = File(path.join(rootPath, 'ios', '$plugin.podspec')); + void _reduceDarwinPluginMinimumVersion(String plugin, String target) { + final File podspec = File(path.join(rootPath, target, '$plugin.podspec')); if (!podspec.existsSync()) { throw TaskResult.failure('podspec file missing at ${podspec.path}'); } - const String versionString = "s.platform = :ios, '8.0'"; + final String versionString = target == 'ios' + ? "s.platform = :ios, '8.0'" + : "s.platform = :osx, '10.11'"; String podspecContent = podspec.readAsStringSync(); if (!podspecContent.contains(versionString)) { - throw TaskResult.failure('Update this test to match plugin minimum iOS deployment version'); + throw TaskResult.failure('Update this test to match plugin minimum $target deployment version'); } podspecContent = podspecContent.replaceFirst( versionString, - "s.platform = :ios, '7.0'", + target == 'ios' + ? "s.platform = :ios, '7.0'" + : "s.platform = :osx, '10.8'" ); podspec.writeAsStringSync(podspecContent, flush: true); } @@ -146,14 +150,37 @@ class _FlutterProject { await inDirectory(Directory(rootPath), () async { final String buildOutput = await evalFlutter('build', options: [target, '-v']); - if (target == 'ios') { + if (target == 'ios' || target == 'macos') { // This warning is confusing and shouldn't be emitted. Plugins often support lower versions than the // Flutter app, but as long as they support the minimum it will work. // warning: The iOS deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, // but the range of supported deployment target versions is 9.0 to 14.0.99. + // + // (or "The macOS deployment target 'MACOSX_DEPLOYMENT_TARGET'"...) if (buildOutput.contains('the range of supported deployment target versions')) { throw TaskResult.failure('Minimum plugin version warning present'); } + + final File podsProject = File(path.join(rootPath, target, 'Pods', 'Pods.xcodeproj', 'project.pbxproj')); + if (!podsProject.existsSync()) { + throw TaskResult.failure('Xcode Pods project file missing at ${podsProject.path}'); + } + + final String podsProjectContent = podsProject.readAsStringSync(); + // This may be a bit brittle, IPHONEOS_DEPLOYMENT_TARGET appears in the + // Pods Xcode project file 6 times. If this number changes, make sure + // it's not a regression in the IPHONEOS_DEPLOYMENT_TARGET override logic. + // The plugintest target should not have IPHONEOS_DEPLOYMENT_TARGET set. + // See _reduceDarwinPluginMinimumVersion for details. + if (target == 'ios' && 'IPHONEOS_DEPLOYMENT_TARGET'.allMatches(podsProjectContent).length != 6) { + throw TaskResult.failure('plugintest may contain IPHONEOS_DEPLOYMENT_TARGET'); + } + + // Same for macOS, but 12. + // The plugintest target should not have MACOSX_DEPLOYMENT_TARGET set. + if (target == 'macos' && 'MACOSX_DEPLOYMENT_TARGET'.allMatches(podsProjectContent).length != 12) { + throw TaskResult.failure('plugintest may contain MACOSX_DEPLOYMENT_TARGET'); + } } }); } diff --git a/packages/flutter_tools/bin/podhelper.rb b/packages/flutter_tools/bin/podhelper.rb index a5d720b31c..b47e2c4124 100644 --- a/packages/flutter_tools/bin/podhelper.rb +++ b/packages/flutter_tools/bin/podhelper.rb @@ -73,9 +73,17 @@ end # Same as flutter_ios_podfile_setup for macOS. def flutter_additional_macos_build_settings(target) - print target.platform_name return unless target.platform_name == :osx + # [target.deployment_target] is a [String] formatted as "10.8". + deployment_target_major, deployment_target_minor = target.deployment_target.match(/(\d+).?(\d*)/).captures + + # Suppress warning when pod supports a version lower than the minimum supported by the latest stable version of Xcode (currently 10.9). + # This warning is harmless but confusing--it's not a bad thing for dependencies to support a lower version. + inherit_deployment_target = !target.deployment_target.blank? && + (deployment_target_major.to_i < 10) || + (deployment_target_major.to_i == 10 && deployment_target_minor.to_i < 9) + # This podhelper script is at $FLUTTER_ROOT/packages/flutter_tools/bin. # Add search paths from $FLUTTER_ROOT/bin/cache/artifacts/engine. artifacts_dir = File.join('..', '..', '..', '..', 'bin', 'cache', 'artifacts', 'engine') @@ -89,6 +97,10 @@ def flutter_additional_macos_build_settings(target) # ARM not yet supported https://github.com/flutter/flutter/issues/69221 build_configuration.build_settings['EXCLUDED_ARCHS'] = 'arm64' + + # When deleted, the deployment version will inherit from the higher version derived from the 'Runner' target. + # If the pod only supports a higher version, do not delete to correctly produce an error. + build_configuration.build_settings.delete 'MACOSX_DEPLOYMENT_TARGET' if inherit_deployment_target end end