[flutter_tools] opt iOS/macOS apps out of Metal API validation via migrator, update templates in repo. (#159228)
Setting "enableGPUValidationMode = "1"" disables Metal API validation. I know, I know. Fixes https://github.com/flutter/flutter/issues/159227
This commit is contained in:
@@ -36,6 +36,7 @@ import 'application_package.dart';
|
||||
import 'code_signing.dart';
|
||||
import 'migrations/host_app_info_plist_migration.dart';
|
||||
import 'migrations/ios_deployment_target_migration.dart';
|
||||
import 'migrations/metal_api_validation_migration.dart';
|
||||
import 'migrations/project_base_configuration_migration.dart';
|
||||
import 'migrations/project_build_location_migration.dart';
|
||||
import 'migrations/remove_bitcode_migration.dart';
|
||||
@@ -178,6 +179,7 @@ Future<XcodeBuildResult> buildXcodeProject({
|
||||
features: featureFlags,
|
||||
),
|
||||
SwiftPackageManagerGitignoreMigration(project, globals.logger),
|
||||
MetalAPIValidationMigrator.ios(app.project, globals.logger),
|
||||
];
|
||||
|
||||
final ProjectMigration migration = ProjectMigration(migrators);
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
// 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 '../../base/file_system.dart';
|
||||
import '../../base/project_migrator.dart';
|
||||
import '../../xcode_project.dart';
|
||||
|
||||
/// Remove Metal API validation setting that slows down applications.
|
||||
class MetalAPIValidationMigrator extends ProjectMigrator {
|
||||
MetalAPIValidationMigrator.ios(
|
||||
IosProject project,
|
||||
super.logger,
|
||||
) : _xcodeProjectScheme = project.xcodeProjectSchemeFile();
|
||||
|
||||
MetalAPIValidationMigrator.macos(
|
||||
MacOSProject project,
|
||||
super.logger,
|
||||
) : _xcodeProjectScheme = project.xcodeProjectSchemeFile();
|
||||
|
||||
final File _xcodeProjectScheme;
|
||||
|
||||
|
||||
@override
|
||||
Future<void> migrate() async {
|
||||
if (_xcodeProjectScheme.existsSync()) {
|
||||
processFileLines(_xcodeProjectScheme);
|
||||
} else {
|
||||
logger.printTrace('default xcscheme file not found. Skipping Metal API validation migration.');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
String migrateFileContents(String fileContents) {
|
||||
// If this string is anywhere in the file, assume that either we already
|
||||
// migrated it or the developer made an intentional choice to opt in or out.
|
||||
if (fileContents.contains('enableGPUValidationMode')) {
|
||||
return fileContents;
|
||||
}
|
||||
// Look for a setting that is included in LaunchAction by default and
|
||||
// insert the opt out after it.
|
||||
final RegExp kDebugServiceExtension = RegExp('(\\s)*debugServiceExtension = "internal"\n');
|
||||
const String kValidationString = 'enableGPUValidationMode = "1"';
|
||||
return fileContents.replaceFirstMapped(kDebugServiceExtension, (Match match) {
|
||||
final String group = match.group(0)!;
|
||||
final int leadingCount = group.split('debugServiceExtension')[0].codeUnits.where((int codeUnit) => codeUnit == 32).length;
|
||||
return '$group${' ' * leadingCount}$kValidationString\n';
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ import '../build_info.dart';
|
||||
import '../convert.dart';
|
||||
import '../features.dart';
|
||||
import '../globals.dart' as globals;
|
||||
import '../ios/migrations/metal_api_validation_migration.dart';
|
||||
import '../ios/xcode_build_settings.dart';
|
||||
import '../ios/xcodeproj.dart';
|
||||
import '../migrations/swift_package_manager_gitignore_migration.dart';
|
||||
@@ -103,6 +104,7 @@ Future<void> buildMacOS({
|
||||
features: featureFlags,
|
||||
),
|
||||
SwiftPackageManagerGitignoreMigration(flutterProject, globals.logger),
|
||||
MetalAPIValidationMigrator.macos(flutterProject.macos, globals.logger),
|
||||
];
|
||||
|
||||
final ProjectMigration migration = ProjectMigration(migrators);
|
||||
|
||||
Reference in New Issue
Block a user