mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
This PR marks the `--ios-language objc` flag as deprecated for plugin creation. It introduces a warning message in the `flutter create` tool when the flag is used, but **does not** remove the functionality at this time. This is the first step towards its eventual removal. ## Context As discussed in the issue, usage metrics show that Objective-C is used in less than 4% of newly created plugins. To streamline the tool and align with modern iOS development practices (i.e., Swift), we are beginning the process of phasing out this option **Changes:** - Adds a deprecation warning to the CLI when the `objc` flag is used. - Updates the `--help` text to reflect the deprecation. - Removes obsolete tests for Objective-C plugin creation and usage tracking. ## Testing I have validated these changes by: 1. Manually running `flutter-dev create` with the `objc` flag to confirm the new deprecation warning appears. 2. Verifying that creating a plugin without the --ios-language flag does **not** trigger the warning. 3. Running the tests in the `test/commands.shard` to ensure no regressions were introduced. 4. CI will validate the changes to the devicelab tests. Fixes #169683 ## Pre-launch Checklist - [X] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [X] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [X] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [X] I signed the [CLA]. - [X] I listed at least one issue that this PR fixes in the description above. - [] I updated/added relevant documentation (doc comments with `///`). - [] I added new tests to check the change I am making, or this PR is [test-exempt]. - [] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [X] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
287 lines
10 KiB
Dart
287 lines
10 KiB
Dart
// Copyright 2014 The Flutter Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
import 'dart:io';
|
|
|
|
import 'package:flutter_devicelab/framework/framework.dart';
|
|
import 'package:flutter_devicelab/framework/task_result.dart';
|
|
import 'package:flutter_devicelab/framework/utils.dart';
|
|
import 'package:path/path.dart' as path;
|
|
|
|
/// Tests that the Flutter plugin template works. Use `pod lib lint`
|
|
/// to confirm the plugin module can be imported into an app.
|
|
Future<void> main() async {
|
|
await task(() async {
|
|
final Directory tempDir = Directory.systemTemp.createTempSync('flutter_plugin_test.');
|
|
try {
|
|
section('Lint integration_test');
|
|
|
|
await inDirectory(tempDir, () async {
|
|
// Update pod repo.
|
|
await exec('pod', <String>['repo', 'update']);
|
|
|
|
// Relative to this script.
|
|
final String flutterRoot = path.dirname(
|
|
path.dirname(path.dirname(path.dirname(path.dirname(path.fromUri(Platform.script))))),
|
|
);
|
|
print('Flutter root at $flutterRoot');
|
|
final String integrationTestPackage = path.join(
|
|
flutterRoot,
|
|
'packages',
|
|
'integration_test',
|
|
);
|
|
final String iosintegrationTestPodspec = path.join(
|
|
integrationTestPackage,
|
|
'ios',
|
|
'integration_test.podspec',
|
|
);
|
|
|
|
await exec('pod', <String>['lib', 'lint', iosintegrationTestPodspec, '--use-libraries']);
|
|
|
|
final String macosintegrationTestPodspec = path.join(
|
|
integrationTestPackage,
|
|
'integration_test_macos',
|
|
'macos',
|
|
'integration_test_macos.podspec',
|
|
);
|
|
await _tryMacOSLint(macosintegrationTestPodspec, <String>[]);
|
|
});
|
|
|
|
section('Create plugin');
|
|
|
|
const String pluginName = 'test_plugin';
|
|
await inDirectory(tempDir, () async {
|
|
await flutter(
|
|
'create',
|
|
options: <String>[
|
|
'--org',
|
|
'io.flutter.devicelab',
|
|
'--template=plugin',
|
|
'--platforms=ios,macos',
|
|
pluginName,
|
|
],
|
|
);
|
|
});
|
|
|
|
section('Lint iOS podspec plugin as framework');
|
|
|
|
final String pluginPath = path.join(tempDir.path, pluginName);
|
|
final String podspecPath = path.join(pluginPath, 'ios', '$pluginName.podspec');
|
|
await inDirectory(tempDir, () async {
|
|
await exec('pod', <String>['lib', 'lint', podspecPath, '--allow-warnings']);
|
|
});
|
|
|
|
section('Lint iOS podspec plugin as library');
|
|
|
|
await inDirectory(tempDir, () async {
|
|
await exec('pod', <String>[
|
|
'lib',
|
|
'lint',
|
|
podspecPath,
|
|
'--allow-warnings',
|
|
'--use-libraries',
|
|
]);
|
|
});
|
|
|
|
section('Lint macOS podspec plugin as framework');
|
|
|
|
final String macOSPodspecPath = path.join(pluginPath, 'macos', '$pluginName.podspec');
|
|
await inDirectory(tempDir, () async {
|
|
await _tryMacOSLint(macOSPodspecPath, <String>['--allow-warnings']);
|
|
});
|
|
|
|
section('Lint macOS podspec plugin as library');
|
|
|
|
await inDirectory(tempDir, () async {
|
|
await _tryMacOSLint(macOSPodspecPath, <String>['--allow-warnings', '--use-libraries']);
|
|
});
|
|
|
|
section('Create iOS application');
|
|
|
|
const String iosAppName = 'test_app';
|
|
await inDirectory(tempDir, () async {
|
|
await flutter(
|
|
'create',
|
|
options: <String>['--org', 'io.flutter.devicelab', '--platforms=ios,macos', iosAppName],
|
|
);
|
|
});
|
|
|
|
section('Build iOS application with plugins as frameworks');
|
|
|
|
final String appPath = path.join(tempDir.path, iosAppName);
|
|
|
|
final File pubspec = File(path.join(appPath, 'pubspec.yaml'));
|
|
|
|
String pubspecContent = pubspec.readAsStringSync();
|
|
// Add (randomly selected) first-party plugins that support iOS and macOS.
|
|
// Add the new plugins we just made.
|
|
pubspecContent = pubspecContent.replaceFirst(
|
|
'\ndependencies:\n',
|
|
'\ndependencies:\n $pluginName:\n path: $pluginPath\n url_launcher: 6.0.16\n url_launcher_macos:\n',
|
|
);
|
|
pubspec.writeAsStringSync(pubspecContent, flush: true);
|
|
|
|
await inDirectory(appPath, () async {
|
|
await flutter('build', options: <String>['ios', '--no-codesign']);
|
|
});
|
|
|
|
final File iosPodfile = File(path.join(appPath, 'ios', 'Podfile'));
|
|
String iosPodfileContent = iosPodfile.readAsStringSync();
|
|
if (!iosPodfileContent.contains('use_frameworks!')) {
|
|
return TaskResult.failure('Expected default Podfile to contain use_frameworks');
|
|
}
|
|
|
|
section('Build iOS application with plugins as libraries');
|
|
|
|
iosPodfileContent = iosPodfileContent.replaceAll('use_frameworks!', '');
|
|
iosPodfile.writeAsStringSync(iosPodfileContent, flush: true);
|
|
|
|
await inDirectory(appPath, () async {
|
|
await flutter('build', options: <String>['ios', '--no-codesign']);
|
|
});
|
|
|
|
_validateIosPodfile(appPath);
|
|
|
|
section('Build macOS application with plugins as frameworks');
|
|
await inDirectory(appPath, () async {
|
|
await flutter('build', options: <String>['macos']);
|
|
});
|
|
|
|
final File macOSPodfile = File(path.join(appPath, 'macos', 'Podfile'));
|
|
String macosPodfileContent = macOSPodfile.readAsStringSync();
|
|
if (!macosPodfileContent.contains('use_frameworks!')) {
|
|
return TaskResult.failure('Expected default Podfile to contain use_frameworks');
|
|
}
|
|
|
|
_validateMacOSPodfile(appPath);
|
|
|
|
section('Remove iOS support from plugin');
|
|
|
|
Directory(path.join(pluginPath, 'ios')).deleteSync(recursive: true);
|
|
|
|
const String iosPlatformMap = '''
|
|
ios:
|
|
pluginClass: TestPlugin''';
|
|
|
|
final File pluginPubspec = File(path.join(pluginPath, 'pubspec.yaml'));
|
|
String pluginPubspecContent = pluginPubspec.readAsStringSync();
|
|
if (!pluginPubspecContent.contains(iosPlatformMap)) {
|
|
return TaskResult.failure('Plugin pubspec.yaml missing iOS platform map');
|
|
}
|
|
|
|
pluginPubspecContent = pluginPubspecContent.replaceFirst(iosPlatformMap, '');
|
|
pluginPubspec.writeAsStringSync(pluginPubspecContent, flush: true);
|
|
|
|
await inDirectory(appPath, () async {
|
|
await flutter('clean');
|
|
await flutter('build', options: <String>['ios', '--no-codesign']);
|
|
});
|
|
|
|
section('Validate plugin without iOS platform');
|
|
|
|
final File podfileLockFile = File(path.join(appPath, 'ios', 'Podfile.lock'));
|
|
final String podfileLockOutput = podfileLockFile.readAsStringSync();
|
|
if (!podfileLockOutput.contains(':path: ".symlinks/plugins/url_launcher_ios/ios"') ||
|
|
!podfileLockOutput.contains(':path: Flutter')
|
|
// test_plugin no longer supports iOS, shouldn't be present.
|
|
||
|
|
podfileLockOutput.contains(':path: ".symlinks/plugins/test_plugin/ios"')) {
|
|
print(podfileLockOutput);
|
|
return TaskResult.failure('Podfile.lock does not contain expected pods');
|
|
}
|
|
|
|
final String pluginSymlinks = path.join(appPath, 'ios', '.symlinks', 'plugins');
|
|
|
|
checkDirectoryExists(path.join(pluginSymlinks, 'url_launcher_ios', 'ios'));
|
|
|
|
// test_plugin no longer supports iOS, shouldn't exist!
|
|
checkDirectoryNotExists(path.join(pluginSymlinks, 'test_plugin'));
|
|
|
|
section('Build macOS application with plugins as libraries');
|
|
|
|
macosPodfileContent = macosPodfileContent.replaceAll('use_frameworks!', '');
|
|
macOSPodfile.writeAsStringSync(macosPodfileContent, flush: true);
|
|
|
|
await inDirectory(appPath, () async {
|
|
await flutter('build', options: <String>['macos']);
|
|
});
|
|
|
|
_validateMacOSPodfile(appPath);
|
|
|
|
return TaskResult.success(null);
|
|
} catch (e, stackTrace) {
|
|
print('Task exception stack trace:\n$stackTrace');
|
|
return TaskResult.failure(e.toString());
|
|
} finally {
|
|
rmTree(tempDir);
|
|
}
|
|
});
|
|
}
|
|
|
|
void _validateIosPodfile(String appPath) {
|
|
section('Validate iOS Podfile');
|
|
|
|
final File podfileLockFile = File(path.join(appPath, 'ios', 'Podfile.lock'));
|
|
final String podfileLockOutput = podfileLockFile.readAsStringSync();
|
|
if (!podfileLockOutput.contains(':path: ".symlinks/plugins/url_launcher_ios/ios"') ||
|
|
!podfileLockOutput.contains(':path: Flutter') ||
|
|
!podfileLockOutput.contains(':path: ".symlinks/plugins/test_plugin/ios"') ||
|
|
podfileLockOutput.contains('url_launcher_macos')) {
|
|
print(podfileLockOutput);
|
|
throw TaskResult.failure('iOS Podfile.lock does not contain expected pods');
|
|
}
|
|
|
|
checkDirectoryNotExists(path.join(appPath, 'ios', 'Flutter', 'Flutter.framework'));
|
|
|
|
checkFileExists(path.join(appPath, 'ios', 'Flutter', 'Flutter.podspec'));
|
|
|
|
final String pluginSymlinks = path.join(appPath, 'ios', '.symlinks', 'plugins');
|
|
|
|
checkDirectoryExists(path.join(pluginSymlinks, 'url_launcher_ios', 'ios'));
|
|
|
|
checkDirectoryNotExists(path.join(pluginSymlinks, 'url_launcher_macos'));
|
|
|
|
checkDirectoryExists(path.join(pluginSymlinks, 'test_plugin', 'ios'));
|
|
|
|
// Make sure no Xcode build settings are leaking derived data/build directory into the ios directory.
|
|
checkDirectoryNotExists(path.join(appPath, 'ios', 'build'));
|
|
}
|
|
|
|
void _validateMacOSPodfile(String appPath) {
|
|
section('Validate macOS Podfile');
|
|
|
|
final File podfileLockFile = File(path.join(appPath, 'macos', 'Podfile.lock'));
|
|
final String podfileLockOutput = podfileLockFile.readAsStringSync();
|
|
if (!podfileLockOutput.contains(':path: Flutter/ephemeral\n') ||
|
|
!podfileLockOutput.contains(
|
|
':path: Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos',
|
|
) ||
|
|
!podfileLockOutput.contains(':path: Flutter/ephemeral/.symlinks/plugins/test_plugin/macos') ||
|
|
podfileLockOutput.contains('url_launcher_ios/')) {
|
|
print(podfileLockOutput);
|
|
throw TaskResult.failure('macOS Podfile.lock does not contain expected pods');
|
|
}
|
|
|
|
checkFileExists(path.join(appPath, 'macos', 'Flutter', 'ephemeral', 'FlutterMacOS.podspec'));
|
|
|
|
final String pluginSymlinks = path.join(
|
|
appPath,
|
|
'macos',
|
|
'Flutter',
|
|
'ephemeral',
|
|
'.symlinks',
|
|
'plugins',
|
|
);
|
|
|
|
checkDirectoryExists(path.join(pluginSymlinks, 'url_launcher_macos', 'macos'));
|
|
|
|
checkDirectoryNotExists(path.join(pluginSymlinks, 'url_launcher_ios'));
|
|
|
|
checkDirectoryExists(path.join(pluginSymlinks, 'test_plugin', 'macos'));
|
|
}
|
|
|
|
Future<void> _tryMacOSLint(String podspecPath, List<String> extraArguments) async {
|
|
await eval('pod', <String>['lib', 'lint', podspecPath, ...extraArguments]);
|
|
}
|