Unverified Commit 50474b29 authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Only run `pod install` on the first iOS build (#108205)

parent 70aaff12
...@@ -62,7 +62,9 @@ class Fingerprinter { ...@@ -62,7 +62,9 @@ class Fingerprinter {
void writeFingerprint() { void writeFingerprint() {
try { try {
final Fingerprint fingerprint = buildFingerprint(); final Fingerprint fingerprint = buildFingerprint();
_fileSystem.file(fingerprintPath).writeAsStringSync(fingerprint.toJson()); final File fingerprintFile = _fileSystem.file(fingerprintPath);
fingerprintFile.createSync(recursive: true);
fingerprintFile.writeAsStringSync(fingerprint.toJson());
} on Exception catch (e) { } on Exception catch (e) {
// Log exception and continue, fingerprinting is only a performance improvement. // Log exception and continue, fingerprinting is only a performance improvement.
_logger.printTrace('Fingerprint write error: $e'); _logger.printTrace('Fingerprint write error: $e');
......
...@@ -28,7 +28,6 @@ Future<void> processPodsIfNeeded( ...@@ -28,7 +28,6 @@ Future<void> processPodsIfNeeded(
paths: <String>[ paths: <String>[
xcodeProject.xcodeProjectInfoFile.path, xcodeProject.xcodeProjectInfoFile.path,
xcodeProject.podfile.path, xcodeProject.podfile.path,
xcodeProject.generatedXcodePropertiesFile.path,
globals.fs.path.join( globals.fs.path.join(
Cache.flutterRoot!, Cache.flutterRoot!,
'packages', 'packages',
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
import 'dart:convert' show json; import 'dart:convert' show json;
import 'package:file/memory.dart'; import 'package:file/memory.dart';
import 'package:file_testing/file_testing.dart';
import 'package:flutter_tools/src/base/fingerprint.dart'; import 'package:flutter_tools/src/base/fingerprint.dart';
import 'package:flutter_tools/src/base/logger.dart'; import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/utils.dart'; import 'package:flutter_tools/src/base/utils.dart';
...@@ -57,29 +58,33 @@ void main() { ...@@ -57,29 +58,33 @@ void main() {
); );
expect(fingerprinter.doesFingerprintMatch(), isFalse); expect(fingerprinter.doesFingerprintMatch(), isFalse);
}); });
testWithoutContext('fingerprint does match if identical', () { testWithoutContext('fingerprint does match if identical', () {
fileSystem.file('a.dart').createSync(); fileSystem.file('a.dart').createSync();
fileSystem.file('b.dart').createSync(); fileSystem.file('b.dart').createSync();
const String fingerprintPath = 'path/to/out.fingerprint';
final Fingerprinter fingerprinter = Fingerprinter( final Fingerprinter fingerprinter = Fingerprinter(
fingerprintPath: 'out.fingerprint', fingerprintPath: fingerprintPath,
paths: <String>['a.dart', 'b.dart'], paths: <String>['a.dart', 'b.dart'],
fileSystem: fileSystem, fileSystem: fileSystem,
logger: BufferLogger.test(), logger: BufferLogger.test(),
); );
fingerprinter.writeFingerprint(); fingerprinter.writeFingerprint();
expect(fingerprinter.doesFingerprintMatch(), isTrue); expect(fingerprinter.doesFingerprintMatch(), isTrue);
expect(fileSystem.file(fingerprintPath), exists);
}); });
testWithoutContext('fails to write fingerprint if inputs are missing', () { testWithoutContext('fails to write fingerprint if inputs are missing', () {
const String fingerprintPath = 'path/to/out.fingerprint';
final Fingerprinter fingerprinter = Fingerprinter( final Fingerprinter fingerprinter = Fingerprinter(
fingerprintPath: 'out.fingerprint', fingerprintPath: fingerprintPath,
paths: <String>['a.dart'], paths: <String>['a.dart'],
fileSystem: fileSystem, fileSystem: fileSystem,
logger: BufferLogger.test(), logger: BufferLogger.test(),
); );
fingerprinter.writeFingerprint(); fingerprinter.writeFingerprint();
expect(fileSystem.file('out.fingerprint').existsSync(), isFalse); expect(fileSystem.file(fingerprintPath), isNot(exists));
}); });
group('Fingerprint', () { group('Fingerprint', () {
......
...@@ -11,7 +11,12 @@ import 'test_utils.dart'; ...@@ -11,7 +11,12 @@ import 'test_utils.dart';
void main() { void main() {
test('flutter build ios --config only updates generated xcconfig file without performing build', () async { test('flutter build ios --config only updates generated xcconfig file without performing build', () async {
final String workingDirectory = fileSystem.path.join(getFlutterRoot(), 'examples', 'hello_world'); final String workingDirectory = fileSystem.path.join(
getFlutterRoot(),
'dev',
'integration_tests',
'flutter_gallery',
);
final String flutterBin = fileSystem.path.join(getFlutterRoot(), 'bin', 'flutter'); final String flutterBin = fileSystem.path.join(getFlutterRoot(), 'bin', 'flutter');
await processManager.run(<String>[ await processManager.run(<String>[
...@@ -19,7 +24,7 @@ void main() { ...@@ -19,7 +24,7 @@ void main() {
...getLocalEngineArguments(), ...getLocalEngineArguments(),
'clean', 'clean',
], workingDirectory: workingDirectory); ], workingDirectory: workingDirectory);
final ProcessResult result = await processManager.run(<String>[ final List<String> buildCommand = <String>[
flutterBin, flutterBin,
...getLocalEngineArguments(), ...getLocalEngineArguments(),
'build', 'build',
...@@ -29,25 +34,48 @@ void main() { ...@@ -29,25 +34,48 @@ void main() {
'--obfuscate', '--obfuscate',
'--split-debug-info=info', '--split-debug-info=info',
'--no-codesign', '--no-codesign',
], workingDirectory: workingDirectory); ];
final ProcessResult firstRunResult = await processManager.run(buildCommand, workingDirectory: workingDirectory);
printOnFailure('Output of flutter build ios:'); printOnFailure('Output of flutter build ios:');
printOnFailure(result.stdout.toString()); final String firstRunStdout = firstRunResult.stdout.toString();
printOnFailure(result.stderr.toString()); printOnFailure('First run stdout: $firstRunStdout');
printOnFailure('First run stderr: ${firstRunResult.stderr.toString()}');
expect(result.exitCode, 0); expect(firstRunResult.exitCode, 0);
expect(firstRunStdout, contains('Running pod install'));
final File generatedConfig = fileSystem.file( final File generatedConfig = fileSystem.file(fileSystem.path.join(
fileSystem.path.join(workingDirectory, 'ios', 'Flutter', 'Generated.xcconfig')); workingDirectory,
'ios',
'Flutter',
'Generated.xcconfig',
));
// Config is updated if command succeeded. // Config is updated if command succeeded.
expect(generatedConfig, exists); expect(generatedConfig, exists);
expect(generatedConfig.readAsStringSync(), contains('DART_OBFUSCATION=true')); expect(generatedConfig.readAsStringSync(), contains('DART_OBFUSCATION=true'));
// file that only exists if app was fully built. // file that only exists if app was fully built.
final File frameworkPlist = fileSystem.file( final File frameworkPlist = fileSystem.file(fileSystem.path.join(
fileSystem.path.join(workingDirectory, 'build', 'ios', 'iphoneos', 'Runner.app', 'AppFrameworkInfo.plist')); workingDirectory,
'build',
'ios',
'iphoneos',
'Runner.app',
'AppFrameworkInfo.plist',
));
expect(frameworkPlist, isNot(exists)); expect(frameworkPlist, isNot(exists));
// Run again with no changes.
final ProcessResult secondRunResult = await processManager.run(buildCommand, workingDirectory: workingDirectory);
final String secondRunStdout = secondRunResult.stdout.toString();
printOnFailure('Second run stdout: $secondRunStdout');
printOnFailure('Second run stderr: ${secondRunResult.stderr.toString()}');
expect(secondRunResult.exitCode, 0);
// Do not run "pod install" when nothing changes.
expect(secondRunStdout, isNot(contains('pod install')));
}, skip: !platform.isMacOS); // [intended] iOS builds only work on macos. }, skip: !platform.isMacOS); // [intended] iOS builds only work on macos.
} }
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