Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tool] New tool to download android dependencies #4408

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .ci/targets/android_platform_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ tasks:
- name: lint
script: script/tool_runner.sh
args: ["lint-android"]
- name: download android deps
reidbaker marked this conversation as resolved.
Show resolved Hide resolved
script: script/tool_runner.sh
infra_step: true
reidbaker marked this conversation as resolved.
Show resolved Hide resolved
args: ["fetch-android-deps"]
# Native unit and native integration are split into two steps to allow for
# different exclusions.
# TODO(stuartmorgan): Eliminate the native unit test exclusion, and combine
Expand Down
74 changes: 74 additions & 0 deletions script/tool/lib/src/fetch_gradle_deps_command.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:file/file.dart';
import 'package:platform/platform.dart';

import 'common/core.dart';
import 'common/gradle.dart';
import 'common/package_looping_command.dart';
import 'common/plugin_utils.dart';
import 'common/process_runner.dart';
import 'common/repository_package.dart';

/// Run 'gradlew dependencies'.
///
/// See https://docs.gradle.org/6.4/userguide/core_dependency_management.html#sec:dependency-mgmt-in-gradle.
class FetchGradleDeps extends PackageLoopingCommand {
reidbaker marked this conversation as resolved.
Show resolved Hide resolved
/// Creates an instance of the linter command.
FetchGradleDeps(
Directory packagesDir, {
ProcessRunner processRunner = const ProcessRunner(),
Platform platform = const LocalPlatform(),
}) : super(packagesDir, processRunner: processRunner, platform: platform);

@override
final String name = 'fetch-gradle-deps';

@override
final String description = 'Runs "gradlew dependencies" on Android plugins.\n\n'
'Requires the examples to have been build at least once before running.';

@override
Future<PackageResult> runForPackage(RepositoryPackage package) async {
if (!pluginSupportsPlatform(platformAndroid, package,
requiredMode: PlatformSupport.inline)) {
return PackageResult.skip(
'Plugin does not have an Android implementation.');
}

for (final RepositoryPackage example in package.getExamples()) {
final GradleProject project = GradleProject(example,
processRunner: processRunner, platform: platform);

if (!project.isConfigured()) {
final int exitCode = await processRunner.runAndStream(
flutterCommand,
<String>['build', 'apk', '--config-only'],
workingDir: example.directory,
);
if (exitCode != 0) {
printError('Unable to configure Gradle project.');
return PackageResult.fail(<String>['Unable to configure Gradle.']);
}
}

final String packageName = package.directory.basename;

// Only lint one build mode to avoid extra work.
// Only lint the plugin project itself, to avoid failing due to errors in
// dependencies.
//
// TODO(stuartmorgan): Consider adding an XML parser to read and summarize
// all results. Currently, only the first three errors will be shown
// inline, and the rest have to be checked via the CI-uploaded artifact.
reidbaker marked this conversation as resolved.
Show resolved Hide resolved
final int exitCode = await project.runCommand('$packageName:dependencies');
if (exitCode != 0) {
return PackageResult.fail();
}
}

return PackageResult.success();
}
}
2 changes: 2 additions & 0 deletions script/tool/lib/src/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import 'dart_test_command.dart';
import 'dependabot_check_command.dart';
import 'drive_examples_command.dart';
import 'federation_safety_check_command.dart';
import 'fetch_gradle_deps_command.dart';
import 'firebase_test_lab_command.dart';
import 'fix_command.dart';
import 'format_command.dart';
Expand Down Expand Up @@ -65,6 +66,7 @@ void main(List<String> args) {
..addCommand(DependabotCheckCommand(packagesDir))
..addCommand(DriveExamplesCommand(packagesDir))
..addCommand(FederationSafetyCheckCommand(packagesDir))
..addCommand(FetchGradleDeps(packagesDir))
..addCommand(FirebaseTestLabCommand(packagesDir))
..addCommand(FixCommand(packagesDir))
..addCommand(FormatCommand(packagesDir))
Expand Down
Loading