mirror of
https://github.com/flutter/packages.git
synced 2025-06-08 21:09:17 +08:00
[flutter_plugin_tools] Add a command to lint Android code (#4206)
Adds a new `lint-android` command to run `gradlew lint` on Android plugins. Also standardizes the names of the Cirrus tasks that run all the build and platform-specific (i.e., not Dart unit test) tests for each platform, as they were getting unnecessarily long and complex in some cases. Fixes https://github.com/flutter/flutter/issues/87071
This commit is contained in:
@ -10,6 +10,7 @@ import 'package:platform/platform.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
import 'common/core.dart';
|
||||
import 'common/gradle.dart';
|
||||
import 'common/package_looping_command.dart';
|
||||
import 'common/process_runner.dart';
|
||||
|
||||
@ -74,8 +75,6 @@ class FirebaseTestLabCommand extends PackageLoopingCommand {
|
||||
'Runs tests in test_instrumentation folder using the '
|
||||
'instrumentation_test package.';
|
||||
|
||||
static const String _gradleWrapper = 'gradlew';
|
||||
|
||||
bool _firebaseProjectConfigured = false;
|
||||
|
||||
Future<void> _configureFirebaseProject() async {
|
||||
@ -138,13 +137,15 @@ class FirebaseTestLabCommand extends PackageLoopingCommand {
|
||||
}
|
||||
|
||||
// Ensures that gradle wrapper exists
|
||||
if (!await _ensureGradleWrapperExists(androidDirectory)) {
|
||||
final GradleProject project = GradleProject(exampleDirectory,
|
||||
processRunner: processRunner, platform: platform);
|
||||
if (!await _ensureGradleWrapperExists(project)) {
|
||||
return PackageResult.fail(<String>['Unable to build example apk']);
|
||||
}
|
||||
|
||||
await _configureFirebaseProject();
|
||||
|
||||
if (!await _runGradle(androidDirectory, 'app:assembleAndroidTest')) {
|
||||
if (!await _runGradle(project, 'app:assembleAndroidTest')) {
|
||||
return PackageResult.fail(<String>['Unable to assemble androidTest']);
|
||||
}
|
||||
|
||||
@ -156,8 +157,7 @@ class FirebaseTestLabCommand extends PackageLoopingCommand {
|
||||
for (final File test in _findIntegrationTestFiles(package)) {
|
||||
final String testName = getRelativePosixPath(test, from: package);
|
||||
print('Testing $testName...');
|
||||
if (!await _runGradle(androidDirectory, 'app:assembleDebug',
|
||||
testFile: test)) {
|
||||
if (!await _runGradle(project, 'app:assembleDebug', testFile: test)) {
|
||||
printError('Could not build $testName');
|
||||
errors.add('$testName failed to build');
|
||||
continue;
|
||||
@ -204,12 +204,12 @@ class FirebaseTestLabCommand extends PackageLoopingCommand {
|
||||
: PackageResult.fail(errors);
|
||||
}
|
||||
|
||||
/// Checks that 'gradlew' exists in [androidDirectory], and if not runs a
|
||||
/// Checks that Gradle has been configured for [project], and if not runs a
|
||||
/// Flutter build to generate it.
|
||||
///
|
||||
/// Returns true if either gradlew was already present, or the build succeeds.
|
||||
Future<bool> _ensureGradleWrapperExists(Directory androidDirectory) async {
|
||||
if (!androidDirectory.childFile(_gradleWrapper).existsSync()) {
|
||||
Future<bool> _ensureGradleWrapperExists(GradleProject project) async {
|
||||
if (!project.isConfigured()) {
|
||||
print('Running flutter build apk...');
|
||||
final String experiment = getStringArg(kEnableExperiment);
|
||||
final int exitCode = await processRunner.runAndStream(
|
||||
@ -219,7 +219,7 @@ class FirebaseTestLabCommand extends PackageLoopingCommand {
|
||||
'apk',
|
||||
if (experiment.isNotEmpty) '--enable-experiment=$experiment',
|
||||
],
|
||||
workingDir: androidDirectory);
|
||||
workingDir: project.androidDirectory);
|
||||
|
||||
if (exitCode != 0) {
|
||||
return false;
|
||||
@ -228,15 +228,15 @@ class FirebaseTestLabCommand extends PackageLoopingCommand {
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Builds [target] using 'gradlew' in the given [directory]. Assumes
|
||||
/// 'gradlew' already exists.
|
||||
/// Builds [target] using Gradle in the given [project]. Assumes Gradle is
|
||||
/// already configured.
|
||||
///
|
||||
/// [testFile] optionally does the Flutter build with the given test file as
|
||||
/// the build target.
|
||||
///
|
||||
/// Returns true if the command succeeds.
|
||||
Future<bool> _runGradle(
|
||||
Directory directory,
|
||||
GradleProject project,
|
||||
String target, {
|
||||
File? testFile,
|
||||
}) async {
|
||||
@ -245,17 +245,15 @@ class FirebaseTestLabCommand extends PackageLoopingCommand {
|
||||
? Uri.encodeComponent('--enable-experiment=$experiment')
|
||||
: null;
|
||||
|
||||
final int exitCode = await processRunner.runAndStream(
|
||||
directory.childFile(_gradleWrapper).path,
|
||||
<String>[
|
||||
target,
|
||||
'-Pverbose=true',
|
||||
if (testFile != null) '-Ptarget=${testFile.path}',
|
||||
if (extraOptions != null) '-Pextra-front-end-options=$extraOptions',
|
||||
if (extraOptions != null)
|
||||
'-Pextra-gen-snapshot-options=$extraOptions',
|
||||
],
|
||||
workingDir: directory);
|
||||
final int exitCode = await project.runCommand(
|
||||
target,
|
||||
arguments: <String>[
|
||||
'-Pverbose=true',
|
||||
if (testFile != null) '-Ptarget=${testFile.path}',
|
||||
if (extraOptions != null) '-Pextra-front-end-options=$extraOptions',
|
||||
if (extraOptions != null) '-Pextra-gen-snapshot-options=$extraOptions',
|
||||
],
|
||||
);
|
||||
|
||||
if (exitCode != 0) {
|
||||
return false;
|
||||
|
Reference in New Issue
Block a user