diff --git a/script/tool/lib/src/fetch_deps_command.dart b/script/tool/lib/src/fetch_deps_command.dart index 2f763a04c26..ecc9b7adc58 100644 --- a/script/tool/lib/src/fetch_deps_command.dart +++ b/script/tool/lib/src/fetch_deps_command.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'package:file/file.dart'; - import 'common/core.dart'; import 'common/gradle.dart'; import 'common/output_utils.dart'; @@ -216,44 +214,15 @@ class FetchDepsCommand extends PackageLoopingCommand { } for (final RepositoryPackage example in package.getExamples()) { - final Directory platformDir = - example.platformDirectory(getPlatformByName(platform)); - - // Running `pod install` requires `flutter pub get` or `flutter build` to - // have been run at some point to create the necessary native build files. - // See https://github.com/flutter/flutter/blob/fb7a763c640d247d090cbb373e4b3a0459ac171b/packages/flutter_tools/templates/cocoapods/Podfile-macos#L13-L15 - // and https://github.com/flutter/flutter/blob/fb7a763c640d247d090cbb373e4b3a0459ac171b/packages/flutter_tools/templates/cocoapods/Podfile-ios-swift#L14-L16 - final File generatedXCConfig = platform == platformMacOS - ? platformDir - .childDirectory('Flutter') - .childDirectory('ephemeral') - .childFile('Flutter-Generated.xcconfig') - : platformDir - .childDirectory('Flutter') - .childFile('Generated.xcconfig'); - if (!generatedXCConfig.existsSync()) { - final int exitCode = await processRunner.runAndStream( - flutterCommand, - ['pub', 'get'], - workingDir: example.directory, - ); - if (exitCode != 0) { - printError('Unable to prepare native project files.'); - return PackageResult.fail(['Unable to configure project.']); - } - } - + // Create the necessary native build files, which will run pub get and pod install if needed. final int exitCode = await processRunner.runAndStream( - 'pod', - ['install'], - workingDir: platformDir, - environment: { - 'LANG': 'en_US.UTF-8', - }, + flutterCommand, + ['build', platform, '--config-only'], + workingDir: example.directory, ); if (exitCode != 0) { - printError('Unable to "pod install"'); - return PackageResult.fail(['Unable to "pod install"']); + printError('Unable to prepare native project files.'); + return PackageResult.fail(['Unable to configure project.']); } } diff --git a/script/tool/test/fetch_deps_command_test.dart b/script/tool/test/fetch_deps_command_test.dart index ab4cd3fbf4d..044b7d3444a 100644 --- a/script/tool/test/fetch_deps_command_test.dart +++ b/script/tool/test/fetch_deps_command_test.dart @@ -385,65 +385,17 @@ void main() { }); group('ios', () { - test('runs pub get before pod install', () async { - final RepositoryPackage plugin = - createFakePlugin('plugin1', packagesDir, extraFiles: [ - 'example/ios/Flutter/Generated.xcconfig', - ], platformSupport: { - platformIOS: const PlatformDetails(PlatformSupport.inline) - }); - - final Directory iOSDir = - plugin.getExamples().first.platformDirectory(FlutterPlatform.ios); - - final List output = - await runCapturingPrint(runner, ['fetch-deps', '--ios']); - - expect( - processRunner.recordedCalls, - orderedEquals([ - const ProcessCall( - 'flutter', - ['precache', '--ios'], - null, - ), - ProcessCall( - 'flutter', - const ['pub', 'get'], - plugin.directory.path, - ), - ProcessCall( - 'pod', - const ['install'], - iOSDir.path, - ), - ]), - ); - - expect( - output, - containsAllInOrder([ - contains('Running for plugin1'), - contains('No issues found!'), - ])); - }); - test('runs on all examples', () async { final List examples = ['example1', 'example2']; final RepositoryPackage plugin = createFakePlugin( 'plugin1', packagesDir, examples: examples, - extraFiles: [ - 'example/example1/ios/Flutter/Generated.xcconfig', - 'example/example2/ios/Flutter/Generated.xcconfig', - ], platformSupport: { platformIOS: const PlatformDetails(PlatformSupport.inline) }); - final Iterable exampleIOSDirs = plugin.getExamples().map( - (RepositoryPackage example) => - example.platformDirectory(FlutterPlatform.ios)); + final Iterable exampleDirs = plugin.getExamples().map( + (RepositoryPackage example) => example.directory); final List output = await runCapturingPrint( runner, ['fetch-deps', '--no-dart', '--ios']); @@ -456,10 +408,10 @@ void main() { ['precache', '--ios'], null, ), - for (final Directory directory in exampleIOSDirs) + for (final Directory directory in exampleDirs) ProcessCall( - 'pod', - const ['install'], + 'flutter', + const ['build', 'ios', '--config-only'], directory.path, ), ]), @@ -473,84 +425,17 @@ void main() { ])); }); - test('runs pub get if example is not configured', () async { - final RepositoryPackage plugin = createFakePlugin( - 'plugin1', packagesDir, platformSupport: { - platformIOS: const PlatformDetails(PlatformSupport.inline) - }); - - final RepositoryPackage example = plugin.getExamples().first; - - final List output = await runCapturingPrint( - runner, ['fetch-deps', '--no-dart', '--ios']); - - expect( - processRunner.recordedCalls, - orderedEquals([ - const ProcessCall( - 'flutter', - ['precache', '--ios'], - null, - ), - ProcessCall( - 'flutter', - const ['pub', 'get'], - example.directory.path, - ), - ProcessCall( - 'pod', - const ['install'], - example.platformDirectory(FlutterPlatform.ios).path, - ), - ]), - ); - - expect( - output, - containsAllInOrder([ - contains('Running for plugin1'), - contains('No issues found!'), - ])); - }); - - test('fails if pre-pod pub get fails', () async { + test('fails if flutter build --config-only fails', () async { createFakePlugin('plugin1', packagesDir, platformSupport: { platformIOS: const PlatformDetails(PlatformSupport.inline) }); processRunner - .mockProcessesForExecutable[getFlutterCommand(mockPlatform)] = - [ + .mockProcessesForExecutable[getFlutterCommand(mockPlatform)] = + [ FakeProcessInfo(MockProcess(), ['precache']), - FakeProcessInfo(MockProcess(exitCode: 1), ['pub', 'get']), - ]; - - Error? commandError; - final List output = await runCapturingPrint( - runner, ['fetch-deps', '--no-dart', '--ios'], - errorHandler: (Error e) { - commandError = e; - }); - - expect(commandError, isA()); - expect( - output, - containsAllInOrder( - [ - contains('Unable to configure project'), - ], - )); - }); - - test('fails if pod install fails', () async { - createFakePlugin('plugin1', packagesDir, - platformSupport: { - platformIOS: const PlatformDetails(PlatformSupport.inline) - }); - - processRunner.mockProcessesForExecutable['pod'] = [ - FakeProcessInfo(MockProcess(exitCode: 1)), + FakeProcessInfo(MockProcess(exitCode: 1), ['build', 'ios', '--config-only']), ]; Error? commandError; @@ -605,65 +490,17 @@ void main() { }); group('macos', () { - test('runs pub get before pod install', () async { - final RepositoryPackage plugin = - createFakePlugin('plugin1', packagesDir, extraFiles: [ - 'example/macos/Flutter/ephemeral/Flutter-Generated.xcconfig', - ], platformSupport: { - platformMacOS: const PlatformDetails(PlatformSupport.inline) - }); - - final Directory macOSDir = - plugin.getExamples().first.platformDirectory(FlutterPlatform.macos); - - final List output = - await runCapturingPrint(runner, ['fetch-deps', '--macos']); - - expect( - processRunner.recordedCalls, - orderedEquals([ - const ProcessCall( - 'flutter', - ['precache', '--macos'], - null, - ), - ProcessCall( - 'flutter', - const ['pub', 'get'], - plugin.directory.path, - ), - ProcessCall( - 'pod', - const ['install'], - macOSDir.path, - ), - ]), - ); - - expect( - output, - containsAllInOrder([ - contains('Running for plugin1'), - contains('No issues found!'), - ])); - }); - test('runs on all examples', () async { final List examples = ['example1', 'example2']; final RepositoryPackage plugin = createFakePlugin( 'plugin1', packagesDir, examples: examples, - extraFiles: [ - 'example/example1/macos/Flutter/ephemeral/Flutter-Generated.xcconfig', - 'example/example2/macos/Flutter/ephemeral/Flutter-Generated.xcconfig', - ], platformSupport: { platformMacOS: const PlatformDetails(PlatformSupport.inline) }); - final Iterable examplemacOSDirs = plugin.getExamples().map( - (RepositoryPackage example) => - example.platformDirectory(FlutterPlatform.macos)); + final Iterable exampleDirs = plugin.getExamples().map( + (RepositoryPackage example) => example.directory); final List output = await runCapturingPrint( runner, ['fetch-deps', '--no-dart', '--macos']); @@ -676,10 +513,10 @@ void main() { ['precache', '--macos'], null, ), - for (final Directory directory in examplemacOSDirs) + for (final Directory directory in exampleDirs) ProcessCall( - 'pod', - const ['install'], + 'flutter', + const ['build', 'macos', '--config-only'], directory.path, ), ]), @@ -693,93 +530,26 @@ void main() { ])); }); - test('runs pub get if example is not configured', () async { - final RepositoryPackage plugin = createFakePlugin( - 'plugin1', packagesDir, platformSupport: { - platformMacOS: const PlatformDetails(PlatformSupport.inline) - }); - - final RepositoryPackage example = plugin.getExamples().first; - - final List output = await runCapturingPrint( - runner, ['fetch-deps', '--no-dart', '--macos']); - - expect( - processRunner.recordedCalls, - orderedEquals([ - const ProcessCall( - 'flutter', - ['precache', '--macos'], - null, - ), - ProcessCall( - 'flutter', - const ['pub', 'get'], - example.directory.path, - ), - ProcessCall( - 'pod', - const ['install'], - example.platformDirectory(FlutterPlatform.macos).path, - ), - ]), - ); - - expect( - output, - containsAllInOrder([ - contains('Running for plugin1'), - contains('No issues found!'), - ])); - }); - - test('fails if pre-pod pub get fails', () async { + test('fails if flutter build --config-only fails', () async { createFakePlugin('plugin1', packagesDir, platformSupport: { platformMacOS: const PlatformDetails(PlatformSupport.inline) }); processRunner - .mockProcessesForExecutable[getFlutterCommand(mockPlatform)] = - [ + .mockProcessesForExecutable[getFlutterCommand(mockPlatform)] = + [ FakeProcessInfo(MockProcess(), ['precache']), - FakeProcessInfo(MockProcess(exitCode: 1), ['pub', 'get']), + FakeProcessInfo(MockProcess(exitCode: 1), ['build', 'macos', '--config-only']), ]; Error? commandError; final List output = await runCapturingPrint( runner, ['fetch-deps', '--no-dart', '--macos'], errorHandler: (Error e) { - commandError = e; - }); - - expect(commandError, isA()); - expect( - output, - containsAllInOrder( - [ - contains('Unable to configure project'), - ], - )); - }); - - test('fails if pod install fails', () async { - createFakePlugin('plugin1', packagesDir, - platformSupport: { - platformMacOS: const PlatformDetails(PlatformSupport.inline) + commandError = e; }); - processRunner.mockProcessesForExecutable['pod'] = [ - FakeProcessInfo(MockProcess(exitCode: 1)), - ]; - - Error? commandError; - final List output = await runCapturingPrint( - runner, ['fetch-deps', '--no-dart', '--macos'], - errorHandler: (Error e) { - commandError = e; - }); - expect(commandError, isA()); expect( output,