mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
[native_assets] Preparation existing tests for future of other (i.e. non-Code) assets (#160436)
In the future a hook may be invoked multiple times with different `supportedAssetTypes` (soon to be renamed to `buildAssetTypes`). The hook should only emit those asset types that are in `supportedAssetTypes` - anything else is an error. Right now flutter happens to invoke hooks only with `Code` asset types, but more asset types are coming, for which this PR is a preparation for.
This commit is contained in:
parent
a5902458c6
commit
181f4244b4
@ -9,6 +9,10 @@ import 'package:native_toolchain_c/native_toolchain_c.dart';
|
|||||||
|
|
||||||
void main(List<String> args) async {
|
void main(List<String> args) async {
|
||||||
await build(args, (BuildConfig config, BuildOutputBuilder output) async {
|
await build(args, (BuildConfig config, BuildOutputBuilder output) async {
|
||||||
|
if (!config.supportedAssetTypes.contains(CodeAsset.type)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
final String assetName;
|
final String assetName;
|
||||||
if (config.linkingEnabled) {
|
if (config.linkingEnabled) {
|
||||||
// The link hook will be run. So emit an asset with a name that is
|
// The link hook will be run. So emit an asset with a name that is
|
||||||
|
@ -6,6 +6,9 @@ import 'package:native_assets_cli/code_assets.dart';
|
|||||||
|
|
||||||
void main(List<String> args) async {
|
void main(List<String> args) async {
|
||||||
await link(args, (LinkConfig config, LinkOutputBuilder output) async {
|
await link(args, (LinkConfig config, LinkOutputBuilder output) async {
|
||||||
|
if (!config.supportedAssetTypes.contains(CodeAsset.type)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
final CodeAsset asset = config.codeAssets.single;
|
final CodeAsset asset = config.codeAssets.single;
|
||||||
final String packageName = config.packageName;
|
final String packageName = config.packageName;
|
||||||
output.codeAssets.add(
|
output.codeAssets.add(
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
@Timeout(Duration(minutes: 10))
|
@Timeout(Duration(minutes: 10))
|
||||||
library;
|
library;
|
||||||
|
|
||||||
|
import 'dart:convert';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:file/file.dart';
|
import 'package:file/file.dart';
|
||||||
@ -465,14 +466,14 @@ void expectCCompilerIsConfigured(Directory appDirectory) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
final File config = subDir.childFile('config.json');
|
final File configFile = subDir.childFile('config.json');
|
||||||
expect(config, exists);
|
expect(configFile, exists);
|
||||||
final String contents = config.readAsStringSync();
|
final Map<String, Object?> config =
|
||||||
// Dry run does not pass compiler info.
|
json.decode(configFile.readAsStringSync()) as Map<String, Object?>;
|
||||||
if (contents.contains('"dry_run": true')) {
|
if (!(config['supported_asset_types']! as List<dynamic>).contains(CodeAsset.type)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
expect(contents, contains('"cc": '));
|
expect((config['c_compiler']! as Map<String, Object?>)['cc'], isNotNull);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,14 +180,18 @@ FFI_PLUGIN_EXPORT intptr_t add(intptr_t a, intptr_t b) {
|
|||||||
|
|
||||||
// Update builder to build the native library and link it into the main library.
|
// Update builder to build the native library and link it into the main library.
|
||||||
const String builderSource = r'''
|
const String builderSource = r'''
|
||||||
import 'package:native_toolchain_c/native_toolchain_c.dart';
|
|
||||||
import 'package:logging/logging.dart';
|
import 'package:logging/logging.dart';
|
||||||
import 'package:native_assets_cli/native_assets_cli.dart';
|
import 'package:native_assets_cli/code_assets.dart';
|
||||||
|
import 'package:native_toolchain_c/native_toolchain_c.dart';
|
||||||
|
|
||||||
void main(List<String> args) async {
|
void main(List<String> args) async {
|
||||||
await build(args, (config, output) async {
|
await build(args, (config, output) async {
|
||||||
final packageName = config.packageName;
|
final packageName = config.packageName;
|
||||||
|
|
||||||
|
if (!config.supportedAssetTypes.contains(CodeAsset.type)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
final builders = [
|
final builders = [
|
||||||
CBuilder.library(
|
CBuilder.library(
|
||||||
name: 'add',
|
name: 'add',
|
||||||
|
Loading…
Reference in New Issue
Block a user