Skip to content

Commit fd1c02d

Browse files
authored
Exclude the top-level engine directory from generate_gradle_lockfiles. (flutter#161635)
For local development workflows, this would find directories we don't want included in the script. Added a simple test.
1 parent 97acba4 commit fd1c02d

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed

dev/tools/bin/generate_gradle_lockfiles.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,13 @@ distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-all.zip
304304

305305
Iterable<Directory> discoverAndroidDirectories(Directory repoRoot) {
306306
return repoRoot
307-
.listSync(recursive: true)
307+
.listSync()
308308
.whereType<Directory>()
309+
// Exclude the top-level "engine/" directory, which is not covered by the the tool.
310+
.where((Directory directory) => directory.basename != 'engine')
311+
// ... and then recurse into every directory (other than the excluded directory).
312+
.expand((Directory d) => d.listSync(recursive: true))
313+
.whereType<Directory>()
314+
// ... where the directory ultimately is named "android".
309315
.where((FileSystemEntity entity) => entity.basename == 'android');
310316
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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:file/file.dart';
6+
import 'package:file/local.dart';
7+
import 'package:path/path.dart' as p;
8+
import 'package:test/test.dart';
9+
10+
import '../bin/generate_gradle_lockfiles.dart' as bin;
11+
12+
void main() {
13+
const FileSystem localFs = LocalFileSystem();
14+
late Directory tmpFlutterRoot;
15+
16+
setUp(() {
17+
tmpFlutterRoot = localFs.systemTempDirectory.createTempSync('generate_gradle_lockfiles_test.');
18+
19+
// Simulate a version of the top-level directory structure.
20+
// It's not critical that it is a "real" structure, as long as it includes:
21+
// - At least one top-level directory that is "engine"
22+
// - At least one top-level directory that is not "engine"
23+
// - At least one nested directory (in not "engine") that is "engine"
24+
final List<String> directoriesToCreate = <String>[
25+
p.join('dev', 'integration_tests', 'android_test', 'android'),
26+
p.join('engine', 'src', 'flutter', 'third_party', 'some_package', 'android'),
27+
p.join('packages', 'flutter_tools', 'test', 'fixtures', 'engine', 'android'),
28+
];
29+
30+
for (final String path in directoriesToCreate) {
31+
localFs.directory(p.join(tmpFlutterRoot.path, path)).createSync(recursive: true);
32+
}
33+
});
34+
35+
tearDown(() {
36+
tmpFlutterRoot.deleteSync(recursive: true);
37+
});
38+
39+
test('discoverAndroidDirectories resolves a total of 2 directories of the possible 3', () {
40+
expect(bin.discoverAndroidDirectories(tmpFlutterRoot), hasLength(2));
41+
});
42+
43+
test('discoverAndroidDirectories does not traverse into the top-level "engine" directory', () {
44+
for (final Directory directory in bin.discoverAndroidDirectories(tmpFlutterRoot)) {
45+
if (directory.path.contains(p.join('engine', 'src', 'flutter'))) {
46+
fail('Unexpected: ${directory.path} should be excluded (top-level engine directory)');
47+
}
48+
}
49+
});
50+
51+
test('discoverAndroidDirectories does traverse into a non top-level "engine" directory', () {
52+
final Iterable<String> paths = bin
53+
.discoverAndroidDirectories(tmpFlutterRoot)
54+
.map((Directory r) => r.path);
55+
expect(
56+
paths,
57+
containsAll(<Matcher>[contains(p.join('test', 'fixtures', 'engine', 'android'))]),
58+
reason: 'A directory named "engine" that is not a root directory should be traversed',
59+
);
60+
});
61+
}

0 commit comments

Comments
 (0)