2019-11-27 23:04:02 +00:00
|
|
|
// Copyright 2014 The Flutter Authors. All rights reserved.
|
2019-05-11 07:08:29 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2021-01-27 23:17:53 +00:00
|
|
|
// @dart = 2.8
|
2020-10-20 16:50:31 +00:00
|
|
|
|
2020-07-29 01:36:05 +00:00
|
|
|
// Do not add package imports to this file.
|
2020-04-22 19:26:49 +00:00
|
|
|
import 'dart:convert'; // ignore: dart_convert_import.
|
2019-12-13 20:23:12 +00:00
|
|
|
import 'dart:io'; // ignore: dart_io_import.
|
2019-05-11 07:08:29 +00:00
|
|
|
|
2019-05-15 23:32:47 +00:00
|
|
|
/// Executes the required flutter tasks for a desktop build.
|
2019-05-11 07:08:29 +00:00
|
|
|
Future<void> main(List<String> arguments) async {
|
|
|
|
final String targetPlatform = arguments[0];
|
2019-09-13 02:13:42 +00:00
|
|
|
final String buildMode = arguments[1].toLowerCase();
|
2019-05-11 07:08:29 +00:00
|
|
|
|
2020-04-23 19:29:48 +00:00
|
|
|
final String dartDefines = Platform.environment['DART_DEFINES'];
|
|
|
|
final bool dartObfuscation = Platform.environment['DART_OBFUSCATION'] == 'true';
|
|
|
|
final String extraFrontEndOptions = Platform.environment['EXTRA_FRONT_END_OPTIONS'];
|
|
|
|
final String extraGenSnapshotOptions = Platform.environment['EXTRA_GEN_SNAPSHOT_OPTIONS'];
|
2019-05-11 07:08:29 +00:00
|
|
|
final String flutterEngine = Platform.environment['FLUTTER_ENGINE'];
|
|
|
|
final String flutterRoot = Platform.environment['FLUTTER_ROOT'];
|
2020-04-23 19:29:48 +00:00
|
|
|
final String flutterTarget = Platform.environment['FLUTTER_TARGET']
|
2020-07-29 01:36:05 +00:00
|
|
|
?? pathJoin(<String>['lib', 'main.dart']);
|
[flutter_tools] support code size tooling on iOS, linux, windows, macOS, and Android on Windows (#63610)
Adds support for size analysis on iOS, macOS, linux, and Windows - using an uncompressed directory based approach. The output format is not currently specified.
Adds support for size analysis on android on windows, switching to package:archive
Updates the console format to display as a tree, allowing longer paths. Increases the number of dart libraries shown (to avoid only ever printing the flutter/dart:ui libraries, which dominate the size)
2020-08-25 17:00:24 +00:00
|
|
|
final String codeSizeDirectory = Platform.environment['CODE_SIZE_DIRECTORY'];
|
2020-04-23 19:29:48 +00:00
|
|
|
final String localEngine = Platform.environment['LOCAL_ENGINE'];
|
|
|
|
final String projectDirectory = Platform.environment['PROJECT_DIR'];
|
|
|
|
final String splitDebugInfo = Platform.environment['SPLIT_DEBUG_INFO'];
|
2020-06-09 18:15:52 +00:00
|
|
|
final String bundleSkSLPath = Platform.environment['BUNDLE_SKSL_PATH'];
|
2020-04-23 19:29:48 +00:00
|
|
|
final bool trackWidgetCreation = Platform.environment['TRACK_WIDGET_CREATION'] == 'true';
|
|
|
|
final bool treeShakeIcons = Platform.environment['TREE_SHAKE_ICONS'] == 'true';
|
|
|
|
final bool verbose = Platform.environment['VERBOSE_SCRIPT_LOGGING'] == 'true';
|
2021-01-14 21:39:05 +00:00
|
|
|
final bool prefixedErrors = Platform.environment['PREFIXED_ERROR_LOGGING'] == 'true';
|
2020-04-23 19:29:48 +00:00
|
|
|
|
2019-05-11 07:08:29 +00:00
|
|
|
Directory.current = projectDirectory;
|
|
|
|
|
|
|
|
if (localEngine != null && !localEngine.contains(buildMode)) {
|
|
|
|
stderr.write('''
|
|
|
|
ERROR: Requested build with Flutter local engine at '$localEngine'
|
|
|
|
This engine is not compatible with FLUTTER_BUILD_MODE: '$buildMode'.
|
|
|
|
You can fix this by updating the LOCAL_ENGINE environment variable, or
|
|
|
|
by running:
|
2019-05-15 23:32:47 +00:00
|
|
|
flutter build <platform> --local-engine=host_$buildMode
|
2019-05-11 07:08:29 +00:00
|
|
|
or
|
2019-05-15 23:32:47 +00:00
|
|
|
flutter build <platform> --local-engine=host_${buildMode}_unopt
|
2019-05-11 07:08:29 +00:00
|
|
|
========================================================================
|
|
|
|
''');
|
|
|
|
exit(1);
|
|
|
|
}
|
2020-07-29 01:36:05 +00:00
|
|
|
final String flutterExecutable = pathJoin(<String>[
|
|
|
|
flutterRoot,
|
|
|
|
'bin',
|
|
|
|
if (Platform.isWindows)
|
|
|
|
'flutter.bat'
|
|
|
|
else
|
|
|
|
'flutter'
|
|
|
|
]);
|
2021-02-12 22:25:30 +00:00
|
|
|
final String bundlePlatform = targetPlatform == 'windows-x64' ? 'windows' : targetPlatform;
|
2020-05-29 22:38:02 +00:00
|
|
|
final String target = '${buildMode}_bundle_${bundlePlatform}_assets';
|
2020-04-22 19:26:49 +00:00
|
|
|
final Process assembleProcess = await Process.start(
|
2019-05-11 07:08:29 +00:00
|
|
|
flutterExecutable,
|
|
|
|
<String>[
|
2020-04-22 19:26:49 +00:00
|
|
|
if (verbose)
|
|
|
|
'--verbose',
|
2021-01-14 21:39:05 +00:00
|
|
|
if (prefixedErrors)
|
|
|
|
'--prefixed-errors',
|
2019-05-11 07:08:29 +00:00
|
|
|
if (flutterEngine != null) '--local-engine-src-path=$flutterEngine',
|
|
|
|
if (localEngine != null) '--local-engine=$localEngine',
|
2020-04-22 19:26:49 +00:00
|
|
|
'assemble',
|
2020-04-23 19:29:48 +00:00
|
|
|
'--output=build',
|
2020-04-22 19:26:49 +00:00
|
|
|
'-dTargetPlatform=$targetPlatform',
|
2020-04-23 19:29:48 +00:00
|
|
|
'-dTrackWidgetCreation=$trackWidgetCreation',
|
2020-05-29 22:38:02 +00:00
|
|
|
'-dBuildMode=$buildMode',
|
2020-04-22 19:26:49 +00:00
|
|
|
'-dTargetFile=$flutterTarget',
|
2020-04-23 19:29:48 +00:00
|
|
|
'-dTreeShakeIcons="$treeShakeIcons"',
|
|
|
|
'-dDartObfuscation=$dartObfuscation',
|
2020-06-09 18:15:52 +00:00
|
|
|
if (bundleSkSLPath != null)
|
|
|
|
'-iBundleSkSLPath=$bundleSkSLPath',
|
[flutter_tools] support code size tooling on iOS, linux, windows, macOS, and Android on Windows (#63610)
Adds support for size analysis on iOS, macOS, linux, and Windows - using an uncompressed directory based approach. The output format is not currently specified.
Adds support for size analysis on android on windows, switching to package:archive
Updates the console format to display as a tree, allowing longer paths. Increases the number of dart libraries shown (to avoid only ever printing the flutter/dart:ui libraries, which dominate the size)
2020-08-25 17:00:24 +00:00
|
|
|
if (codeSizeDirectory != null)
|
|
|
|
'-dCodeSizeDirectory=$codeSizeDirectory',
|
2020-04-23 19:29:48 +00:00
|
|
|
if (splitDebugInfo != null)
|
|
|
|
'-dSplitDebugInfo=$splitDebugInfo',
|
|
|
|
if (dartDefines != null)
|
|
|
|
'--DartDefines=$dartDefines',
|
|
|
|
if (extraGenSnapshotOptions != null)
|
|
|
|
'--ExtraGenSnapshotOptions=$extraGenSnapshotOptions',
|
|
|
|
if (extraFrontEndOptions != null)
|
2020-06-04 04:02:07 +00:00
|
|
|
'--ExtraFrontEndOptions=$extraFrontEndOptions',
|
2020-04-22 19:26:49 +00:00
|
|
|
target,
|
|
|
|
],
|
|
|
|
);
|
|
|
|
assembleProcess.stdout
|
|
|
|
.transform(utf8.decoder)
|
|
|
|
.transform(const LineSplitter())
|
|
|
|
.listen(stdout.writeln);
|
|
|
|
assembleProcess.stderr
|
|
|
|
.transform(utf8.decoder)
|
|
|
|
.transform(const LineSplitter())
|
|
|
|
.listen(stderr.writeln);
|
|
|
|
|
|
|
|
if (await assembleProcess.exitCode != 0) {
|
2019-05-11 07:08:29 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
2020-07-29 01:36:05 +00:00
|
|
|
|
|
|
|
/// Perform a simple path join on the segments based on the current platform.
|
|
|
|
///
|
|
|
|
/// Does not normalize paths that have repeated separators.
|
|
|
|
String pathJoin(List<String> segments) {
|
|
|
|
final String separator = Platform.isWindows ? r'\' : '/';
|
|
|
|
return segments.join(separator);
|
|
|
|
}
|