mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
![auto-submit[bot]](/assets/img/avatar_default.png)
Reverts: flutter/flutter#145376 Initiated by: loic-sharma Reason for reverting: It caused the following post-submit failures: 1. https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket/8752928710548811665/+/u/run_run_release_test_windows/stdout 2. https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket/8752927564747697169/+/u/run_run_release_test_windows/stdout Original PR Author: guidezpl Reviewed By: {loic-sharma} This change reverts the following previous change: Reland #128236, reverted in https://github.com/flutter/flutter/pull/143125 and https://github.com/flutter/flutter/pull/145261. This PR contains 3 additional commits, fixing post-submit tests on Android and Windows. ## 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
766 lines
23 KiB
Dart
766 lines
23 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:archive/archive.dart';
|
|
import 'package:file/file.dart';
|
|
import 'package:file/memory.dart';
|
|
import 'package:file_testing/file_testing.dart';
|
|
import 'package:flutter_tools/src/base/file_system.dart';
|
|
import 'package:flutter_tools/src/base/logger.dart';
|
|
import 'package:flutter_tools/src/base/os.dart';
|
|
import 'package:flutter_tools/src/base/platform.dart';
|
|
|
|
import '../../src/common.dart';
|
|
import '../../src/fake_process_manager.dart';
|
|
|
|
const String kExecutable = 'foo';
|
|
const String kPath1 = '/bar/bin/$kExecutable';
|
|
const String kPath2 = '/another/bin/$kExecutable';
|
|
|
|
void main() {
|
|
late FakeProcessManager fakeProcessManager;
|
|
|
|
setUp(() {
|
|
fakeProcessManager = FakeProcessManager.empty();
|
|
});
|
|
|
|
OperatingSystemUtils createOSUtils(Platform platform) {
|
|
return OperatingSystemUtils(
|
|
fileSystem: MemoryFileSystem.test(),
|
|
logger: BufferLogger.test(),
|
|
platform: platform,
|
|
processManager: fakeProcessManager,
|
|
);
|
|
}
|
|
|
|
group('which on POSIX', () {
|
|
testWithoutContext('returns null when executable does not exist', () async {
|
|
fakeProcessManager.addCommand(
|
|
const FakeCommand(
|
|
command: <String>[
|
|
'which',
|
|
kExecutable,
|
|
],
|
|
exitCode: 1,
|
|
),
|
|
);
|
|
final OperatingSystemUtils utils = createOSUtils(FakePlatform());
|
|
expect(utils.which(kExecutable), isNull);
|
|
});
|
|
|
|
testWithoutContext('returns exactly one result', () async {
|
|
fakeProcessManager.addCommand(
|
|
const FakeCommand(
|
|
command: <String>[
|
|
'which',
|
|
'foo',
|
|
],
|
|
stdout: kPath1,
|
|
),
|
|
);
|
|
final OperatingSystemUtils utils = createOSUtils(FakePlatform());
|
|
expect(utils.which(kExecutable)!.path, kPath1);
|
|
});
|
|
|
|
testWithoutContext('returns all results for whichAll', () async {
|
|
fakeProcessManager.addCommand(
|
|
const FakeCommand(
|
|
command: <String>[
|
|
'which',
|
|
'-a',
|
|
kExecutable,
|
|
],
|
|
stdout: '$kPath1\n$kPath2',
|
|
),
|
|
);
|
|
final OperatingSystemUtils utils = createOSUtils(FakePlatform());
|
|
final List<File> result = utils.whichAll(kExecutable);
|
|
expect(result, hasLength(2));
|
|
expect(result[0].path, kPath1);
|
|
expect(result[1].path, kPath2);
|
|
});
|
|
});
|
|
|
|
group('which on Windows', () {
|
|
testWithoutContext('throws tool exit if where.exe cannot be run', () async {
|
|
fakeProcessManager.excludedExecutables.add('where');
|
|
|
|
final OperatingSystemUtils utils = OperatingSystemUtils(
|
|
fileSystem: MemoryFileSystem.test(),
|
|
logger: BufferLogger.test(),
|
|
platform: FakePlatform(operatingSystem: 'windows'),
|
|
processManager: fakeProcessManager,
|
|
);
|
|
|
|
expect(() => utils.which(kExecutable), throwsToolExit());
|
|
});
|
|
|
|
testWithoutContext('returns null when executable does not exist', () async {
|
|
fakeProcessManager.addCommand(
|
|
const FakeCommand(
|
|
command: <String>[
|
|
'where',
|
|
kExecutable,
|
|
],
|
|
exitCode: 1,
|
|
),
|
|
);
|
|
|
|
final OperatingSystemUtils utils = createOSUtils(FakePlatform(operatingSystem: 'windows'));
|
|
expect(utils.which(kExecutable), isNull);
|
|
});
|
|
|
|
testWithoutContext('returns exactly one result', () async {
|
|
fakeProcessManager.addCommand(
|
|
const FakeCommand(
|
|
command: <String>[
|
|
'where',
|
|
'foo',
|
|
],
|
|
stdout: '$kPath1\n$kPath2',
|
|
),
|
|
);
|
|
final OperatingSystemUtils utils = createOSUtils(FakePlatform(operatingSystem: 'windows'));
|
|
expect(utils.which(kExecutable)!.path, kPath1);
|
|
});
|
|
|
|
testWithoutContext('returns all results for whichAll', () async {
|
|
fakeProcessManager.addCommand(
|
|
const FakeCommand(
|
|
command: <String>[
|
|
'where',
|
|
kExecutable,
|
|
],
|
|
stdout: '$kPath1\n$kPath2',
|
|
),
|
|
);
|
|
final OperatingSystemUtils utils = createOSUtils(FakePlatform(operatingSystem: 'windows'));
|
|
final List<File> result = utils.whichAll(kExecutable);
|
|
expect(result, hasLength(2));
|
|
expect(result[0].path, kPath1);
|
|
expect(result[1].path, kPath2);
|
|
});
|
|
});
|
|
|
|
group('host platform', () {
|
|
testWithoutContext('unknown defaults to Linux', () async {
|
|
fakeProcessManager.addCommand(
|
|
const FakeCommand(
|
|
command: <String>[
|
|
'uname',
|
|
'-m',
|
|
],
|
|
stdout: 'x86_64',
|
|
),
|
|
);
|
|
|
|
final OperatingSystemUtils utils =
|
|
createOSUtils(FakePlatform(operatingSystem: 'fuchsia'));
|
|
expect(utils.hostPlatform, HostPlatform.linux_x64);
|
|
});
|
|
|
|
testWithoutContext('Windows default', () async {
|
|
final OperatingSystemUtils utils =
|
|
createOSUtils(FakePlatform(operatingSystem: 'windows'));
|
|
expect(utils.hostPlatform, HostPlatform.windows_x64);
|
|
});
|
|
|
|
testWithoutContext('Linux x64', () async {
|
|
fakeProcessManager.addCommand(
|
|
const FakeCommand(
|
|
command: <String>[
|
|
'uname',
|
|
'-m',
|
|
],
|
|
stdout: 'x86_64',
|
|
),
|
|
);
|
|
|
|
final OperatingSystemUtils utils =
|
|
createOSUtils(FakePlatform());
|
|
expect(utils.hostPlatform, HostPlatform.linux_x64);
|
|
});
|
|
|
|
testWithoutContext('Linux ARM', () async {
|
|
fakeProcessManager.addCommand(
|
|
const FakeCommand(
|
|
command: <String>[
|
|
'uname',
|
|
'-m',
|
|
],
|
|
stdout: 'aarch64',
|
|
),
|
|
);
|
|
|
|
final OperatingSystemUtils utils =
|
|
createOSUtils(FakePlatform());
|
|
expect(utils.hostPlatform, HostPlatform.linux_arm64);
|
|
});
|
|
|
|
testWithoutContext('macOS ARM', () async {
|
|
fakeProcessManager.addCommands(
|
|
<FakeCommand>[
|
|
const FakeCommand(
|
|
command: <String>[
|
|
'which',
|
|
'sysctl',
|
|
],
|
|
),
|
|
const FakeCommand(
|
|
command: <String>[
|
|
'sysctl',
|
|
'hw.optional.arm64',
|
|
],
|
|
stdout: 'hw.optional.arm64: 1',
|
|
),
|
|
],
|
|
);
|
|
|
|
final OperatingSystemUtils utils =
|
|
createOSUtils(FakePlatform(operatingSystem: 'macos'));
|
|
expect(utils.hostPlatform, HostPlatform.darwin_arm64);
|
|
});
|
|
|
|
testWithoutContext('macOS 11 x86', () async {
|
|
fakeProcessManager.addCommands(
|
|
<FakeCommand>[
|
|
const FakeCommand(
|
|
command: <String>[
|
|
'which',
|
|
'sysctl',
|
|
],
|
|
),
|
|
const FakeCommand(
|
|
command: <String>[
|
|
'sysctl',
|
|
'hw.optional.arm64',
|
|
],
|
|
stdout: 'hw.optional.arm64: 0',
|
|
),
|
|
],
|
|
);
|
|
|
|
final OperatingSystemUtils utils =
|
|
createOSUtils(FakePlatform(operatingSystem: 'macos'));
|
|
expect(utils.hostPlatform, HostPlatform.darwin_x64);
|
|
});
|
|
|
|
testWithoutContext('sysctl not found', () async {
|
|
fakeProcessManager.addCommands(
|
|
<FakeCommand>[
|
|
const FakeCommand(
|
|
command: <String>[
|
|
'which',
|
|
'sysctl',
|
|
],
|
|
exitCode: 1,
|
|
),
|
|
],
|
|
);
|
|
|
|
final OperatingSystemUtils utils =
|
|
createOSUtils(FakePlatform(operatingSystem: 'macos'));
|
|
expect(() => utils.hostPlatform, throwsToolExit(message: 'sysctl'));
|
|
});
|
|
|
|
testWithoutContext('macOS 10 x86', () async {
|
|
fakeProcessManager.addCommands(
|
|
<FakeCommand>[
|
|
const FakeCommand(
|
|
command: <String>[
|
|
'which',
|
|
'sysctl',
|
|
],
|
|
),
|
|
const FakeCommand(
|
|
command: <String>[
|
|
'sysctl',
|
|
'hw.optional.arm64',
|
|
],
|
|
exitCode: 1,
|
|
),
|
|
],
|
|
);
|
|
|
|
final OperatingSystemUtils utils =
|
|
createOSUtils(FakePlatform(operatingSystem: 'macos'));
|
|
expect(utils.hostPlatform, HostPlatform.darwin_x64);
|
|
});
|
|
|
|
testWithoutContext('macOS ARM name', () async {
|
|
fakeProcessManager.addCommands(<FakeCommand>[
|
|
const FakeCommand(
|
|
command: <String>[
|
|
'sw_vers',
|
|
'-productName',
|
|
],
|
|
stdout: 'product',
|
|
),
|
|
const FakeCommand(
|
|
command: <String>[
|
|
'sw_vers',
|
|
'-productVersion',
|
|
],
|
|
stdout: 'version',
|
|
),
|
|
const FakeCommand(
|
|
command: <String>[
|
|
'sw_vers',
|
|
'-buildVersion',
|
|
],
|
|
stdout: 'build',
|
|
),
|
|
const FakeCommand(
|
|
command: <String>[
|
|
'uname',
|
|
'-m',
|
|
],
|
|
stdout: 'arm64',
|
|
),
|
|
const FakeCommand(
|
|
command: <String>[
|
|
'which',
|
|
'sysctl',
|
|
],
|
|
),
|
|
const FakeCommand(
|
|
command: <String>[
|
|
'sysctl',
|
|
'hw.optional.arm64',
|
|
],
|
|
stdout: 'hw.optional.arm64: 1',
|
|
),
|
|
]);
|
|
|
|
final OperatingSystemUtils utils =
|
|
createOSUtils(FakePlatform(operatingSystem: 'macos'));
|
|
expect(utils.name, 'product version build darwin-arm64');
|
|
});
|
|
|
|
testWithoutContext('macOS ARM on Rosetta name', () async {
|
|
fakeProcessManager.addCommands(<FakeCommand>[
|
|
const FakeCommand(
|
|
command: <String>[
|
|
'sw_vers',
|
|
'-productName',
|
|
],
|
|
stdout: 'product',
|
|
),
|
|
const FakeCommand(
|
|
command: <String>[
|
|
'sw_vers',
|
|
'-productVersion',
|
|
],
|
|
stdout: 'version',
|
|
),
|
|
const FakeCommand(
|
|
command: <String>[
|
|
'sw_vers',
|
|
'-buildVersion',
|
|
],
|
|
stdout: 'build',
|
|
),
|
|
const FakeCommand(
|
|
command: <String>[
|
|
'uname',
|
|
'-m',
|
|
],
|
|
stdout: 'x86_64', // Running on Rosetta
|
|
),
|
|
const FakeCommand(
|
|
command: <String>[
|
|
'which',
|
|
'sysctl',
|
|
],
|
|
),
|
|
const FakeCommand(
|
|
command: <String>[
|
|
'sysctl',
|
|
'hw.optional.arm64',
|
|
],
|
|
stdout: 'hw.optional.arm64: 1',
|
|
),
|
|
]);
|
|
|
|
final OperatingSystemUtils utils =
|
|
createOSUtils(FakePlatform(operatingSystem: 'macos'));
|
|
expect(utils.name, 'product version build darwin-arm64 (Rosetta)');
|
|
});
|
|
|
|
testWithoutContext('macOS x86 name', () async {
|
|
fakeProcessManager.addCommands(<FakeCommand>[
|
|
const FakeCommand(
|
|
command: <String>[
|
|
'sw_vers',
|
|
'-productName',
|
|
],
|
|
stdout: 'product',
|
|
),
|
|
const FakeCommand(
|
|
command: <String>[
|
|
'sw_vers',
|
|
'-productVersion',
|
|
],
|
|
stdout: 'version',
|
|
),
|
|
const FakeCommand(
|
|
command: <String>[
|
|
'sw_vers',
|
|
'-buildVersion',
|
|
],
|
|
stdout: 'build',
|
|
),
|
|
const FakeCommand(
|
|
command: <String>[
|
|
'uname',
|
|
'-m',
|
|
],
|
|
stdout: 'x86_64',
|
|
),
|
|
const FakeCommand(
|
|
command: <String>[
|
|
'which',
|
|
'sysctl',
|
|
],
|
|
),
|
|
const FakeCommand(
|
|
command: <String>[
|
|
'sysctl',
|
|
'hw.optional.arm64',
|
|
],
|
|
exitCode: 1,
|
|
),
|
|
]);
|
|
|
|
final OperatingSystemUtils utils =
|
|
createOSUtils(FakePlatform(operatingSystem: 'macos'));
|
|
expect(utils.name, 'product version build darwin-x64');
|
|
});
|
|
|
|
testWithoutContext('Windows name', () async {
|
|
fakeProcessManager.addCommands(<FakeCommand>[
|
|
const FakeCommand(
|
|
command: <String>[
|
|
'ver',
|
|
],
|
|
stdout: 'version',
|
|
),
|
|
]);
|
|
|
|
final OperatingSystemUtils utils =
|
|
createOSUtils(FakePlatform(operatingSystem: 'windows'));
|
|
expect(utils.name, 'version');
|
|
});
|
|
|
|
testWithoutContext('Linux name', () async {
|
|
const String fakeOsRelease = '''
|
|
NAME="Name"
|
|
ID=id
|
|
ID_LIKE=id_like
|
|
BUILD_ID=build_id
|
|
PRETTY_NAME="Pretty Name"
|
|
ANSI_COLOR="ansi color"
|
|
HOME_URL="https://home.url/"
|
|
DOCUMENTATION_URL="https://documentation.url/"
|
|
SUPPORT_URL="https://support.url/"
|
|
BUG_REPORT_URL="https://bug.report.url/"
|
|
LOGO=logo
|
|
''';
|
|
final FileSystem fileSystem = MemoryFileSystem.test();
|
|
fileSystem.directory('/etc').createSync();
|
|
fileSystem.file('/etc/os-release').writeAsStringSync(fakeOsRelease);
|
|
|
|
final OperatingSystemUtils utils = OperatingSystemUtils(
|
|
fileSystem: fileSystem,
|
|
logger: BufferLogger.test(),
|
|
platform: FakePlatform(
|
|
operatingSystemVersion: 'Linux 1.2.3-abcd #1 SMP PREEMPT Sat Jan 1 00:00:00 UTC 2000',
|
|
),
|
|
processManager: fakeProcessManager,
|
|
);
|
|
expect(utils.name, 'Pretty Name 1.2.3-abcd');
|
|
});
|
|
|
|
testWithoutContext('Linux name reads from "/usr/lib/os-release" if "/etc/os-release" is missing', () async {
|
|
const String fakeOsRelease = '''
|
|
NAME="Name"
|
|
ID=id
|
|
ID_LIKE=id_like
|
|
BUILD_ID=build_id
|
|
PRETTY_NAME="Pretty Name"
|
|
ANSI_COLOR="ansi color"
|
|
HOME_URL="https://home.url/"
|
|
DOCUMENTATION_URL="https://documentation.url/"
|
|
SUPPORT_URL="https://support.url/"
|
|
BUG_REPORT_URL="https://bug.report.url/"
|
|
LOGO=logo
|
|
''';
|
|
final FileSystem fileSystem = MemoryFileSystem.test();
|
|
fileSystem.directory('/usr/lib').createSync(recursive: true);
|
|
fileSystem.file('/usr/lib/os-release').writeAsStringSync(fakeOsRelease);
|
|
|
|
expect(fileSystem.file('/etc/os-release').existsSync(), false);
|
|
|
|
final OperatingSystemUtils utils = OperatingSystemUtils(
|
|
fileSystem: fileSystem,
|
|
logger: BufferLogger.test(),
|
|
platform: FakePlatform(
|
|
operatingSystemVersion: 'Linux 1.2.3-abcd #1 SMP PREEMPT Sat Jan 1 00:00:00 UTC 2000',
|
|
),
|
|
processManager: fakeProcessManager,
|
|
);
|
|
expect(utils.name, 'Pretty Name 1.2.3-abcd');
|
|
});
|
|
|
|
testWithoutContext('Linux name when reading "/etc/os-release" fails', () async {
|
|
final FileExceptionHandler handler = FileExceptionHandler();
|
|
final FileSystem fileSystem = MemoryFileSystem.test(opHandle: handler.opHandle);
|
|
|
|
fileSystem.directory('/etc').createSync();
|
|
final File osRelease = fileSystem.file('/etc/os-release');
|
|
|
|
handler.addError(osRelease, FileSystemOp.read, const FileSystemException());
|
|
|
|
final OperatingSystemUtils utils = OperatingSystemUtils(
|
|
fileSystem: fileSystem,
|
|
logger: BufferLogger.test(),
|
|
platform: FakePlatform(
|
|
operatingSystemVersion: 'Linux 1.2.3-abcd #1 SMP PREEMPT Sat Jan 1 00:00:00 UTC 2000',
|
|
),
|
|
processManager: fakeProcessManager,
|
|
);
|
|
expect(utils.name, 'Linux 1.2.3-abcd');
|
|
});
|
|
|
|
testWithoutContext('Linux name omits kernel release if undefined', () async {
|
|
const String fakeOsRelease = '''
|
|
NAME="Name"
|
|
ID=id
|
|
ID_LIKE=id_like
|
|
BUILD_ID=build_id
|
|
PRETTY_NAME="Pretty Name"
|
|
ANSI_COLOR="ansi color"
|
|
HOME_URL="https://home.url/"
|
|
DOCUMENTATION_URL="https://documentation.url/"
|
|
SUPPORT_URL="https://support.url/"
|
|
BUG_REPORT_URL="https://bug.report.url/"
|
|
LOGO=logo
|
|
''';
|
|
final FileSystem fileSystem = MemoryFileSystem.test();
|
|
fileSystem.directory('/etc').createSync();
|
|
fileSystem.file('/etc/os-release').writeAsStringSync(fakeOsRelease);
|
|
|
|
final OperatingSystemUtils utils = OperatingSystemUtils(
|
|
fileSystem: fileSystem,
|
|
logger: BufferLogger.test(),
|
|
platform: FakePlatform(
|
|
operatingSystemVersion: 'undefinedOperatingSystemVersion',
|
|
),
|
|
processManager: fakeProcessManager,
|
|
);
|
|
expect(utils.name, 'Pretty Name');
|
|
});
|
|
|
|
// See https://snyk.io/research/zip-slip-vulnerability for more context
|
|
testWithoutContext('Windows validates paths when unzipping', () {
|
|
// on POSIX systems we use the `unzip` binary, which will fail to extract
|
|
// files with paths outside the target directory
|
|
final OperatingSystemUtils utils = createOSUtils(FakePlatform(operatingSystem: 'windows'));
|
|
final MemoryFileSystem fs = MemoryFileSystem.test();
|
|
final File fakeZipFile = fs.file('archive.zip');
|
|
final Directory targetDirectory = fs.directory('output')..createSync(recursive: true);
|
|
const String content = 'hello, world!';
|
|
final Archive archive = Archive()..addFile(
|
|
// This file would be extracted outside of the target extraction dir
|
|
ArchiveFile(r'..\..\..\Target File.txt', content.length, content.codeUnits),
|
|
);
|
|
final List<int> zipData = ZipEncoder().encode(archive)!;
|
|
fakeZipFile.writeAsBytesSync(zipData);
|
|
expect(
|
|
() => utils.unzip(fakeZipFile, targetDirectory),
|
|
throwsA(
|
|
isA<StateError>().having(
|
|
(StateError error) => error.message,
|
|
'correct error message',
|
|
contains('Tried to extract the file '),
|
|
),
|
|
),
|
|
);
|
|
});
|
|
});
|
|
|
|
testWithoutContext('If unzip fails, include stderr in exception text', () {
|
|
const String exceptionMessage = 'Something really bad happened.';
|
|
final FileExceptionHandler handler = FileExceptionHandler();
|
|
final FileSystem fileSystem = MemoryFileSystem.test(opHandle: handler.opHandle);
|
|
|
|
fakeProcessManager.addCommand(
|
|
const FakeCommand(command: <String>[
|
|
'unzip',
|
|
'-o',
|
|
'-q',
|
|
'bar.zip',
|
|
'-d',
|
|
'foo',
|
|
], exitCode: 1, stderr: exceptionMessage),
|
|
);
|
|
|
|
final Directory foo = fileSystem.directory('foo')
|
|
..createSync();
|
|
final File bar = fileSystem.file('bar.zip')
|
|
..createSync();
|
|
handler.addError(bar, FileSystemOp.read, const FileSystemException(exceptionMessage));
|
|
|
|
final OperatingSystemUtils osUtils = OperatingSystemUtils(
|
|
fileSystem: fileSystem,
|
|
logger: BufferLogger.test(),
|
|
platform: FakePlatform(),
|
|
processManager: fakeProcessManager,
|
|
);
|
|
|
|
expect(
|
|
() => osUtils.unzip(bar, foo),
|
|
throwsProcessException(message: exceptionMessage),
|
|
);
|
|
});
|
|
|
|
group('unzip on macOS', () {
|
|
testWithoutContext('falls back to unzip when rsync cannot run', () {
|
|
final FileSystem fileSystem = MemoryFileSystem.test();
|
|
fakeProcessManager.excludedExecutables.add('rsync');
|
|
|
|
final BufferLogger logger = BufferLogger.test();
|
|
final OperatingSystemUtils macOSUtils = OperatingSystemUtils(
|
|
fileSystem: fileSystem,
|
|
logger: logger,
|
|
platform: FakePlatform(operatingSystem: 'macos'),
|
|
processManager: fakeProcessManager,
|
|
);
|
|
|
|
final Directory targetDirectory = fileSystem.currentDirectory;
|
|
fakeProcessManager.addCommand(FakeCommand(
|
|
command: <String>['unzip', '-o', '-q', 'foo.zip', '-d', targetDirectory.path],
|
|
));
|
|
|
|
macOSUtils.unzip(fileSystem.file('foo.zip'), targetDirectory);
|
|
expect(fakeProcessManager, hasNoRemainingExpectations);
|
|
expect(logger.traceText, contains('Unable to find rsync'));
|
|
});
|
|
|
|
testWithoutContext('unzip and rsyncs', () {
|
|
final FileSystem fileSystem = MemoryFileSystem.test();
|
|
|
|
final OperatingSystemUtils macOSUtils = OperatingSystemUtils(
|
|
fileSystem: fileSystem,
|
|
logger: BufferLogger.test(),
|
|
platform: FakePlatform(operatingSystem: 'macos'),
|
|
processManager: fakeProcessManager,
|
|
);
|
|
|
|
final Directory targetDirectory = fileSystem.currentDirectory;
|
|
final Directory tempDirectory = fileSystem.systemTempDirectory.childDirectory('flutter_foo.zip.rand0');
|
|
fakeProcessManager.addCommands(<FakeCommand>[
|
|
FakeCommand(
|
|
command: <String>[
|
|
'unzip',
|
|
'-o',
|
|
'-q',
|
|
'foo.zip',
|
|
'-d',
|
|
tempDirectory.path,
|
|
],
|
|
onRun: (_) {
|
|
expect(tempDirectory, exists);
|
|
tempDirectory.childDirectory('dirA').childFile('fileA').createSync(recursive: true);
|
|
tempDirectory.childDirectory('dirB').childFile('fileB').createSync(recursive: true);
|
|
},
|
|
),
|
|
FakeCommand(command: <String>[
|
|
'rsync',
|
|
'-8',
|
|
'-av',
|
|
'--delete',
|
|
tempDirectory.childDirectory('dirA').path,
|
|
targetDirectory.path,
|
|
]),
|
|
FakeCommand(command: <String>[
|
|
'rsync',
|
|
'-8',
|
|
'-av',
|
|
'--delete',
|
|
tempDirectory.childDirectory('dirB').path,
|
|
targetDirectory.path,
|
|
]),
|
|
]);
|
|
|
|
macOSUtils.unzip(fileSystem.file('foo.zip'), fileSystem.currentDirectory);
|
|
expect(fakeProcessManager, hasNoRemainingExpectations);
|
|
expect(tempDirectory, isNot(exists));
|
|
});
|
|
});
|
|
|
|
group('display an install message when unzip cannot be run', () {
|
|
testWithoutContext('Linux', () {
|
|
final FileSystem fileSystem = MemoryFileSystem.test();
|
|
fakeProcessManager.excludedExecutables.add('unzip');
|
|
|
|
final OperatingSystemUtils linuxOsUtils = OperatingSystemUtils(
|
|
fileSystem: fileSystem,
|
|
logger: BufferLogger.test(),
|
|
platform: FakePlatform(),
|
|
processManager: fakeProcessManager,
|
|
);
|
|
|
|
expect(
|
|
() => linuxOsUtils.unzip(fileSystem.file('foo.zip'), fileSystem.currentDirectory),
|
|
throwsToolExit(
|
|
message: 'Missing "unzip" tool. Unable to extract foo.zip.\n'
|
|
'Consider running "sudo apt-get install unzip".'),
|
|
);
|
|
});
|
|
|
|
testWithoutContext('macOS', () {
|
|
final FileSystem fileSystem = MemoryFileSystem.test();
|
|
fakeProcessManager.excludedExecutables.add('unzip');
|
|
|
|
final OperatingSystemUtils macOSUtils = OperatingSystemUtils(
|
|
fileSystem: fileSystem,
|
|
logger: BufferLogger.test(),
|
|
platform: FakePlatform(operatingSystem: 'macos'),
|
|
processManager: fakeProcessManager,
|
|
);
|
|
|
|
expect(
|
|
() => macOSUtils.unzip(fileSystem.file('foo.zip'), fileSystem.currentDirectory),
|
|
throwsToolExit
|
|
(message: 'Missing "unzip" tool. Unable to extract foo.zip.\n'
|
|
'Consider running "brew install unzip".'),
|
|
);
|
|
});
|
|
|
|
testWithoutContext('unknown OS', () {
|
|
final FileSystem fileSystem = MemoryFileSystem.test();
|
|
fakeProcessManager.excludedExecutables.add('unzip');
|
|
|
|
final OperatingSystemUtils unknownOsUtils = OperatingSystemUtils(
|
|
fileSystem: fileSystem,
|
|
logger: BufferLogger.test(),
|
|
platform: FakePlatform(operatingSystem: 'fuchsia'),
|
|
processManager: fakeProcessManager,
|
|
);
|
|
|
|
expect(
|
|
() => unknownOsUtils.unzip(fileSystem.file('foo.zip'), fileSystem.currentDirectory),
|
|
throwsToolExit
|
|
(message: 'Missing "unzip" tool. Unable to extract foo.zip.\n'
|
|
'Please install unzip.'),
|
|
);
|
|
});
|
|
});
|
|
|
|
testWithoutContext('stream compression level', () {
|
|
expect(OperatingSystemUtils.gzipLevel1.level, equals(1));
|
|
});
|
|
}
|