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