Skip to content

Commit

Permalink
Add a --no-gradle-generation mode to the `generate_gradle_lockfiles…
Browse files Browse the repository at this point in the history
….dart` script (flutter#145568)

The script currently overwrites existing `settings.gradle`, `build.gradle`, and `gradle-wrapper.properties` files in the directories it processes. This mode makes it not do that, and just generate the lockfiles themselves.

Related to flutter#145564 (comment)
  • Loading branch information
gmackall committed Mar 21, 2024
1 parent a36569d commit 3b390c5
Showing 1 changed file with 32 additions and 8 deletions.
40 changes: 32 additions & 8 deletions dev/tools/bin/generate_gradle_lockfiles.dart
Expand Up @@ -8,16 +8,38 @@

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;

void main(List<String> arguments) {
print(
"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"
);
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'";

final ArgParser argParser = ArgParser()
..addFlag(
'gradle-generation',
help: 'Re-generate gradle files in each processed directory.',
defaultsTo: true,
);

ArgResults args;
try {
args = argParser.parse(arguments);
} on FormatException catch (error) {
stderr.writeln('${error.message}\n');
stderr.writeln(usageMessage);
exit(1);
}

print(usageMessage);

/// Re-generate gradle files in each processed directory.
final bool gradleGeneration = (args['gradle-generation'] as bool?) ?? true;

const FileSystem fileSystem = LocalFileSystem();
final List<String> androidDirectories = getFilesFromStdin();
Expand Down Expand Up @@ -86,9 +108,11 @@ void main(List<String> arguments) {
// noop
}

rootBuildGradle.writeAsStringSync(rootGradleFileContent);
settingsGradle.writeAsStringSync(settingGradleFile);
wrapperGradle.writeAsStringSync(wrapperGradleFileContent);
if (gradleGeneration) {
rootBuildGradle.writeAsStringSync(rootGradleFileContent);
settingsGradle.writeAsStringSync(settingGradleFile);
wrapperGradle.writeAsStringSync(wrapperGradleFileContent);
}

final String appDirectory = androidDirectory.parent.absolute.path;

Expand Down

0 comments on commit 3b390c5

Please sign in to comment.