2
2
// Use of this source code is governed by a BSD-style license that can be
3
3
// found in the LICENSE file.
4
4
5
- // For each directory specified in the stdin , this script generates:
5
+ // For `android` directory in the repo , this script generates:
6
6
// 1. The top-level build.gradle (android/build.gradle).
7
7
// 2. The top level settings.gradle (android/settings.gradle).
8
8
// 3. The gradle wrapper file (android/gradle/wrapper/gradle-wrapper.properties).
9
9
// Then it generate the lockfiles for each Gradle project.
10
- // To regenerate these files, run `find . -type d -name 'android' | dart dev/tools/bin/generate_gradle_lockfiles.dart`.
10
+ // To regenerate these files, run `dart dev/tools/bin/generate_gradle_lockfiles.dart`.
11
11
12
12
import 'dart:collection' ;
13
13
import 'dart:io' ;
14
14
15
15
import 'package:args/args.dart' ;
16
16
import 'package:file/file.dart' ;
17
17
import 'package:file/local.dart' ;
18
- import 'package:path/path.dart' as path;
19
18
import 'package:yaml/yaml.dart' ;
20
19
21
20
void main (List <String > arguments) {
22
- const String usageMessage = "Usage: find . -type d -name 'android' | dart dev/tools/bin/generate_gradle_lockfiles.dart\n "
23
- 'If you would rather enter the files manually, just run `dart dev/tools/bin/generate_gradle_lockfiles.dart`,\n '
24
- "enter the absolute paths to the app's android directory, then press CTRL-D.\n "
25
- "If you don't wish to re-generate the settings.gradle, build.gradle, and gradle-wrapper.properties files,\n "
21
+ const String usageMessage = "If you don't wish to re-generate the "
22
+ 'settings.gradle, build.gradle, and gradle-wrapper.properties files,\n '
26
23
'add the flag `--no-gradle-generation`.\n '
27
- 'This tool automatically excludes a set of android subdirectories, defined at dev/tools/bin/config/lockfile_exclusion.yaml.\n '
24
+ 'This tool automatically excludes a set of android subdirectories, '
25
+ 'defined at dev/tools/bin/config/lockfile_exclusion.yaml.\n '
28
26
'To disable this behavior, run with `--no-exclusion`.\n ' ;
29
27
30
28
final ArgParser argParser = ArgParser ()
@@ -56,10 +54,25 @@ void main(List<String> arguments) {
56
54
final bool useExclusion = (args['exclusion' ] as bool ? ) ?? true ;
57
55
58
56
const FileSystem fileSystem = LocalFileSystem ();
59
- final List <String > androidDirectories = getFilesFromStdin ();
60
57
61
- final File exclusionFile = fileSystem
62
- .currentDirectory.childDirectory ('dev' ).childDirectory ('tools' ).childDirectory ('bin' )
58
+ final Directory repoRoot = (() {
59
+ final String repoRootPath = exec (
60
+ 'git' ,
61
+ const < String > ['rev-parse' , '--show-toplevel' ],
62
+ ).trim ();
63
+ final Directory repoRoot = fileSystem.directory (repoRootPath);
64
+ if (! repoRoot.existsSync ()) {
65
+ throw StateError ("Expected $repoRoot to exist but it didn't!" );
66
+ }
67
+ return repoRoot;
68
+ })();
69
+
70
+ final Iterable <Directory > androidDirectories = discoverAndroidDirectories (repoRoot);
71
+
72
+ final File exclusionFile = repoRoot
73
+ .childDirectory ('dev' )
74
+ .childDirectory ('tools' )
75
+ .childDirectory ('bin' )
63
76
.childDirectory ('config' )
64
77
.childFile ('lockfile_exclusion.yaml' );
65
78
@@ -77,10 +90,7 @@ void main(List<String> arguments) {
77
90
print ('Running without exclusion.' );
78
91
}
79
92
80
-
81
- for (final String androidDirectoryPath in androidDirectories) {
82
- final Directory androidDirectory = fileSystem.directory (path.normalize (androidDirectoryPath));
83
-
93
+ for (final Directory androidDirectory in androidDirectories) {
84
94
if (! androidDirectory.existsSync ()) {
85
95
throw '$androidDirectory does not exist' ;
86
96
}
@@ -188,19 +198,7 @@ void main(List<String> arguments) {
188
198
}
189
199
}
190
200
191
- List <String > getFilesFromStdin () {
192
- final List <String > files = < String > [];
193
- while (true ) {
194
- final String ? file = stdin.readLineSync ();
195
- if (file == null ) {
196
- break ;
197
- }
198
- files.add (file);
199
- }
200
- return files;
201
- }
202
-
203
- void exec (
201
+ String exec (
204
202
String cmd,
205
203
List <String > args, {
206
204
String ? workingDirectory,
@@ -210,6 +208,7 @@ void exec(
210
208
throw ProcessException (
211
209
cmd, args, '${result .stdout }${result .stderr }' , result.exitCode);
212
210
}
211
+ return result.stdout as String ;
213
212
}
214
213
215
214
const String rootGradleFileContent = r'''
@@ -300,3 +299,9 @@ zipStoreBase=GRADLE_USER_HOME
300
299
zipStorePath=wrapper/dists
301
300
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-all.zip
302
301
''' ;
302
+
303
+ Iterable <Directory > discoverAndroidDirectories (Directory repoRoot) {
304
+ return repoRoot.listSync (recursive: true )
305
+ .whereType <Directory >()
306
+ .where ((FileSystemEntity entity) => entity.basename == 'android' );
307
+ }
0 commit comments