diff --git a/dev/conductor/core/lib/src/packages_autoroller.dart b/dev/conductor/core/lib/src/packages_autoroller.dart index b39a15936b..2f64ef070c 100644 --- a/dev/conductor/core/lib/src/packages_autoroller.dart +++ b/dev/conductor/core/lib/src/packages_autoroller.dart @@ -5,6 +5,8 @@ import 'dart:convert'; import 'dart:io' as io; +import 'package:file/file.dart'; +import 'package:meta/meta.dart'; import 'package:process/process.dart'; import 'git.dart'; @@ -93,6 +95,7 @@ This PR was generated by the automated log('Packages are already at latest.'); return; } + await generateGradleLockfiles(await framework.checkoutDirectory); await pushBranch(); await createPr(repository: await framework.checkoutDirectory); await authLogout(); @@ -135,6 +138,15 @@ This PR was generated by the automated return true; } + @visibleForTesting + Future generateGradleLockfiles(Directory repoRoot) async { + await framework.runDart([ + '${repoRoot.path}/dev/tools/bin/generate_gradle_lockfiles.dart', + '--no-gradle-generation', + '--no-exclusion', + ]); + } + Future pushBranch() async { final String projectName = framework.mirrorRemote!.url.split(r'/').last; // Encode the token into the remote URL for authentication to work diff --git a/dev/conductor/core/lib/src/repository.dart b/dev/conductor/core/lib/src/repository.dart index 64ba997870..8ca5f78f83 100644 --- a/dev/conductor/core/lib/src/repository.dart +++ b/dev/conductor/core/lib/src/repository.dart @@ -601,6 +601,13 @@ class FrameworkRepository extends Repository { ]); } + Future runDart(List args) async { + return processManager.run([ + fileSystem.path.join((await checkoutDirectory).path, 'bin', 'dart'), + ...args, + ]); + } + Future runFlutter(List args) async { await _ensureToolReady(); return processManager.run([ diff --git a/dev/conductor/core/test/packages_autoroller_test.dart b/dev/conductor/core/test/packages_autoroller_test.dart index 19d96d8171..4984319fc6 100644 --- a/dev/conductor/core/test/packages_autoroller_test.dart +++ b/dev/conductor/core/test/packages_autoroller_test.dart @@ -432,6 +432,12 @@ void main() { 'rev-parse', 'HEAD', ], stdout: '000deadbeef'), + const FakeCommand(command: [ + '$checkoutsParentDirectory/flutter_conductor_checkouts/framework/bin/dart', + '$checkoutsParentDirectory/flutter_conductor_checkouts/framework/dev/tools/bin/generate_gradle_lockfiles.dart', + '--no-gradle-generation', + '--no-exclusion', + ]), const FakeCommand(command: [ 'git', 'push', diff --git a/dev/tools/bin/generate_gradle_lockfiles.dart b/dev/tools/bin/generate_gradle_lockfiles.dart index 4c3f56bb80..b3d1b5efaf 100644 --- a/dev/tools/bin/generate_gradle_lockfiles.dart +++ b/dev/tools/bin/generate_gradle_lockfiles.dart @@ -2,12 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// For each directory specified in the stdin, this script generates: +// For `android` directory in the repo, this script generates: // 1. The top-level build.gradle (android/build.gradle). // 2. The top level settings.gradle (android/settings.gradle). // 3. The gradle wrapper file (android/gradle/wrapper/gradle-wrapper.properties). // Then it generate the lockfiles for each Gradle project. -// To regenerate these files, run `find . -type d -name 'android' | dart dev/tools/bin/generate_gradle_lockfiles.dart`. +// To regenerate these files, run `dart dev/tools/bin/generate_gradle_lockfiles.dart`. import 'dart:collection'; import 'dart:io'; @@ -15,16 +15,14 @@ import 'dart:io'; import 'package:args/args.dart'; import 'package:file/file.dart'; import 'package:file/local.dart'; -import 'package:path/path.dart' as path; import 'package:yaml/yaml.dart'; void main(List arguments) { - const String usageMessage = "Usage: find . -type d -name 'android' | dart dev/tools/bin/generate_gradle_lockfiles.dart\n" - 'If you would rather enter the files manually, just run `dart dev/tools/bin/generate_gradle_lockfiles.dart`,\n' - "enter the absolute paths to the app's android directory, then press CTRL-D.\n" - "If you don't wish to re-generate the settings.gradle, build.gradle, and gradle-wrapper.properties files,\n" + const String usageMessage = "If you don't wish to re-generate the " + 'settings.gradle, build.gradle, and gradle-wrapper.properties files,\n' 'add the flag `--no-gradle-generation`.\n' - 'This tool automatically excludes a set of android subdirectories, defined at dev/tools/bin/config/lockfile_exclusion.yaml.\n' + 'This tool automatically excludes a set of android subdirectories, ' + 'defined at dev/tools/bin/config/lockfile_exclusion.yaml.\n' 'To disable this behavior, run with `--no-exclusion`.\n'; final ArgParser argParser = ArgParser() @@ -56,10 +54,25 @@ void main(List arguments) { final bool useExclusion = (args['exclusion'] as bool?) ?? true; const FileSystem fileSystem = LocalFileSystem(); - final List androidDirectories = getFilesFromStdin(); - final File exclusionFile = fileSystem - .currentDirectory.childDirectory('dev').childDirectory('tools').childDirectory('bin') + final Directory repoRoot = (() { + final String repoRootPath = exec( + 'git', + const ['rev-parse', '--show-toplevel'], + ).trim(); + final Directory repoRoot = fileSystem.directory(repoRootPath); + if (!repoRoot.existsSync()) { + throw StateError("Expected $repoRoot to exist but it didn't!"); + } + return repoRoot; + })(); + + final Iterable androidDirectories = discoverAndroidDirectories(repoRoot); + + final File exclusionFile = repoRoot + .childDirectory('dev') + .childDirectory('tools') + .childDirectory('bin') .childDirectory('config') .childFile('lockfile_exclusion.yaml'); @@ -77,10 +90,7 @@ void main(List arguments) { print('Running without exclusion.'); } - - for (final String androidDirectoryPath in androidDirectories) { - final Directory androidDirectory = fileSystem.directory(path.normalize(androidDirectoryPath)); - + for (final Directory androidDirectory in androidDirectories) { if (!androidDirectory.existsSync()) { throw '$androidDirectory does not exist'; } @@ -188,19 +198,7 @@ void main(List arguments) { } } -List getFilesFromStdin() { - final List files = []; - while (true) { - final String? file = stdin.readLineSync(); - if (file == null) { - break; - } - files.add(file); - } - return files; -} - -void exec( +String exec( String cmd, List args, { String? workingDirectory, @@ -210,6 +208,7 @@ void exec( throw ProcessException( cmd, args, '${result.stdout}${result.stderr}', result.exitCode); } + return result.stdout as String; } const String rootGradleFileContent = r''' @@ -300,3 +299,9 @@ zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-all.zip '''; + +Iterable discoverAndroidDirectories(Directory repoRoot) { + return repoRoot.listSync(recursive: true) + .whereType() + .where((FileSystemEntity entity) => entity.basename == 'android'); +}