mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00

This PR rolls in a number of breaking changes from dart-lang/native: * `BuildMode` is no longer part of the protocol, so Flutter no longer passes it in. * This means all code dealing with the name conflict between `native_assets_cli.BuildMode` and `flutter_tools.BuildMode` has been cleaned up. * Also, the logs no longer mention the build mode. * The tests still exercise both modes, because linking only happens in release mode. * `OS` is no longer part of the main protocol, but of the "code" "protocol extension". * The code now aligns more with `OS?` being nullable in a bunch of places, since it is nullable if there's no code assets. * The OS-specific config is nested in an object per OS. * `CCompilerConfig`s fields are non-nullable now. * So instead of passing an object with nullable fields around, a null instead of the object is returned in various places. * `FileSystem` is now passed in to the native assets builder. This PR contains no feature changes. This PR will need to be followed up by restricting what environment variables are passed in (similar to https://github.com/dart-lang/native/pull/1764), I will do this in a follow up PR. Tests: * All existing features should be covered by existing tests.
53 lines
2.0 KiB
Dart
53 lines
2.0 KiB
Dart
// Copyright 2014 The Flutter Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
import 'package:logging/logging.dart';
|
|
import 'package:native_assets_cli/code_assets.dart';
|
|
import 'package:native_assets_cli/code_assets_builder.dart';
|
|
import 'package:native_toolchain_c/native_toolchain_c.dart';
|
|
|
|
void main(List<String> args) async {
|
|
await build(args, (BuildConfig config, BuildOutputBuilder output) async {
|
|
if (!config.buildAssetTypes.contains(CodeAsset.type)) {
|
|
return;
|
|
}
|
|
|
|
final String assetName;
|
|
if (config.linkingEnabled) {
|
|
// The link hook will be run. So emit an asset with a name that is
|
|
// not used, so that the link hook can rename it.
|
|
// This will ensure the test fails if the link-hooks are not run
|
|
// while being reported that linking is enabled.
|
|
assetName = 'some_asset_name_that_is_not_used';
|
|
} else {
|
|
// The link hook will not be run, so immediately emit an asset for
|
|
// bundling.
|
|
assetName = '${config.packageName}_bindings_generated.dart';
|
|
}
|
|
final String packageName = config.packageName;
|
|
final CBuilder cbuilder = CBuilder.library(
|
|
name: packageName,
|
|
assetName: assetName,
|
|
sources: <String>['src/$packageName.c'],
|
|
dartBuildFiles: <String>['hook/build.dart'],
|
|
);
|
|
final BuildOutputBuilder outputCatcher = BuildOutputBuilder();
|
|
await cbuilder.run(
|
|
config: config,
|
|
output: outputCatcher,
|
|
logger:
|
|
Logger('')
|
|
..level = Level.ALL
|
|
..onRecord.listen((LogRecord record) => print(record.message)),
|
|
);
|
|
final BuildOutput catchedOutput = BuildOutput(outputCatcher.json);
|
|
output.addDependencies(catchedOutput.dependencies);
|
|
// Send the asset to hook/link.dart or immediately for bundling.
|
|
output.codeAssets.add(
|
|
catchedOutput.codeAssets.single,
|
|
linkInPackage: config.linkingEnabled ? 'link_hook' : null,
|
|
);
|
|
});
|
|
}
|