Skip to content

Commit 238dac1

Browse files
author
Jonah Williams
authored
Revert "[flutter_tools] More Linux version detail (flutter#50739)" (flutter#50840)
This reverts commit c725f10.
1 parent 1602be6 commit 238dac1

File tree

3 files changed

+83
-178
lines changed

3 files changed

+83
-178
lines changed

packages/flutter_tools/lib/src/base/os.dart

Lines changed: 14 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -251,48 +251,21 @@ class _PosixUtils extends OperatingSystemUtils {
251251

252252
@override
253253
String get name {
254-
if (_name != null) {
255-
return _name;
256-
}
257-
if (_platform.isMacOS) {
258-
return _name = _macName;
259-
} else if (_platform.isLinux) {
260-
return _name = _linuxName;
261-
}
262-
return _name = super.name;
263-
}
264-
265-
String get _macName {
266-
final List<RunResult> results = <RunResult>[
267-
_processUtils.runSync(<String>['sw_vers', '-productName']),
268-
_processUtils.runSync(<String>['sw_vers', '-productVersion']),
269-
_processUtils.runSync(<String>['sw_vers', '-buildVersion']),
270-
];
271-
if (results.every((RunResult result) => result.exitCode == 0)) {
272-
return '${results[0].stdout.trim()} '
273-
'${results[1].stdout.trim()} '
274-
'${results[2].stdout.trim()}';
275-
}
276-
return super.name;
277-
}
278-
279-
String get _linuxName {
280-
final String fullVersion = _platform.operatingSystemVersion;
281-
// This is formatted as 'Linux version build'. The 'build' part can be
282-
// somewhat long and is not very informative, so omit it.
283-
final List<String> versionParts = fullVersion.split(' ');
284-
if (versionParts.length < 2) {
285-
// The version string didn't have the expected format. Just return the
286-
// full string.
287-
return fullVersion;
288-
}
289-
final String system = versionParts[0];
290-
final String version = versionParts[1];
291-
if (system != 'Linux') {
292-
// If the system name isn't 'Linux', then just return the full string.
293-
return fullVersion;
254+
if (_name == null) {
255+
if (_platform.isMacOS) {
256+
final List<RunResult> results = <RunResult>[
257+
_processUtils.runSync(<String>['sw_vers', '-productName']),
258+
_processUtils.runSync(<String>['sw_vers', '-productVersion']),
259+
_processUtils.runSync(<String>['sw_vers', '-buildVersion']),
260+
];
261+
if (results.every((RunResult result) => result.exitCode == 0)) {
262+
_name = '${results[0].stdout.trim()} ${results[1].stdout
263+
.trim()} ${results[2].stdout.trim()}';
264+
}
265+
}
266+
_name ??= super.name;
294267
}
295-
return '$system $version';
268+
return _name;
296269
}
297270

298271
@override

packages/flutter_tools/test/general.shard/base/os_test.dart

Lines changed: 25 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,16 @@
44

55
import 'package:file/file.dart';
66
import 'package:file/memory.dart';
7+
import 'package:flutter_tools/src/base/io.dart';
78
import 'package:flutter_tools/src/base/file_system.dart';
89
import 'package:flutter_tools/src/base/logger.dart';
910
import 'package:flutter_tools/src/base/os.dart';
10-
import 'package:flutter_tools/src/globals.dart' as globals;
1111
import 'package:mockito/mockito.dart';
1212
import 'package:process/process.dart';
1313
import 'package:platform/platform.dart';
1414

1515
import '../../src/common.dart';
1616
import '../../src/context.dart';
17-
import '../../src/fake_process_manager.dart';
1817

1918
const String kExecutable = 'foo';
2019
const String kPath1 = '/bar/bin/$kExecutable';
@@ -23,51 +22,40 @@ const String kPath2 = '/another/bin/$kExecutable';
2322
class MockLogger extends Mock implements Logger {}
2423

2524
void main() {
26-
FakeProcessManager fakeProcessManager;
25+
MockProcessManager mockProcessManager;
26+
27+
setUp(() {
28+
mockProcessManager = MockProcessManager();
29+
});
2730

2831
OperatingSystemUtils createOSUtils(Platform platform) {
2932
return OperatingSystemUtils(
3033
fileSystem: MemoryFileSystem(),
3134
logger: MockLogger(),
3235
platform: platform,
33-
processManager: fakeProcessManager,
36+
processManager: mockProcessManager,
3437
);
3538
}
3639

3740
group('which on POSIX', () {
3841
testWithoutContext('returns null when executable does not exist', () async {
39-
fakeProcessManager = FakeProcessManager.list(<FakeCommand>[
40-
const FakeCommand(command: <String>['which', kExecutable], exitCode: 1),
41-
]);
42-
final OperatingSystemUtils utils = createOSUtils(
43-
FakePlatform(operatingSystem: 'linux'),
44-
);
42+
when(mockProcessManager.runSync(<String>['which', kExecutable]))
43+
.thenReturn(ProcessResult(0, 1, null, null));
44+
final OperatingSystemUtils utils = createOSUtils(FakePlatform(operatingSystem: 'linux'));
4545
expect(utils.which(kExecutable), isNull);
4646
});
4747

4848
testWithoutContext('returns exactly one result', () async {
49-
fakeProcessManager = FakeProcessManager.list(<FakeCommand>[
50-
const FakeCommand(
51-
command: <String>['which', kExecutable],
52-
stdout: kPath1,
53-
),
54-
]);
55-
final OperatingSystemUtils utils = createOSUtils(
56-
FakePlatform(operatingSystem: 'linux'),
57-
);
49+
when(mockProcessManager.runSync(<String>['which', 'foo']))
50+
.thenReturn(ProcessResult(0, 0, kPath1, null));
51+
final OperatingSystemUtils utils = createOSUtils(FakePlatform(operatingSystem: 'linux'));
5852
expect(utils.which(kExecutable).path, kPath1);
5953
});
6054

6155
testWithoutContext('returns all results for whichAll', () async {
62-
fakeProcessManager = FakeProcessManager.list(<FakeCommand>[
63-
const FakeCommand(
64-
command: <String>['which', '-a', kExecutable],
65-
stdout: '$kPath1\n$kPath2\n',
66-
),
67-
]);
68-
final OperatingSystemUtils utils = createOSUtils(
69-
FakePlatform(operatingSystem: 'linux'),
70-
);
56+
when(mockProcessManager.runSync(<String>['which', '-a', kExecutable]))
57+
.thenReturn(ProcessResult(0, 0, '$kPath1\n$kPath2', null));
58+
final OperatingSystemUtils utils = createOSUtils(FakePlatform(operatingSystem: 'linux'));
7159
final List<File> result = utils.whichAll(kExecutable);
7260
expect(result, hasLength(2));
7361
expect(result[0].path, kPath1);
@@ -77,129 +65,29 @@ void main() {
7765

7866
group('which on Windows', () {
7967
testWithoutContext('returns null when executable does not exist', () async {
80-
fakeProcessManager = FakeProcessManager.list(<FakeCommand>[
81-
const FakeCommand(
82-
command: <String>['where', kExecutable],
83-
exitCode: 1,
84-
),
85-
]);
86-
final OperatingSystemUtils utils = createOSUtils(
87-
FakePlatform(operatingSystem: 'windows'),
88-
);
68+
when(mockProcessManager.runSync(<String>['where', kExecutable]))
69+
.thenReturn(ProcessResult(0, 1, null, null));
70+
final OperatingSystemUtils utils = createOSUtils(FakePlatform(operatingSystem: 'windows'));
8971
expect(utils.which(kExecutable), isNull);
9072
});
9173

9274
testWithoutContext('returns exactly one result', () async {
93-
fakeProcessManager = FakeProcessManager.list(<FakeCommand>[
94-
const FakeCommand(
95-
command: <String>['where', kExecutable],
96-
stdout: '$kPath1\n$kPath2\n',
97-
),
98-
]);
99-
final OperatingSystemUtils utils = createOSUtils(
100-
FakePlatform(operatingSystem: 'windows'),
101-
);
75+
when(mockProcessManager.runSync(<String>['where', 'foo']))
76+
.thenReturn(ProcessResult(0, 0, '$kPath1\n$kPath2', null));
77+
final OperatingSystemUtils utils = createOSUtils(FakePlatform(operatingSystem: 'windows'));
10278
expect(utils.which(kExecutable).path, kPath1);
10379
});
10480

10581
testWithoutContext('returns all results for whichAll', () async {
106-
fakeProcessManager = FakeProcessManager.list(<FakeCommand>[
107-
const FakeCommand(
108-
command: <String>['where', kExecutable],
109-
stdout: '$kPath1\n$kPath2\n',
110-
),
111-
]);
112-
final OperatingSystemUtils utils = createOSUtils(
113-
FakePlatform(operatingSystem: 'windows'),
114-
);
82+
when(mockProcessManager.runSync(<String>['where', kExecutable]))
83+
.thenReturn(ProcessResult(0, 0, '$kPath1\n$kPath2', null));
84+
final OperatingSystemUtils utils = createOSUtils(FakePlatform(operatingSystem: 'windows'));
11585
final List<File> result = utils.whichAll(kExecutable);
11686
expect(result, hasLength(2));
11787
expect(result[0].path, kPath1);
11888
expect(result[1].path, kPath2);
11989
});
12090
});
121-
122-
group('name', () {
123-
testWithoutContext('on Linux', () {
124-
final FakePlatform platform = FakePlatform(
125-
operatingSystem: 'linux',
126-
operatingSystemVersion: 'Linux 5.2.17-amd64 '
127-
'#1 SMP Debian 5.2.17 (2019-10-21 > 2018)',
128-
);
129-
final OperatingSystemUtils utils = createOSUtils(platform);
130-
expect(utils.name, 'Linux 5.2.17-amd64');
131-
});
132-
133-
testWithoutContext('on Mac', () {
134-
fakeProcessManager = FakeProcessManager.list(<FakeCommand>[
135-
const FakeCommand(
136-
command: <String>['sw_vers', '-productName'],
137-
stdout: 'Mac OS X\n',
138-
),
139-
const FakeCommand(
140-
command: <String>['sw_vers', '-productVersion'],
141-
stdout: '10.14.6\n',
142-
),
143-
const FakeCommand(
144-
command: <String>['sw_vers', '-buildVersion'],
145-
stdout: '16G2128\n',
146-
),
147-
]);
148-
final FakePlatform platform = FakePlatform(
149-
operatingSystem: 'macos',
150-
);
151-
final OperatingSystemUtils utils = createOSUtils(platform);
152-
expect(utils.name, 'Mac OS X 10.14.6 16G2128');
153-
});
154-
155-
testWithoutContext('on Windows', () {
156-
fakeProcessManager = FakeProcessManager.list(<FakeCommand>[
157-
const FakeCommand(
158-
command: <String>['ver'],
159-
stdout: 'Microsoft Windows [Version 10.0.17763.740]',
160-
),
161-
]);
162-
final FakePlatform platform = FakePlatform(
163-
operatingSystem: 'windows',
164-
);
165-
final OperatingSystemUtils utils = createOSUtils(platform);
166-
expect(utils.name, 'Microsoft Windows [Version 10.0.17763.740]');
167-
});
168-
});
169-
170-
group('makeExecutable', () {
171-
Directory tempDir;
172-
173-
setUp(() {
174-
tempDir = globals.fs.systemTempDirectory.createTempSync(
175-
'flutter_tools_os_utils_test.',
176-
);
177-
});
178-
179-
tearDown(() {
180-
tryToDelete(tempDir);
181-
});
182-
183-
testUsingContext('makeExecutable', () async {
184-
final File file = globals.fs.file(globals.fs.path.join(
185-
tempDir.path,
186-
'foo.script',
187-
));
188-
file.writeAsStringSync('hello world');
189-
globals.os.makeExecutable(file);
190-
191-
final String mode = file.statSync().modeString();
192-
// rwxr--r--
193-
expect(mode.substring(0, 3), endsWith('x'));
194-
}, overrides: <Type, Generator>{
195-
OperatingSystemUtils: () => OperatingSystemUtils(
196-
fileSystem: globals.fs,
197-
logger: globals.logger,
198-
platform: globals.platform,
199-
processManager: globals.processManager,
200-
),
201-
}, skip: const LocalPlatform().isWindows);
202-
});
20391
}
20492

20593
class MockProcessManager extends Mock implements ProcessManager {}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:flutter_tools/src/base/file_system.dart';
6+
import 'package:flutter_tools/src/base/os.dart';
7+
import 'package:flutter_tools/src/globals.dart' as globals;
8+
9+
import '../../src/common.dart';
10+
import '../../src/context.dart';
11+
12+
void main() {
13+
group('OperatingSystemUtils', () {
14+
Directory tempDir;
15+
16+
setUp(() {
17+
tempDir = globals.fs.systemTempDirectory.createTempSync('flutter_tools_os_utils_test.');
18+
});
19+
20+
tearDown(() {
21+
tryToDelete(tempDir);
22+
});
23+
24+
testUsingContext('makeExecutable', () async {
25+
final File file = globals.fs.file(globals.fs.path.join(tempDir.path, 'foo.script'));
26+
file.writeAsStringSync('hello world');
27+
globals.os.makeExecutable(file);
28+
29+
// Skip this test on windows.
30+
if (!globals.platform.isWindows) {
31+
final String mode = file.statSync().modeString();
32+
// rwxr--r--
33+
expect(mode.substring(0, 3), endsWith('x'));
34+
}
35+
}, overrides: <Type, Generator>{
36+
OperatingSystemUtils: () => OperatingSystemUtils(
37+
fileSystem: globals.fs,
38+
logger: globals.logger,
39+
platform: globals.platform,
40+
processManager: globals.processManager,
41+
),
42+
});
43+
});
44+
}

0 commit comments

Comments
 (0)