|
1 | | -void main(List<String> args) async {} |
| 1 | +import 'dart:io'; |
| 2 | +import 'package:http/http.dart' as http; |
| 3 | +import 'package:native_assets_cli/native_assets_cli.dart'; |
| 4 | +import 'package:native_toolchain_c/native_toolchain_c.dart'; |
| 5 | + |
| 6 | +const assetFilename = 'libtext_classifier.dylib'; |
| 7 | +const assetLocation = |
| 8 | + 'https://storage.cloud.google.com/random-storage-asdf/$assetFilename'; |
| 9 | + |
| 10 | +File outputFile = File( |
| 11 | + '/Users/craiglabenz/Dev/git/google/flutter-mediapipe/packages/mediapipe-task-text/logs-build.txt'); |
| 12 | + |
| 13 | +final logs = <String>[]; |
| 14 | + |
| 15 | +void main(List<String> args) async { |
| 16 | + if (await outputFile.exists()) { |
| 17 | + await outputFile.delete(); |
| 18 | + } |
| 19 | + await outputFile.create(); |
| 20 | + |
| 21 | + log(args.join(' ')); |
| 22 | + _build(args); |
| 23 | + outputFile.writeAsString(logs.join('\n')); |
| 24 | +} |
| 25 | + |
| 26 | +Future<void> _build(List<String> args) async { |
| 27 | + final buildConfig = await BuildConfig.fromArgs(args); |
| 28 | + final buildOutput = BuildOutput(); |
| 29 | + final downloadUri = Uri.parse(assetLocation); |
| 30 | + final downloadFileLocation = buildConfig.outDir.resolve(assetFilename); |
| 31 | + log('Downloading $downloadUri'); |
| 32 | + final downloadResponse = await http.get(downloadUri); |
| 33 | + final downloadedFile = File(downloadFileLocation.toFilePath()); |
| 34 | + if (downloadResponse.statusCode == 200) { |
| 35 | + if (downloadedFile.existsSync()) { |
| 36 | + downloadedFile.deleteSync(); |
| 37 | + } |
| 38 | + downloadedFile.createSync(); |
| 39 | + downloadedFile.writeAsBytes(downloadResponse.bodyBytes); |
| 40 | + } |
| 41 | + buildOutput.dependencies.dependencies |
| 42 | + .add(buildConfig.packageRoot.resolve('build.dart')); |
| 43 | + buildOutput.assets.add( |
| 44 | + Asset( |
| 45 | + id: 'package:mediapipe_text/src/mediapipe_text_bindings.dart', |
| 46 | + linkMode: LinkMode.dynamic, |
| 47 | + target: Target.macOSArm64, |
| 48 | + path: AssetAbsolutePath(downloadFileLocation), |
| 49 | + ), |
| 50 | + ); |
| 51 | + await buildOutput.writeToFile(outDir: buildConfig.outDir); |
| 52 | + log(buildConfig.outDir.toString()); |
| 53 | +} |
| 54 | + |
| 55 | +void log(String val) { |
| 56 | + logs.add('\n[${DateTime.now().toIso8601String()}] $val\n'); |
| 57 | +} |
0 commit comments