Add create app and plugin templates for Swift Package Manager (#147082)
When Swift Package Manager feature is enabled, create app and create plugin will have Swift Package Manager integration already added and will not need to undergo a migration. Fixes https://github.com/flutter/flutter/issues/146371. ``` flutter config --enable-swift-package-manager flutter create --ios-language swift --platforms ios,macos swift_app_name flutter create --ios-language objc --platforms ios objc_app_name flutter create --template=plugin --ios-language swift --platforms ios,macos swift_plugin_name flutter create --template=plugin --ios-language objc --platforms ios objc_plugin_name ```
This commit is contained in:
committed by
GitHub
parent
d85571b46b
commit
5a63b1df95
@@ -87,6 +87,7 @@ void main() {
|
||||
globals.fs.path.join('flutter', 'packages', 'flutter_tools', 'templates', 'plugin'),
|
||||
globals.fs.path.join('flutter', 'packages', 'flutter_tools', 'templates', 'plugin_ffi'),
|
||||
globals.fs.path.join('flutter', 'packages', 'flutter_tools', 'templates', 'plugin_shared'),
|
||||
globals.fs.path.join('flutter', 'packages', 'flutter_tools', 'templates', 'plugin_cocoapods'),
|
||||
];
|
||||
for (final String templatePath in templatePaths) {
|
||||
globals.fs.directory(templatePath).createSync(recursive: true);
|
||||
|
||||
@@ -718,6 +718,55 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
testUsingContext('swift plugin project with Swift Package Manager', () async {
|
||||
return _createProject(
|
||||
projectDir,
|
||||
<String>['--no-pub', '--template=plugin', '--ios-language', 'swift', '--platforms', 'ios,macos'],
|
||||
<String>[
|
||||
'ios/flutter_project/Package.swift',
|
||||
'ios/flutter_project/Sources/flutter_project/FlutterProjectPlugin.swift',
|
||||
'ios/flutter_project/Sources/flutter_project/Resources/.gitkeep',
|
||||
'macos/flutter_project/Package.swift',
|
||||
'macos/flutter_project/Sources/flutter_project/FlutterProjectPlugin.swift',
|
||||
'macos/flutter_project/Sources/flutter_project/Resources/.gitkeep',
|
||||
],
|
||||
unexpectedPaths: <String>[
|
||||
'ios/Classes/FlutterProjectPlugin.swift',
|
||||
'macos/Classes/FlutterProjectPlugin.swift',
|
||||
'ios/Classes/FlutterProjectPlugin.h',
|
||||
'ios/Classes/FlutterProjectPlugin.m',
|
||||
'ios/Assets/.gitkeep',
|
||||
'macos/Assets/.gitkeep',
|
||||
],
|
||||
);
|
||||
}, overrides: <Type, Generator>{
|
||||
FeatureFlags: () => TestFeatureFlags(
|
||||
isSwiftPackageManagerEnabled: true,
|
||||
isMacOSEnabled: true,
|
||||
),
|
||||
});
|
||||
|
||||
testUsingContext('objc plugin project with Swift Package Manager', () async {
|
||||
return _createProject(
|
||||
projectDir,
|
||||
<String>['--no-pub', '--template=plugin', '--ios-language', 'objc', '--platforms', 'ios'],
|
||||
<String>[
|
||||
'ios/flutter_project/Package.swift',
|
||||
'ios/flutter_project/Sources/flutter_project/include/flutter_project/FlutterProjectPlugin.h',
|
||||
'ios/flutter_project/Sources/flutter_project/FlutterProjectPlugin.m',
|
||||
'ios/flutter_project/Sources/flutter_project/Resources/.gitkeep',
|
||||
],
|
||||
unexpectedPaths: <String>[
|
||||
'ios/Classes/FlutterProjectPlugin.swift',
|
||||
'ios/Classes/FlutterProjectPlugin.h',
|
||||
'ios/Classes/FlutterProjectPlugin.m',
|
||||
'ios/Assets/.gitkeep',
|
||||
],
|
||||
);
|
||||
}, overrides: <Type, Generator>{
|
||||
FeatureFlags: () => TestFeatureFlags(isSwiftPackageManagerEnabled: true),
|
||||
});
|
||||
|
||||
testUsingContext('plugin project with custom org', () async {
|
||||
return _createProject(
|
||||
projectDir,
|
||||
|
||||
@@ -0,0 +1,151 @@
|
||||
// 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 'package:flutter_tools/src/base/error_handling_io.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
|
||||
import '../src/common.dart';
|
||||
import 'swift_package_manager_utils.dart';
|
||||
import 'test_utils.dart';
|
||||
|
||||
void main() {
|
||||
final String flutterBin = fileSystem.path.join(
|
||||
getFlutterRoot(),
|
||||
'bin',
|
||||
'flutter',
|
||||
);
|
||||
|
||||
final List<String> platforms = <String>['ios', 'macos'];
|
||||
for (final String platformName in platforms) {
|
||||
final List<String> iosLanguages = <String>[
|
||||
if (platformName == 'ios') 'objc',
|
||||
'swift',
|
||||
];
|
||||
|
||||
for (final String iosLanguage in iosLanguages) {
|
||||
test('Create $platformName $iosLanguage app with Swift Package Manager disabled', () async {
|
||||
final Directory workingDirectory = fileSystem.systemTempDirectory
|
||||
.createTempSync('swift_package_manager_create_app_disabled.');
|
||||
final String workingDirectoryPath = workingDirectory.path;
|
||||
try {
|
||||
await SwiftPackageManagerUtils.disableSwiftPackageManager(flutterBin, workingDirectoryPath);
|
||||
|
||||
final String appDirectoryPath = await SwiftPackageManagerUtils.createApp(
|
||||
flutterBin,
|
||||
workingDirectoryPath,
|
||||
iosLanguage: iosLanguage,
|
||||
platform: platformName,
|
||||
options: <String>['--platforms=$platformName'],
|
||||
);
|
||||
|
||||
final File pbxprojFile = fileSystem
|
||||
.directory(appDirectoryPath)
|
||||
.childDirectory(platformName)
|
||||
.childDirectory('Runner.xcodeproj')
|
||||
.childFile('project.pbxproj');
|
||||
expect(pbxprojFile.existsSync(), isTrue);
|
||||
expect(
|
||||
pbxprojFile.readAsStringSync().contains('FlutterGeneratedPluginSwiftPackage'),
|
||||
isFalse,
|
||||
);
|
||||
|
||||
final File xcschemeFile = fileSystem
|
||||
.directory(appDirectoryPath)
|
||||
.childDirectory(platformName)
|
||||
.childDirectory('Runner.xcodeproj')
|
||||
.childDirectory('xcshareddata')
|
||||
.childDirectory('xcschemes')
|
||||
.childFile('Runner.xcscheme');
|
||||
expect(xcschemeFile.existsSync(), isTrue);
|
||||
expect(
|
||||
xcschemeFile.readAsStringSync().contains('Run Prepare Flutter Framework Script'),
|
||||
isFalse,
|
||||
);
|
||||
|
||||
await SwiftPackageManagerUtils.buildApp(
|
||||
flutterBin,
|
||||
appDirectoryPath,
|
||||
options: <String>[platformName, '--debug', '-v'],
|
||||
expectedLines: SwiftPackageManagerUtils.expectedLines(
|
||||
platform: platformName,
|
||||
appDirectoryPath: appDirectoryPath,
|
||||
),
|
||||
unexpectedLines: SwiftPackageManagerUtils.unexpectedLines(
|
||||
platform: platformName,
|
||||
appDirectoryPath: appDirectoryPath,
|
||||
),
|
||||
);
|
||||
} finally {
|
||||
await SwiftPackageManagerUtils.disableSwiftPackageManager(flutterBin, workingDirectoryPath);
|
||||
ErrorHandlingFileSystem.deleteIfExists(
|
||||
workingDirectory,
|
||||
recursive: true,
|
||||
);
|
||||
}
|
||||
}, skip: !platform.isMacOS); // [intended] Swift Package Manager only works on macos.
|
||||
|
||||
test('Create $platformName $iosLanguage app with Swift Package Manager enabled', () async {
|
||||
final Directory workingDirectory = fileSystem.systemTempDirectory
|
||||
.createTempSync('swift_package_manager_create_app_enabled.');
|
||||
final String workingDirectoryPath = workingDirectory.path;
|
||||
try {
|
||||
await SwiftPackageManagerUtils.enableSwiftPackageManager(flutterBin, workingDirectoryPath);
|
||||
|
||||
final String appDirectoryPath = await SwiftPackageManagerUtils.createApp(
|
||||
flutterBin,
|
||||
workingDirectoryPath,
|
||||
iosLanguage: iosLanguage,
|
||||
platform: platformName,
|
||||
options: <String>['--platforms=$platformName'],
|
||||
);
|
||||
|
||||
final File pbxprojFile = fileSystem
|
||||
.directory(appDirectoryPath)
|
||||
.childDirectory(platformName)
|
||||
.childDirectory('Runner.xcodeproj')
|
||||
.childFile('project.pbxproj');
|
||||
expect(pbxprojFile.existsSync(), isTrue);
|
||||
expect(
|
||||
pbxprojFile.readAsStringSync(),
|
||||
contains('FlutterGeneratedPluginSwiftPackage'),
|
||||
);
|
||||
|
||||
final File xcschemeFile = fileSystem
|
||||
.directory(appDirectoryPath)
|
||||
.childDirectory(platformName)
|
||||
.childDirectory('Runner.xcodeproj')
|
||||
.childDirectory('xcshareddata')
|
||||
.childDirectory('xcschemes')
|
||||
.childFile('Runner.xcscheme');
|
||||
expect(xcschemeFile.existsSync(), isTrue);
|
||||
expect(
|
||||
xcschemeFile.readAsStringSync(),
|
||||
contains('Run Prepare Flutter Framework Script'),
|
||||
);
|
||||
|
||||
await SwiftPackageManagerUtils.buildApp(
|
||||
flutterBin,
|
||||
appDirectoryPath,
|
||||
options: <String>[platformName, '--debug', '-v'],
|
||||
expectedLines: SwiftPackageManagerUtils.expectedLines(
|
||||
platform: platformName,
|
||||
appDirectoryPath: appDirectoryPath,
|
||||
),
|
||||
unexpectedLines: SwiftPackageManagerUtils.unexpectedLines(
|
||||
platform: platformName,
|
||||
appDirectoryPath: appDirectoryPath,
|
||||
),
|
||||
);
|
||||
|
||||
} finally {
|
||||
await SwiftPackageManagerUtils.disableSwiftPackageManager(flutterBin, workingDirectoryPath);
|
||||
ErrorHandlingFileSystem.deleteIfExists(
|
||||
workingDirectory,
|
||||
recursive: true,
|
||||
);
|
||||
}
|
||||
}, skip: !platform.isMacOS); // [intended] Swift Package Manager only works on macos.
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
// 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 'package:flutter_tools/src/base/error_handling_io.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
|
||||
import '../src/common.dart';
|
||||
import 'swift_package_manager_utils.dart';
|
||||
import 'test_utils.dart';
|
||||
|
||||
void main() {
|
||||
final String flutterBin = fileSystem.path.join(
|
||||
getFlutterRoot(),
|
||||
'bin',
|
||||
'flutter',
|
||||
);
|
||||
|
||||
final List<String> platforms = <String>['ios', 'macos'];
|
||||
for (final String platformName in platforms) {
|
||||
final List<String> iosLanguages = <String>[
|
||||
if (platformName == 'ios') 'objc',
|
||||
'swift',
|
||||
];
|
||||
|
||||
for (final String iosLanguage in iosLanguages) {
|
||||
test('Create $platformName $iosLanguage plugin with Swift Package Manager disabled', () async {
|
||||
final Directory workingDirectory = fileSystem.systemTempDirectory
|
||||
.createTempSync('swift_package_manager_create_plugin_disabled.');
|
||||
final String workingDirectoryPath = workingDirectory.path;
|
||||
try {
|
||||
await SwiftPackageManagerUtils.disableSwiftPackageManager(flutterBin, workingDirectoryPath);
|
||||
|
||||
final SwiftPackageManagerPlugin createdCocoaPodsPlugin = await SwiftPackageManagerUtils.createPlugin(
|
||||
flutterBin,
|
||||
workingDirectoryPath,
|
||||
platform: platformName,
|
||||
iosLanguage: iosLanguage,
|
||||
);
|
||||
|
||||
final String appDirectoryPath = createdCocoaPodsPlugin.exampleAppPath;
|
||||
|
||||
final File pbxprojFile = fileSystem
|
||||
.directory(appDirectoryPath)
|
||||
.childDirectory(platformName)
|
||||
.childDirectory('Runner.xcodeproj')
|
||||
.childFile('project.pbxproj');
|
||||
expect(pbxprojFile.existsSync(), isTrue);
|
||||
expect(
|
||||
pbxprojFile.readAsStringSync().contains('FlutterGeneratedPluginSwiftPackage'),
|
||||
isFalse,
|
||||
);
|
||||
|
||||
final File xcschemeFile = fileSystem
|
||||
.directory(appDirectoryPath)
|
||||
.childDirectory(platformName)
|
||||
.childDirectory('Runner.xcodeproj')
|
||||
.childDirectory('xcshareddata')
|
||||
.childDirectory('xcschemes')
|
||||
.childFile('Runner.xcscheme');
|
||||
expect(xcschemeFile.existsSync(), isTrue);
|
||||
expect(
|
||||
xcschemeFile.readAsStringSync().contains('Run Prepare Flutter Framework Script'),
|
||||
isFalse,
|
||||
);
|
||||
|
||||
final File podspec = fileSystem
|
||||
.directory(createdCocoaPodsPlugin.pluginPath)
|
||||
.childDirectory(platformName)
|
||||
.childFile('${createdCocoaPodsPlugin.pluginName}.podspec');
|
||||
expect(podspec.existsSync(), isTrue);
|
||||
expect(podspec.readAsStringSync(), contains('Classes'));
|
||||
expect(podspec.readAsStringSync().contains('Sources'), isFalse);
|
||||
|
||||
await SwiftPackageManagerUtils.buildApp(
|
||||
flutterBin,
|
||||
appDirectoryPath,
|
||||
options: <String>[platformName, '--debug', '-v'],
|
||||
expectedLines: SwiftPackageManagerUtils.expectedLines(
|
||||
platform: platformName,
|
||||
appDirectoryPath: appDirectoryPath,
|
||||
cocoaPodsPlugin: createdCocoaPodsPlugin,
|
||||
),
|
||||
unexpectedLines: SwiftPackageManagerUtils.unexpectedLines(
|
||||
platform: platformName,
|
||||
appDirectoryPath: appDirectoryPath,
|
||||
cocoaPodsPlugin: createdCocoaPodsPlugin,
|
||||
),
|
||||
);
|
||||
} finally {
|
||||
await SwiftPackageManagerUtils.disableSwiftPackageManager(flutterBin, workingDirectoryPath);
|
||||
ErrorHandlingFileSystem.deleteIfExists(
|
||||
workingDirectory,
|
||||
recursive: true,
|
||||
);
|
||||
}
|
||||
}, skip: !platform.isMacOS); // [intended] Swift Package Manager only works on macos.
|
||||
|
||||
test('Create $platformName $iosLanguage plugin with Swift Package Manager enabled', () async {
|
||||
final Directory workingDirectory = fileSystem.systemTempDirectory
|
||||
.createTempSync('swift_package_manager_create_plugin_enabled.');
|
||||
final String workingDirectoryPath = workingDirectory.path;
|
||||
try {
|
||||
await SwiftPackageManagerUtils.enableSwiftPackageManager(flutterBin, workingDirectoryPath);
|
||||
|
||||
final SwiftPackageManagerPlugin createdSwiftPackagePlugin = await SwiftPackageManagerUtils.createPlugin(
|
||||
flutterBin,
|
||||
workingDirectoryPath,
|
||||
platform: platformName,
|
||||
iosLanguage: iosLanguage,
|
||||
);
|
||||
|
||||
final String appDirectoryPath = createdSwiftPackagePlugin.exampleAppPath;
|
||||
|
||||
final File pbxprojFile = fileSystem
|
||||
.directory(appDirectoryPath)
|
||||
.childDirectory(platformName)
|
||||
.childDirectory('Runner.xcodeproj')
|
||||
.childFile('project.pbxproj');
|
||||
expect(pbxprojFile.existsSync(), isTrue);
|
||||
expect(
|
||||
pbxprojFile.readAsStringSync(),
|
||||
contains('FlutterGeneratedPluginSwiftPackage'),
|
||||
);
|
||||
|
||||
final File xcschemeFile = fileSystem
|
||||
.directory(appDirectoryPath)
|
||||
.childDirectory(platformName)
|
||||
.childDirectory('Runner.xcodeproj')
|
||||
.childDirectory('xcshareddata')
|
||||
.childDirectory('xcschemes')
|
||||
.childFile('Runner.xcscheme');
|
||||
expect(xcschemeFile.existsSync(), isTrue);
|
||||
expect(
|
||||
xcschemeFile.readAsStringSync(),
|
||||
contains('Run Prepare Flutter Framework Script'),
|
||||
);
|
||||
|
||||
final File podspec = fileSystem
|
||||
.directory(createdSwiftPackagePlugin.pluginPath)
|
||||
.childDirectory(platformName)
|
||||
.childFile('${createdSwiftPackagePlugin.pluginName}.podspec');
|
||||
expect(podspec.existsSync(), isTrue);
|
||||
expect(podspec.readAsStringSync(), contains('Sources'));
|
||||
expect(podspec.readAsStringSync().contains('Classes'), isFalse);
|
||||
|
||||
await SwiftPackageManagerUtils.buildApp(
|
||||
flutterBin,
|
||||
appDirectoryPath,
|
||||
options: <String>[platformName, '--debug', '-v'],
|
||||
expectedLines: SwiftPackageManagerUtils.expectedLines(
|
||||
platform: platformName,
|
||||
appDirectoryPath: appDirectoryPath,
|
||||
swiftPackagePlugin: createdSwiftPackagePlugin,
|
||||
swiftPackageMangerEnabled: true,
|
||||
),
|
||||
unexpectedLines: SwiftPackageManagerUtils.unexpectedLines(
|
||||
platform: platformName,
|
||||
appDirectoryPath: appDirectoryPath,
|
||||
swiftPackagePlugin: createdSwiftPackagePlugin,
|
||||
swiftPackageMangerEnabled: true,
|
||||
),
|
||||
);
|
||||
|
||||
} finally {
|
||||
await SwiftPackageManagerUtils.disableSwiftPackageManager(flutterBin, workingDirectoryPath);
|
||||
ErrorHandlingFileSystem.deleteIfExists(
|
||||
workingDirectory,
|
||||
recursive: true,
|
||||
);
|
||||
}
|
||||
}, skip: !platform.isMacOS); // [intended] Swift Package Manager only works on macos.
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,13 +2,11 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter_tools/src/base/error_handling_io.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/base/io.dart';
|
||||
|
||||
import '../src/common.dart';
|
||||
import 'swift_package_manager_utils.dart';
|
||||
import 'test_utils.dart';
|
||||
|
||||
void main() {
|
||||
@@ -24,39 +22,36 @@ void main() {
|
||||
if (platformName == 'ios') 'objc',
|
||||
'swift',
|
||||
];
|
||||
final _Plugin integrationTestPlugin = _integrationTestPlugin(platformName);
|
||||
final SwiftPackageManagerPlugin integrationTestPlugin = SwiftPackageManagerUtils.integrationTestPlugin(platformName);
|
||||
|
||||
for (final String iosLanguage in iosLanguages) {
|
||||
test('Swift Package Manager not used when feature is disabled for $platformName with $iosLanguage', () async {
|
||||
test('Swift Package Manager integration for $platformName with $iosLanguage', () async {
|
||||
final Directory workingDirectory = fileSystem.systemTempDirectory
|
||||
.createTempSync('swift_package_manager_disabled.');
|
||||
.createTempSync('swift_package_manager_enabled.');
|
||||
final String workingDirectoryPath = workingDirectory.path;
|
||||
try {
|
||||
await _disableSwiftPackageManager(flutterBin, workingDirectoryPath);
|
||||
|
||||
// Create and build an app using the CocoaPods version of
|
||||
// integration_test.
|
||||
final String appDirectoryPath = await _createApp(
|
||||
await SwiftPackageManagerUtils.disableSwiftPackageManager(flutterBin, workingDirectoryPath);
|
||||
final String appDirectoryPath = await SwiftPackageManagerUtils.createApp(
|
||||
flutterBin,
|
||||
workingDirectoryPath,
|
||||
iosLanguage: iosLanguage,
|
||||
platform: platformName,
|
||||
usesSwiftPackageManager: true,
|
||||
options: <String>['--platforms=$platformName'],
|
||||
);
|
||||
_addDependency(
|
||||
appDirectoryPath: appDirectoryPath,
|
||||
plugin: integrationTestPlugin,
|
||||
);
|
||||
await _buildApp(
|
||||
SwiftPackageManagerUtils.addDependency(appDirectoryPath: appDirectoryPath, plugin: integrationTestPlugin);
|
||||
await SwiftPackageManagerUtils.buildApp(
|
||||
flutterBin,
|
||||
appDirectoryPath,
|
||||
options: <String>[platformName, '--debug', '-v'],
|
||||
expectedLines: _expectedLines(
|
||||
expectedLines: SwiftPackageManagerUtils.expectedLines(
|
||||
platform: platformName,
|
||||
appDirectoryPath: appDirectoryPath,
|
||||
cocoaPodsPlugin: integrationTestPlugin,
|
||||
),
|
||||
unexpectedLines: _unexpectedLines(
|
||||
unexpectedLines: SwiftPackageManagerUtils.unexpectedLines(
|
||||
platform: platformName,
|
||||
appDirectoryPath: appDirectoryPath,
|
||||
cocoaPodsPlugin: integrationTestPlugin,
|
||||
@@ -81,47 +76,34 @@ void main() {
|
||||
.existsSync(),
|
||||
isFalse,
|
||||
);
|
||||
} finally {
|
||||
ErrorHandlingFileSystem.deleteIfExists(
|
||||
workingDirectory,
|
||||
recursive: true,
|
||||
);
|
||||
}
|
||||
}, skip: !platform.isMacOS); // [intended] Swift Package Manager only works on macos.
|
||||
|
||||
test('Swift Package Manager integration for $platformName with $iosLanguage', () async {
|
||||
final Directory workingDirectory = fileSystem.systemTempDirectory
|
||||
.createTempSync('swift_package_manager_enabled.');
|
||||
final String workingDirectoryPath = workingDirectory.path;
|
||||
try {
|
||||
// Create and build an app using the Swift Package Manager version of
|
||||
// integration_test.
|
||||
await _enableSwiftPackageManager(flutterBin, workingDirectoryPath);
|
||||
|
||||
final String appDirectoryPath = await _createApp(
|
||||
final SwiftPackageManagerPlugin createdCocoaPodsPlugin = await SwiftPackageManagerUtils.createPlugin(
|
||||
flutterBin,
|
||||
workingDirectoryPath,
|
||||
iosLanguage: iosLanguage,
|
||||
platform: platformName,
|
||||
usesSwiftPackageManager: true,
|
||||
options: <String>['--platforms=$platformName'],
|
||||
iosLanguage: iosLanguage,
|
||||
);
|
||||
_addDependency(appDirectoryPath: appDirectoryPath, plugin: integrationTestPlugin);
|
||||
await _buildApp(
|
||||
|
||||
// Rebuild app with Swift Package Manager enabled, migrating the app and using the Swift Package Manager version of
|
||||
// integration_test.
|
||||
await SwiftPackageManagerUtils.enableSwiftPackageManager(flutterBin, workingDirectoryPath);
|
||||
await SwiftPackageManagerUtils.buildApp(
|
||||
flutterBin,
|
||||
appDirectoryPath,
|
||||
options: <String>[platformName, '--debug', '-v'],
|
||||
expectedLines: _expectedLines(
|
||||
expectedLines: SwiftPackageManagerUtils.expectedLines(
|
||||
platform: platformName,
|
||||
appDirectoryPath: appDirectoryPath,
|
||||
swiftPackageMangerEnabled: true,
|
||||
swiftPackagePlugin: integrationTestPlugin,
|
||||
migrated: true,
|
||||
),
|
||||
unexpectedLines: _unexpectedLines(
|
||||
unexpectedLines: SwiftPackageManagerUtils.unexpectedLines(
|
||||
platform: platformName,
|
||||
appDirectoryPath: appDirectoryPath,
|
||||
swiftPackageMangerEnabled: true,
|
||||
swiftPackagePlugin: integrationTestPlugin,
|
||||
migrated: true,
|
||||
),
|
||||
);
|
||||
|
||||
@@ -131,7 +113,7 @@ void main() {
|
||||
.childDirectory(platformName)
|
||||
.childFile('Podfile')
|
||||
.existsSync(),
|
||||
isFalse,
|
||||
isTrue,
|
||||
);
|
||||
expect(
|
||||
fileSystem
|
||||
@@ -146,29 +128,22 @@ void main() {
|
||||
);
|
||||
|
||||
// Build an app using both a CocoaPods and Swift Package Manager plugin.
|
||||
await _cleanApp(flutterBin, appDirectoryPath);
|
||||
final _Plugin createdCocoaPodsPlugin = await _createPlugin(
|
||||
flutterBin,
|
||||
workingDirectoryPath,
|
||||
platform: platformName,
|
||||
iosLanguage: iosLanguage,
|
||||
);
|
||||
_addDependency(
|
||||
SwiftPackageManagerUtils.addDependency(
|
||||
appDirectoryPath: appDirectoryPath,
|
||||
plugin: createdCocoaPodsPlugin,
|
||||
);
|
||||
await _buildApp(
|
||||
await SwiftPackageManagerUtils.buildApp(
|
||||
flutterBin,
|
||||
appDirectoryPath,
|
||||
options: <String>[platformName, '--debug', '-v'],
|
||||
expectedLines: _expectedLines(
|
||||
expectedLines: SwiftPackageManagerUtils.expectedLines(
|
||||
platform: platformName,
|
||||
appDirectoryPath: appDirectoryPath,
|
||||
cocoaPodsPlugin: createdCocoaPodsPlugin,
|
||||
swiftPackageMangerEnabled: true,
|
||||
swiftPackagePlugin: integrationTestPlugin,
|
||||
),
|
||||
unexpectedLines: _unexpectedLines(
|
||||
unexpectedLines: SwiftPackageManagerUtils.unexpectedLines(
|
||||
platform: platformName,
|
||||
appDirectoryPath: appDirectoryPath,
|
||||
cocoaPodsPlugin: createdCocoaPodsPlugin,
|
||||
@@ -199,18 +174,18 @@ void main() {
|
||||
|
||||
// Build app again but with Swift Package Manager disabled by config.
|
||||
// App will now use CocoaPods version of integration_test plugin.
|
||||
await _disableSwiftPackageManager(flutterBin, workingDirectoryPath);
|
||||
await _cleanApp(flutterBin, appDirectoryPath);
|
||||
await _buildApp(
|
||||
await SwiftPackageManagerUtils.disableSwiftPackageManager(flutterBin, workingDirectoryPath);
|
||||
await SwiftPackageManagerUtils.cleanApp(flutterBin, appDirectoryPath);
|
||||
await SwiftPackageManagerUtils.buildApp(
|
||||
flutterBin,
|
||||
appDirectoryPath,
|
||||
options: <String>[platformName, '--debug', '-v'],
|
||||
expectedLines: _expectedLines(
|
||||
expectedLines: SwiftPackageManagerUtils.expectedLines(
|
||||
platform: platformName,
|
||||
appDirectoryPath: appDirectoryPath,
|
||||
cocoaPodsPlugin: integrationTestPlugin,
|
||||
),
|
||||
unexpectedLines: _unexpectedLines(
|
||||
unexpectedLines: SwiftPackageManagerUtils.unexpectedLines(
|
||||
platform: platformName,
|
||||
appDirectoryPath: appDirectoryPath,
|
||||
cocoaPodsPlugin: integrationTestPlugin,
|
||||
@@ -219,26 +194,26 @@ void main() {
|
||||
|
||||
// Build app again but with Swift Package Manager disabled by pubspec.
|
||||
// App will still use CocoaPods version of integration_test plugin.
|
||||
await _enableSwiftPackageManager(flutterBin, workingDirectoryPath);
|
||||
await _cleanApp(flutterBin, appDirectoryPath);
|
||||
_disableSwiftPackageManagerByPubspec(appDirectoryPath: appDirectoryPath);
|
||||
await _buildApp(
|
||||
await SwiftPackageManagerUtils.enableSwiftPackageManager(flutterBin, workingDirectoryPath);
|
||||
await SwiftPackageManagerUtils.cleanApp(flutterBin, appDirectoryPath);
|
||||
SwiftPackageManagerUtils.disableSwiftPackageManagerByPubspec(appDirectoryPath: appDirectoryPath);
|
||||
await SwiftPackageManagerUtils.buildApp(
|
||||
flutterBin,
|
||||
appDirectoryPath,
|
||||
options: <String>[platformName, '--debug', '-v'],
|
||||
expectedLines: _expectedLines(
|
||||
expectedLines: SwiftPackageManagerUtils.expectedLines(
|
||||
platform: platformName,
|
||||
appDirectoryPath: appDirectoryPath,
|
||||
cocoaPodsPlugin: integrationTestPlugin,
|
||||
),
|
||||
unexpectedLines: _unexpectedLines(
|
||||
unexpectedLines: SwiftPackageManagerUtils.unexpectedLines(
|
||||
platform: platformName,
|
||||
appDirectoryPath: appDirectoryPath,
|
||||
cocoaPodsPlugin: integrationTestPlugin,
|
||||
),
|
||||
);
|
||||
} finally {
|
||||
await _disableSwiftPackageManager(flutterBin, workingDirectoryPath);
|
||||
await SwiftPackageManagerUtils.disableSwiftPackageManager(flutterBin, workingDirectoryPath);
|
||||
ErrorHandlingFileSystem.deleteIfExists(
|
||||
workingDirectory,
|
||||
recursive: true,
|
||||
@@ -254,9 +229,9 @@ void main() {
|
||||
try {
|
||||
// Create and build an app using the Swift Package Manager version of
|
||||
// integration_test.
|
||||
await _enableSwiftPackageManager(flutterBin, workingDirectoryPath);
|
||||
await SwiftPackageManagerUtils.enableSwiftPackageManager(flutterBin, workingDirectoryPath);
|
||||
|
||||
final String appDirectoryPath = await _createApp(
|
||||
final String appDirectoryPath = await SwiftPackageManagerUtils.createApp(
|
||||
flutterBin,
|
||||
workingDirectoryPath,
|
||||
iosLanguage: 'swift',
|
||||
@@ -264,15 +239,12 @@ void main() {
|
||||
usesSwiftPackageManager: true,
|
||||
options: <String>['--platforms=$platformName'],
|
||||
);
|
||||
_addDependency(appDirectoryPath: appDirectoryPath, plugin: integrationTestPlugin);
|
||||
SwiftPackageManagerUtils.addDependency(appDirectoryPath: appDirectoryPath, plugin: integrationTestPlugin);
|
||||
|
||||
await _buildApp(
|
||||
await SwiftPackageManagerUtils.buildApp(
|
||||
flutterBin,
|
||||
appDirectoryPath,
|
||||
options: <String>[platformName, '--config-only', '-v'],
|
||||
expectedLines: <String>[
|
||||
'Adding Swift Package Manager integration...'
|
||||
]
|
||||
);
|
||||
|
||||
expect(
|
||||
@@ -297,7 +269,7 @@ void main() {
|
||||
|
||||
// Create and build framework using the CocoaPods version of
|
||||
// integration_test even though Swift Package Manager is enabled.
|
||||
await _buildApp(
|
||||
await SwiftPackageManagerUtils.buildApp(
|
||||
flutterBin,
|
||||
appDirectoryPath,
|
||||
options: <String>[
|
||||
@@ -323,7 +295,7 @@ void main() {
|
||||
isTrue,
|
||||
);
|
||||
} finally {
|
||||
await _disableSwiftPackageManager(flutterBin, workingDirectoryPath);
|
||||
await SwiftPackageManagerUtils.disableSwiftPackageManager(flutterBin, workingDirectoryPath);
|
||||
ErrorHandlingFileSystem.deleteIfExists(
|
||||
workingDirectory,
|
||||
recursive: true,
|
||||
@@ -339,9 +311,9 @@ void main() {
|
||||
try {
|
||||
// Create and build module and framework using the CocoaPods version of
|
||||
// integration_test even though Swift Package Manager is enabled.
|
||||
await _enableSwiftPackageManager(flutterBin, workingDirectoryPath);
|
||||
await SwiftPackageManagerUtils.enableSwiftPackageManager(flutterBin, workingDirectoryPath);
|
||||
|
||||
final String appDirectoryPath = await _createApp(
|
||||
final String appDirectoryPath = await SwiftPackageManagerUtils.createApp(
|
||||
flutterBin,
|
||||
workingDirectoryPath,
|
||||
iosLanguage: 'swift',
|
||||
@@ -349,16 +321,13 @@ void main() {
|
||||
usesSwiftPackageManager: true,
|
||||
options: <String>['--template=module'],
|
||||
);
|
||||
final _Plugin integrationTestPlugin = _integrationTestPlugin('ios');
|
||||
_addDependency(appDirectoryPath: appDirectoryPath, plugin: integrationTestPlugin);
|
||||
final SwiftPackageManagerPlugin integrationTestPlugin = SwiftPackageManagerUtils.integrationTestPlugin('ios');
|
||||
SwiftPackageManagerUtils.addDependency(appDirectoryPath: appDirectoryPath, plugin: integrationTestPlugin);
|
||||
|
||||
await _buildApp(
|
||||
await SwiftPackageManagerUtils.buildApp(
|
||||
flutterBin,
|
||||
appDirectoryPath,
|
||||
options: <String>['ios', '--config-only', '-v'],
|
||||
unexpectedLines: <String>[
|
||||
'Adding Swift Package Manager integration...'
|
||||
]
|
||||
);
|
||||
|
||||
expect(
|
||||
@@ -380,8 +349,30 @@ void main() {
|
||||
.existsSync(),
|
||||
isFalse,
|
||||
);
|
||||
final File pbxprojFile = fileSystem
|
||||
.directory(appDirectoryPath)
|
||||
.childDirectory('.ios')
|
||||
.childDirectory('Runner.xcodeproj')
|
||||
.childFile('project.pbxproj');
|
||||
expect(pbxprojFile.existsSync(), isTrue);
|
||||
expect(
|
||||
pbxprojFile.readAsStringSync().contains('FlutterGeneratedPluginSwiftPackage'),
|
||||
isFalse,
|
||||
);
|
||||
final File xcschemeFile = fileSystem
|
||||
.directory(appDirectoryPath)
|
||||
.childDirectory('.ios')
|
||||
.childDirectory('Runner.xcodeproj')
|
||||
.childDirectory('xcshareddata')
|
||||
.childDirectory('xcschemes')
|
||||
.childFile('Runner.xcscheme');
|
||||
expect(xcschemeFile.existsSync(), isTrue);
|
||||
expect(
|
||||
xcschemeFile.readAsStringSync().contains('Run Prepare Flutter Framework Script'),
|
||||
isFalse,
|
||||
);
|
||||
|
||||
await _buildApp(
|
||||
await SwiftPackageManagerUtils.buildApp(
|
||||
flutterBin,
|
||||
appDirectoryPath,
|
||||
options: <String>[
|
||||
@@ -408,7 +399,7 @@ void main() {
|
||||
isTrue,
|
||||
);
|
||||
} finally {
|
||||
await _disableSwiftPackageManager(flutterBin, workingDirectoryPath);
|
||||
await SwiftPackageManagerUtils.disableSwiftPackageManager(flutterBin, workingDirectoryPath);
|
||||
ErrorHandlingFileSystem.deleteIfExists(
|
||||
workingDirectory,
|
||||
recursive: true,
|
||||
@@ -416,355 +407,3 @@ void main() {
|
||||
}
|
||||
}, skip: !platform.isMacOS); // [intended] Swift Package Manager only works on macos.
|
||||
}
|
||||
|
||||
Future<void> _enableSwiftPackageManager(
|
||||
String flutterBin,
|
||||
String workingDirectory,
|
||||
) async {
|
||||
final ProcessResult result = await processManager.run(
|
||||
<String>[
|
||||
flutterBin,
|
||||
...getLocalEngineArguments(),
|
||||
'config',
|
||||
'--enable-swift-package-manager',
|
||||
'-v',
|
||||
],
|
||||
workingDirectory: workingDirectory,
|
||||
);
|
||||
expect(
|
||||
result.exitCode,
|
||||
0,
|
||||
reason: 'Failed to enable Swift Package Manager: \n'
|
||||
'stdout: \n${result.stdout}\n'
|
||||
'stderr: \n${result.stderr}\n',
|
||||
verbose: true,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _disableSwiftPackageManager(
|
||||
String flutterBin,
|
||||
String workingDirectory,
|
||||
) async {
|
||||
final ProcessResult result = await processManager.run(
|
||||
<String>[
|
||||
flutterBin,
|
||||
...getLocalEngineArguments(),
|
||||
'config',
|
||||
'--no-enable-swift-package-manager',
|
||||
'-v',
|
||||
],
|
||||
workingDirectory: workingDirectory,
|
||||
);
|
||||
expect(
|
||||
result.exitCode,
|
||||
0,
|
||||
reason: 'Failed to disable Swift Package Manager: \n'
|
||||
'stdout: \n${result.stdout}\n'
|
||||
'stderr: \n${result.stderr}\n',
|
||||
verbose: true,
|
||||
);
|
||||
}
|
||||
|
||||
Future<String> _createApp(
|
||||
String flutterBin,
|
||||
String workingDirectory, {
|
||||
required String platform,
|
||||
required String iosLanguage,
|
||||
required List<String> options,
|
||||
bool usesSwiftPackageManager = false,
|
||||
}) async {
|
||||
final String appTemplateType = usesSwiftPackageManager ? 'spm' : 'default';
|
||||
|
||||
final String appName = '${platform}_${iosLanguage}_${appTemplateType}_app';
|
||||
final ProcessResult result = await processManager.run(
|
||||
<String>[
|
||||
flutterBin,
|
||||
...getLocalEngineArguments(),
|
||||
'create',
|
||||
'--org',
|
||||
'io.flutter.devicelab',
|
||||
'-i',
|
||||
iosLanguage,
|
||||
...options,
|
||||
appName,
|
||||
],
|
||||
workingDirectory: workingDirectory,
|
||||
);
|
||||
|
||||
expect(
|
||||
result.exitCode,
|
||||
0,
|
||||
reason: 'Failed to create app: \n'
|
||||
'stdout: \n${result.stdout}\n'
|
||||
'stderr: \n${result.stderr}\n',
|
||||
);
|
||||
|
||||
return fileSystem.path.join(
|
||||
workingDirectory,
|
||||
appName,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _buildApp(
|
||||
String flutterBin,
|
||||
String workingDirectory, {
|
||||
required List<String> options,
|
||||
List<Pattern>? expectedLines,
|
||||
List<String>? unexpectedLines,
|
||||
}) async {
|
||||
final List<Pattern> remainingExpectedLines = expectedLines ?? <Pattern>[];
|
||||
final List<String> unexpectedLinesFound = <String>[];
|
||||
final List<String> command = <String>[
|
||||
flutterBin,
|
||||
...getLocalEngineArguments(),
|
||||
'build',
|
||||
...options,
|
||||
];
|
||||
|
||||
final ProcessResult result = await processManager.run(
|
||||
command,
|
||||
workingDirectory: workingDirectory,
|
||||
);
|
||||
|
||||
final List<String> stdout = LineSplitter.split(result.stdout.toString()).toList();
|
||||
final List<String> stderr = LineSplitter.split(result.stderr.toString()).toList();
|
||||
final List<String> output = stdout + stderr;
|
||||
for (final String line in output) {
|
||||
// Remove "[ +3 ms] " prefix
|
||||
String trimmedLine = line.trim();
|
||||
if (trimmedLine.startsWith('[')) {
|
||||
final int prefixEndIndex = trimmedLine.indexOf(']');
|
||||
if (prefixEndIndex > 0) {
|
||||
trimmedLine = trimmedLine
|
||||
.substring(prefixEndIndex + 1, trimmedLine.length)
|
||||
.trim();
|
||||
}
|
||||
}
|
||||
remainingExpectedLines.remove(trimmedLine);
|
||||
remainingExpectedLines.removeWhere((Pattern expectedLine) => trimmedLine.contains(expectedLine));
|
||||
if (unexpectedLines != null && unexpectedLines.contains(trimmedLine)) {
|
||||
unexpectedLinesFound.add(trimmedLine);
|
||||
}
|
||||
}
|
||||
expect(
|
||||
result.exitCode,
|
||||
0,
|
||||
reason: 'Failed to build app for "${command.join(' ')}":\n'
|
||||
'stdout: \n${result.stdout}\n'
|
||||
'stderr: \n${result.stderr}\n',
|
||||
);
|
||||
expect(
|
||||
remainingExpectedLines,
|
||||
isEmpty,
|
||||
reason: 'Did not find expected lines for "${command.join(' ')}":\n'
|
||||
'stdout: \n${result.stdout}\n'
|
||||
'stderr: \n${result.stderr}\n',
|
||||
);
|
||||
expect(
|
||||
unexpectedLinesFound,
|
||||
isEmpty,
|
||||
reason: 'Found unexpected lines for "${command.join(' ')}":\n'
|
||||
'stdout: \n${result.stdout}\n'
|
||||
'stderr: \n${result.stderr}\n',
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _cleanApp(String flutterBin, String workingDirectory) async {
|
||||
final ProcessResult result = await processManager.run(
|
||||
<String>[
|
||||
flutterBin,
|
||||
...getLocalEngineArguments(),
|
||||
'clean',
|
||||
],
|
||||
workingDirectory: workingDirectory,
|
||||
);
|
||||
expect(
|
||||
result.exitCode,
|
||||
0,
|
||||
reason: 'Failed to clean app: \n'
|
||||
'stdout: \n${result.stdout}\n'
|
||||
'stderr: \n${result.stderr}\n',
|
||||
);
|
||||
}
|
||||
|
||||
Future<_Plugin> _createPlugin(
|
||||
String flutterBin,
|
||||
String workingDirectory, {
|
||||
required String platform,
|
||||
required String iosLanguage,
|
||||
bool usesSwiftPackageManager = false,
|
||||
}) async {
|
||||
final String dependencyManager = usesSwiftPackageManager ? 'spm' : 'cocoapods';
|
||||
|
||||
// Create plugin
|
||||
final String pluginName = '${platform}_${iosLanguage}_${dependencyManager}_plugin';
|
||||
final ProcessResult result = await processManager.run(
|
||||
<String>[
|
||||
flutterBin,
|
||||
...getLocalEngineArguments(),
|
||||
'create',
|
||||
'--org',
|
||||
'io.flutter.devicelab',
|
||||
'--template=plugin',
|
||||
'--platforms=$platform',
|
||||
'-i',
|
||||
iosLanguage,
|
||||
pluginName,
|
||||
],
|
||||
workingDirectory: workingDirectory,
|
||||
);
|
||||
|
||||
expect(
|
||||
result.exitCode,
|
||||
0,
|
||||
reason: 'Failed to create plugin: \n'
|
||||
'stdout: \n${result.stdout}\n'
|
||||
'stderr: \n${result.stderr}\n',
|
||||
);
|
||||
|
||||
final Directory pluginDirectory = fileSystem.directory(
|
||||
fileSystem.path.join(workingDirectory, pluginName),
|
||||
);
|
||||
|
||||
return _Plugin(
|
||||
pluginName: pluginName,
|
||||
pluginPath: pluginDirectory.path,
|
||||
platform: platform,
|
||||
);
|
||||
}
|
||||
|
||||
void _addDependency({
|
||||
required _Plugin plugin,
|
||||
required String appDirectoryPath,
|
||||
}) {
|
||||
final File pubspec = fileSystem.file(
|
||||
fileSystem.path.join(appDirectoryPath, 'pubspec.yaml'),
|
||||
);
|
||||
final String pubspecContent = pubspec.readAsStringSync();
|
||||
pubspec.writeAsStringSync(
|
||||
pubspecContent.replaceFirst(
|
||||
'\ndependencies:\n',
|
||||
'\ndependencies:\n ${plugin.pluginName}:\n path: ${plugin.pluginPath}\n',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _disableSwiftPackageManagerByPubspec({
|
||||
required String appDirectoryPath,
|
||||
}) {
|
||||
final File pubspec = fileSystem.file(
|
||||
fileSystem.path.join(appDirectoryPath, 'pubspec.yaml'),
|
||||
);
|
||||
final String pubspecContent = pubspec.readAsStringSync();
|
||||
pubspec.writeAsStringSync(
|
||||
pubspecContent.replaceFirst(
|
||||
'\n# The following section is specific to Flutter packages.\nflutter:\n',
|
||||
'\n# The following section is specific to Flutter packages.\nflutter:\n disable-swift-package-manager: true',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
_Plugin _integrationTestPlugin(String platform) {
|
||||
final String flutterRoot = getFlutterRoot();
|
||||
return _Plugin(
|
||||
platform: platform,
|
||||
pluginName:
|
||||
(platform == 'ios') ? 'integration_test' : 'integration_test_macos',
|
||||
pluginPath: (platform == 'ios')
|
||||
? fileSystem.path.join(flutterRoot, 'packages', 'integration_test')
|
||||
: fileSystem.path.join(flutterRoot, 'packages', 'integration_test', 'integration_test_macos'),
|
||||
);
|
||||
}
|
||||
|
||||
List<Pattern> _expectedLines({
|
||||
required String platform,
|
||||
required String appDirectoryPath,
|
||||
_Plugin? cocoaPodsPlugin,
|
||||
_Plugin? swiftPackagePlugin,
|
||||
bool swiftPackageMangerEnabled = false,
|
||||
}) {
|
||||
final String frameworkName = platform == 'ios' ? 'Flutter' : 'FlutterMacOS';
|
||||
final String appPlatformDirectoryPath = fileSystem.path.join(
|
||||
appDirectoryPath,
|
||||
platform,
|
||||
);
|
||||
|
||||
final List<Pattern> expectedLines = <Pattern>[];
|
||||
if (swiftPackageMangerEnabled) {
|
||||
expectedLines.addAll(<String>[
|
||||
'FlutterGeneratedPluginSwiftPackage: $appPlatformDirectoryPath/Flutter/ephemeral/Packages/FlutterGeneratedPluginSwiftPackage',
|
||||
"➜ Explicit dependency on target 'FlutterGeneratedPluginSwiftPackage' in project 'FlutterGeneratedPluginSwiftPackage'",
|
||||
]);
|
||||
}
|
||||
if (swiftPackagePlugin != null) {
|
||||
// If using a Swift Package plugin, but Swift Package Manager is not enabled, it falls back to being used as a CocoaPods plugin.
|
||||
if (swiftPackageMangerEnabled) {
|
||||
expectedLines.addAll(<Pattern>[
|
||||
RegExp('${swiftPackagePlugin.pluginName}: [/private]*${swiftPackagePlugin.pluginPath}/$platform/${swiftPackagePlugin.pluginName} @ local'),
|
||||
"➜ Explicit dependency on target '${swiftPackagePlugin.pluginName}' in project '${swiftPackagePlugin.pluginName}'",
|
||||
]);
|
||||
} else {
|
||||
expectedLines.addAll(<String>[
|
||||
'-> Installing ${swiftPackagePlugin.pluginName} (0.0.1)',
|
||||
"➜ Explicit dependency on target '${swiftPackagePlugin.pluginName}' in project 'Pods'",
|
||||
]);
|
||||
}
|
||||
}
|
||||
if (cocoaPodsPlugin != null) {
|
||||
expectedLines.addAll(<String>[
|
||||
'Running pod install...',
|
||||
'-> Installing $frameworkName (1.0.0)',
|
||||
'-> Installing ${cocoaPodsPlugin.pluginName} (0.0.1)',
|
||||
"Target 'Pods-Runner' in project 'Pods'",
|
||||
"➜ Explicit dependency on target '$frameworkName' in project 'Pods'",
|
||||
"➜ Explicit dependency on target '${cocoaPodsPlugin.pluginName}' in project 'Pods'",
|
||||
]);
|
||||
}
|
||||
return expectedLines;
|
||||
}
|
||||
|
||||
List<String> _unexpectedLines({
|
||||
required String platform,
|
||||
required String appDirectoryPath,
|
||||
_Plugin? cocoaPodsPlugin,
|
||||
_Plugin? swiftPackagePlugin,
|
||||
bool swiftPackageMangerEnabled = false,
|
||||
}) {
|
||||
final String frameworkName = platform == 'ios' ? 'Flutter' : 'FlutterMacOS';
|
||||
final List<String> unexpectedLines = <String>[];
|
||||
if (cocoaPodsPlugin == null) {
|
||||
unexpectedLines.addAll(<String>[
|
||||
'Running pod install...',
|
||||
'-> Installing $frameworkName (1.0.0)',
|
||||
"Target 'Pods-Runner' in project 'Pods'",
|
||||
]);
|
||||
}
|
||||
if (swiftPackagePlugin != null) {
|
||||
if (swiftPackageMangerEnabled) {
|
||||
unexpectedLines.addAll(<String>[
|
||||
'-> Installing ${swiftPackagePlugin.pluginName} (0.0.1)',
|
||||
"➜ Explicit dependency on target '${swiftPackagePlugin.pluginName}' in project 'Pods'",
|
||||
]);
|
||||
} else {
|
||||
unexpectedLines.addAll(<String>[
|
||||
'${swiftPackagePlugin.pluginName}: ${swiftPackagePlugin.pluginPath}/$platform/${swiftPackagePlugin.pluginName} @ local',
|
||||
"➜ Explicit dependency on target '${swiftPackagePlugin.pluginName}' in project '${swiftPackagePlugin.pluginName}'",
|
||||
]);
|
||||
}
|
||||
}
|
||||
return unexpectedLines;
|
||||
}
|
||||
|
||||
class _Plugin {
|
||||
_Plugin({
|
||||
required this.pluginName,
|
||||
required this.pluginPath,
|
||||
required this.platform,
|
||||
});
|
||||
|
||||
final String pluginName;
|
||||
final String pluginPath;
|
||||
final String platform;
|
||||
String get exampleAppPath => fileSystem.path.join(pluginPath, 'example');
|
||||
String get exampleAppPlatformPath => fileSystem.path.join(exampleAppPath, platform);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,379 @@
|
||||
// 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:convert';
|
||||
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/base/io.dart';
|
||||
|
||||
import '../src/common.dart';
|
||||
import 'test_utils.dart';
|
||||
|
||||
class SwiftPackageManagerUtils {
|
||||
static Future<void> enableSwiftPackageManager(
|
||||
String flutterBin,
|
||||
String workingDirectory,
|
||||
) async {
|
||||
final ProcessResult result = await processManager.run(
|
||||
<String>[
|
||||
flutterBin,
|
||||
...getLocalEngineArguments(),
|
||||
'config',
|
||||
'--enable-swift-package-manager',
|
||||
'-v',
|
||||
],
|
||||
workingDirectory: workingDirectory,
|
||||
);
|
||||
expect(
|
||||
result.exitCode,
|
||||
0,
|
||||
reason: 'Failed to enable Swift Package Manager: \n'
|
||||
'stdout: \n${result.stdout}\n'
|
||||
'stderr: \n${result.stderr}\n',
|
||||
verbose: true,
|
||||
);
|
||||
}
|
||||
|
||||
static Future<void> disableSwiftPackageManager(
|
||||
String flutterBin,
|
||||
String workingDirectory,
|
||||
) async {
|
||||
final ProcessResult result = await processManager.run(
|
||||
<String>[
|
||||
flutterBin,
|
||||
...getLocalEngineArguments(),
|
||||
'config',
|
||||
'--no-enable-swift-package-manager',
|
||||
'-v',
|
||||
],
|
||||
workingDirectory: workingDirectory,
|
||||
);
|
||||
expect(
|
||||
result.exitCode,
|
||||
0,
|
||||
reason: 'Failed to disable Swift Package Manager: \n'
|
||||
'stdout: \n${result.stdout}\n'
|
||||
'stderr: \n${result.stderr}\n',
|
||||
verbose: true,
|
||||
);
|
||||
}
|
||||
|
||||
static Future<String> createApp(
|
||||
String flutterBin,
|
||||
String workingDirectory, {
|
||||
required String platform,
|
||||
required String iosLanguage,
|
||||
required List<String> options,
|
||||
bool usesSwiftPackageManager = false,
|
||||
}) async {
|
||||
final String appTemplateType = usesSwiftPackageManager ? 'spm' : 'default';
|
||||
|
||||
final String appName = '${platform}_${iosLanguage}_${appTemplateType}_app';
|
||||
final ProcessResult result = await processManager.run(
|
||||
<String>[
|
||||
flutterBin,
|
||||
...getLocalEngineArguments(),
|
||||
'create',
|
||||
'--org',
|
||||
'io.flutter.devicelab',
|
||||
'-i',
|
||||
iosLanguage,
|
||||
...options,
|
||||
appName,
|
||||
],
|
||||
workingDirectory: workingDirectory,
|
||||
);
|
||||
|
||||
expect(
|
||||
result.exitCode,
|
||||
0,
|
||||
reason: 'Failed to create app: \n'
|
||||
'stdout: \n${result.stdout}\n'
|
||||
'stderr: \n${result.stderr}\n',
|
||||
);
|
||||
|
||||
return fileSystem.path.join(
|
||||
workingDirectory,
|
||||
appName,
|
||||
);
|
||||
}
|
||||
|
||||
static Future<void> buildApp(
|
||||
String flutterBin,
|
||||
String workingDirectory, {
|
||||
required List<String> options,
|
||||
List<Pattern>? expectedLines,
|
||||
List<String>? unexpectedLines,
|
||||
}) async {
|
||||
final List<Pattern> remainingExpectedLines = expectedLines ?? <Pattern>[];
|
||||
final List<String> unexpectedLinesFound = <String>[];
|
||||
final List<String> command = <String>[
|
||||
flutterBin,
|
||||
...getLocalEngineArguments(),
|
||||
'build',
|
||||
...options,
|
||||
];
|
||||
|
||||
final ProcessResult result = await processManager.run(
|
||||
command,
|
||||
workingDirectory: workingDirectory,
|
||||
);
|
||||
|
||||
final List<String> stdout = LineSplitter.split(result.stdout.toString()).toList();
|
||||
final List<String> stderr = LineSplitter.split(result.stderr.toString()).toList();
|
||||
final List<String> output = stdout + stderr;
|
||||
for (final String line in output) {
|
||||
// Remove "[ +3 ms] " prefix
|
||||
String trimmedLine = line.trim();
|
||||
if (trimmedLine.startsWith('[')) {
|
||||
final int prefixEndIndex = trimmedLine.indexOf(']');
|
||||
if (prefixEndIndex > 0) {
|
||||
trimmedLine = trimmedLine
|
||||
.substring(prefixEndIndex + 1, trimmedLine.length)
|
||||
.trim();
|
||||
}
|
||||
}
|
||||
remainingExpectedLines.remove(trimmedLine);
|
||||
remainingExpectedLines.removeWhere((Pattern expectedLine) => trimmedLine.contains(expectedLine));
|
||||
if (unexpectedLines != null && unexpectedLines.contains(trimmedLine)) {
|
||||
unexpectedLinesFound.add(trimmedLine);
|
||||
}
|
||||
}
|
||||
expect(
|
||||
result.exitCode,
|
||||
0,
|
||||
reason: 'Failed to build app for "${command.join(' ')}":\n'
|
||||
'stdout: \n${result.stdout}\n'
|
||||
'stderr: \n${result.stderr}\n',
|
||||
);
|
||||
expect(
|
||||
remainingExpectedLines,
|
||||
isEmpty,
|
||||
reason: 'Did not find expected lines for "${command.join(' ')}":\n'
|
||||
'stdout: \n${result.stdout}\n'
|
||||
'stderr: \n${result.stderr}\n',
|
||||
);
|
||||
expect(
|
||||
unexpectedLinesFound,
|
||||
isEmpty,
|
||||
reason: 'Found unexpected lines for "${command.join(' ')}":\n'
|
||||
'stdout: \n${result.stdout}\n'
|
||||
'stderr: \n${result.stderr}\n',
|
||||
);
|
||||
}
|
||||
|
||||
static Future<void> cleanApp(String flutterBin, String workingDirectory) async {
|
||||
final ProcessResult result = await processManager.run(
|
||||
<String>[
|
||||
flutterBin,
|
||||
...getLocalEngineArguments(),
|
||||
'clean',
|
||||
],
|
||||
workingDirectory: workingDirectory,
|
||||
);
|
||||
expect(
|
||||
result.exitCode,
|
||||
0,
|
||||
reason: 'Failed to clean app: \n'
|
||||
'stdout: \n${result.stdout}\n'
|
||||
'stderr: \n${result.stderr}\n',
|
||||
);
|
||||
}
|
||||
|
||||
static Future<SwiftPackageManagerPlugin> createPlugin(
|
||||
String flutterBin,
|
||||
String workingDirectory, {
|
||||
required String platform,
|
||||
required String iosLanguage,
|
||||
bool usesSwiftPackageManager = false,
|
||||
}) async {
|
||||
final String dependencyManager = usesSwiftPackageManager ? 'spm' : 'cocoapods';
|
||||
|
||||
// Create plugin
|
||||
final String pluginName = '${platform}_${iosLanguage}_${dependencyManager}_plugin';
|
||||
final ProcessResult result = await processManager.run(
|
||||
<String>[
|
||||
flutterBin,
|
||||
...getLocalEngineArguments(),
|
||||
'create',
|
||||
'--org',
|
||||
'io.flutter.devicelab',
|
||||
'--template=plugin',
|
||||
'--platforms=$platform',
|
||||
'-i',
|
||||
iosLanguage,
|
||||
pluginName,
|
||||
],
|
||||
workingDirectory: workingDirectory,
|
||||
);
|
||||
|
||||
expect(
|
||||
result.exitCode,
|
||||
0,
|
||||
reason: 'Failed to create plugin: \n'
|
||||
'stdout: \n${result.stdout}\n'
|
||||
'stderr: \n${result.stderr}\n',
|
||||
);
|
||||
|
||||
final Directory pluginDirectory = fileSystem.directory(
|
||||
fileSystem.path.join(workingDirectory, pluginName),
|
||||
);
|
||||
|
||||
return SwiftPackageManagerPlugin(
|
||||
pluginName: pluginName,
|
||||
pluginPath: pluginDirectory.path,
|
||||
platform: platform,
|
||||
);
|
||||
}
|
||||
|
||||
static void addDependency({
|
||||
required SwiftPackageManagerPlugin plugin,
|
||||
required String appDirectoryPath,
|
||||
}) {
|
||||
final File pubspec = fileSystem.file(
|
||||
fileSystem.path.join(appDirectoryPath, 'pubspec.yaml'),
|
||||
);
|
||||
final String pubspecContent = pubspec.readAsStringSync();
|
||||
pubspec.writeAsStringSync(
|
||||
pubspecContent.replaceFirst(
|
||||
'\ndependencies:\n',
|
||||
'\ndependencies:\n ${plugin.pluginName}:\n path: ${plugin.pluginPath}\n',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
static void disableSwiftPackageManagerByPubspec({
|
||||
required String appDirectoryPath,
|
||||
}) {
|
||||
final File pubspec = fileSystem.file(
|
||||
fileSystem.path.join(appDirectoryPath, 'pubspec.yaml'),
|
||||
);
|
||||
final String pubspecContent = pubspec.readAsStringSync();
|
||||
pubspec.writeAsStringSync(
|
||||
pubspecContent.replaceFirst(
|
||||
'\n# The following section is specific to Flutter packages.\nflutter:\n',
|
||||
'\n# The following section is specific to Flutter packages.\nflutter:\n disable-swift-package-manager: true',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
static SwiftPackageManagerPlugin integrationTestPlugin(String platform) {
|
||||
final String flutterRoot = getFlutterRoot();
|
||||
return SwiftPackageManagerPlugin(
|
||||
platform: platform,
|
||||
pluginName:
|
||||
(platform == 'ios') ? 'integration_test' : 'integration_test_macos',
|
||||
pluginPath: (platform == 'ios')
|
||||
? fileSystem.path.join(flutterRoot, 'packages', 'integration_test')
|
||||
: fileSystem.path.join(flutterRoot, 'packages', 'integration_test', 'integration_test_macos'),
|
||||
);
|
||||
}
|
||||
|
||||
static List<Pattern> expectedLines({
|
||||
required String platform,
|
||||
required String appDirectoryPath,
|
||||
SwiftPackageManagerPlugin? cocoaPodsPlugin,
|
||||
SwiftPackageManagerPlugin? swiftPackagePlugin,
|
||||
bool swiftPackageMangerEnabled = false,
|
||||
bool migrated = false,
|
||||
}) {
|
||||
final String frameworkName = platform == 'ios' ? 'Flutter' : 'FlutterMacOS';
|
||||
final String appPlatformDirectoryPath = fileSystem.path.join(
|
||||
appDirectoryPath,
|
||||
platform,
|
||||
);
|
||||
|
||||
final List<Pattern> expectedLines = <Pattern>[];
|
||||
if (swiftPackageMangerEnabled) {
|
||||
expectedLines.addAll(<String>[
|
||||
'FlutterGeneratedPluginSwiftPackage: $appPlatformDirectoryPath/Flutter/ephemeral/Packages/FlutterGeneratedPluginSwiftPackage',
|
||||
"➜ Explicit dependency on target 'FlutterGeneratedPluginSwiftPackage' in project 'FlutterGeneratedPluginSwiftPackage'",
|
||||
]);
|
||||
}
|
||||
if (swiftPackagePlugin != null) {
|
||||
// If using a Swift Package plugin, but Swift Package Manager is not enabled, it falls back to being used as a CocoaPods plugin.
|
||||
if (swiftPackageMangerEnabled) {
|
||||
expectedLines.addAll(<Pattern>[
|
||||
RegExp('${swiftPackagePlugin.pluginName}: [/private]*${swiftPackagePlugin.pluginPath}/$platform/${swiftPackagePlugin.pluginName} @ local'),
|
||||
"➜ Explicit dependency on target '${swiftPackagePlugin.pluginName}' in project '${swiftPackagePlugin.pluginName}'",
|
||||
]);
|
||||
} else {
|
||||
expectedLines.addAll(<String>[
|
||||
'-> Installing ${swiftPackagePlugin.pluginName} (0.0.1)',
|
||||
"➜ Explicit dependency on target '${swiftPackagePlugin.pluginName}' in project 'Pods'",
|
||||
]);
|
||||
}
|
||||
}
|
||||
if (cocoaPodsPlugin != null) {
|
||||
expectedLines.addAll(<String>[
|
||||
'Running pod install...',
|
||||
'-> Installing $frameworkName (1.0.0)',
|
||||
'-> Installing ${cocoaPodsPlugin.pluginName} (0.0.1)',
|
||||
"Target 'Pods-Runner' in project 'Pods'",
|
||||
"➜ Explicit dependency on target '$frameworkName' in project 'Pods'",
|
||||
"➜ Explicit dependency on target '${cocoaPodsPlugin.pluginName}' in project 'Pods'",
|
||||
]);
|
||||
}
|
||||
if (migrated) {
|
||||
expectedLines.addAll(<String>[
|
||||
'Adding Swift Package Manager integration...',
|
||||
'Running pod install...',
|
||||
"Target 'Pods-Runner' in project 'Pods'",
|
||||
]);
|
||||
}
|
||||
return expectedLines;
|
||||
}
|
||||
|
||||
static List<String> unexpectedLines({
|
||||
required String platform,
|
||||
required String appDirectoryPath,
|
||||
SwiftPackageManagerPlugin? cocoaPodsPlugin,
|
||||
SwiftPackageManagerPlugin? swiftPackagePlugin,
|
||||
bool swiftPackageMangerEnabled = false,
|
||||
bool migrated = false,
|
||||
}) {
|
||||
final String frameworkName = platform == 'ios' ? 'Flutter' : 'FlutterMacOS';
|
||||
final List<String> unexpectedLines = <String>[];
|
||||
if (cocoaPodsPlugin == null && !migrated) {
|
||||
unexpectedLines.addAll(<String>[
|
||||
'Running pod install...',
|
||||
'-> Installing $frameworkName (1.0.0)',
|
||||
"Target 'Pods-Runner' in project 'Pods'",
|
||||
]);
|
||||
}
|
||||
if (swiftPackagePlugin != null) {
|
||||
if (swiftPackageMangerEnabled) {
|
||||
unexpectedLines.addAll(<String>[
|
||||
'-> Installing ${swiftPackagePlugin.pluginName} (0.0.1)',
|
||||
"➜ Explicit dependency on target '${swiftPackagePlugin.pluginName}' in project 'Pods'",
|
||||
]);
|
||||
} else {
|
||||
unexpectedLines.addAll(<String>[
|
||||
'${swiftPackagePlugin.pluginName}: ${swiftPackagePlugin.pluginPath}/$platform/${swiftPackagePlugin.pluginName} @ local',
|
||||
"➜ Explicit dependency on target '${swiftPackagePlugin.pluginName}' in project '${swiftPackagePlugin.pluginName}'",
|
||||
]);
|
||||
}
|
||||
}
|
||||
if (!migrated) {
|
||||
unexpectedLines.addAll(<String>[
|
||||
'Adding Swift Package Manager integration...',
|
||||
]);
|
||||
}
|
||||
return unexpectedLines;
|
||||
}
|
||||
}
|
||||
|
||||
class SwiftPackageManagerPlugin {
|
||||
SwiftPackageManagerPlugin({
|
||||
required this.pluginName,
|
||||
required this.pluginPath,
|
||||
required this.platform,
|
||||
});
|
||||
|
||||
final String pluginName;
|
||||
final String pluginPath;
|
||||
final String platform;
|
||||
String get exampleAppPath => fileSystem.path.join(pluginPath, 'example');
|
||||
String get exampleAppPlatformPath => fileSystem.path.join(exampleAppPath, platform);
|
||||
}
|
||||
Reference in New Issue
Block a user