![auto-submit[bot]](/assets/img/avatar_default.png)
Reverts flutter/flutter#128236 Initiated by: vashworth Reason for reverting: Causing `Mac_pixel_7pro run_release_test` and `Mac_arm64_android run_release_test` to fail: https://ci.chromium.org/ui/p/flutter/builders/prod/Mac_pixel_7pro%20run_release_test/547/overview https://ci.chromium.org/ui/p/flutter/builders/prod/Mac_arm64_android%20run_release_test/10516/overview Original PR Author: guidezpl Reviewed By: {christopherfujino, loic-sharma} This change reverts the following previous change: Original Description: Improves the build output: 1. Gives confirmation that the build succeeded, in green 1. Gives the path to the built executable, without a trailing period to make it slightly easier to cmd/ctrl+open 1. Gives the size of the built executable (when the built executable is self contained) ### `apk`, `appbundle` <img width="607" alt="image" src="https://github.com/flutter/flutter/assets/6655696/ecc52abe-cd2e-4116-b22a-8385ae3e980d"> <img width="634" alt="image" src="https://github.com/flutter/flutter/assets/6655696/8af8bd33-c0bd-4215-9a06-9652ee019436"> ### `macos`, `ios`, `ipa` Build executables are self-contained and use a newly introduced `OperatingSystemUtils.getDirectorySize`. <img width="514" alt="image" src="https://github.com/flutter/flutter/assets/6655696/b5918a69-3959-4417-9205-4f501d185257"> <img width="581" alt="image" src="https://github.com/flutter/flutter/assets/6655696/d72fd420-18cf-4470-9e4b-b6ac10fbcd50"> <img width="616" alt="image" src="https://github.com/flutter/flutter/assets/6655696/5f235ce1-252a-4c13-898f-139f6c7bc698"> ### `windows`, `linux`, and `web` Build executables aren't self-contained, and folder size can sometimes overestimate distribution size, therefore their size isn't mentioned (see discussion below). <img width="647" alt="image" src="https://github.com/flutter/flutter/assets/6655696/7179e771-1eb7-48f6-b770-975bc073437b"> <img width="658" alt="image" src="https://github.com/flutter/flutter/assets/6655696/a6801cab-7b5a-4975-a406-f4c9fa44d7a2"> <img width="608" alt="image" src="https://github.com/flutter/flutter/assets/6655696/ee7c4125-a273-4a65-95d7-ab441edf8ac5"> ### Size reporting When applicable, the printed size matches the OS reported size. - macOS <img width="391" alt="image" src="https://github.com/flutter/flutter/assets/6655696/881cbfb1-d355-444b-ab44-c1a6343190ce"> - Windows <img width="338" alt="image" src="https://github.com/flutter/flutter/assets/6655696/3b806def-3d15-48a9-8a25-df200d6feef7"> - Linux <img width="320" alt="image" src="https://github.com/flutter/flutter/assets/6655696/89a4aa3d-2148-4f3b-b231-f93a057fee2b"> ## Related issues Part of #120127 Fixes https://github.com/flutter/flutter/issues/121401
238 lines
10 KiB
Dart
238 lines
10 KiB
Dart
// Copyright 2014 The Flutter Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
import 'package:unified_analytics/unified_analytics.dart';
|
|
|
|
import '../base/analyze_size.dart';
|
|
import '../base/common.dart';
|
|
import '../base/file_system.dart';
|
|
import '../base/logger.dart';
|
|
import '../base/project_migrator.dart';
|
|
import '../build_info.dart';
|
|
import '../convert.dart';
|
|
import '../globals.dart' as globals;
|
|
import '../ios/xcode_build_settings.dart';
|
|
import '../ios/xcodeproj.dart';
|
|
import '../migrations/xcode_project_object_version_migration.dart';
|
|
import '../migrations/xcode_script_build_phase_migration.dart';
|
|
import '../migrations/xcode_thin_binary_build_phase_input_paths_migration.dart';
|
|
import '../project.dart';
|
|
import 'cocoapod_utils.dart';
|
|
import 'migrations/flutter_application_migration.dart';
|
|
import 'migrations/macos_deployment_target_migration.dart';
|
|
import 'migrations/remove_macos_framework_link_and_embedding_migration.dart';
|
|
|
|
/// When run in -quiet mode, Xcode should only print from the underlying tasks to stdout.
|
|
/// Passing this regexp to trace moves the stdout output to stderr.
|
|
///
|
|
/// Filter out xcodebuild logging unrelated to macOS builds:
|
|
/// ```
|
|
/// xcodebuild[2096:1927385] Requested but did not find extension point with identifier Xcode.IDEKit.ExtensionPointIdentifierToBundleIdentifier for extension Xcode.DebuggerFoundation.AppExtensionToBundleIdentifierMap.watchOS of plug-in com.apple.dt.IDEWatchSupportCore
|
|
///
|
|
/// note: Using new build system
|
|
///
|
|
/// xcodebuild[61115:1017566] [MT] DVTAssertions: Warning in /System/Volumes/Data/SWE/Apps/DT/BuildRoots/BuildRoot11/ActiveBuildRoot/Library/Caches/com.apple.xbs/Sources/IDEFrameworks/IDEFrameworks-22267/IDEFoundation/Provisioning/Capabilities Infrastructure/IDECapabilityQuerySelection.swift:103
|
|
/// Details: createItemModels creation requirements should not create capability item model for a capability item model that already exists.
|
|
/// Function: createItemModels(for:itemModelSource:)
|
|
/// Thread: <_NSMainThread: 0x6000027c0280>{number = 1, name = main}
|
|
/// Please file a bug at https://feedbackassistant.apple.com with this warning message and any useful information you can provide.
|
|
|
|
/// ```
|
|
final RegExp _filteredOutput = RegExp(
|
|
r'^((?!'
|
|
r'Requested but did not find extension point with identifier|'
|
|
r'note\:|'
|
|
r'\[MT\] DVTAssertions: Warning in /System/Volumes/Data/SWE/|'
|
|
r'Details\: createItemModels|'
|
|
r'Function\: createItemModels|'
|
|
r'Thread\: <_NSMainThread\:|'
|
|
r'Please file a bug at https\://feedbackassistant\.apple\.'
|
|
r').)*$'
|
|
);
|
|
|
|
/// Builds the macOS project through xcodebuild.
|
|
// TODO(zanderso): refactor to share code with the existing iOS code.
|
|
Future<void> buildMacOS({
|
|
required FlutterProject flutterProject,
|
|
required BuildInfo buildInfo,
|
|
String? targetOverride,
|
|
required bool verboseLogging,
|
|
bool configOnly = false,
|
|
SizeAnalyzer? sizeAnalyzer,
|
|
}) async {
|
|
final Directory? xcodeWorkspace = flutterProject.macos.xcodeWorkspace;
|
|
if (xcodeWorkspace == null) {
|
|
throwToolExit('No macOS desktop project configured. '
|
|
'See https://docs.flutter.dev/desktop#add-desktop-support-to-an-existing-flutter-app '
|
|
'to learn about adding macOS support to a project.');
|
|
}
|
|
|
|
final List<ProjectMigrator> migrators = <ProjectMigrator>[
|
|
RemoveMacOSFrameworkLinkAndEmbeddingMigration(
|
|
flutterProject.macos,
|
|
globals.logger,
|
|
globals.flutterUsage,
|
|
globals.analytics,
|
|
),
|
|
MacOSDeploymentTargetMigration(flutterProject.macos, globals.logger),
|
|
XcodeProjectObjectVersionMigration(flutterProject.macos, globals.logger),
|
|
XcodeScriptBuildPhaseMigration(flutterProject.macos, globals.logger),
|
|
XcodeThinBinaryBuildPhaseInputPathsMigration(flutterProject.macos, globals.logger),
|
|
FlutterApplicationMigration(flutterProject.macos, globals.logger),
|
|
];
|
|
|
|
final ProjectMigration migration = ProjectMigration(migrators);
|
|
migration.run();
|
|
|
|
final Directory flutterBuildDir = globals.fs.directory(getMacOSBuildDirectory());
|
|
if (!flutterBuildDir.existsSync()) {
|
|
flutterBuildDir.createSync(recursive: true);
|
|
}
|
|
// Write configuration to an xconfig file in a standard location.
|
|
await updateGeneratedXcodeProperties(
|
|
project: flutterProject,
|
|
buildInfo: buildInfo,
|
|
targetOverride: targetOverride,
|
|
useMacOSConfig: true,
|
|
);
|
|
await processPodsIfNeeded(flutterProject.macos, getMacOSBuildDirectory(), buildInfo.mode);
|
|
// If the xcfilelists do not exist, create empty version.
|
|
if (!flutterProject.macos.inputFileList.existsSync()) {
|
|
flutterProject.macos.inputFileList.createSync(recursive: true);
|
|
}
|
|
if (!flutterProject.macos.outputFileList.existsSync()) {
|
|
flutterProject.macos.outputFileList.createSync(recursive: true);
|
|
}
|
|
if (configOnly) {
|
|
return;
|
|
}
|
|
|
|
final Directory xcodeProject = flutterProject.macos.xcodeProject;
|
|
|
|
// If the standard project exists, specify it to getInfo to handle the case where there are
|
|
// other Xcode projects in the macos/ directory. Otherwise pass no name, which will work
|
|
// regardless of the project name so long as there is exactly one project.
|
|
final String? xcodeProjectName = xcodeProject.existsSync() ? xcodeProject.basename : null;
|
|
final XcodeProjectInfo? projectInfo = await globals.xcodeProjectInterpreter?.getInfo(
|
|
xcodeProject.parent.path,
|
|
projectFilename: xcodeProjectName,
|
|
);
|
|
final String? scheme = projectInfo?.schemeFor(buildInfo);
|
|
if (scheme == null) {
|
|
projectInfo!.reportFlavorNotFoundAndExit();
|
|
}
|
|
final String? configuration = projectInfo?.buildConfigurationFor(buildInfo, scheme);
|
|
if (configuration == null) {
|
|
throwToolExit('Unable to find expected configuration in Xcode project.');
|
|
}
|
|
// Run the Xcode build.
|
|
final Stopwatch sw = Stopwatch()..start();
|
|
final Status status = globals.logger.startProgress(
|
|
'Building macOS application...',
|
|
);
|
|
int result;
|
|
try {
|
|
result = await globals.processUtils.stream(<String>[
|
|
'/usr/bin/env',
|
|
'xcrun',
|
|
'xcodebuild',
|
|
'-workspace', xcodeWorkspace.path,
|
|
'-configuration', configuration,
|
|
'-scheme', scheme,
|
|
'-derivedDataPath', flutterBuildDir.absolute.path,
|
|
'-destination', 'platform=macOS',
|
|
'OBJROOT=${globals.fs.path.join(flutterBuildDir.absolute.path, 'Build', 'Intermediates.noindex')}',
|
|
'SYMROOT=${globals.fs.path.join(flutterBuildDir.absolute.path, 'Build', 'Products')}',
|
|
if (verboseLogging)
|
|
'VERBOSE_SCRIPT_LOGGING=YES'
|
|
else
|
|
'-quiet',
|
|
'COMPILER_INDEX_STORE_ENABLE=NO',
|
|
...environmentVariablesAsXcodeBuildSettings(globals.platform),
|
|
],
|
|
trace: true,
|
|
stdoutErrorMatcher: verboseLogging ? null : _filteredOutput,
|
|
mapFunction: verboseLogging ? null : (String line) => _filteredOutput.hasMatch(line) ? line : null,
|
|
);
|
|
} finally {
|
|
status.cancel();
|
|
}
|
|
if (result != 0) {
|
|
throwToolExit('Build process failed');
|
|
}
|
|
await _writeCodeSizeAnalysis(buildInfo, sizeAnalyzer);
|
|
final Duration elapsedDuration = sw.elapsed;
|
|
globals.flutterUsage.sendTiming('build', 'xcode-macos', elapsedDuration);
|
|
globals.analytics.send(Event.timing(
|
|
workflow: 'build',
|
|
variableName: 'xcode-macos',
|
|
elapsedMilliseconds: elapsedDuration.inMilliseconds,
|
|
));
|
|
}
|
|
|
|
/// Performs a size analysis of the AOT snapshot and writes to an analysis file, if configured.
|
|
///
|
|
/// Size analysis will be run for release builds where the --analyze-size
|
|
/// option has been specified. By default, size analysis JSON output is written
|
|
/// to ~/.flutter-devtools/macos-code-size-analysis_NN.json.
|
|
Future<void> _writeCodeSizeAnalysis(BuildInfo buildInfo, SizeAnalyzer? sizeAnalyzer) async {
|
|
// Bail out if the size analysis option was not specified.
|
|
if (buildInfo.codeSizeDirectory == null || sizeAnalyzer == null) {
|
|
return;
|
|
}
|
|
final File? aotSnapshot = DarwinArch.values.map<File?>((DarwinArch arch) {
|
|
return globals.fs.directory(buildInfo.codeSizeDirectory).childFile('snapshot.${arch.name}.json');
|
|
// Pick the first if there are multiple for simplicity
|
|
}).firstWhere(
|
|
(File? file) => file!.existsSync(),
|
|
orElse: () => null,
|
|
);
|
|
if (aotSnapshot == null) {
|
|
throw StateError('No code size snapshot file (snapshot.<ARCH>.json) found in ${buildInfo.codeSizeDirectory}');
|
|
}
|
|
final File? precompilerTrace = DarwinArch.values.map<File?>((DarwinArch arch) {
|
|
return globals.fs.directory(buildInfo.codeSizeDirectory).childFile('trace.${arch.name}.json');
|
|
}).firstWhere(
|
|
(File? file) => file!.existsSync(),
|
|
orElse: () => null,
|
|
);
|
|
if (precompilerTrace == null) {
|
|
throw StateError('No precompiler trace file (trace.<ARCH>.json) found in ${buildInfo.codeSizeDirectory}');
|
|
}
|
|
|
|
// This analysis is only supported for release builds.
|
|
// Attempt to guess the correct .app by picking the first one.
|
|
final Directory candidateDirectory = globals.fs.directory(
|
|
globals.fs.path.join(getMacOSBuildDirectory(), 'Build', 'Products', 'Release'),
|
|
);
|
|
final Directory appDirectory = candidateDirectory.listSync()
|
|
.whereType<Directory>()
|
|
.firstWhere((Directory directory) {
|
|
return globals.fs.path.extension(directory.path) == '.app';
|
|
});
|
|
final Map<String, Object?> output = await sizeAnalyzer.analyzeAotSnapshot(
|
|
aotSnapshot: aotSnapshot,
|
|
precompilerTrace: precompilerTrace,
|
|
outputDirectory: appDirectory,
|
|
type: 'macos',
|
|
excludePath: 'Versions', // Avoid double counting caused by symlinks
|
|
);
|
|
final File outputFile = globals.fsUtils.getUniqueFile(
|
|
globals.fs
|
|
.directory(globals.fsUtils.homeDirPath)
|
|
.childDirectory('.flutter-devtools'), 'macos-code-size-analysis', 'json',
|
|
)..writeAsStringSync(jsonEncode(output));
|
|
// This message is used as a sentinel in analyze_apk_size_test.dart
|
|
globals.printStatus(
|
|
'A summary of your macOS bundle analysis can be found at: ${outputFile.path}',
|
|
);
|
|
|
|
// DevTools expects a file path relative to the .flutter-devtools/ dir.
|
|
final String relativeAppSizePath = outputFile.path.split('.flutter-devtools/').last.trim();
|
|
globals.printStatus(
|
|
'\nTo analyze your app size in Dart DevTools, run the following command:\n'
|
|
'dart devtools --appSizeBase=$relativeAppSizePath'
|
|
);
|
|
}
|