Skip to content

Commit f3ad3b5

Browse files
committed
updates in response to code review
1 parent c81cfb1 commit f3ad3b5

File tree

3 files changed

+64
-7
lines changed

3 files changed

+64
-7
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ test: generate_text test_text generate_core test_core
1111
# Runs `ffigen` for all packages and all tests for all packages
1212
test_only: test_core test_text
1313

14+
# Runs `sdks_finder` to update manifest files
15+
sdks:
16+
dart tool/builder/bin/main.dart sdks
17+
1418
# Core ---
1519

1620
# Runs `ffigen` for `mediapipe_core`

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
11
# Flutter-MediaPipe
22

33
This repository will be home to the source code for the mediapipe_task_vision, mediapipe_task_audio, and mediapipe_task_text plugins for Flutter.
4+
5+
## Releasing
6+
7+
### Updating MediaPipe SDKs
8+
9+
Anytime MediaPipe releases new versions of their SDKs, this package will need to be updated to incorporate those latest builds. SDK versions are pinned in the `sdk_downloads.json` files in each package, which are updated by running the following command from the root of the repository:
10+
11+
```
12+
$ make sdks
13+
```
14+
15+
The Google Cloud Storage bucket in question only gives read-list access to a specific list of Googlers' accounts, so this command must be run from such a Googler's corp machines.
16+
17+
After this, create and merge a PR with the changes and then proceed to `Releasing to pub.dev`.
18+
19+
### Releasing to pub.dev
20+
21+
TODO

tool/builder/lib/sdks_finder.dart

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'dart:convert';
22
import 'dart:io';
3+
import 'dart:io' as io;
34

45
import 'package:args/command_runner.dart';
56
import 'package:builder/extensions.dart';
@@ -47,9 +48,12 @@ enum MediaPipeSdk {
4748
/// command helps by automating a portion of the task.
4849
///
4950
/// The cache-busting mechanism of Flutter's native assets feature is a hash
50-
/// of the contents of any build dependencies, so if this command leads to any
51-
/// new build state, this must be reflected by *some change* to the associated
52-
/// library's `build.dart` script.
51+
/// of the contents of any build dependencies. The output files of this command
52+
/// are included in the build dependencies (as specified by the contents of each
53+
/// package's `build.dart` file), so if this command generates new SDK locations
54+
/// in those files, Flutter's CLI will have a cache miss, will re-run
55+
/// `build.dart` during the build phase, and in turn will download the newest
56+
/// versions of the MediaPipe SDKs onto the developer's machine.
5357
///
5458
/// Operationally, [SdksFinderCommand]'s implementation involves orchestrating
5559
/// one [_OsFinder] instance for each supported [OS] value, which in turn
@@ -67,7 +71,7 @@ class SdksFinderCommand extends Command with RepoFinderMixin {
6771
}
6872
@override
6973
String description =
70-
'Downloads the appropriate MediaPipe SDKs for the current build target';
74+
'Updates MediaPipe SDK manifest files for the current build target';
7175

7276
@override
7377
String name = 'sdks';
@@ -120,9 +124,26 @@ final Map<String, Map<String, String>> sdkDownloadUrls = ${encoder.convert(resul
120124
}
121125

122126
void _checkGsUtil() async {
127+
if (!io.Platform.isMacOS && !io.Platform.isLinux) {
128+
// `which` is not available on Windows, so allow the command to attempt
129+
// to run on Windows
130+
// TODO: possibly add Windows-specific support
131+
return;
132+
}
123133
final process = await Process.start('which', ['gsutil']);
124-
await process.exitCode;
125-
if ((await process.processedStdOut).isEmpty) {
134+
final exitCode = await process.exitCode;
135+
final List<String> processStdOut = (await process.processedStdOut);
136+
if (exitCode != 0) {
137+
stderr.writeln(
138+
wrapWith(
139+
'Warning: Unexpected exit code $exitCode checking for gsutil. Output:'
140+
'${processStdOut.join('\n')}',
141+
[yellow],
142+
),
143+
);
144+
// Not exiting here, since this could be a false-negative.
145+
}
146+
if (processStdOut.isEmpty) {
126147
stderr.writeln(
127148
wrapWith(
128149
'gsutil command not found. Visit: '
@@ -297,7 +318,21 @@ Future<List<String>> _gsUtil(String path, {bool recursive = false}) async {
297318
];
298319
_log.finest('Running: `gsutil ${cmd.join(' ')}`');
299320
final process = await Process.start('gsutil', cmd);
300-
await process.exitCode;
321+
final exitCode = await process.exitCode;
322+
if (exitCode > 1) {
323+
// Exit codes of 1 appear when `gsutil` checks for a file that does not
324+
// exist, which for our purposes does not constitute an actual error, and is
325+
// handled later when `process.processedStdOut` is empty.
326+
stderr.writeln(
327+
wrapWith(
328+
'Warning: Unexpected exit code $exitCode running '
329+
'`gsutil ${cmd.join(' ')}`. Output: '
330+
'${(await process.processedStdOut).join('\n')}',
331+
[red],
332+
),
333+
);
334+
exit(exitCode);
335+
}
301336
final processStdout = await process.processedStdOut;
302337
final filtered = (processStdout).where((String line) => line != '').toList();
303338
return filtered;

0 commit comments

Comments
 (0)