Skip to content

Commit 6a7dacb

Browse files
authored
[FFI] MediaPipe SDKs finder automation (#16)
* adds sdks_finder command to builder utility * propagates changes to existing commands * adds manifest files generated by new sdks_finder command * updates in response to code review
1 parent 7850d32 commit 6a7dacb

File tree

12 files changed

+483
-12
lines changed

12 files changed

+483
-12
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
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Generated file. Do not manually edit.
2+
final Map<String, Map<String, String>> sdkDownloadUrls = {};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Generated file. Do not manually edit.
2+
final Map<String, Map<String, String>> sdkDownloadUrls = {
3+
'android': {
4+
'arm64': 'https://storage.googleapis.com/mediapipe-nightly-public/prod/mediapipe/gcp_ubuntu_flutter/release/17/20231212-090734/android_arm64/libtext.so'
5+
},
6+
'macos': {
7+
'arm64': 'https://storage.googleapis.com/mediapipe-nightly-public/prod/mediapipe/macos_flutter/release/7/20231204-130423/arm64/libtext.dylib',
8+
'x64': 'https://storage.googleapis.com/mediapipe-nightly-public/prod/mediapipe/macos_flutter/release/7/20231204-130423/x86_64/libtext.dylib'
9+
}
10+
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Generated file. Do not manually edit.
2+
final Map<String, Map<String, String>> sdkDownloadUrls = {
3+
'android': {
4+
'arm64': 'https://storage.googleapis.com/mediapipe-nightly-public/prod/mediapipe/gcp_ubuntu_flutter/release/17/20231212-090734/android_arm64/libvision.so'
5+
},
6+
'macos': {
7+
'arm64': 'https://storage.googleapis.com/mediapipe-nightly-public/prod/mediapipe/macos_flutter/release/7/20231204-130423/arm64/libvision.dylib',
8+
'x64': 'https://storage.googleapis.com/mediapipe-nightly-public/prod/mediapipe/macos_flutter/release/7/20231204-130423/x86_64/libvision.dylib'
9+
}
10+
};

tool/builder/bin/main.dart

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,18 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
import 'dart:io' as io;
65
import 'package:args/command_runner.dart';
76
import 'package:builder/download_model.dart';
7+
import 'package:builder/sdks_finder.dart';
88
import 'package:builder/sync_headers.dart';
9-
import 'package:logging/logging.dart';
109

1110
final runner = CommandRunner(
1211
'build',
1312
'Performs build operations for google/flutter-mediapipe that '
1413
'depend on contents in this repository',
1514
)
16-
..addCommand(SyncHeadersCommand())
17-
..addCommand(DownloadModelCommand());
15+
..addCommand(DownloadModelCommand())
16+
..addCommand(SdksFinderCommand())
17+
..addCommand(SyncHeadersCommand());
1818

19-
void main(List<String> arguments) {
20-
Logger.root.onRecord.listen((LogRecord record) {
21-
io.stdout
22-
.writeln('${record.level.name}: ${record.time}: ${record.message}');
23-
});
24-
runner.run(arguments);
25-
}
19+
void main(List<String> arguments) => runner.run(arguments);

tool/builder/lib/download_model.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class DownloadModelCommand extends Command with RepoFinderMixin {
6161
'if you use the `custommodel` option, but optional if you use the '
6262
'`model` option.',
6363
);
64+
addVerboseOption(argParser);
6465
}
6566

6667
static final Map<String, String> _standardModelSources = {
@@ -79,6 +80,7 @@ class DownloadModelCommand extends Command with RepoFinderMixin {
7980

8081
@override
8182
Future<void> run() async {
83+
setUpLogging();
8284
final io.Directory flutterMediaPipeDirectory = findFlutterMediaPipeRoot();
8385

8486
late final String modelSource;

tool/builder/lib/extensions.dart

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import 'dart:convert';
2+
import 'dart:io';
3+
4+
extension EasyOutput on Process {
5+
Future<List<String>> get processedStdErr => _process(this.stderr);
6+
7+
Future<List<String>> get processedStdOut => _process(this.stdout);
8+
9+
Future<List<String>> _process(Stream<List<int>> stream) async {
10+
return utf8.decoder
11+
.convert((await stream.toList())
12+
.fold<List<int>>([], (arr, el) => arr..addAll(el)))
13+
.split('\n');
14+
}
15+
}
16+
17+
/// Returns the last full chunk from a Url-like String.
18+
///
19+
/// From "/an/awesome/url/", returns "url".
20+
/// From "/an/awesome/url", returns "url".
21+
/// From "/an/awesome/url/", with a depth of 1, returns "awesome"
22+
/// From "/an/awesome/url", with a depth of 1, returns "awesome"
23+
String lastChunk(String url, {int depth = 0}) {
24+
final indexOffset = (url.endsWith('/')) ? -2 - depth : -1 - depth;
25+
final splitUrl = url.split('/');
26+
return splitUrl[splitUrl.length + indexOffset];
27+
}
28+
29+
extension DefaultableMap<K, V> on Map {
30+
void setDefault(K key, V def) {
31+
if (!containsKey(key)) {
32+
this[key] = def;
33+
}
34+
}
35+
}

tool/builder/lib/repo_finder.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import 'dart:io' as io;
66
import 'package:args/args.dart';
77
import 'package:args/command_runner.dart';
8+
import 'package:logging/logging.dart';
89
import 'package:path/path.dart' as path;
910
import 'package:io/ansi.dart';
1011

@@ -34,6 +35,18 @@ mixin RepoFinderMixin on Command {
3435
);
3536
}
3637

38+
void addVerboseOption(ArgParser argParser) =>
39+
argParser.addFlag('verbose', abbr: 'v', defaultsTo: false);
40+
41+
void setUpLogging() {
42+
final bool verbose = argResults!['verbose'];
43+
Logger.root.level = verbose ? Level.FINEST : Level.INFO;
44+
Logger.root.onRecord.listen((LogRecord record) {
45+
io.stdout.writeln(
46+
'[${record.loggerName}][${record.level.name}] ${record.message}');
47+
});
48+
}
49+
3750
/// Looks upward for the root of the `google/mediapipe` repository. This assumes
3851
/// the `dart build` command is executed from within said repository. If it is
3952
/// not executed from within, then this searching algorithm will reach the root

0 commit comments

Comments
 (0)