mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Rebase ios-experimental branch onto main. This will make the PRs experimenting with newer versions of Xcode (like https://github.com/flutter/flutter/pull/173123) smaller and easier to reason about. Rebases #168860 and #170274 ``` $ git rebase main -Xtheirs ``` --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: gaaclarke <30870216+gaaclarke@users.noreply.github.com> Co-authored-by: Siva <a-siva@users.noreply.github.com> Co-authored-by: engine-flutter-autoroll <engine-flutter-autoroll@skia.org> Co-authored-by: Jamil Saadeh <jssaadeh@outlook.com> Co-authored-by: Dara Adedeji <76637177+SunkenInTime@users.noreply.github.com> Co-authored-by: Greg Price <gnprice@gmail.com> Co-authored-by: Ben Konyi <bkonyi@google.com> Co-authored-by: Ricardo Dalarme <ricardodalarme@outlook.com> Co-authored-by: Flutter GitHub Bot <fluttergithubbot@gmail.com> Co-authored-by: Justin McCandless <jmccandless@google.com> Co-authored-by: Alex Talebi <31685655+SalehTZ@users.noreply.github.com> Co-authored-by: Qun Cheng <36861262+QuncCccccc@users.noreply.github.com> Co-authored-by: Mouad Debbar <mdebbar@google.com> Co-authored-by: Zuckjet <1083941774@qq.com> Co-authored-by: Loïc Sharma <737941+loic-sharma@users.noreply.github.com> Co-authored-by: auto-submit[bot] <98614782+auto-submit[bot]@users.noreply.github.com> Co-authored-by: auto-submit[bot] <flutter-engprod-team@google.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: yim <ybz975218925@gmail.com> Co-authored-by: bufffun <chenmingding.cmd@alibaba-inc.com> Co-authored-by: Chinmay Garde <chinmaygarde@google.com> Co-authored-by: Hannah Jin <jhy03261997@gmail.com> Co-authored-by: Kate Lovett <katelovett@google.com> Co-authored-by: Valentin Vignal <32538273+ValentinVignal@users.noreply.github.com> Co-authored-by: Derek Xu <derekx@google.com> Co-authored-by: Yash Dhrangdhariya <72062416+Yash-Dhrangdhariya@users.noreply.github.com> Co-authored-by: bungeman <bungeman@chromium.org> Co-authored-by: Ahmed Mohamed Sameh <ahmedsameha1@gmail.com> Co-authored-by: John "codefu" McDole <codefu@google.com> Co-authored-by: Dmitry Grand <dmgr@google.com> Co-authored-by: Kostia Sokolovskyi <sokolovskyi.konstantin@gmail.com> Co-authored-by: Reid Baker <1063596+reidbaker@users.noreply.github.com> Co-authored-by: Matthew Kosarek <matt.kosarek@canonical.com> Co-authored-by: Jason Simmons <jason-simmons@users.noreply.github.com> Co-authored-by: Jim Graham <flar@google.com> Co-authored-by: Michael Goderbauer <goderbauer@google.com> Co-authored-by: Gray Mackall <34871572+gmackall@users.noreply.github.com> Co-authored-by: Gray Mackall <mackall@google.com> Co-authored-by: Tong Mu <dkwingsmt@users.noreply.github.com> Co-authored-by: Jon Ihlas <jon.i@hotmail.fr> Co-authored-by: Micael Cid <micaelcid10@gmail.com> Co-authored-by: Alexander Aprelev <aam@google.com> Co-authored-by: hellohuanlin <41930132+hellohuanlin@users.noreply.github.com> Co-authored-by: Luke Memet <1598289+lukemmtt@users.noreply.github.com> Co-authored-by: Victoria Ashworth <15619084+vashworth@users.noreply.github.com> Co-authored-by: Mairramer <50643541+Mairramer@users.noreply.github.com> Co-authored-by: Florin Malita <fmalita@gmail.com> Co-authored-by: chunhtai <47866232+chunhtai@users.noreply.github.com> Co-authored-by: Salem Iranloye <127918074+salemiranloye@users.noreply.github.com> Co-authored-by: Kevin Moore <kevmoo@google.com> Co-authored-by: Sydney Bao <sydneybao@google.com> Co-authored-by: Wdestroier <Wdestroier@gmail.com> Co-authored-by: Matt Boetger <matt.boetger@gmail.com> Co-authored-by: Reid Baker <reidbaker@google.com> Co-authored-by: Victor Sanni <victorsanniay@gmail.com> Co-authored-by: Jessy Yameogo <jessy.yameogo@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: romain.gyh <11901536+romaingyh@users.noreply.github.com> Co-authored-by: Robert Ancell <robert.ancell@canonical.com> Co-authored-by: TheLastFlame <131446187+TheLastFlame@users.noreply.github.com> Co-authored-by: masato <returnymgstokh@icloud.com> Co-authored-by: Albin PK <56157868+albinpk@users.noreply.github.com> Co-authored-by: Huy <huy@nevercode.io> Co-authored-by: Matan Lurey <matanlurey@users.noreply.github.com> Co-authored-by: Azat Chorekliyev <azat24680@gmail.com> Co-authored-by: EdwynZN <edwinzn9@gmail.com> Co-authored-by: Bruno Leroux <bruno.leroux@gmail.com> Co-authored-by: Dev TtangKong <ttankkeo112@gmail.com> Co-authored-by: LongCatIsLooong <31859944+LongCatIsLooong@users.noreply.github.com> Co-authored-by: Houssem Eddine Fadhli <houssemeddinefadhli81@gmail.com>
337 lines
12 KiB
Dart
337 lines
12 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 Objective-C plugin');
|
|
|
|
const String objcPluginName = 'test_plugin_objc';
|
|
await inDirectory(tempDir, () async {
|
|
await flutter(
|
|
'create',
|
|
options: <String>[
|
|
'--org',
|
|
'io.flutter.devicelab',
|
|
'--template=plugin',
|
|
'--platforms=ios,android',
|
|
'--ios-language=objc',
|
|
objcPluginName,
|
|
],
|
|
);
|
|
});
|
|
|
|
section('Lint Objective-C iOS podspec plugin as framework');
|
|
|
|
final String objcPluginPath = path.join(tempDir.path, objcPluginName);
|
|
final String objcPodspecPath = path.join(objcPluginPath, 'ios', '$objcPluginName.podspec');
|
|
await inDirectory(tempDir, () async {
|
|
await exec('pod', <String>['lib', 'lint', objcPodspecPath, '--allow-warnings']);
|
|
});
|
|
|
|
section('Lint Objective-C iOS podspec plugin as library');
|
|
|
|
await inDirectory(tempDir, () async {
|
|
await exec('pod', <String>[
|
|
'lib',
|
|
'lint',
|
|
objcPodspecPath,
|
|
'--allow-warnings',
|
|
'--use-libraries',
|
|
]);
|
|
});
|
|
|
|
section('Create Swift plugin');
|
|
|
|
const String swiftPluginName = 'test_plugin_swift';
|
|
await inDirectory(tempDir, () async {
|
|
await flutter(
|
|
'create',
|
|
options: <String>[
|
|
'--org',
|
|
'io.flutter.devicelab',
|
|
'--template=plugin',
|
|
'--platforms=ios,macos',
|
|
'--ios-language=swift',
|
|
swiftPluginName,
|
|
],
|
|
);
|
|
});
|
|
|
|
section('Lint Swift iOS podspec plugin as framework');
|
|
|
|
final String swiftPluginPath = path.join(tempDir.path, swiftPluginName);
|
|
final String swiftPodspecPath = path.join(swiftPluginPath, 'ios', '$swiftPluginName.podspec');
|
|
await inDirectory(tempDir, () async {
|
|
await exec('pod', <String>['lib', 'lint', swiftPodspecPath, '--allow-warnings']);
|
|
});
|
|
|
|
section('Lint Swift iOS podspec plugin as library');
|
|
|
|
await inDirectory(tempDir, () async {
|
|
await exec('pod', <String>[
|
|
'lib',
|
|
'lint',
|
|
swiftPodspecPath,
|
|
'--allow-warnings',
|
|
'--use-libraries',
|
|
]);
|
|
});
|
|
|
|
section('Lint Swift macOS podspec plugin as framework');
|
|
|
|
final String macOSPodspecPath = path.join(
|
|
swiftPluginPath,
|
|
'macos',
|
|
'$swiftPluginName.podspec',
|
|
);
|
|
await inDirectory(tempDir, () async {
|
|
await _tryMacOSLint(macOSPodspecPath, <String>['--allow-warnings']);
|
|
});
|
|
|
|
section('Lint Swift 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 Swift and Objective-C 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 $objcPluginName:\n path: $objcPluginPath\n $swiftPluginName:\n path: $swiftPluginPath\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 Swift and Objective-C 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('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);
|
|
|
|
section('Remove iOS support from plugin');
|
|
|
|
Directory(path.join(objcPluginPath, 'ios')).deleteSync(recursive: true);
|
|
|
|
const String iosPlatformMap = '''
|
|
ios:
|
|
pluginClass: TestPluginObjcPlugin''';
|
|
|
|
final File pluginPubspec = File(path.join(objcPluginPath, '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_objc no longer supports iOS, shouldn't be present.
|
|
||
|
|
podfileLockOutput.contains(':path: ".symlinks/plugins/test_plugin_objc/ios"') ||
|
|
!podfileLockOutput.contains(':path: ".symlinks/plugins/test_plugin_swift/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'));
|
|
|
|
checkDirectoryExists(path.join(pluginSymlinks, 'test_plugin_swift', 'ios'));
|
|
|
|
// test_plugin_objc no longer supports iOS, shouldn't exist!
|
|
checkDirectoryNotExists(path.join(pluginSymlinks, 'test_plugin_objc'));
|
|
|
|
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_objc/ios"') ||
|
|
!podfileLockOutput.contains(':path: ".symlinks/plugins/test_plugin_swift/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_objc', 'ios'));
|
|
|
|
checkDirectoryExists(path.join(pluginSymlinks, 'test_plugin_swift', '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_swift/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_swift', 'macos'));
|
|
}
|
|
|
|
Future<void> _tryMacOSLint(String podspecPath, List<String> extraArguments) async {
|
|
await eval('pod', <String>['lib', 'lint', podspecPath, ...extraArguments]);
|
|
}
|