From e090b32f0db12f3ca078a30f654d052292dfa9ae Mon Sep 17 00:00:00 2001 From: Daco Harkes Date: Tue, 10 Dec 2024 10:15:16 +0100 Subject: [PATCH] [native_assets_builder] Remove dry run (#1788) --- pkgs/native_assets_builder/CHANGELOG.md | 9 +- .../lib/native_assets_builder.dart | 1 - .../lib/src/build_runner/build_runner.dart | 127 ----------- .../lib/src/model/build_dry_run_result.dart | 15 -- .../lib/src/model/hook_result.dart | 2 +- pkgs/native_assets_builder/pubspec.yaml | 2 +- .../build_runner_build_dry_run_test.dart | 84 ------- .../build_runner/build_runner_cycle_test.dart | 20 -- .../build_runner_reusability_test.dart | 18 +- .../test/build_runner/helpers.dart | 32 --- .../native_dynamic_linking_test.dart | 207 +++++++++--------- .../package_reading_metadata/hook/build.dart | 23 +- .../test_data/transformer/hook/build.dart | 26 +-- .../test_data/wrong_linker/hook/build.dart | 6 +- .../wrong_namespace_asset/hook/build.dart | 6 +- pkgs/native_assets_cli/CHANGELOG.md | 11 +- pkgs/native_assets_cli/pubspec.yaml | 4 +- 17 files changed, 139 insertions(+), 454 deletions(-) delete mode 100644 pkgs/native_assets_builder/lib/src/model/build_dry_run_result.dart delete mode 100644 pkgs/native_assets_builder/test/build_runner/build_runner_build_dry_run_test.dart diff --git a/pkgs/native_assets_builder/CHANGELOG.md b/pkgs/native_assets_builder/CHANGELOG.md index 7f60b74ef..97f2bf472 100644 --- a/pkgs/native_assets_builder/CHANGELOG.md +++ b/pkgs/native_assets_builder/CHANGELOG.md @@ -1,10 +1,7 @@ -## 0.9.1-wip +## 0.10.0-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. +- Removed support for dry run (Flutter no long requires it). +- Various fixes to caching. ## 0.9.0 diff --git a/pkgs/native_assets_builder/lib/native_assets_builder.dart b/pkgs/native_assets_builder/lib/native_assets_builder.dart index ec69de6cd..b71f7a6f2 100644 --- a/pkgs/native_assets_builder/lib/native_assets_builder.dart +++ b/pkgs/native_assets_builder/lib/native_assets_builder.dart @@ -3,7 +3,6 @@ // BSD-style license that can be found in the LICENSE file. export 'package:native_assets_builder/src/build_runner/build_runner.dart'; -export 'package:native_assets_builder/src/model/build_dry_run_result.dart'; export 'package:native_assets_builder/src/model/build_result.dart'; export 'package:native_assets_builder/src/model/kernel_assets.dart'; export 'package:native_assets_builder/src/model/link_result.dart'; diff --git a/pkgs/native_assets_builder/lib/src/build_runner/build_runner.dart b/pkgs/native_assets_builder/lib/src/build_runner/build_runner.dart index ef524724e..8390608cd 100644 --- a/pkgs/native_assets_builder/lib/src/build_runner/build_runner.dart +++ b/pkgs/native_assets_builder/lib/src/build_runner/build_runner.dart @@ -12,7 +12,6 @@ import 'package:package_config/package_config.dart'; import '../dependencies_hash_file/dependencies_hash_file.dart'; import '../locking/locking.dart'; -import '../model/build_dry_run_result.dart'; import '../model/build_result.dart'; import '../model/hook_result.dart'; import '../model/link_result.dart'; @@ -315,132 +314,6 @@ class NativeAssetsBuildRunner { return (buildDirUri, outDirUri, outDirSharedUri); } - /// [workingDirectory] is expected to contain `.dart_tool`. - /// - /// This method is invoked by launchers such as dartdev (for `dart run`) and - /// flutter_tools (for `flutter run` and `flutter build`). - /// - /// If provided, only native assets of all transitive dependencies of - /// [runPackageName] are built. - Future buildDryRun({ - required BuildConfigCreator configCreator, - required BuildValidator buildValidator, - required OS targetOS, - required Uri workingDirectory, - required bool linkingEnabled, - PackageLayout? packageLayout, - String? runPackageName, - required List buildAssetTypes, - }) => - _runDryRun( - targetOS: targetOS, - configCreator: configCreator, - validator: (HookConfig config, HookOutput output) => - buildValidator(config as BuildConfig, output as BuildOutput), - workingDirectory: workingDirectory, - packageLayout: packageLayout, - runPackageName: runPackageName, - buildAssetTypes: buildAssetTypes, - linkingEnabled: linkingEnabled, - ); - - Future _runDryRun({ - required BuildConfigCreator configCreator, - required _HookValidator validator, - required OS targetOS, - required Uri workingDirectory, - PackageLayout? packageLayout, - String? runPackageName, - required bool linkingEnabled, - required List buildAssetTypes, - }) async { - const hook = Hook.build; - - packageLayout ??= await PackageLayout.fromRootPackageRoot(workingDirectory); - final (buildPlan, _) = await _makePlan( - hook: hook, - packageLayout: packageLayout, - runPackageName: runPackageName, - ); - if (buildPlan == null) { - return null; - } - - var hookResult = HookResult(); - for (final package in buildPlan) { - final configBuilder = configCreator(); - configBuilder.setupHookConfig( - targetOS: targetOS, - buildAssetTypes: buildAssetTypes, - buildMode: null, // not set in dry-run mode - packageName: package.name, - packageRoot: packageLayout.packageRoot(package.name), - ); - configBuilder.setupBuildConfig( - dryRun: true, - linkingEnabled: linkingEnabled, - metadata: const {}, - ); - - final buildDirName = configBuilder.computeChecksum(); - final buildDirUri = - packageLayout.dartToolNativeAssetsBuilder.resolve('$buildDirName/'); - final outDirUri = buildDirUri.resolve('out/'); - final outDir = Directory.fromUri(outDirUri); - if (!await outDir.exists()) { - // TODO(https://dartbug.com/50565): Purge old or unused folders. - await outDir.create(recursive: true); - } - final outputDirectoryShared = packageLayout.dartToolNativeAssetsBuilder - .resolve('shared/${package.name}/$hook/'); - final outDirShared = Directory.fromUri(outputDirectoryShared); - if (!await outDirShared.exists()) { - // TODO(https://dartbug.com/50565): Purge old or unused folders. - await outDirShared.create(recursive: true); - } - configBuilder.setupBuildRunConfig( - outputDirectory: outDirUri, - outputDirectoryShared: outputDirectoryShared, - ); - - final config = BuildConfig(configBuilder.json); - final packageConfigUri = packageLayout.packageConfigUri; - final hookCompileResult = await _compileHookForPackageCached( - config.packageName, - config.outputDirectory, - config.packageRoot.resolve('hook/${hook.scriptName}'), - packageConfigUri, - workingDirectory, - ); - if (hookCompileResult == null) return null; - final (hookKernelFile, _) = hookCompileResult; - - // TODO(https://github.com/dart-lang/native/issues/1321): Should dry runs be cached? - final buildOutput = await runUnderDirectoriesLock( - [ - Directory.fromUri(config.outputDirectoryShared.parent), - Directory.fromUri(config.outputDirectory.parent), - ], - timeout: singleHookTimeout, - logger: logger, - () => _runHookForPackage( - hook, - config, - validator, - packageConfigUri, - workingDirectory, - null, - hookKernelFile, - packageLayout!, - _filteredEnvironment(_environmentVariablesFilter), - ), - ); - if (buildOutput == null) return null; - hookResult = hookResult.copyAdd(buildOutput, [/*dry run is not cached*/]); - } - return hookResult; - } - Future<(HookOutput, List)?> _runHookForPackageCached( Hook hook, HookConfig config, diff --git a/pkgs/native_assets_builder/lib/src/model/build_dry_run_result.dart b/pkgs/native_assets_builder/lib/src/model/build_dry_run_result.dart deleted file mode 100644 index 9863d2ba1..000000000 --- a/pkgs/native_assets_builder/lib/src/model/build_dry_run_result.dart +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file -// for details. 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:native_assets_cli/native_assets_cli_internal.dart'; - -/// The result of executing the build hooks in dry run mode from all packages in -/// the dependency tree of the entry point application. -abstract interface class BuildDryRunResult { - /// The native assets produced by the hooks, which should be bundled. - List get encodedAssets; - - /// The native assets produced by the hooks, which should be linked. - Map> get encodedAssetsForLinking; -} diff --git a/pkgs/native_assets_builder/lib/src/model/hook_result.dart b/pkgs/native_assets_builder/lib/src/model/hook_result.dart index 655688a19..5a157f1a4 100644 --- a/pkgs/native_assets_builder/lib/src/model/hook_result.dart +++ b/pkgs/native_assets_builder/lib/src/model/hook_result.dart @@ -9,7 +9,7 @@ import '../../native_assets_builder.dart'; /// The result from a [NativeAssetsBuildRunner.build] or /// [NativeAssetsBuildRunner.link]. -final class HookResult implements BuildResult, BuildDryRunResult, LinkResult { +final class HookResult implements BuildResult, LinkResult { /// The native encodedAssets produced by the hooks, which should be bundled. @override final List encodedAssets; diff --git a/pkgs/native_assets_builder/pubspec.yaml b/pkgs/native_assets_builder/pubspec.yaml index 1eaaee1a1..e050da08c 100644 --- a/pkgs/native_assets_builder/pubspec.yaml +++ b/pkgs/native_assets_builder/pubspec.yaml @@ -1,7 +1,7 @@ name: native_assets_builder description: >- This package is the backend that invokes build hooks. -version: 0.9.1-wip +version: 0.10.0-wip repository: https://github.com/dart-lang/native/tree/main/pkgs/native_assets_builder publish_to: none diff --git a/pkgs/native_assets_builder/test/build_runner/build_runner_build_dry_run_test.dart b/pkgs/native_assets_builder/test/build_runner/build_runner_build_dry_run_test.dart deleted file mode 100644 index caf8e980a..000000000 --- a/pkgs/native_assets_builder/test/build_runner/build_runner_build_dry_run_test.dart +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import 'dart:io'; - -import 'package:file_testing/file_testing.dart'; -import 'package:test/test.dart'; - -import '../helpers.dart'; -import 'helpers.dart'; - -const Timeout longTimeout = Timeout(Duration(minutes: 5)); - -void main() async { - test('dry_run', timeout: longTimeout, () async { - await inTempDir((tempUri) async { - await copyTestProjects(targetUri: tempUri); - final packageUri = tempUri.resolve('native_add/'); - - await runPubGet( - workingDirectory: packageUri, - logger: logger, - ); - - final dryRunResult = (await buildDryRun( - packageUri, - logger, - dartExecutable, - linkingEnabled: false, - buildAssetTypes: [CodeAsset.type], - buildValidator: validateCodeAssetBuildOutput, - ))!; - final buildResult = (await build( - packageUri, - logger, - dartExecutable, - buildAssetTypes: [CodeAsset.type], - configValidator: validateCodeAssetBuildConfig, - buildValidator: validateCodeAssetBuildOutput, - applicationAssetValidator: validateCodeAssetInApplication, - ))!; - - expect(dryRunResult.encodedAssets.length, 1); - expect(buildResult.encodedAssets.length, 1); - - final dryRunAsset = dryRunResult.encodedAssets[0]; - expect(dryRunAsset.type, CodeAsset.type); - final dryRunCodeAsset = CodeAsset.fromEncoded(dryRunAsset); - - final buildAsset = buildResult.encodedAssets[0]; - final buildCodeAsset = CodeAsset.fromEncoded(buildAsset); - expect(buildAsset.type, CodeAsset.type); - - // Common across dry-run & build - expect(dryRunCodeAsset.id, buildCodeAsset.id); - expect(dryRunCodeAsset.os, buildCodeAsset.os); - expect(dryRunCodeAsset.linkMode, buildCodeAsset.linkMode); - expect(dryRunCodeAsset.file?.pathSegments.last, - buildCodeAsset.file?.pathSegments.last); - - // Different in dry-run: No architecture - expect(dryRunCodeAsset.architecture, isNull); - expect(buildCodeAsset.architecture, isNotNull); - - final nativeAssetsBuilderDirectory = - packageUri.resolve('.dart_tool/native_assets_builder/'); - final buildDirectories = - Directory.fromUri(nativeAssetsBuilderDirectory).list(); - await for (final directory in buildDirectories) { - if (directory is! Directory) { - expect( - File.fromUri(directory.uri.resolve('config.json')), - exists, - ); - expect( - File.fromUri(directory.uri.resolve('out/build_output.json')), - exists, - ); - } - } - }); - }); -} diff --git a/pkgs/native_assets_builder/test/build_runner/build_runner_cycle_test.dart b/pkgs/native_assets_builder/test/build_runner/build_runner_cycle_test.dart index 17476eac1..7e3f3a75c 100644 --- a/pkgs/native_assets_builder/test/build_runner/build_runner_cycle_test.dart +++ b/pkgs/native_assets_builder/test/build_runner/build_runner_cycle_test.dart @@ -20,26 +20,6 @@ void main() async { workingDirectory: packageUri, logger: logger, ); - { - final logMessages = []; - final result = await buildDryRun( - packageUri, - createCapturingLogger(logMessages, level: Level.SEVERE), - dartExecutable, - linkingEnabled: false, - buildAssetTypes: [], - buildValidator: (config, output) async => [], - ); - final fullLog = logMessages.join('\n'); - expect(result, isNull); - expect( - fullLog, - contains( - 'Cyclic dependency for native asset builds in the following ' - 'packages: [cyclic_package_1, cyclic_package_2]', - ), - ); - } { final logMessages = []; diff --git a/pkgs/native_assets_builder/test/build_runner/build_runner_reusability_test.dart b/pkgs/native_assets_builder/test/build_runner/build_runner_reusability_test.dart index 193784b08..548276f29 100644 --- a/pkgs/native_assets_builder/test/build_runner/build_runner_reusability_test.dart +++ b/pkgs/native_assets_builder/test/build_runner/build_runner_reusability_test.dart @@ -11,7 +11,7 @@ import 'helpers.dart'; const Timeout longTimeout = Timeout(Duration(minutes: 5)); void main() async { - test('multiple dryRun and build invocations', timeout: longTimeout, () async { + test('multiple build invocations', timeout: longTimeout, () async { await inTempDir((tempUri) async { await copyTestProjects(targetUri: tempUri); final packageUri = tempUri.resolve('package_reading_metadata/'); @@ -33,22 +33,6 @@ void main() async { linkModePreference: LinkModePreference.dynamic, ); - await buildRunner.buildDryRun( - configCreator: configCreator, - targetOS: Target.current.os, - workingDirectory: packageUri, - linkingEnabled: false, - buildAssetTypes: [], - buildValidator: (config, output) async => [], - ); - await buildRunner.buildDryRun( - configCreator: configCreator, - targetOS: Target.current.os, - workingDirectory: packageUri, - linkingEnabled: false, - buildAssetTypes: [], - buildValidator: (config, output) async => [], - ); await buildRunner.build( configCreator: configCreator, targetOS: OS.current, diff --git a/pkgs/native_assets_builder/test/build_runner/helpers.dart b/pkgs/native_assets_builder/test/build_runner/helpers.dart index f252da7d4..56a54c445 100644 --- a/pkgs/native_assets_builder/test/build_runner/helpers.dart +++ b/pkgs/native_assets_builder/test/build_runner/helpers.dart @@ -265,38 +265,6 @@ Future runWithLog( return result; } -Future buildDryRun( - Uri packageUri, - Logger logger, - Uri dartExecutable, { - required BuildValidator buildValidator, - LinkModePreference linkModePreference = LinkModePreference.dynamic, - CCompilerConfig? cCompilerConfig, - List? capturedLogs, - PackageLayout? packageLayout, - required bool linkingEnabled, - required List buildAssetTypes, -}) async => - runWithLog(capturedLogs, () async { - final result = await NativeAssetsBuildRunner( - logger: logger, - dartExecutable: dartExecutable, - ).buildDryRun( - configCreator: () => BuildConfigBuilder() - ..setupCodeConfig( - targetArchitecture: null, - linkModePreference: linkModePreference, - ), - targetOS: Target.current.os, - workingDirectory: packageUri, - packageLayout: packageLayout, - linkingEnabled: linkingEnabled, - buildAssetTypes: buildAssetTypes, - buildValidator: buildValidator, - ); - return result; - }); - Future expectSymbols({ required CodeAsset asset, required List symbols, diff --git a/pkgs/native_assets_builder/test/test_data/native_dynamic_linking_test.dart b/pkgs/native_assets_builder/test/test_data/native_dynamic_linking_test.dart index c105e4552..eacf9e375 100644 --- a/pkgs/native_assets_builder/test/test_data/native_dynamic_linking_test.dart +++ b/pkgs/native_assets_builder/test/test_data/native_dynamic_linking_test.dart @@ -18,116 +18,109 @@ import '../helpers.dart'; void main() async { const name = 'native_dynamic_linking'; - for (final dryRun in [true, false]) { - final testSuffix = dryRun ? ' dry_run' : ''; - test( - 'native_dynamic_linking build$testSuffix', - () => inTempDir((tempUri) async { - final outputDirectory = tempUri.resolve('out/'); - await Directory.fromUri(outputDirectory).create(); - final outputDirectoryShared = tempUri.resolve('out_shared/'); - await Directory.fromUri(outputDirectoryShared).create(); - final testTempUri = tempUri.resolve('test1/'); - await Directory.fromUri(testTempUri).create(); - final testPackageUri = testDataUri.resolve('$name/'); - final dartUri = Uri.file(Platform.resolvedExecutable); + test( + 'native_dynamic_linking build', + () => inTempDir((tempUri) async { + final outputDirectory = tempUri.resolve('out/'); + await Directory.fromUri(outputDirectory).create(); + final outputDirectoryShared = tempUri.resolve('out_shared/'); + await Directory.fromUri(outputDirectoryShared).create(); + final testTempUri = tempUri.resolve('test1/'); + await Directory.fromUri(testTempUri).create(); + final testPackageUri = testDataUri.resolve('$name/'); + final dartUri = Uri.file(Platform.resolvedExecutable); - final configBuilder = BuildConfigBuilder() - ..setupHookConfig( - packageName: name, - packageRoot: testPackageUri, - targetOS: OS.current, - buildAssetTypes: [CodeAsset.type], - buildMode: dryRun ? null : BuildMode.debug) - ..setupBuildConfig(dryRun: dryRun, linkingEnabled: false) - ..setupBuildRunConfig( - outputDirectory: outputDirectory, - outputDirectoryShared: outputDirectoryShared) - ..setupCodeConfig( - targetArchitecture: dryRun ? null : Architecture.current, - linkModePreference: LinkModePreference.dynamic, - cCompilerConfig: dryRun ? null : cCompiler, - ); + final configBuilder = BuildConfigBuilder() + ..setupHookConfig( + packageName: name, + packageRoot: testPackageUri, + targetOS: OS.current, + buildAssetTypes: [CodeAsset.type], + buildMode: BuildMode.debug) + ..setupBuildConfig(dryRun: false, linkingEnabled: false) + ..setupBuildRunConfig( + outputDirectory: outputDirectory, + outputDirectoryShared: outputDirectoryShared) + ..setupCodeConfig( + targetArchitecture: Architecture.current, + linkModePreference: LinkModePreference.dynamic, + cCompilerConfig: cCompiler, + ); - final buildConfigUri = testTempUri.resolve('build_config.json'); - File.fromUri(buildConfigUri) - .writeAsStringSync(jsonEncode(configBuilder.json)); + final buildConfigUri = testTempUri.resolve('build_config.json'); + File.fromUri(buildConfigUri) + .writeAsStringSync(jsonEncode(configBuilder.json)); - final processResult = await Process.run( - dartUri.toFilePath(), - [ - 'hook/build.dart', - '--config=${buildConfigUri.toFilePath()}', - ], - workingDirectory: testPackageUri.toFilePath(), - ); - if (processResult.exitCode != 0) { - print(processResult.stdout); - print(processResult.stderr); - print(processResult.exitCode); - } - expect(processResult.exitCode, 0); + final processResult = await Process.run( + dartUri.toFilePath(), + [ + 'hook/build.dart', + '--config=${buildConfigUri.toFilePath()}', + ], + workingDirectory: testPackageUri.toFilePath(), + ); + if (processResult.exitCode != 0) { + print(processResult.stdout); + print(processResult.stderr); + print(processResult.exitCode); + } + expect(processResult.exitCode, 0); + + final buildOutputUri = outputDirectory.resolve('build_output.json'); + final buildOutput = BuildOutput( + json.decode(await File.fromUri(buildOutputUri).readAsString()) + as Map); + final assets = buildOutput.encodedAssets; + final dependencies = buildOutput.dependencies; - final buildOutputUri = outputDirectory.resolve('build_output.json'); - final buildOutput = BuildOutput( - json.decode(await File.fromUri(buildOutputUri).readAsString()) - as Map); - final assets = buildOutput.encodedAssets; - final dependencies = buildOutput.dependencies; - if (dryRun) { - expect(assets.length, greaterThanOrEqualTo(3)); - expect(dependencies, []); - } else { - expect(assets.length, 3); - expect(await assets.allExist(), true); - expect( - dependencies, - [ - testPackageUri.resolve('src/debug.c'), - testPackageUri.resolve('src/math.c'), - testPackageUri.resolve('src/add.c'), - ], - ); + expect(assets.length, 3); + expect(await assets.allExist(), true); + expect( + dependencies, + [ + testPackageUri.resolve('src/debug.c'), + testPackageUri.resolve('src/math.c'), + testPackageUri.resolve('src/add.c'), + ], + ); - final addLibraryPath = assets - .where((e) => e.type == CodeAsset.type) - .map(CodeAsset.fromEncoded) - .firstWhere((asset) => asset.id.endsWith('add.dart')) - .file! - .toFilePath(); - final addResult = await runProcess( - executable: dartExecutable, - arguments: [ - 'run', - pkgNativeAssetsBuilderUri - .resolve('test/test_data/native_dynamic_linking_helper.dart') - .toFilePath(), - addLibraryPath, - '1', - '2', - ], - environment: { - // Add the directory containing the linked dynamic libraries to - // the PATH so that the dynamic linker can find them. - // TODO(https://github.com/dart-lang/sdk/issues/56551): We could - // skip this if Dart would implicitly add dylib containing - // directories to the PATH. - if (Platform.isWindows) - 'PATH': '${outputDirectory.toFilePath()};' - '${Platform.environment['PATH']}', - }, - throwOnUnexpectedExitCode: true, - logger: logger, - ); - expect( - addResult.stdout, - allOf( - contains('Adding 1 and 2.'), - contains('Result: 3'), - ), - ); - } - }), - ); - } + final addLibraryPath = assets + .where((e) => e.type == CodeAsset.type) + .map(CodeAsset.fromEncoded) + .firstWhere((asset) => asset.id.endsWith('add.dart')) + .file! + .toFilePath(); + final addResult = await runProcess( + executable: dartExecutable, + arguments: [ + 'run', + pkgNativeAssetsBuilderUri + .resolve('test/test_data/native_dynamic_linking_helper.dart') + .toFilePath(), + addLibraryPath, + '1', + '2', + ], + environment: { + // Add the directory containing the linked dynamic libraries to + // the PATH so that the dynamic linker can find them. + // TODO(https://github.com/dart-lang/sdk/issues/56551): We could + // skip this if Dart would implicitly add dylib containing + // directories to the PATH. + if (Platform.isWindows) + 'PATH': '${outputDirectory.toFilePath()};' + '${Platform.environment['PATH']}', + }, + throwOnUnexpectedExitCode: true, + logger: logger, + ); + expect( + addResult.stdout, + allOf( + contains('Adding 1 and 2.'), + contains('Result: 3'), + ), + ); + }), + ); } diff --git a/pkgs/native_assets_builder/test_data/package_reading_metadata/hook/build.dart b/pkgs/native_assets_builder/test_data/package_reading_metadata/hook/build.dart index 5ae35355f..148fb9b6b 100644 --- a/pkgs/native_assets_builder/test_data/package_reading_metadata/hook/build.dart +++ b/pkgs/native_assets_builder/test_data/package_reading_metadata/hook/build.dart @@ -8,19 +8,14 @@ import 'package:native_assets_cli/native_assets_cli.dart'; void main(List args) async { await build(args, (buildConfig, _) async { - if (!buildConfig.dryRun) { - final someValue = - buildConfig.metadatum('package_with_metadata', 'some_key'); - assert(someValue != null); - final someInt = - buildConfig.metadatum('package_with_metadata', 'some_int'); - assert(someInt != null); - print({ - 'some_int': someInt, - 'some_key': someValue, - }); - } else { - print('meta data not available in dry run'); - } + final someValue = + buildConfig.metadatum('package_with_metadata', 'some_key'); + assert(someValue != null); + final someInt = buildConfig.metadatum('package_with_metadata', 'some_int'); + assert(someInt != null); + print({ + 'some_int': someInt, + 'some_key': someValue, + }); }); } diff --git a/pkgs/native_assets_builder/test_data/transformer/hook/build.dart b/pkgs/native_assets_builder/test_data/transformer/hook/build.dart index 1a2ff86e6..53fba9533 100644 --- a/pkgs/native_assets_builder/test_data/transformer/hook/build.dart +++ b/pkgs/native_assets_builder/test_data/transformer/hook/build.dart @@ -28,17 +28,14 @@ void main(List arguments) async { final targetFile = File.fromUri(config.outputDirectoryShared .resolve(sourceName.replaceFirst('data', 'data_transformed'))); - // ignore: deprecated_member_use - if (!config.dryRun) { - // TODO(dacoharkes): Timestamps are not enough for correct caching. - if (!await targetFile.exists() || - !(await sourceFile.lastModified()) - .isBefore(await targetFile.lastModified())) { - await transformFile(sourceFile, targetFile); - transformedFiles++; - } else { - cachedFiles++; - } + // TODO(dacoharkes): Timestamps are not enough for correct caching. + if (!await targetFile.exists() || + !(await sourceFile.lastModified()) + .isBefore(await targetFile.lastModified())) { + await transformFile(sourceFile, targetFile); + transformedFiles++; + } else { + cachedFiles++; } output.dataAssets.add( @@ -53,10 +50,7 @@ void main(List arguments) async { ); } - // ignore: deprecated_member_use - if (!config.dryRun) { - print('Transformed $transformedFiles files.'); - print('Reused $cachedFiles cached files.'); - } + print('Transformed $transformedFiles files.'); + print('Reused $cachedFiles cached files.'); }); } diff --git a/pkgs/native_assets_builder/test_data/wrong_linker/hook/build.dart b/pkgs/native_assets_builder/test_data/wrong_linker/hook/build.dart index 4f1509250..e0d486071 100644 --- a/pkgs/native_assets_builder/test_data/wrong_linker/hook/build.dart +++ b/pkgs/native_assets_builder/test_data/wrong_linker/hook/build.dart @@ -11,10 +11,8 @@ void main(List arguments) async { final assetUri = config.outputDirectory.resolve( OS.current.dylibFileName('foo'), ); - // ignore: deprecated_member_use - if (!config.dryRun) { - await File.fromUri(assetUri).writeAsBytes([1, 2, 3]); - } + + await File.fromUri(assetUri).writeAsBytes([1, 2, 3]); output.codeAssets.add( CodeAsset( diff --git a/pkgs/native_assets_builder/test_data/wrong_namespace_asset/hook/build.dart b/pkgs/native_assets_builder/test_data/wrong_namespace_asset/hook/build.dart index 1ce65d36f..f776f1aa1 100644 --- a/pkgs/native_assets_builder/test_data/wrong_namespace_asset/hook/build.dart +++ b/pkgs/native_assets_builder/test_data/wrong_namespace_asset/hook/build.dart @@ -11,10 +11,8 @@ void main(List arguments) async { final assetUri = config.outputDirectory.resolve( OS.current.dylibFileName('foo'), ); - // ignore: deprecated_member_use - if (!config.dryRun) { - await File.fromUri(assetUri).writeAsBytes([1, 2, 3]); - } + + await File.fromUri(assetUri).writeAsBytes([1, 2, 3]); output.codeAssets.add( CodeAsset( diff --git a/pkgs/native_assets_cli/CHANGELOG.md b/pkgs/native_assets_cli/CHANGELOG.md index 76345f3a3..3b7baec21 100644 --- a/pkgs/native_assets_cli/CHANGELOG.md +++ b/pkgs/native_assets_cli/CHANGELOG.md @@ -1,6 +1,11 @@ -## 0.9.1-wip - -- Update pubspec.yaml of examples to use 0.9.0 of package:native_assets_cli +## 0.10.0-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. +- Update pubspec.yaml of examples to use 0.9.0 of `package:native_assets_cli`. - Consolidate [CodeAsset] specific things into `lib/src/code_assets/*` ## 0.9.0 diff --git a/pkgs/native_assets_cli/pubspec.yaml b/pkgs/native_assets_cli/pubspec.yaml index cdc0cf5e0..193e6783e 100644 --- a/pkgs/native_assets_cli/pubspec.yaml +++ b/pkgs/native_assets_cli/pubspec.yaml @@ -4,7 +4,7 @@ description: >- native assets CLI. # Note: Bump BuildConfig.version and BuildOutput.version on breaking changes! -version: 0.9.1-wip +version: 0.10.0-wip repository: https://github.com/dart-lang/native/tree/main/pkgs/native_assets_cli publish_to: none @@ -24,7 +24,7 @@ dependencies: meta: ^1.15.0 pub_semver: ^2.1.3 test: ^1.25.7 - yaml: ^3.1.2 # Used for reading pubspec.yaml to obtain the package name + yaml: ^3.1.2 # Used for reading pubspec.yaml to obtain the package name dev_dependencies: dart_flutter_team_lints: ^2.1.1