forked from firka/flutter
Reland #128236, reverted in https://github.com/flutter/flutter/pull/143125, https://github.com/flutter/flutter/pull/145261, and https://github.com/flutter/flutter/pull/145487. The errors were raised in post-submit tests on Windows. I have finally obtained a Windows machine to reproduce the errors locally and adjust the test (remove size expectation and rename output `.exe`). ## 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
This commit is contained in:
@@ -105,6 +105,18 @@ abstract class OperatingSystemUtils {
|
||||
/// Return the File representing a new pipe.
|
||||
File makePipe(String path);
|
||||
|
||||
/// Return a directory's total size in bytes.
|
||||
int? getDirectorySize(Directory directory) {
|
||||
int? size;
|
||||
for (final FileSystemEntity entity in directory.listSync(recursive: true, followLinks: false)) {
|
||||
if (entity is File) {
|
||||
size ??= 0;
|
||||
size += entity.lengthSync();
|
||||
}
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
void unzip(File file, Directory targetDirectory);
|
||||
|
||||
void unpack(File gzippedTarFile, Directory targetDirectory);
|
||||
|
||||
@@ -7,9 +7,11 @@ import 'dart:math' as math;
|
||||
|
||||
import 'package:file/file.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:path/path.dart' as path; // flutter_ignore: package_path_import
|
||||
|
||||
import '../convert.dart';
|
||||
import 'platform.dart';
|
||||
|
||||
/// A path jointer for URL paths.
|
||||
final path.Context urlContext = path.url;
|
||||
@@ -88,9 +90,14 @@ String getElapsedAsMilliseconds(Duration duration) {
|
||||
return '${kMillisecondsFormat.format(duration.inMilliseconds)}ms';
|
||||
}
|
||||
|
||||
/// Return a String - with units - for the size in MB of the given number of bytes.
|
||||
String getSizeAsMB(int bytesLength) {
|
||||
return '${(bytesLength / (1024 * 1024)).toStringAsFixed(1)}MB';
|
||||
/// Return a platform-appropriate [String] representing the size of the given number of bytes.
|
||||
String getSizeAsPlatformMB(int bytesLength, {
|
||||
@visibleForTesting Platform platform = const LocalPlatform()
|
||||
}) {
|
||||
// Because Windows displays 'MB' but actually reports MiB, we calculate MiB
|
||||
// accordingly on Windows.
|
||||
final int bytesInPlatformMB = platform.isWindows ? 1024 * 1024 : 1000 * 1000;
|
||||
return '${(bytesLength / bytesInPlatformMB).toStringAsFixed(1)}MB';
|
||||
}
|
||||
|
||||
/// A class to maintain a list of items, fire events when items are added or
|
||||
|
||||
Reference in New Issue
Block a user