Skip to content

Commit a99fc87

Browse files
[tool/ci] Add iOS/macOS and Dart support to fetch-deps (flutter#4562)
Adds `fetch-deps` support for: - iOS/macOS dependencies, using `pod install` - Dart package dependencies, using `pub get` To make avoid doing extra work in the Dart dependencies step when using this with `*_platform_tests` CI, also adds flags for all of the other platforms, and adds a flag that allows skipping Dart dependencies for any package that doesn't have an example supporting any requested platform. This means that we can pass, e.g., `--windows --supporting-target-platforms-only` to only fetch Dart packages for packages with examples that will be build during the build-and-drive Windows tests. Adds this as a new step in every platform tests CI task, and in the standard analyze step, so that we will pre-fetch Dart packages (and for iOS/macOS, pods). This won't yet fully eliminate later network access (see flutter/flutter#131204), but will give us early warning on any major failures, such as pub being entirely unreachable from the bots. - These are marked as an infrastructure step; we'll have to see if this ends up being confusing in practice. If `pub` resolution fails for legitimate reasons, such as a PR that tries to require a version of a package that doesn't exist or that has conflicts, this will cause a failure that is marked as infra. My assumption is that the much more common case is going to be that it is actually an infra failure. Fixes flutter/flutter#130280
1 parent 406eac1 commit a99fc87

15 files changed

+903
-65
lines changed

.ci/targets/analyze.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ tasks:
44
infra_step: true # Note infra steps failing prevents "always" from running.
55
- name: analyze repo tools
66
script: .ci/scripts/analyze_repo_tools.sh
7+
- name: download Dart deps
8+
script: script/tool_runner.sh
9+
args: ["fetch-deps"]
10+
infra_step: true
711
- name: analyze
812
script: script/tool_runner.sh
913
# DO NOT change the custom-analysis argument here without changing the Dart repo.

.ci/targets/android_platform_tests.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ tasks:
22
- name: prepare tool
33
script: .ci/scripts/prepare_tool.sh
44
infra_step: true # Note infra steps failing prevents "always" from running.
5-
- name: download android deps
5+
- name: download Dart and Android deps
66
script: script/tool_runner.sh
77
infra_step: true
8-
args: ["fetch-deps"]
8+
args: ["fetch-deps", "--android", "--supporting-target-platforms-only"]
99
- name: build examples
1010
script: script/tool_runner.sh
1111
args: ["build-examples", "--apk"]

.ci/targets/ios_platform_tests.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ tasks:
55
- name: create simulator
66
script: .ci/scripts/create_simulator.sh
77
infra_step: true # Note infra steps failing prevents "always" from running.
8+
- name: download Dart and iOS deps
9+
script: script/tool_runner.sh
10+
args: ["fetch-deps", "--ios", "--supporting-target-platforms-only"]
11+
infra_step: true
812
- name: build examples
913
script: script/tool_runner.sh
1014
args: ["build-examples", "--ios"]

.ci/targets/linux_platform_tests.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ tasks:
33
script: .ci/scripts/prepare_tool.sh
44
- name: set default apps
55
script: .ci/scripts/set_default_linux_apps.sh
6+
infra_step: true
7+
- name: download Dart deps
8+
script: script/tool_runner.sh
9+
args: ["fetch-deps", "--linux", "--supporting-target-platforms-only"]
10+
infra_step: true
611
- name: build examples
712
script: script/tool_runner.sh
813
args: ["build-examples", "--linux"]

.ci/targets/macos_platform_tests.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ tasks:
22
- name: prepare tool
33
script: .ci/scripts/prepare_tool.sh
44
infra_step: true # Note infra steps failing prevents "always" from running.
5+
- name: download Dart and macOS deps
6+
script: script/tool_runner.sh
7+
args: ["fetch-deps", "--macos", "--supporting-target-platforms-only"]
8+
infra_step: true
59
- name: build examples
610
script: script/tool_runner.sh
711
args: ["build-examples", "--macos"]

.ci/targets/web_platform_tests.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ tasks:
22
- name: prepare tool
33
script: .ci/scripts/prepare_tool.sh
44
infra_step: true # Note infra steps failing prevents "always" from running.
5+
- name: download Dart deps
6+
script: script/tool_runner.sh
7+
args: ["fetch-deps", "--web", "--supporting-target-platforms-only"]
8+
infra_step: true
59
- name: build examples
610
script: script/tool_runner.sh
711
args: ["build-examples", "--web"]

.ci/targets/windows_build_and_platform_tests.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ tasks:
22
- name: prepare tool
33
script: .ci/scripts/prepare_tool.sh
44
infra_step: true # Note infra steps failing prevents "always" from running.
5+
- name: download Dart deps
6+
script: script/tool_runner.sh
7+
args: ["fetch-deps", "--windows", "--supporting-target-platforms-only"]
8+
infra_step: true
59
- name: build examples (Win32)
610
script: .ci/scripts/build_examples_win32.sh
711
- name: native unit tests (Win32)

script/tool/lib/src/build_examples_command.dart

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,8 @@ class BuildExamplesCommand extends PackageLoopingCommand {
176176
// supported platforms. For packages, just log and skip any requested
177177
// platform that a package doesn't have set up.
178178
if (!isPlugin &&
179-
!example.directory
180-
.childDirectory(platform.flutterPlatformDirectory)
181-
.existsSync()) {
179+
!example.appSupportsPlatform(
180+
getPlatformByName(platform.pluginPlatform))) {
182181
print('Skipping ${platform.label} for $packageName; not supported.');
183182
continue;
184183
}
@@ -304,11 +303,6 @@ class _PlatformDetails {
304303
/// The `flutter build` build type.
305304
final String flutterBuildType;
306305

307-
/// The Flutter platform directory name.
308-
// In practice, this is the same as the plugin platform key for all platforms.
309-
// If that changes, this can be adjusted.
310-
String get flutterPlatformDirectory => pluginPlatform;
311-
312306
/// Any extra flags to pass to `flutter build`.
313307
final List<String> extraBuildFlags;
314308
}

script/tool/lib/src/common/core.dart

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,25 @@ const String kEnableExperiment = 'enable-experiment';
3737
// ignore: public_member_api_docs
3838
enum FlutterPlatform { android, ios, linux, macos, web, windows }
3939

40+
const Map<String, FlutterPlatform> _platformByName = <String, FlutterPlatform>{
41+
platformAndroid: FlutterPlatform.android,
42+
platformIOS: FlutterPlatform.ios,
43+
platformLinux: FlutterPlatform.linux,
44+
platformMacOS: FlutterPlatform.macos,
45+
platformWeb: FlutterPlatform.web,
46+
platformWindows: FlutterPlatform.windows,
47+
};
48+
49+
/// Maps from a platform name (e.g., flag or platform directory) to the
50+
/// corresponding platform enum.
51+
FlutterPlatform getPlatformByName(String name) {
52+
final FlutterPlatform? platform = _platformByName[name];
53+
if (platform == null) {
54+
throw ArgumentError('Invalid platform: $name');
55+
}
56+
return platform;
57+
}
58+
4059
// Flutter->Dart SDK version mapping. Any time a command fails to look up a
4160
// corresponding version, this map should be updated.
4261
final Map<Version, Version> _dartSdkForFlutterSdk = <Version, Version>{

script/tool/lib/src/common/process_runner.dart

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,13 @@ class ProcessRunner {
3030
String executable,
3131
List<String> args, {
3232
Directory? workingDir,
33+
Map<String, String>? environment,
3334
bool exitOnError = false,
3435
}) async {
3536
print(
3637
'Running command: "$executable ${args.join(' ')}" in ${workingDir?.path ?? io.Directory.current.path}');
3738
final io.Process process = await io.Process.start(executable, args,
38-
workingDirectory: workingDir?.path);
39+
workingDirectory: workingDir?.path, environment: environment);
3940
await Future.wait(<Future<dynamic>>[
4041
io.stdout.addStream(process.stdout),
4142
io.stderr.addStream(process.stderr),
@@ -62,14 +63,19 @@ class ProcessRunner {
6263
/// Defaults to `false`
6364
///
6465
/// Returns the [io.ProcessResult] of the [executable].
65-
Future<io.ProcessResult> run(String executable, List<String> args,
66-
{Directory? workingDir,
67-
bool exitOnError = false,
68-
bool logOnError = false,
69-
Encoding stdoutEncoding = io.systemEncoding,
70-
Encoding stderrEncoding = io.systemEncoding}) async {
66+
Future<io.ProcessResult> run(
67+
String executable,
68+
List<String> args, {
69+
Directory? workingDir,
70+
Map<String, String>? environment,
71+
bool exitOnError = false,
72+
bool logOnError = false,
73+
Encoding stdoutEncoding = io.systemEncoding,
74+
Encoding stderrEncoding = io.systemEncoding,
75+
}) async {
7176
final io.ProcessResult result = await io.Process.run(executable, args,
7277
workingDirectory: workingDir?.path,
78+
environment: environment,
7379
stdoutEncoding: stdoutEncoding,
7480
stderrEncoding: stderrEncoding);
7581
if (result.exitCode != 0) {

script/tool/lib/src/common/repository_package.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,16 @@ class RepositoryPackage {
9292
return directory.childDirectory(directoryName);
9393
}
9494

95+
/// Returns true if the package is an app that supports [platform].
96+
///
97+
/// The "app" prefix on this method is because this currently only works
98+
/// for app packages (e.g., examples).
99+
// TODO(stuartmorgan): Add support for non-app packages, by parsing the
100+
// pubspec for `flutter:platform:` or `platform:` sections.
101+
bool appSupportsPlatform(FlutterPlatform platform) {
102+
return platformDirectory(platform).existsSync();
103+
}
104+
95105
late final Pubspec _parsedPubspec =
96106
Pubspec.parse(pubspecFile.readAsStringSync());
97107

script/tool/lib/src/drive_examples_command.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ class DriveExamplesCommand extends PackageLoopingCommand {
254254
for (final MapEntry<String, List<String>> entry
255255
in _targetDeviceFlags.entries) {
256256
final String platform = entry.key;
257-
if (example.directory.childDirectory(platform).existsSync()) {
257+
if (example.appSupportsPlatform(getPlatformByName(platform))) {
258258
deviceFlags.addAll(entry.value);
259259
} else {
260260
final String exampleName =

0 commit comments

Comments
 (0)