Delete unused engine_hash.dart script (and test), simplify engine_hash.sh. (#160549)
Closes https://github.com/flutter/flutter/issues/160527. We don't use the Dart script anyway, and the shell script could be simplified to the single use in g3 (cl/688973229).
This commit is contained in:
@@ -2,98 +2,71 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
@TestOn('posix')
|
||||
library;
|
||||
|
||||
import 'dart:io' as io;
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import '../bin/engine_hash.dart' show GitRevisionStrategy, engineHash;
|
||||
|
||||
/// Tests that `/dev/tools/bin/engine_hash.sh` _appears_ to work.
|
||||
void main() {
|
||||
test('Produces an engine hash for merge-base', () async {
|
||||
final Future<io.ProcessResult> Function(List<String>) runProcess = _fakeProcesses(
|
||||
processes: <FakeProcess>[
|
||||
(
|
||||
exe: 'git',
|
||||
command: 'merge-base',
|
||||
rest: <String>['upstream/master', 'HEAD'],
|
||||
exitCode: 0,
|
||||
stdout: 'abcdef1234',
|
||||
stderr: null,
|
||||
),
|
||||
(
|
||||
exe: 'git',
|
||||
command: 'ls-tree',
|
||||
rest: <String>['-r', 'abcdef1234', 'engine', 'DEPS'],
|
||||
exitCode: 0,
|
||||
stdout: 'one\r\ntwo\r\n',
|
||||
stderr: null,
|
||||
),
|
||||
],
|
||||
);
|
||||
late final io.File engineHashSh;
|
||||
|
||||
final Future<String> result = engineHash(runProcess);
|
||||
|
||||
expect(result, completion('c708d7ef841f7e1748436b8ef5670d0b2de1a227'));
|
||||
setUpAll(() {
|
||||
engineHashSh = io.File(p.join(p.current, 'bin', 'engine_hash.sh'));
|
||||
if (!engineHashSh.existsSync()) {
|
||||
fail('No engine_hash.sh at "${p.absolute(engineHashSh.path)}".');
|
||||
}
|
||||
});
|
||||
|
||||
test('Produces an engine hash for HEAD', () async {
|
||||
final Future<io.ProcessResult> Function(List<String>) runProcess = _fakeProcesses(
|
||||
processes: <FakeProcess>[
|
||||
(
|
||||
exe: 'git',
|
||||
command: 'ls-tree',
|
||||
rest: <String>['-r', 'HEAD', 'engine', 'DEPS'],
|
||||
exitCode: 0,
|
||||
stdout: 'one\ntwo\n',
|
||||
stderr: null,
|
||||
),
|
||||
],
|
||||
);
|
||||
late io.Directory tmpFlutterRoot;
|
||||
|
||||
final Future<String> result = engineHash(
|
||||
runProcess,
|
||||
revisionStrategy: GitRevisionStrategy.head,
|
||||
);
|
||||
setUp(() {
|
||||
tmpFlutterRoot = io.Directory.systemTemp.createTempSync('engine_hash_test.');
|
||||
|
||||
expect(result, completion('c708d7ef841f7e1748436b8ef5670d0b2de1a227'));
|
||||
// Create engine_hash.sh at the same component it would be in the real root.
|
||||
io.Directory(p.join(tmpFlutterRoot.path, 'dev', 'tools', 'bin')).createSync(recursive: true);
|
||||
engineHashSh.copySync(p.join(tmpFlutterRoot.path, 'dev', 'tools', 'bin', 'engine_hash.sh'));
|
||||
|
||||
// Create FLUTTER_ROOT/DEPS.
|
||||
io.File(p.join(tmpFlutterRoot.path, 'DEPS')).createSync();
|
||||
});
|
||||
|
||||
test('Returns error in non-monorepo', () async {
|
||||
final Future<io.ProcessResult> Function(List<String>) runProcess = _fakeProcesses(
|
||||
processes: <FakeProcess>[
|
||||
(
|
||||
exe: 'git',
|
||||
command: 'ls-tree',
|
||||
rest: <String>['-r', 'HEAD', 'engine', 'DEPS'],
|
||||
exitCode: 0,
|
||||
stdout: '',
|
||||
stderr: null,
|
||||
),
|
||||
],
|
||||
);
|
||||
tearDown(() {
|
||||
tmpFlutterRoot.deleteSync(recursive: true);
|
||||
});
|
||||
|
||||
final Future<String> result = engineHash(
|
||||
runProcess,
|
||||
revisionStrategy: GitRevisionStrategy.head,
|
||||
);
|
||||
test('omission of FLUTTER_ROOT/DEPS falls back to engine.version', () {
|
||||
io.File(p.join(tmpFlutterRoot.path, 'bin', 'internal', 'engine.version'))
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync('12345');
|
||||
io.File(p.join(tmpFlutterRoot.path, 'DEPS')).deleteSync();
|
||||
|
||||
expect(result, throwsA('Not in a monorepo'));
|
||||
final io.ProcessResult result = io.Process.runSync(
|
||||
p.join(tmpFlutterRoot.path, 'dev', 'tools', 'bin', 'engine_hash.sh'),
|
||||
<String>[],
|
||||
);
|
||||
expect(result.exitCode, 0, reason: result.stderr.toString());
|
||||
expect(result.stdout, '12345\n');
|
||||
});
|
||||
|
||||
test('uses git -C merge-base HEAD origin/master', () {
|
||||
final io.ProcessResult result = io.Process.runSync(
|
||||
p.join(tmpFlutterRoot.path, 'dev', 'tools', 'bin', 'engine_hash.sh'),
|
||||
<String>[],
|
||||
environment: <String, String>{'GIT': p.join(p.current, 'test', 'mock_git.sh')},
|
||||
);
|
||||
expect(result.exitCode, 0, reason: result.stderr.toString());
|
||||
expect(
|
||||
result.stdout,
|
||||
stringContainsInOrder(<String>[
|
||||
'Mock Git: -C',
|
||||
'engine_hash_test',
|
||||
// This needs to be origin/master if the google3 script is running from a fresh checkout.
|
||||
'merge-base HEAD origin/master',
|
||||
]),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
typedef FakeProcess =
|
||||
({String exe, String command, List<String> rest, dynamic stdout, dynamic stderr, int exitCode});
|
||||
|
||||
Future<io.ProcessResult> Function(List<String>) _fakeProcesses({
|
||||
required List<FakeProcess> processes,
|
||||
}) => (List<String> cmd) async {
|
||||
for (final FakeProcess process in processes) {
|
||||
if (process.exe.endsWith(cmd[0]) &&
|
||||
process.command.endsWith(cmd[1]) &&
|
||||
process.rest.equals(cmd.sublist(2))) {
|
||||
return io.ProcessResult(1, process.exitCode, process.stdout, process.stderr);
|
||||
}
|
||||
}
|
||||
return io.ProcessResult(1, -42, '', '404 command not found: $cmd');
|
||||
};
|
||||
|
||||
6
dev/tools/test/mock_git.sh
Executable file
6
dev/tools/test/mock_git.sh
Executable file
@@ -0,0 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
# 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.
|
||||
|
||||
echo "Mock Git: $@"
|
||||
Reference in New Issue
Block a user