Skip to content

Commit 7362d07

Browse files
authored
Make the pub roller bot re-generate gradle lockfiles (#149355)
Fixes flutter/flutter#142475
1 parent 6608936 commit 7362d07

File tree

4 files changed

+58
-28
lines changed

4 files changed

+58
-28
lines changed

dev/conductor/core/lib/src/packages_autoroller.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import 'dart:convert';
66
import 'dart:io' as io;
77

8+
import 'package:file/file.dart';
9+
import 'package:meta/meta.dart';
810
import 'package:process/process.dart';
911

1012
import 'git.dart';
@@ -93,6 +95,7 @@ This PR was generated by the automated
9395
log('Packages are already at latest.');
9496
return;
9597
}
98+
await generateGradleLockfiles(await framework.checkoutDirectory);
9699
await pushBranch();
97100
await createPr(repository: await framework.checkoutDirectory);
98101
await authLogout();
@@ -135,6 +138,15 @@ This PR was generated by the automated
135138
return true;
136139
}
137140

141+
@visibleForTesting
142+
Future<void> generateGradleLockfiles(Directory repoRoot) async {
143+
await framework.runDart(<String>[
144+
'${repoRoot.path}/dev/tools/bin/generate_gradle_lockfiles.dart',
145+
'--no-gradle-generation',
146+
'--no-exclusion',
147+
]);
148+
}
149+
138150
Future<void> pushBranch() async {
139151
final String projectName = framework.mirrorRemote!.url.split(r'/').last;
140152
// Encode the token into the remote URL for authentication to work

dev/conductor/core/lib/src/repository.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,13 @@ class FrameworkRepository extends Repository {
601601
]);
602602
}
603603

604+
Future<io.ProcessResult> runDart(List<String> args) async {
605+
return processManager.run(<String>[
606+
fileSystem.path.join((await checkoutDirectory).path, 'bin', 'dart'),
607+
...args,
608+
]);
609+
}
610+
604611
Future<io.ProcessResult> runFlutter(List<String> args) async {
605612
await _ensureToolReady();
606613
return processManager.run(<String>[

dev/conductor/core/test/packages_autoroller_test.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,12 @@ void main() {
432432
'rev-parse',
433433
'HEAD',
434434
], stdout: '000deadbeef'),
435+
const FakeCommand(command: <String>[
436+
'$checkoutsParentDirectory/flutter_conductor_checkouts/framework/bin/dart',
437+
'$checkoutsParentDirectory/flutter_conductor_checkouts/framework/dev/tools/bin/generate_gradle_lockfiles.dart',
438+
'--no-gradle-generation',
439+
'--no-exclusion',
440+
]),
435441
const FakeCommand(command: <String>[
436442
'git',
437443
'push',

dev/tools/bin/generate_gradle_lockfiles.dart

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

5-
// For each directory specified in the stdin, this script generates:
5+
// For `android` directory in the repo, this script generates:
66
// 1. The top-level build.gradle (android/build.gradle).
77
// 2. The top level settings.gradle (android/settings.gradle).
88
// 3. The gradle wrapper file (android/gradle/wrapper/gradle-wrapper.properties).
99
// 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`.
1111

1212
import 'dart:collection';
1313
import 'dart:io';
1414

1515
import 'package:args/args.dart';
1616
import 'package:file/file.dart';
1717
import 'package:file/local.dart';
18-
import 'package:path/path.dart' as path;
1918
import 'package:yaml/yaml.dart';
2019

2120
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'
2623
'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'
2826
'To disable this behavior, run with `--no-exclusion`.\n';
2927

3028
final ArgParser argParser = ArgParser()
@@ -56,10 +54,25 @@ void main(List<String> arguments) {
5654
final bool useExclusion = (args['exclusion'] as bool?) ?? true;
5755

5856
const FileSystem fileSystem = LocalFileSystem();
59-
final List<String> androidDirectories = getFilesFromStdin();
6057

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')
6376
.childDirectory('config')
6477
.childFile('lockfile_exclusion.yaml');
6578

@@ -77,10 +90,7 @@ void main(List<String> arguments) {
7790
print('Running without exclusion.');
7891
}
7992

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) {
8494
if (!androidDirectory.existsSync()) {
8595
throw '$androidDirectory does not exist';
8696
}
@@ -188,19 +198,7 @@ void main(List<String> arguments) {
188198
}
189199
}
190200

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(
204202
String cmd,
205203
List<String> args, {
206204
String? workingDirectory,
@@ -210,6 +208,7 @@ void exec(
210208
throw ProcessException(
211209
cmd, args, '${result.stdout}${result.stderr}', result.exitCode);
212210
}
211+
return result.stdout as String;
213212
}
214213

215214
const String rootGradleFileContent = r'''
@@ -300,3 +299,9 @@ zipStoreBase=GRADLE_USER_HOME
300299
zipStorePath=wrapper/dists
301300
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-all.zip
302301
''';
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

Comments
 (0)