Skip to content

Commit

Permalink
[native_assets_cli] Rename supportedAssetTypes to buildAssetTypes (
Browse files Browse the repository at this point in the history
…#1786)

This PR changes the `supportedAssetTypes` to `buildAssetTypes`.

Hooks should not fail early if an asset type is not supported. This enables the following situations:

1. If some part of the Dart code requires an asset, but is not invoked transitively, the Dart code can still run in JIT, instead of failing on the build hook.
2. If an asset is not available, Dart code could fallback on a Dart implementation.
3. Hot reload hook invocations can omit the asset types that are not supported for hot reload (#1207 (comment)).

The PR changes both the Dart API and the JSON protocol. The JSON protocol passes and parses the old key for the time being to allow for a graceful transition until this rolls into a next Dart stable release and we can bump the lower SDK bound.

Side note:

* The refactorings somehow started disallowing version skew where an older SDK is used with a newer `package:native_assets_cli`, but we do allow this, we can fill in the blanks (see `pkgs/native_assets_cli/lib/src/model/build_config_CHANGELOG.md`). So this PR adds a lowest-parsable-version.
  • Loading branch information
dcharkes authored Dec 6, 2024
1 parent 7e9897b commit 0caab92
Show file tree
Hide file tree
Showing 58 changed files with 243 additions and 226 deletions.
6 changes: 6 additions & 0 deletions pkgs/native_assets_builder/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## 0.9.1-wip

- **Breaking change**: Rename `supportedAssetTypes` to `buildAssetTypes`. Hooks
should no longer fail. Instead, the code should fail at runtime if an asset is
missing. This enables (1) code to run if an asset is missing but that code is
not invoked at runtime, and (2) doing fallback implementations in Dart if an
asset is missing.

## 0.9.0

- Also lock `BuildConfig` and `LinkConfig` `outputDirectoryShared` when invoking
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class NativeAssetsBuildRunner {
required Uri workingDirectory,
PackageLayout? packageLayout,
String? runPackageName,
required List<String> supportedAssetTypes,
required List<String> buildAssetTypes,
required bool linkingEnabled,
}) async {
packageLayout ??= await PackageLayout.fromRootPackageRoot(workingDirectory);
Expand All @@ -124,7 +124,7 @@ class NativeAssetsBuildRunner {
final configBuilder = configCreator()
..setupHookConfig(
targetOS: targetOS,
supportedAssetTypes: supportedAssetTypes,
buildAssetTypes: buildAssetTypes,
buildMode: buildMode,
packageName: package.name,
packageRoot: packageLayout.packageRoot(package.name),
Expand Down Expand Up @@ -206,7 +206,7 @@ class NativeAssetsBuildRunner {
PackageLayout? packageLayout,
Uri? resourceIdentifiers,
String? runPackageName,
required List<String> supportedAssetTypes,
required List<String> buildAssetTypes,
required BuildResult buildResult,
}) async {
packageLayout ??= await PackageLayout.fromRootPackageRoot(workingDirectory);
Expand All @@ -224,7 +224,7 @@ class NativeAssetsBuildRunner {
final configBuilder = configCreator()
..setupHookConfig(
targetOS: targetOS,
supportedAssetTypes: supportedAssetTypes,
buildAssetTypes: buildAssetTypes,
buildMode: buildMode,
packageName: package.name,
packageRoot: packageLayout.packageRoot(package.name),
Expand Down Expand Up @@ -328,7 +328,7 @@ class NativeAssetsBuildRunner {
required bool linkingEnabled,
PackageLayout? packageLayout,
String? runPackageName,
required List<String> supportedAssetTypes,
required List<String> buildAssetTypes,
}) =>
_runDryRun(
targetOS: targetOS,
Expand All @@ -338,7 +338,7 @@ class NativeAssetsBuildRunner {
workingDirectory: workingDirectory,
packageLayout: packageLayout,
runPackageName: runPackageName,
supportedAssetTypes: supportedAssetTypes,
buildAssetTypes: buildAssetTypes,
linkingEnabled: linkingEnabled,
);

Expand All @@ -350,7 +350,7 @@ class NativeAssetsBuildRunner {
PackageLayout? packageLayout,
String? runPackageName,
required bool linkingEnabled,
required List<String> supportedAssetTypes,
required List<String> buildAssetTypes,
}) async {
const hook = Hook.build;

Expand All @@ -369,7 +369,7 @@ class NativeAssetsBuildRunner {
final configBuilder = configCreator();
configBuilder.setupHookConfig(
targetOS: targetOS,
supportedAssetTypes: supportedAssetTypes,
buildAssetTypes: buildAssetTypes,
buildMode: null, // not set in dry-run mode
packageName: package.name,
packageRoot: packageLayout.packageRoot(package.name),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void main() async {
logger,
dartExecutable,
capturedLogs: logMessages,
supportedAssetTypes: [CodeAsset.type],
buildAssetTypes: [CodeAsset.type],
configValidator: validateCodeAssetBuildConfig,
buildValidator: validateCodeAssetBuildOutput,
applicationAssetValidator: validateCodeAssetInApplication,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void main() async {
packageUri,
createCapturingLogger(logMessages, level: Level.SEVERE),
dartExecutable,
supportedAssetTypes: [CodeAsset.type],
buildAssetTypes: [CodeAsset.type],
configValidator: validateCodeAssetBuildConfig,
buildValidator: validateCodeAssetBuildOutput,
applicationAssetValidator: validateCodeAssetInApplication,
Expand Down Expand Up @@ -63,7 +63,7 @@ void main() async {
packageUri,
logger,
dartExecutable,
supportedAssetTypes: [CodeAsset.type],
buildAssetTypes: [CodeAsset.type],
configValidator: validateCodeAssetBuildConfig,
buildValidator: validateCodeAssetBuildOutput,
applicationAssetValidator: validateCodeAssetInApplication,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ void main() async {
logger,
dartExecutable,
linkingEnabled: false,
supportedAssetTypes: [CodeAsset.type],
buildAssetTypes: [CodeAsset.type],
buildValidator: validateCodeAssetBuildOutput,
))!;
final buildResult = (await build(
packageUri,
logger,
dartExecutable,
supportedAssetTypes: [CodeAsset.type],
buildAssetTypes: [CodeAsset.type],
configValidator: validateCodeAssetBuildConfig,
buildValidator: validateCodeAssetBuildOutput,
applicationAssetValidator: validateCodeAssetInApplication,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void main() async {
packageUri,
createCapturingLogger(logMessages, level: Level.SEVERE),
dartExecutable,
supportedAssetTypes: [],
buildAssetTypes: [],
configValidator: (config) async => [],
buildValidator: (config, output) async => [],
applicationAssetValidator: validateCodeAssetInApplication,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void main() async {
logger,
dartExecutable,
capturedLogs: logMessages,
supportedAssetTypes: [CodeAsset.type],
buildAssetTypes: [CodeAsset.type],
configValidator: validateCodeAssetBuildConfig,
buildValidator: validateCodeAssetBuildOutput,
applicationAssetValidator: validateCodeAssetInApplication,
Expand All @@ -57,7 +57,7 @@ void main() async {
logger,
dartExecutable,
capturedLogs: logMessages,
supportedAssetTypes: [CodeAsset.type],
buildAssetTypes: [CodeAsset.type],
configValidator: validateCodeAssetBuildConfig,
buildValidator: validateCodeAssetBuildOutput,
applicationAssetValidator: validateCodeAssetInApplication,
Expand Down Expand Up @@ -107,7 +107,7 @@ void main() async {
packageUri,
logger,
dartExecutable,
supportedAssetTypes: [CodeAsset.type],
buildAssetTypes: [CodeAsset.type],
configValidator: validateCodeAssetBuildConfig,
buildValidator: validateCodeAssetBuildOutput,
applicationAssetValidator: validateCodeAssetInApplication,
Expand All @@ -128,7 +128,7 @@ void main() async {
packageUri,
logger,
dartExecutable,
supportedAssetTypes: [CodeAsset.type],
buildAssetTypes: [CodeAsset.type],
configValidator: validateCodeAssetBuildConfig,
buildValidator: validateCodeAssetBuildOutput,
applicationAssetValidator: validateCodeAssetInApplication,
Expand Down Expand Up @@ -171,7 +171,7 @@ void main() async {
packageUri,
logger,
dartExecutable,
supportedAssetTypes: [CodeAsset.type],
buildAssetTypes: [CodeAsset.type],
configValidator: validateCodeAssetBuildConfig,
buildValidator: validateCodeAssetBuildOutput,
applicationAssetValidator: validateCodeAssetInApplication,
Expand Down Expand Up @@ -199,7 +199,7 @@ void main() async {
packageUri,
logger,
dartExecutable,
supportedAssetTypes: [CodeAsset.type],
buildAssetTypes: [CodeAsset.type],
configValidator: validateCodeAssetBuildConfig,
buildValidator: validateCodeAssetBuildOutput,
applicationAssetValidator: validateCodeAssetInApplication,
Expand Down Expand Up @@ -239,7 +239,7 @@ void main() async {
packageUri,
logger,
dartExecutable,
supportedAssetTypes: [CodeAsset.type],
buildAssetTypes: [CodeAsset.type],
configValidator: validateCodeAssetBuildConfig,
buildValidator: validateCodeAssetBuildOutput,
applicationAssetValidator: validateCodeAssetInApplication,
Expand Down Expand Up @@ -271,7 +271,7 @@ void main() async {
packageUri,
logger,
dartExecutable,
supportedAssetTypes: [CodeAsset.type],
buildAssetTypes: [CodeAsset.type],
configValidator: validateCodeAssetBuildConfig,
buildValidator: validateCodeAssetBuildOutput,
applicationAssetValidator: validateCodeAssetInApplication,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void main() async {
createCapturingLogger(logMessages, level: Level.SEVERE),
dartExecutable,
linkingEnabled: false,
supportedAssetTypes: [],
buildAssetTypes: [],
buildValidator: (config, output) async => [],
);
final fullLog = logMessages.join('\n');
Expand All @@ -47,7 +47,7 @@ void main() async {
packageUri,
createCapturingLogger(logMessages, level: Level.SEVERE),
dartExecutable,
supportedAssetTypes: [],
buildAssetTypes: [],
configValidator: (config) async => [],
buildValidator: (config, output) async => [],
applicationAssetValidator: (_) async => [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void main() async {
packageUri,
logger,
dartExecutable,
supportedAssetTypes: [CodeAsset.type],
buildAssetTypes: [CodeAsset.type],
configValidator: validateCodeAssetBuildConfig,
buildValidator: validateCodeAssetBuildOutput,
applicationAssetValidator: validateCodeAssetInApplication,
Expand Down Expand Up @@ -56,7 +56,7 @@ void main() async {
packageUri,
createCapturingLogger(logMessages, level: Level.SEVERE),
dartExecutable,
supportedAssetTypes: [CodeAsset.type],
buildAssetTypes: [CodeAsset.type],
configValidator: validateCodeAssetBuildConfig,
buildValidator: validateCodeAssetBuildOutput,
applicationAssetValidator: validateCodeAssetInApplication,
Expand Down Expand Up @@ -84,7 +84,7 @@ void main() async {
packageUri,
logger,
dartExecutable,
supportedAssetTypes: [CodeAsset.type],
buildAssetTypes: [CodeAsset.type],
configValidator: validateCodeAssetBuildConfig,
buildValidator: validateCodeAssetBuildOutput,
applicationAssetValidator: validateCodeAssetInApplication,
Expand Down Expand Up @@ -120,7 +120,7 @@ void main() async {
logger,
capturedLogs: logMessages,
dartExecutable,
supportedAssetTypes: [CodeAsset.type],
buildAssetTypes: [CodeAsset.type],
configValidator: validateCodeAssetBuildConfig,
buildValidator: validateCodeAssetBuildOutput,
applicationAssetValidator: validateCodeAssetInApplication,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void main() async {
dartExecutable,
capturedLogs: logMessages,
runPackageName: 'some_dev_dep',
supportedAssetTypes: [CodeAsset.type],
buildAssetTypes: [CodeAsset.type],
configValidator: validateDataAssetBuildConfig,
buildValidator: validateCodeAssetBuildOutput,
applicationAssetValidator: validateCodeAssetInApplication,
Expand All @@ -47,7 +47,7 @@ void main() async {
dartExecutable,
capturedLogs: logMessages,
runPackageName: 'native_add',
supportedAssetTypes: [CodeAsset.type],
buildAssetTypes: [CodeAsset.type],
configValidator: validateDataAssetBuildConfig,
buildValidator: validateCodeAssetBuildOutput,
applicationAssetValidator: validateCodeAssetInApplication,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ void main() async {
targetOS: Target.current.os,
workingDirectory: packageUri,
linkingEnabled: false,
supportedAssetTypes: [],
buildAssetTypes: [],
buildValidator: (config, output) async => [],
);
await buildRunner.buildDryRun(
configCreator: configCreator,
targetOS: Target.current.os,
workingDirectory: packageUri,
linkingEnabled: false,
supportedAssetTypes: [],
buildAssetTypes: [],
buildValidator: (config, output) async => [],
);
await buildRunner.build(
Expand All @@ -55,7 +55,7 @@ void main() async {
buildMode: BuildMode.release,
workingDirectory: packageUri,
linkingEnabled: false,
supportedAssetTypes: [],
buildAssetTypes: [],
configValidator: (config) async => [],
buildValidator: (config, output) async => [],
applicationAssetValidator: (_) async => [],
Expand All @@ -66,7 +66,7 @@ void main() async {
targetOS: OS.current,
workingDirectory: packageUri,
linkingEnabled: false,
supportedAssetTypes: [],
buildAssetTypes: [],
configValidator: (config) async => [],
buildValidator: (config, output) async => [],
applicationAssetValidator: (_) async => [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void main() async {
dartExecutable,
capturedLogs: logMessages,
configValidator: validateCodeAssetBuildConfig,
supportedAssetTypes: [CodeAsset.type],
buildAssetTypes: [CodeAsset.type],
buildValidator: validateCodeAssetBuildOutput,
applicationAssetValidator: validateCodeAssetInApplication,
))!;
Expand All @@ -59,7 +59,7 @@ void main() async {
dartExecutable,
capturedLogs: logMessages,
packageLayout: packageLayout,
supportedAssetTypes: [CodeAsset.type],
buildAssetTypes: [CodeAsset.type],
configValidator: validateCodeAssetBuildConfig,
buildValidator: validateCodeAssetBuildOutput,
applicationAssetValidator: validateCodeAssetInApplication,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void main(List<String> args) async {
targetOS: target.os,
workingDirectory: packageUri,
linkingEnabled: false,
supportedAssetTypes: [DataAsset.type],
buildAssetTypes: [DataAsset.type],
configValidator: validateDataAssetBuildConfig,
buildValidator: (config, output) async =>
await validateDataAssetBuildOutput(config, output),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void main(List<String> args) async {
targetOS: OS.current,
workingDirectory: packageUri,
linkingEnabled: false,
supportedAssetTypes: [CodeAsset.type, DataAsset.type],
buildAssetTypes: [CodeAsset.type, DataAsset.type],
configValidator: (config) async => [
...await validateDataAssetBuildConfig(config),
...await validateCodeAssetBuildConfig(config),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void main() async {
packageUri,
createCapturingLogger(logMessages, level: Level.SEVERE),
dartExecutable,
supportedAssetTypes: [CodeAsset.type],
buildAssetTypes: [CodeAsset.type],
configValidator: validateCodeAssetBuildConfig,
buildValidator: validateCodeAssetBuildOutput,
applicationAssetValidator: validateCodeAssetInApplication,
Expand Down Expand Up @@ -58,7 +58,7 @@ void main() async {
logger,
linkingEnabled: true,
dartExecutable,
supportedAssetTypes: [CodeAsset.type],
buildAssetTypes: [CodeAsset.type],
configValidator: validateCodeAssetBuildConfig,
buildValidator: validateCodeAssetBuildOutput,
applicationAssetValidator: validateCodeAssetInApplication,
Expand All @@ -69,7 +69,7 @@ void main() async {
logger,
dartExecutable,
buildResult: buildResult,
supportedAssetTypes: [CodeAsset.type],
buildAssetTypes: [CodeAsset.type],
configValidator: validateCodeAssetLinkConfig,
linkValidator: validateCodeAssetLinkOutput,
applicationAssetValidator: validateCodeAssetInApplication,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void main() async {
packageUri,
createCapturingLogger(logMessages, level: Level.SEVERE),
dartExecutable,
supportedAssetTypes: [CodeAsset.type, DataAsset.type],
buildAssetTypes: [CodeAsset.type, DataAsset.type],
buildConfigValidator: (config) async => [
...await validateDataAssetBuildConfig(config),
...await validateCodeAssetBuildConfig(config),
Expand Down
Loading

0 comments on commit 0caab92

Please sign in to comment.