forked from firka/flutter
Improve build time when using SwiftPM (#150052)
When using SwiftPM, we use `flutter assemble` in an Xcode Pre-action to run the `debug_unpack_macos` (or profile/release) target. This target is also later used in a Run Script build phase. Depending on `ARCHS` build setting, the Flutter/FlutterMacOS binary is thinned. In the Run Script build phase, `ARCHS` is filtered to the active arch. However, in the Pre-action it doesn't always filter to the active arch. As a workaround, assume arm64 if the [`NATIVE_ARCH`](https://developer.apple.com/documentation/xcode/build-settings-reference/#NATIVEARCH) is arm, otherwise assume x86_64. Also, this PR adds a define flag `PreBuildAction`, which gives the Pre-action a [unique configuration of defines](fdb74fd3e7/packages/flutter_tools/lib/src/build_system/build_system.dart (L355-L372)) and therefore a separate filecache from the Run Script build phase filecache. This improves caching so the Run Script build phase action doesn't find missing targets in the filecache. It also uses this flag to skip cleaning up the previous build files. Lastly, skip the Pre-action if the build command is `clean`. Note: For iOS, if [`CodesignIdentity`](14df7be3f9/packages/flutter_tools/bin/xcode_backend.dart (L470-L473)) is set, the Pre-action and Run Script build phase will not match because the Pre-action does not send the `EXPANDED_CODE_SIGN_IDENTITY` and therefore will codesign it with [`-`](14df7be3f9/packages/flutter_tools/lib/src/build_system/targets/ios.dart (L695)) instead. This will cause `debug_unpack_macos` to invalidate and rerun every time. A potential solution would be to move [codesigning out of the Run Script build phase](14df7be3f9/packages/flutter_tools/lib/src/build_system/targets/ios.dart (L299)) to the [Thin Binary build phase](14df7be3f9/packages/flutter_tools/bin/xcode_backend.dart (L204-L257)) after it's copied into the TARGET_BUILD_DIR, like we do with [macOS](14df7be3f9/packages/flutter_tools/bin/macos_assemble.sh (L179-L183)).
This commit is contained in:
committed by
GitHub
parent
d68e05bf36
commit
e18c5e209c
@@ -958,6 +958,12 @@ const String kBuildNumber = 'BuildNumber';
|
||||
/// Will be "build" when building and "install" when archiving.
|
||||
const String kXcodeAction = 'Action';
|
||||
|
||||
/// The define of the Xcode build Pre-action.
|
||||
///
|
||||
/// Will be "PrepareFramework" when copying the Flutter/FlutterMacOS framework
|
||||
/// to the BUILT_PRODUCTS_DIR prior to the build.
|
||||
const String kXcodePreAction = 'PreBuildAction';
|
||||
|
||||
final Converter<String, String> _defineEncoder = utf8.encoder.fuse(base64.encoder);
|
||||
final Converter<String, String> _defineDecoder = base64.decoder.fuse(utf8.decoder);
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ import '../base/file_system.dart';
|
||||
import '../base/logger.dart';
|
||||
import '../base/platform.dart';
|
||||
import '../base/utils.dart';
|
||||
import '../build_info.dart';
|
||||
import '../cache.dart';
|
||||
import '../convert.dart';
|
||||
import '../reporting/reporting.dart';
|
||||
@@ -735,6 +736,13 @@ class FlutterBuildSystem extends BuildSystem {
|
||||
FileSystem fileSystem,
|
||||
Map<String, File> currentOutputs,
|
||||
) {
|
||||
if (environment.defines[kXcodePreAction] == 'PrepareFramework') {
|
||||
// If the current build is the PrepareFramework Xcode pre-action, skip
|
||||
// updating the last build identifier and cleaning up the previous build
|
||||
// since this build is not a complete build.
|
||||
return;
|
||||
}
|
||||
|
||||
final String currentBuildId = fileSystem.path.basename(environment.buildDir.path);
|
||||
final File lastBuildIdFile = environment.outputDir.childFile('.last_build_id');
|
||||
if (!lastBuildIdFile.existsSync()) {
|
||||
|
||||
Reference in New Issue
Block a user