Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 82 additions & 10 deletions packages/flutter_tools/lib/src/ios/mac.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ import 'package:unified_analytics/unified_analytics.dart';

import '../artifacts.dart';
import '../base/file_system.dart';
import '../base/fingerprint.dart';
import '../base/io.dart';
import '../base/logger.dart';
import '../base/process.dart';
import '../base/project_migrator.dart';
import '../base/utils.dart';
import '../base/version.dart';
import '../build_info.dart';
import '../cache.dart';
import '../darwin/darwin.dart';
Expand Down Expand Up @@ -270,6 +272,16 @@ Future<XcodeBuildResult> buildXcodeProject({
'file version field before submitting to the App Store.',
);
}
final XcodeSdk sdk = environmentType == EnvironmentType.physical
? XcodeSdk.IPhoneOS
: XcodeSdk.IPhoneSimulator;
final String buildDirectoryPath = getIosBuildDirectory();
final Directory buildDirectory = globals.fs.directory(buildDirectoryPath);
final bool incrementalBuild =
buildDirectory.existsSync() &&
buildDirectory.listSync().any(
(FileSystemEntity entity) => entity.basename.contains(sdk.platformName),
);

Map<String, String>? autoSigningConfigs;

Expand Down Expand Up @@ -310,7 +322,7 @@ Future<XcodeBuildResult> buildXcodeProject({
);
}
}
await processPodsIfNeeded(project.ios, getIosBuildDirectory(), buildInfo.mode);
await processPodsIfNeeded(project.ios, buildDirectoryPath, buildInfo.mode);
if (configOnly) {
return XcodeBuildResult(success: true);
}
Expand All @@ -322,6 +334,26 @@ Future<XcodeBuildResult> buildXcodeProject({
configuration,
];

// Check the public headers before checking Xcode version so headers fingerprinter is created
// regardless of Xcode version.
final bool headersChanged = publicHeadersChanged(
environmentType: environmentType,
mode: buildInfo.mode,
buildDirectory: buildDirectoryPath,
artifacts: globals.artifacts,
fileSystem: globals.fs,
logger: globals.logger,
);
final Version? xcodeVersion = globals.xcode?.currentVersion;
if (headersChanged &&
incrementalBuild &&
(xcodeVersion != null && xcodeVersion >= Version(26, 0, 0))) {
// Xcode 26 changed the way headers are pre-compiled and will throw an error if the headers
// have changed since the last time they were compiled. To avoid this error, clean before
// building if headers have changed.
buildCommands.addAll(<String>['clean', 'build']);
}

if (globals.logger.isVerbose) {
// An environment variable to be passed to xcode_backend.sh determining
// whether to echo back executed commands.
Expand Down Expand Up @@ -351,7 +383,7 @@ Future<XcodeBuildResult> buildXcodeProject({
scheme,
if (buildAction !=
XcodeBuildAction.archive) // dSYM files aren't copied to the archive if BUILD_DIR is set.
'BUILD_DIR=${globals.fs.path.absolute(getIosBuildDirectory())}',
'BUILD_DIR=${globals.fs.path.absolute(buildDirectoryPath)}',
]);
}

Expand All @@ -373,20 +405,14 @@ Future<XcodeBuildResult> buildXcodeProject({
return XcodeBuildResult(success: false);
}
} else {
if (environmentType == EnvironmentType.physical) {
buildCommands.addAll(<String>['-sdk', XcodeSdk.IPhoneOS.platformName]);
} else {
buildCommands.addAll(<String>['-sdk', XcodeSdk.IPhoneSimulator.platformName]);
}
buildCommands.addAll(<String>['-sdk', sdk.platformName]);
}

buildCommands.add('-destination');
if (deviceID != null) {
buildCommands.add('id=$deviceID');
} else if (environmentType == EnvironmentType.physical) {
buildCommands.add(XcodeSdk.IPhoneOS.genericPlatform);
} else {
buildCommands.add(XcodeSdk.IPhoneSimulator.genericPlatform);
buildCommands.add(sdk.genericPlatform);
}

if (activeArch != null) {
Expand Down Expand Up @@ -628,6 +654,52 @@ Future<XcodeBuildResult> buildXcodeProject({
}
}

/// Check if the Flutter framework's public headers have changed since last built.
bool publicHeadersChanged({
required BuildMode mode,
required EnvironmentType environmentType,
required String buildDirectory,
required Artifacts? artifacts,
required FileSystem fileSystem,
required Logger logger,
}) {
final String? basePath = artifacts?.getArtifactPath(
Artifact.flutterFramework,
platform: TargetPlatform.ios,
mode: mode,
environmentType: environmentType,
);
if (basePath == null) {
return false;
}
final Directory headersDirectory = fileSystem.directory(
fileSystem.path.join(basePath, 'Headers'),
);
if (!headersDirectory.existsSync()) {
return false;
}
final List<String> files = headersDirectory
.listSync()
.map<String>((FileSystemEntity header) => header.path)
.toList();

final String fingerprintPath = fileSystem.path.join(
buildDirectory,
'framework_public_headers.fingerprint',
);
final fingerprinter = Fingerprinter(
fingerprintPath: fingerprintPath,
paths: files,
fileSystem: fileSystem,
logger: logger,
);
final bool headersChanged = !fingerprinter.doesFingerprintMatch();
if (headersChanged) {
fingerprinter.writeFingerprint();
}
return headersChanged;
}

/// Extended attributes applied by Finder can cause code signing errors. Remove them.
/// https://developer.apple.com/library/archive/qa/qa1940/_index.html
Future<void> removeFinderExtendedAttributes(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import 'package:args/command_runner.dart';
import 'package:file/memory.dart';
import 'package:flutter_tools/src/android/android_sdk.dart';
import 'package:flutter_tools/src/artifacts.dart';
import 'package:flutter_tools/src/base/common.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/logger.dart';
Expand Down Expand Up @@ -314,6 +315,7 @@ void main() {
]),
Platform: () => macosPlatform,
XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(),
Artifacts: () => Artifacts.test(),
},
);

Expand Down Expand Up @@ -350,6 +352,7 @@ void main() {
Pub: ThrowingPub.new,
Platform: () => macosPlatform,
XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(),
Artifacts: () => Artifacts.test(),
},
);

Expand Down Expand Up @@ -387,6 +390,7 @@ void main() {
Pub: ThrowingPub.new,
Platform: () => macosPlatform,
XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(),
Artifacts: () => Artifacts.test(),
},
);

Expand Down Expand Up @@ -423,6 +427,7 @@ void main() {
Pub: ThrowingPub.new,
Platform: () => macosPlatform,
XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(),
Artifacts: () => Artifacts.test(),
},
);

Expand Down Expand Up @@ -470,6 +475,7 @@ void main() {
Pub: ThrowingPub.new,
Platform: () => macosPlatform,
XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(),
Artifacts: () => Artifacts.test(),
},
);

Expand Down Expand Up @@ -508,6 +514,7 @@ void main() {
Pub: ThrowingPub.new,
Platform: () => macosPlatform,
XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(),
Artifacts: () => Artifacts.test(),
},
);

Expand Down Expand Up @@ -545,6 +552,7 @@ void main() {
Pub: ThrowingPub.new,
Platform: () => macosPlatform,
XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(),
Artifacts: () => Artifacts.test(),
},
);

Expand Down Expand Up @@ -580,6 +588,7 @@ void main() {
Pub: ThrowingPub.new,
Platform: () => macosPlatform,
XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(),
Artifacts: () => Artifacts.test(),
},
);

Expand Down Expand Up @@ -642,6 +651,7 @@ void main() {
FileSystemUtils: () => FileSystemUtils(fileSystem: fileSystem, platform: macosPlatform),
Analytics: () => fakeAnalytics,
XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(),
Artifacts: () => Artifacts.test(),
},
);

Expand Down Expand Up @@ -703,6 +713,7 @@ void main() {
XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(),
Pub: ThrowingPub.new,
Analytics: () => fakeAnalytics,
Artifacts: () => Artifacts.test(),
},
);

Expand Down Expand Up @@ -766,6 +777,7 @@ void main() {
),
Pub: ThrowingPub.new,
Analytics: () => fakeAnalytics,
Artifacts: () => Artifacts.test(),
},
);
});
Expand Down Expand Up @@ -809,6 +821,7 @@ void main() {
Pub: ThrowingPub.new,
Platform: () => macosPlatform,
XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(),
Artifacts: () => Artifacts.test(),
},
);

Expand Down Expand Up @@ -857,6 +870,7 @@ void main() {
Pub: ThrowingPub.new,
Platform: () => macosPlatform,
XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(),
Artifacts: () => Artifacts.test(),
},
);

Expand Down Expand Up @@ -910,6 +924,7 @@ void main() {
Pub: ThrowingPub.new,
Platform: () => macosPlatform,
XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(),
Artifacts: () => Artifacts.test(),
},
);

Expand Down Expand Up @@ -948,6 +963,7 @@ void main() {
Pub: ThrowingPub.new,
Platform: () => macosPlatform,
XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(),
Artifacts: () => Artifacts.test(),
},
);

Expand Down Expand Up @@ -1004,6 +1020,7 @@ void main() {
Pub: ThrowingPub.new,
Platform: () => macosPlatform,
XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(),
Artifacts: () => Artifacts.test(),
},
);

Expand Down Expand Up @@ -1051,6 +1068,7 @@ void main() {
Pub: ThrowingPub.new,
Platform: () => macosPlatform,
XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(),
Artifacts: () => Artifacts.test(),
},
);

Expand Down Expand Up @@ -1092,6 +1110,7 @@ void main() {
Pub: ThrowingPub.new,
Platform: () => macosPlatform,
XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(),
Artifacts: () => Artifacts.test(),
},
);

Expand Down Expand Up @@ -1150,6 +1169,7 @@ void main() {
Pub: ThrowingPub.new,
Platform: () => macosPlatform,
XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(),
Artifacts: () => Artifacts.test(),
},
);

Expand Down Expand Up @@ -1194,6 +1214,7 @@ Runner requires a provisioning profile. Select a provisioning profile in the Sig
Pub: ThrowingPub.new,
Platform: () => macosPlatform,
XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(),
Artifacts: () => Artifacts.test(),
},
);

Expand Down Expand Up @@ -1236,6 +1257,7 @@ Runner requires a provisioning profile. Select a provisioning profile in the Sig
Platform: () => macosPlatform,
XcodeProjectInterpreter: () =>
FakeXcodeProjectInterpreterWithBuildSettings(developmentTeam: null),
Artifacts: () => Artifacts.test(),
},
);

Expand Down Expand Up @@ -1279,6 +1301,7 @@ Runner requires a provisioning profile. Select a provisioning profile in the Sig
EnvironmentType: () => EnvironmentType.physical,
Platform: () => macosPlatform,
XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(),
Artifacts: () => Artifacts.test(),
},
);

Expand Down Expand Up @@ -1320,6 +1343,7 @@ Runner requires a provisioning profile. Select a provisioning profile in the Sig
Platform: () => macosPlatform,
XcodeProjectInterpreter: () =>
FakeXcodeProjectInterpreterWithBuildSettings(developmentTeam: null),
Artifacts: () => Artifacts.test(),
},
);

Expand Down Expand Up @@ -1363,6 +1387,7 @@ Runner requires a provisioning profile. Select a provisioning profile in the Sig
Platform: () => macosPlatform,
XcodeProjectInterpreter: () =>
FakeXcodeProjectInterpreterWithBuildSettings(developmentTeam: null),
Artifacts: () => Artifacts.test(),
},
);

Expand Down Expand Up @@ -1413,6 +1438,7 @@ Runner requires a provisioning profile. Select a provisioning profile in the Sig
Platform: () => macosPlatform,
XcodeProjectInterpreter: () =>
FakeXcodeProjectInterpreterWithBuildSettings(developmentTeam: null),
Artifacts: () => Artifacts.test(),
},
);
});
Expand Down Expand Up @@ -1459,6 +1485,7 @@ Runner requires a provisioning profile. Select a provisioning profile in the Sig
Pub: ThrowingPub.new,
Platform: () => macosPlatform,
XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(),
Artifacts: () => Artifacts.test(),
},
);

Expand Down Expand Up @@ -1507,6 +1534,7 @@ Runner requires a provisioning profile. Select a provisioning profile in the Sig
Pub: ThrowingPub.new,
Platform: () => macosPlatform,
XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(),
Artifacts: () => Artifacts.test(),
},
);

Expand Down Expand Up @@ -1564,6 +1592,7 @@ Runner requires a provisioning profile. Select a provisioning profile in the Sig
Pub: ThrowingPub.new,
Platform: () => macosPlatform,
XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(),
Artifacts: () => Artifacts.test(),
},
);

Expand Down Expand Up @@ -1605,6 +1634,7 @@ Runner requires a provisioning profile. Select a provisioning profile in the Sig
Pub: ThrowingPub.new,
Platform: () => macosPlatform,
XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(),
Artifacts: () => Artifacts.test(),
},
);
});
Expand Down
Loading