Give generate_gradle_lockfiles.dart
functionality to exclude certain subdirectories (#146228)
Fixes https://github.com/flutter/flutter/issues/146216.
This commit is contained in:
parent
226546b640
commit
1d89ae3f65
13
dev/tools/bin/config/lockfile_exclusion.yaml
Normal file
13
dev/tools/bin/config/lockfile_exclusion.yaml
Normal file
@ -0,0 +1,13 @@
|
||||
# Tests that are excluded from batch Gradle updating and lockfile generation.
|
||||
# Each exclusion must have an associated reason. Please avoid adding to this list unless necessary,
|
||||
# as each exclusion must be updated by hand.
|
||||
|
||||
# flutter_gallery uses discontinued plugins with old AGP versions that block the app itself using
|
||||
# a newer AGP version.
|
||||
- dev/integration_tests/flutter_gallery/android
|
||||
|
||||
# gradle_deprecated_settings intentionally uses a Gradle file structure matching an old output of
|
||||
# `flutter create`. It must be updated manually, by changing the desired versions in the Gradle
|
||||
# files, and then running `rm buildscript-gradle.lockfile && ./gradlew :generateLockfiles` from
|
||||
# its android subdirectory.
|
||||
- dev/integration_tests/gradle_deprecated_settings/android
|
@ -2,29 +2,40 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// This script generates `android/build.gradle` for each directory specify in the stdin.
|
||||
// For each directory specified in the stdin, 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 `find . -type d -name 'android' | dart dev/tools/bin/generate_gradle_lockfiles.dart`.
|
||||
|
||||
import 'dart:collection';
|
||||
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<String> 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"
|
||||
"add the flag '--no-gradle-generation'";
|
||||
'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'
|
||||
'To disable this behavior, run with `--no-exclusion`.\n';
|
||||
|
||||
final ArgParser argParser = ArgParser()
|
||||
..addFlag(
|
||||
'gradle-generation',
|
||||
help: 'Re-generate gradle files in each processed directory.',
|
||||
defaultsTo: true,
|
||||
)..addFlag(
|
||||
'exclusion',
|
||||
help: 'Run the script using the config file at ./configs/lockfile_exclusion.yaml to skip the specified subdirectories.',
|
||||
defaultsTo: true,
|
||||
);
|
||||
|
||||
ArgResults args;
|
||||
@ -41,9 +52,32 @@ void main(List<String> arguments) {
|
||||
/// Re-generate gradle files in each processed directory.
|
||||
final bool gradleGeneration = (args['gradle-generation'] as bool?) ?? true;
|
||||
|
||||
// Skip android subdirectories specified in the ./config/lockfile_exclusion.yaml file.
|
||||
final bool useExclusion = (args['exclusion'] as bool?) ?? true;
|
||||
|
||||
const FileSystem fileSystem = LocalFileSystem();
|
||||
final List<String> androidDirectories = getFilesFromStdin();
|
||||
|
||||
final File exclusionFile = fileSystem
|
||||
.currentDirectory.childDirectory('dev').childDirectory('tools').childDirectory('bin')
|
||||
.childDirectory('config')
|
||||
.childFile('lockfile_exclusion.yaml');
|
||||
|
||||
// Load the exclusion set, or make an empty exclusion set.
|
||||
final Set<String> exclusionSet;
|
||||
if (useExclusion) {
|
||||
exclusionSet = HashSet<String>.from(
|
||||
(loadYaml(exclusionFile.readAsStringSync()) as YamlList)
|
||||
.toList()
|
||||
.cast<String>()
|
||||
);
|
||||
print('Loaded exclusion file from ${exclusionFile.path}.');
|
||||
} else {
|
||||
exclusionSet = <String>{};
|
||||
print('Running without exclusion.');
|
||||
}
|
||||
|
||||
|
||||
for (final String androidDirectoryPath in androidDirectories) {
|
||||
final Directory androidDirectory = fileSystem.directory(path.normalize(androidDirectoryPath));
|
||||
|
||||
@ -51,6 +85,11 @@ void main(List<String> arguments) {
|
||||
throw '$androidDirectory does not exist';
|
||||
}
|
||||
|
||||
if (exclusionSet.contains(androidDirectory.path)) {
|
||||
print('${androidDirectory.path} is included in the exclusion config file at ${exclusionFile.path} - skipping');
|
||||
continue;
|
||||
}
|
||||
|
||||
final File rootBuildGradle = androidDirectory.childFile('build.gradle');
|
||||
if (!rootBuildGradle.existsSync()) {
|
||||
print('${rootBuildGradle.path} does not exist - skipping');
|
||||
|
@ -13,6 +13,7 @@ dependencies:
|
||||
path: 1.9.0
|
||||
process: 5.0.2
|
||||
pub_semver: 2.1.4
|
||||
yaml: 3.1.2
|
||||
|
||||
async: 2.11.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
clock: 1.1.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
@ -60,6 +61,5 @@ dev_dependencies:
|
||||
web: 0.5.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
web_socket_channel: 2.4.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
webkit_inspection_protocol: 1.2.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
yaml: 3.1.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
|
||||
|
||||
# PUBSPEC CHECKSUM: 146d
|
||||
|
Loading…
x
Reference in New Issue
Block a user