Skip to content

Commit 1f5cb0d

Browse files
authored
support running et fetch from anywhere (#162712)
Support running `et fetch` from any directory.
1 parent 1d85de0 commit 1f5cb0d

File tree

14 files changed

+232
-138
lines changed

14 files changed

+232
-138
lines changed

engine/src/flutter/testing/skia_gold_client/test/skia_gold_client_test.dart

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ void main() {
5252
Map<String, String>? dimensions,
5353
String? prefix,
5454
bool verbose = false,
55-
io.ProcessResult Function(List<String> command) onRun = _runUnhandled,
55+
io.ProcessResult Function(FakeCommandLogEntry entry) onRun = _runUnhandled,
5656
}) {
5757
return SkiaGoldClient.forTesting(
5858
fixture.workDirectory,
@@ -97,8 +97,8 @@ void main() {
9797
final SkiaGoldClient client = createClient(
9898
fixture,
9999
environment: {...presubmitEnv, 'GIT_BRANCH': 'merge-queue-foo'},
100-
onRun: (List<String> command) {
101-
expect(command, <String>[
100+
onRun: (FakeCommandLogEntry entry) {
101+
expect(entry.command, <String>[
102102
'python tools/goldctl.py',
103103
'auth',
104104
'--work-dir',
@@ -132,8 +132,8 @@ void main() {
132132
final SkiaGoldClient client = createClient(
133133
fixture,
134134
environment: {...presubmitEnv, 'GIT_BRANCH': 'merge-queue-foo'},
135-
onRun: (List<String> command) {
136-
expect(command, <String>[
135+
onRun: (FakeCommandLogEntry entry) {
136+
expect(entry.command, <String>[
137137
'python tools/goldctl.py',
138138
'auth',
139139
'--work-dir',
@@ -165,8 +165,8 @@ void main() {
165165
final SkiaGoldClient client = createClient(
166166
fixture,
167167
environment: presubmitEnv,
168-
onRun: (List<String> command) {
169-
expect(command, <String>[
168+
onRun: (FakeCommandLogEntry entry) {
169+
expect(entry.command, <String>[
170170
'python tools/goldctl.py',
171171
'auth',
172172
'--work-dir',
@@ -190,9 +190,9 @@ void main() {
190190
final SkiaGoldClient client = createClient(
191191
fixture,
192192
environment: presubmitEnv,
193-
onRun: (List<String> command) {
193+
onRun: (FakeCommandLogEntry entry) {
194194
callsToGoldctl++;
195-
expect(command, <String>[
195+
expect(entry.command, <String>[
196196
'python tools/goldctl.py',
197197
'auth',
198198
'--work-dir',
@@ -219,8 +219,8 @@ void main() {
219219
fixture,
220220
environment: presubmitEnv,
221221
verbose: true,
222-
onRun: (List<String> command) {
223-
expect(command, <String>[
222+
onRun: (FakeCommandLogEntry entry) {
223+
expect(entry.command, <String>[
224224
'python tools/goldctl.py',
225225
'auth',
226226
'--verbose',
@@ -246,7 +246,7 @@ void main() {
246246
final SkiaGoldClient client = createClient(
247247
fixture,
248248
environment: presubmitEnv,
249-
onRun: (List<String> command) {
249+
onRun: (FakeCommandLogEntry entry) {
250250
return io.ProcessResult(1, 0, 'stdout-text', 'stderr-text');
251251
},
252252
);
@@ -270,14 +270,14 @@ void main() {
270270
final SkiaGoldClient client = createClient(
271271
fixture,
272272
environment: presubmitEnv,
273-
onRun: (List<String> command) {
274-
if (command case ['git', ...]) {
273+
onRun: (FakeCommandLogEntry entry) {
274+
if (entry.command case ['git', ...]) {
275275
return io.ProcessResult(0, 0, mockCommitHash, '');
276276
}
277-
if (command case ['python tools/goldctl.py', 'imgtest', 'init', ...]) {
277+
if (entry.command case ['python tools/goldctl.py', 'imgtest', 'init', ...]) {
278278
return io.ProcessResult(0, 0, '', '');
279279
}
280-
expect(command, <String>[
280+
expect(entry.command, <String>[
281281
'python tools/goldctl.py',
282282
'imgtest',
283283
'add',
@@ -315,14 +315,14 @@ void main() {
315315
fixture,
316316
environment: presubmitEnv,
317317
prefix: 'engine.',
318-
onRun: (List<String> command) {
319-
if (command case ['git', ...]) {
318+
onRun: (FakeCommandLogEntry entry) {
319+
if (entry.command case ['git', ...]) {
320320
return io.ProcessResult(0, 0, mockCommitHash, '');
321321
}
322-
if (command case ['python tools/goldctl.py', 'imgtest', 'init', ...]) {
322+
if (entry.command case ['python tools/goldctl.py', 'imgtest', 'init', ...]) {
323323
return io.ProcessResult(0, 0, '', '');
324324
}
325-
expect(command, <String>[
325+
expect(entry.command, <String>[
326326
'python tools/goldctl.py',
327327
'imgtest',
328328
'add',
@@ -363,14 +363,14 @@ void main() {
363363
final SkiaGoldClient client = createClient(
364364
fixture,
365365
environment: presubmitEnv,
366-
onRun: (List<String> command) {
367-
if (command case ['git', ...]) {
366+
onRun: (FakeCommandLogEntry entry) {
367+
if (entry.command case ['git', ...]) {
368368
return io.ProcessResult(0, 0, mockCommitHash, '');
369369
}
370-
if (command case ['python tools/goldctl.py', 'imgtest', 'init', ...]) {
370+
if (entry.command case ['python tools/goldctl.py', 'imgtest', 'init', ...]) {
371371
return io.ProcessResult(0, 0, '', '');
372372
}
373-
expect(command, <String>[
373+
expect(entry.command, <String>[
374374
'python tools/goldctl.py',
375375
'imgtest',
376376
'add',
@@ -409,14 +409,14 @@ void main() {
409409
fixture,
410410
environment: presubmitEnv,
411411
verbose: true,
412-
onRun: (List<String> command) {
413-
if (command case ['git', ...]) {
412+
onRun: (FakeCommandLogEntry entry) {
413+
if (entry.command case ['git', ...]) {
414414
return io.ProcessResult(0, 0, mockCommitHash, '');
415415
}
416-
if (command case ['python tools/goldctl.py', 'imgtest', 'init', ...]) {
416+
if (entry.command case ['python tools/goldctl.py', 'imgtest', 'init', ...]) {
417417
return io.ProcessResult(0, 0, '', '');
418418
}
419-
expect(command, <String>[
419+
expect(entry.command, <String>[
420420
'python tools/goldctl.py',
421421
'imgtest',
422422
'add',
@@ -458,14 +458,14 @@ void main() {
458458
final SkiaGoldClient client = createClient(
459459
fixture,
460460
environment: presubmitEnv,
461-
onRun: (List<String> command) {
462-
if (command case ['git', ...]) {
461+
onRun: (FakeCommandLogEntry entry) {
462+
if (entry.command case ['git', ...]) {
463463
return io.ProcessResult(0, 0, mockCommitHash, '');
464464
}
465-
if (command case ['python tools/goldctl.py', 'imgtest', 'init', ...]) {
465+
if (entry.command case ['python tools/goldctl.py', 'imgtest', 'init', ...]) {
466466
return io.ProcessResult(0, 0, '', '');
467467
}
468-
expect(command, <String>[
468+
expect(entry.command, <String>[
469469
'python tools/goldctl.py',
470470
'imgtest',
471471
'add',
@@ -507,11 +507,11 @@ void main() {
507507
final SkiaGoldClient client = createClient(
508508
fixture,
509509
environment: presubmitEnv,
510-
onRun: (List<String> command) {
511-
if (command case ['git', ...]) {
510+
onRun: (FakeCommandLogEntry entry) {
511+
if (entry.command case ['git', ...]) {
512512
return io.ProcessResult(0, 0, mockCommitHash, '');
513513
}
514-
if (command case ['python tools/goldctl.py', 'imgtest', 'init', ...]) {
514+
if (entry.command case ['python tools/goldctl.py', 'imgtest', 'init', ...]) {
515515
return io.ProcessResult(0, 0, '', '');
516516
}
517517
return io.ProcessResult(1, 0, 'stdout-text', 'stderr-text');
@@ -541,14 +541,14 @@ void main() {
541541
final SkiaGoldClient client = createClient(
542542
fixture,
543543
environment: postsubmitEnv,
544-
onRun: (List<String> command) {
545-
if (command case ['git', ...]) {
544+
onRun: (FakeCommandLogEntry entry) {
545+
if (entry.command case ['git', ...]) {
546546
return io.ProcessResult(0, 0, mockCommitHash, '');
547547
}
548-
if (command case ['python tools/goldctl.py', 'imgtest', 'init', ...]) {
548+
if (entry.command case ['python tools/goldctl.py', 'imgtest', 'init', ...]) {
549549
return io.ProcessResult(0, 0, '', '');
550550
}
551-
expect(command, <String>[
551+
expect(entry.command, <String>[
552552
'python tools/goldctl.py',
553553
'imgtest',
554554
'add',
@@ -587,14 +587,14 @@ void main() {
587587
fixture,
588588
environment: postsubmitEnv,
589589
verbose: true,
590-
onRun: (List<String> command) {
591-
if (command case ['git', ...]) {
590+
onRun: (FakeCommandLogEntry entry) {
591+
if (entry.command case ['git', ...]) {
592592
return io.ProcessResult(0, 0, mockCommitHash, '');
593593
}
594-
if (command case ['python tools/goldctl.py', 'imgtest', 'init', ...]) {
594+
if (entry.command case ['python tools/goldctl.py', 'imgtest', 'init', ...]) {
595595
return io.ProcessResult(0, 0, '', '');
596596
}
597-
expect(command, <String>[
597+
expect(entry.command, <String>[
598598
'python tools/goldctl.py',
599599
'imgtest',
600600
'add',
@@ -636,11 +636,11 @@ void main() {
636636
final SkiaGoldClient client = createClient(
637637
fixture,
638638
environment: postsubmitEnv,
639-
onRun: (List<String> command) {
640-
if (command case ['git', ...]) {
639+
onRun: (FakeCommandLogEntry entry) {
640+
if (entry.command case ['git', ...]) {
641641
return io.ProcessResult(0, 0, mockCommitHash, '');
642642
}
643-
if (command case ['python tools/goldctl.py', 'imgtest', 'init', ...]) {
643+
if (entry.command case ['python tools/goldctl.py', 'imgtest', 'init', ...]) {
644644
return io.ProcessResult(0, 0, '', '');
645645
}
646646
return io.ProcessResult(1, 0, 'stdout-text', 'stderr-text');
@@ -670,8 +670,8 @@ void main() {
670670
final SkiaGoldClient client = createClient(
671671
fixture,
672672
environment: presubmitEnv,
673-
onRun: (List<String> command) {
674-
expect(command, <String>[
673+
onRun: (FakeCommandLogEntry entry) {
674+
expect(entry.command, <String>[
675675
'python tools/goldctl.py',
676676
'imgtest',
677677
'get',
@@ -728,8 +728,8 @@ final class _TestFixture {
728728
}
729729
}
730730

731-
io.ProcessResult _runUnhandled(List<String> command) {
732-
throw UnimplementedError('Unhandled run: ${command.join(' ')}');
731+
io.ProcessResult _runUnhandled(FakeCommandLogEntry entry) {
732+
throw UnimplementedError('Unhandled run: ${entry.command.join(' ')}');
733733
}
734734

735735
/// An in-memory fake of [io.HttpClient] that allows [getUrl] to be mocked.

engine/src/flutter/tools/clang_tidy/test/clang_tidy_test.dart

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -340,12 +340,12 @@ void main() {
340340
lintTarget: const LintChanged(),
341341
),
342342
processManager: FakeProcessManager(
343-
onStart: (List<String> command) {
344-
if (command.first == 'git') {
343+
onStart: (FakeCommandLogEntry entry) {
344+
if (entry.command.first == 'git') {
345345
// This just allows git to not actually be called.
346346
return FakeProcess();
347347
}
348-
return FakeProcessManager.unhandledStart(command);
348+
return FakeProcessManager.unhandledStart(entry);
349349
},
350350
),
351351
);
@@ -360,12 +360,12 @@ void main() {
360360
lintTarget: const LintRegex(r'.*test.*\.cc$'),
361361
),
362362
processManager: FakeProcessManager(
363-
onStart: (List<String> command) {
364-
if (command.first == 'git') {
363+
onStart: (FakeCommandLogEntry entry) {
364+
if (entry.command.first == 'git') {
365365
// This just allows git to not actually be called.
366366
return FakeProcess();
367367
}
368-
return FakeProcessManager.unhandledStart(command);
368+
return FakeProcessManager.unhandledStart(entry);
369369
},
370370
),
371371
);
@@ -377,12 +377,12 @@ void main() {
377377
final Fixture fixture = Fixture.fromOptions(
378378
Options(buildCommandsPath: io.File(buildCommands), lintTarget: const LintAll()),
379379
processManager: FakeProcessManager(
380-
onStart: (List<String> command) {
381-
if (command.first == 'git') {
380+
onStart: (FakeCommandLogEntry entry) {
381+
if (entry.command.first == 'git') {
382382
// This just allows git to not actually be called.
383383
return FakeProcess();
384384
}
385-
return FakeProcessManager.unhandledStart(command);
385+
return FakeProcessManager.unhandledStart(entry);
386386
},
387387
),
388388
);
@@ -622,11 +622,11 @@ void main() {
622622
final String firstFilePath = (await fileListFixture.tool.computeFilesOfInterest()).first.path;
623623

624624
final FakeProcessManager fakeProcessManager = FakeProcessManager(
625-
onStart: (List<String> command) {
626-
if (command.first.endsWith('clang-tidy')) {
625+
onStart: (FakeCommandLogEntry entry) {
626+
if (entry.command.first.endsWith('clang-tidy')) {
627627
return FakeProcess(exitCode: -io.ProcessSignal.sigsegv.signalNumber);
628628
}
629-
return FakeProcessManager.unhandledStart(command);
629+
return FakeProcessManager.unhandledStart(entry);
630630
},
631631
);
632632

engine/src/flutter/tools/engine_tool/lib/src/dart_utils.dart

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
import 'dart:io' as io;
6+
7+
import 'package:collection/collection.dart';
58
import 'package:path/path.dart' as p;
69
import 'environment.dart';
710

@@ -14,3 +17,21 @@ String findDartBinDirectory(Environment env) {
1417
String findDartBinary(Environment env) {
1518
return p.join(findDartBinDirectory(env), 'dart');
1619
}
20+
21+
/// Returns the path to `.gclient` file, or null if it cannot be found.
22+
String? findDotGclient(Environment env) {
23+
io.Directory directory = env.engine.srcDir;
24+
io.File? dotGclientFile;
25+
while (dotGclientFile == null) {
26+
dotGclientFile = directory.listSync().whereType<io.File>().firstWhereOrNull((file) {
27+
return p.basename(file.path) == '.gclient';
28+
});
29+
30+
final parent = directory.parent;
31+
if (parent.path == directory.path) {
32+
break;
33+
}
34+
directory = parent;
35+
}
36+
return dotGclientFile?.path;
37+
}

engine/src/flutter/tools/engine_tool/lib/src/dependencies.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'dart:io' as io;
66

77
import 'package:process_runner/process_runner.dart';
88

9+
import 'dart_utils.dart';
910
import 'environment.dart';
1011
import 'logger.dart';
1112

@@ -16,8 +17,21 @@ Future<int> fetchDependencies(Environment environment) async {
1617
return 1;
1718
}
1819

20+
final dotGclientPath = findDotGclient(environment);
21+
22+
if (dotGclientPath == null) {
23+
environment.logger.error(
24+
'Failed to find the .gclient file. Make sure your local engine build '
25+
'environment is configured as described in '
26+
'https://github.com/flutter/flutter/blob/master/engine/README.md',
27+
);
28+
return 1;
29+
}
30+
1931
environment.logger.status('Fetching dependencies... ', newline: environment.verbose);
2032

33+
final dotGclient = io.File(dotGclientPath);
34+
2135
Spinner? spinner;
2236
ProcessRunnerResult result;
2337
try {
@@ -30,6 +44,7 @@ Future<int> fetchDependencies(Environment environment) async {
3044
runInShell: true,
3145
startMode:
3246
environment.verbose ? io.ProcessStartMode.inheritStdio : io.ProcessStartMode.normal,
47+
workingDirectory: dotGclient.parent,
3348
);
3449
} finally {
3550
spinner?.finish();

0 commit comments

Comments
 (0)