Unverified Commit 7feb7ddd authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Inject platform into build ios-framework command (#49463)

parent 92a7cd42
......@@ -4,10 +4,12 @@
import 'dart:async';
import '../aot.dart';
import '../bundle.dart';
import '../commands/build_linux.dart';
import '../commands/build_macos.dart';
import '../commands/build_windows.dart';
import '../globals.dart' as globals;
import '../runner/flutter_command.dart';
import 'build_aar.dart';
import 'build_aot.dart';
......@@ -26,7 +28,12 @@ class BuildCommand extends FlutterCommand {
addSubcommand(BuildAppBundleCommand(verboseHelp: verboseHelp));
addSubcommand(BuildAotCommand(verboseHelp: verboseHelp));
addSubcommand(BuildIOSCommand());
addSubcommand(BuildIOSFrameworkCommand());
addSubcommand(BuildIOSFrameworkCommand(
aotBuilder: AotBuilder(),
bundleBuilder: BundleBuilder(),
cache: globals.cache,
platform: globals.platform,
));
addSubcommand(BuildBundleCommand(verboseHelp: verboseHelp));
addSubcommand(BuildWebCommand());
addSubcommand(BuildMacosCommand());
......
......@@ -6,6 +6,7 @@ import 'dart:async';
import 'package:file/file.dart';
import 'package:meta/meta.dart';
import 'package:platform/platform.dart';
import '../aot.dart';
import '../application_package.dart';
......@@ -33,7 +34,17 @@ import 'build.dart';
/// be integrated into plain Xcode projects without using or other package
/// managers.
class BuildIOSFrameworkCommand extends BuildSubCommand {
BuildIOSFrameworkCommand({this.aotBuilder, this.bundleBuilder, this.flutterVersion, this.cache}) {
BuildIOSFrameworkCommand({
FlutterVersion flutterVersion, // Instantiating FlutterVersion kicks off networking, so delay until it's needed, but allow test injection.
@required AotBuilder aotBuilder,
@required BundleBuilder bundleBuilder,
@required Cache cache,
@required Platform platform
}) : _flutterVersion = flutterVersion,
_aotBuilder = aotBuilder,
_bundleBuilder = bundleBuilder,
_cache = cache,
_platform = platform {
usesTargetOption();
usesFlavorOption();
usesPubOption();
......@@ -76,10 +87,12 @@ class BuildIOSFrameworkCommand extends BuildSubCommand {
);
}
AotBuilder aotBuilder;
BundleBuilder bundleBuilder;
FlutterVersion flutterVersion;
Cache cache;
final AotBuilder _aotBuilder;
final BundleBuilder _bundleBuilder;
final Cache _cache;
final Platform _platform;
FlutterVersion _flutterVersion;
@override
final String name = 'ios-framework';
......@@ -120,7 +133,7 @@ class BuildIOSFrameworkCommand extends BuildSubCommand {
throwToolExit('Building frameworks for iOS is only supported from a module.');
}
if (!globals.platform.isMacOS) {
if (!_platform.isMacOS) {
throwToolExit('Building frameworks for iOS is only supported on the Mac.');
}
......@@ -154,10 +167,6 @@ class BuildIOSFrameworkCommand extends BuildSubCommand {
final Directory outputDirectory = globals.fs.directory(globals.fs.path.absolute(globals.fs.path.normalize(outputArgument)));
aotBuilder ??= AotBuilder();
bundleBuilder ??= BundleBuilder();
cache ??= globals.cache;
for (final BuildMode mode in buildModes) {
globals.printStatus('Building frameworks for $iosProject in ${getNameForBuildMode(mode)} mode...');
final String xcodeBuildConfiguration = toTitleCase(getNameForBuildMode(mode));
......@@ -171,7 +180,7 @@ class BuildIOSFrameworkCommand extends BuildSubCommand {
if (boolArg('cocoapods')) {
// FlutterVersion.instance kicks off git processing which can sometimes fail, so don't try it until needed.
flutterVersion ??= FlutterVersion.instance;
_flutterVersion ??= FlutterVersion.instance;
produceFlutterPodspec(mode, modeDirectory);
} else {
// Copy Flutter.framework.
......@@ -213,10 +222,10 @@ class BuildIOSFrameworkCommand extends BuildSubCommand {
void produceFlutterPodspec(BuildMode mode, Directory modeDirectory) {
final Status status = globals.logger.startProgress(' ├─Creating Flutter.podspec...', timeout: timeoutConfiguration.fastOperation);
try {
final GitTagVersion gitTagVersion = flutterVersion.gitTagVersion;
final GitTagVersion gitTagVersion = _flutterVersion.gitTagVersion;
if (gitTagVersion.x == null || gitTagVersion.y == null || gitTagVersion.z == null || gitTagVersion.commits != 0) {
throwToolExit(
'--cocoapods is only supported on the dev, beta, or stable channels. Detected version is ${flutterVersion.frameworkVersion}');
'--cocoapods is only supported on the dev, beta, or stable channels. Detected version is ${_flutterVersion.frameworkVersion}');
}
// Podspecs use semantic versioning, which don't support hotfixes.
......@@ -225,7 +234,7 @@ class BuildIOSFrameworkCommand extends BuildSubCommand {
// new artifacts when the source URL changes.
final int minorHotfixVersion = gitTagVersion.z * 100 + (gitTagVersion.hotfix ?? 0);
final File license = cache.getLicenseFile();
final File license = _cache.getLicenseFile();
if (!license.existsSync()) {
throwToolExit('Could not find license at ${license.path}');
}
......@@ -235,7 +244,7 @@ class BuildIOSFrameworkCommand extends BuildSubCommand {
final String podspecContents = '''
Pod::Spec.new do |s|
s.name = 'Flutter'
s.version = '${gitTagVersion.x}.${gitTagVersion.y}.$minorHotfixVersion' # ${flutterVersion.frameworkVersion}
s.version = '${gitTagVersion.x}.${gitTagVersion.y}.$minorHotfixVersion' # ${_flutterVersion.frameworkVersion}
s.summary = 'Flutter Engine Framework'
s.description = <<-DESC
Flutter is Google’s UI toolkit for building beautiful, natively compiled applications for mobile, web, and desktop from a single codebase.
......@@ -248,7 +257,7 @@ $licenseSource
LICENSE
}
s.author = { 'Flutter Dev Team' => 'flutter-dev@googlegroups.com' }
s.source = { :http => '${cache.storageBaseUrl}/flutter_infra/flutter/${cache.engineRevision}/$artifactsMode/artifacts.zip' }
s.source = { :http => '${_cache.storageBaseUrl}/flutter_infra/flutter/${_cache.engineRevision}/$artifactsMode/artifacts.zip' }
s.documentation_url = 'https://flutter.dev/docs'
s.platform = :ios, '8.0'
s.vendored_frameworks = 'Flutter.framework'
......@@ -347,7 +356,7 @@ end
final Status status = globals.logger.startProgress(
' ├─Assembling Flutter resources for App.framework...', timeout: timeoutConfiguration.slowOperation);
try {
await bundleBuilder.build(
await _bundleBuilder.build(
platform: TargetPlatform.ios,
buildMode: mode,
// Relative paths show noise in the compiler https://github.com/dart-lang/sdk/issues/37978.
......@@ -408,7 +417,7 @@ end
timeout: timeoutConfiguration.slowOperation,
);
try {
await aotBuilder.build(
await _aotBuilder.build(
platform: TargetPlatform.ios,
outputPath: destinationDirectory.path,
buildMode: mode,
......
......@@ -5,41 +5,54 @@
import 'dart:io';
import 'package:file/memory.dart';
import 'package:flutter_tools/src/aot.dart';
import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/bundle.dart';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/commands/build_ios_framework.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/version.dart';
import 'package:flutter_tools/src/globals.dart' as globals;
import 'package:mockito/mockito.dart';
import 'package:platform/platform.dart';
import '../../src/common.dart';
import '../../src/context.dart';
void main() {
group('build ios-framework', () {
MemoryFileSystem memoryFileSystem;
MockFlutterVersion mockFlutterVersion;
MockGitTagVersion mockGitTagVersion;
MockCache mockCache;
Directory outputDirectory;
FakePlatform fakePlatform;
setUpAll(() {
Cache.disableLocking();
});
setUp(() {
memoryFileSystem = MemoryFileSystem();
mockFlutterVersion = MockFlutterVersion();
mockGitTagVersion = MockGitTagVersion();
mockCache = MockCache();
fakePlatform = FakePlatform()..operatingSystem = 'macos';
when(mockFlutterVersion.gitTagVersion).thenReturn(mockGitTagVersion);
outputDirectory = globals.fs.systemTempDirectory
.createTempSync('flutter_build_ios_framework_test_output.')
.childDirectory('Debug')
..createSync();
});
group('podspec', () {
MemoryFileSystem memoryFileSystem;
MockFlutterVersion mockFlutterVersion;
MockGitTagVersion mockGitTagVersion;
MockCache mockCache;
Directory outputDirectory;
const String storageBaseUrl = 'https://fake.googleapis.com';
const String engineRevision = '0123456789abcdef';
File licenseFile;
setUp(() {
memoryFileSystem = MemoryFileSystem();
mockFlutterVersion = MockFlutterVersion();
mockGitTagVersion = MockGitTagVersion();
mockCache = MockCache();
when(mockFlutterVersion.gitTagVersion).thenReturn(mockGitTagVersion);
outputDirectory = globals.fs.systemTempDirectory
.createTempSync('flutter_build_ios_framework_test_output.')
.childDirectory('Debug')
..createSync();
when(mockCache.storageBaseUrl).thenReturn(storageBaseUrl);
when(mockCache.engineRevision).thenReturn(engineRevision);
licenseFile = memoryFileSystem.file('LICENSE');
......@@ -51,6 +64,9 @@ void main() {
when(mockFlutterVersion.frameworkVersion).thenReturn(frameworkVersion);
final BuildIOSFrameworkCommand command = BuildIOSFrameworkCommand(
aotBuilder: MockAotBuilder(),
bundleBuilder: MockBundleBuilder(),
platform: fakePlatform,
flutterVersion: mockFlutterVersion,
cache: mockCache
);
......@@ -73,6 +89,9 @@ void main() {
when(mockGitTagVersion.commits).thenReturn(2);
final BuildIOSFrameworkCommand command = BuildIOSFrameworkCommand(
aotBuilder: MockAotBuilder(),
bundleBuilder: MockBundleBuilder(),
platform: fakePlatform,
flutterVersion: mockFlutterVersion,
cache: mockCache
);
......@@ -92,6 +111,9 @@ void main() {
when(mockGitTagVersion.commits).thenReturn(0);
final BuildIOSFrameworkCommand command = BuildIOSFrameworkCommand(
aotBuilder: MockAotBuilder(),
bundleBuilder: MockBundleBuilder(),
platform: fakePlatform,
flutterVersion: mockFlutterVersion,
cache: mockCache
);
......@@ -123,8 +145,11 @@ void main() {
testUsingContext('contains license and version', () async {
final BuildIOSFrameworkCommand command = BuildIOSFrameworkCommand(
flutterVersion: mockFlutterVersion,
cache: mockCache
aotBuilder: MockAotBuilder(),
bundleBuilder: MockBundleBuilder(),
platform: fakePlatform,
flutterVersion: mockFlutterVersion,
cache: mockCache
);
command.produceFlutterPodspec(BuildMode.debug, outputDirectory);
......@@ -140,8 +165,11 @@ void main() {
testUsingContext('debug URL', () async {
final BuildIOSFrameworkCommand command = BuildIOSFrameworkCommand(
flutterVersion: mockFlutterVersion,
cache: mockCache
aotBuilder: MockAotBuilder(),
bundleBuilder: MockBundleBuilder(),
platform: fakePlatform,
flutterVersion: mockFlutterVersion,
cache: mockCache
);
command.produceFlutterPodspec(BuildMode.debug, outputDirectory);
......@@ -155,8 +183,11 @@ void main() {
testUsingContext('profile URL', () async {
final BuildIOSFrameworkCommand command = BuildIOSFrameworkCommand(
flutterVersion: mockFlutterVersion,
cache: mockCache
aotBuilder: MockAotBuilder(),
bundleBuilder: MockBundleBuilder(),
platform: fakePlatform,
flutterVersion: mockFlutterVersion,
cache: mockCache
);
command.produceFlutterPodspec(BuildMode.profile, outputDirectory);
......@@ -170,8 +201,11 @@ void main() {
testUsingContext('release URL', () async {
final BuildIOSFrameworkCommand command = BuildIOSFrameworkCommand(
flutterVersion: mockFlutterVersion,
cache: mockCache
aotBuilder: MockAotBuilder(),
bundleBuilder: MockBundleBuilder(),
platform: fakePlatform,
flutterVersion: mockFlutterVersion,
cache: mockCache
);
command.produceFlutterPodspec(BuildMode.release, outputDirectory);
......@@ -190,3 +224,5 @@ void main() {
class MockFlutterVersion extends Mock implements FlutterVersion {}
class MockGitTagVersion extends Mock implements GitTagVersion {}
class MockCache extends Mock implements Cache {}
class MockAotBuilder extends Mock implements AotBuilder {}
class MockBundleBuilder extends Mock implements BundleBuilder {}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment