diff --git a/.github/workflows/native.yaml b/.github/workflows/native.yaml index fa6e3c3ad..a9996fc6a 100644 --- a/.github/workflows/native.yaml +++ b/.github/workflows/native.yaml @@ -45,6 +45,12 @@ jobs: sdk: 3.3.0 - os: windows sdk: stable + # native_assets_builder uses `dart compile kernel --depfile` which is only available in 3.5.0. + # We don't care too much about native_assets_builder on stable. It will be pulled into Dart and Flutter on last master/main. + - sdk: stable + package: native_assets_builder + - sdk: 3.3.0 + package: native_assets_builder runs-on: ${{ matrix.os }}-latest diff --git a/pkgs/native_assets_builder/CHANGELOG.md b/pkgs/native_assets_builder/CHANGELOG.md index a374918d4..da6859107 100644 --- a/pkgs/native_assets_builder/CHANGELOG.md +++ b/pkgs/native_assets_builder/CHANGELOG.md @@ -1,5 +1,7 @@ ## 0.8.1-wip +- `BuildRunner` now automatically invokes build hooks again if any of their Dart + sources changed. - Add more data asset test files. ## 0.8.0 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 faa0b6e9c..1a18c95fe 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 @@ -6,6 +6,7 @@ import 'dart:async'; import 'dart:io'; import 'package:logging/logging.dart'; +import 'package:native_assets_cli/native_assets_cli.dart' as api; import 'package:native_assets_cli/native_assets_cli_internal.dart'; import 'package:package_config/package_config.dart'; @@ -15,7 +16,9 @@ import '../model/hook_result.dart'; import '../model/link_dry_run_result.dart'; import '../model/link_result.dart'; import '../package_layout/package_layout.dart'; +import '../utils/file.dart'; import '../utils/run_process.dart'; +import '../utils/uri.dart'; import 'build_planner.dart'; typedef DependencyMetadata = Map; @@ -24,6 +27,10 @@ typedef DependencyMetadata = Map; /// /// These methods are invoked by launchers such as dartdev (for `dart run`) /// and flutter_tools (for `flutter run` and `flutter build`). +/// +/// The native assets build runner does not support reentrancy for identical +/// [api.BuildConfig] and [api.LinkConfig]! For more info see: +/// https://github.com/dart-lang/native/issues/1319 class NativeAssetsBuildRunner { final Logger logger; final Uri dartExecutable; @@ -40,6 +47,10 @@ class NativeAssetsBuildRunner { /// /// If provided, only assets of all transitive dependencies of /// [runPackageName] are built. + /// + /// The native assets build runner does not support reentrancy for identical + /// [api.BuildConfig] and [api.LinkConfig]! For more info see: + /// https://github.com/dart-lang/native/issues/1319 Future build({ required LinkModePreferenceImpl linkModePreference, required Target target, @@ -81,6 +92,10 @@ class NativeAssetsBuildRunner { /// /// If provided, only assets of all transitive dependencies of /// [runPackageName] are linked. + /// + /// The native assets build runner does not support reentrancy for identical + /// [api.BuildConfig] and [api.LinkConfig]! For more info see: + /// https://github.com/dart-lang/native/issues/1319 Future link({ required LinkModePreferenceImpl linkModePreference, required Target target, @@ -371,6 +386,7 @@ class NativeAssetsBuildRunner { var hookResult = HookResult(); for (final package in buildPlan) { final config = await _cliConfigDryRun( + package: package, packageName: package.name, packageRoot: packageLayout.packageRoot(package.name), targetOS: targetOS, @@ -381,13 +397,30 @@ class NativeAssetsBuildRunner { buildDryRunResult: buildDryRunResult, linkingEnabled: linkingEnabled, ); + final packageConfigUri = packageLayout.packageConfigUri; + final ( + compileSuccess, + hookKernelFile, + _, + ) = await _compileHookForPackageCached( + config, + packageConfigUri, + workingDirectory, + includeParentEnvironment, + ); + if (!compileSuccess) { + hookResult.copyAdd(HookOutputImpl(), false); + continue; + } + // TODO(https://github.com/dart-lang/native/issues/1321): Should dry runs be cached? var (buildOutput, packageSuccess) = await _runHookForPackage( hook, config, - packageLayout.packageConfigUri, + packageConfigUri, workingDirectory, includeParentEnvironment, null, + hookKernelFile, ); buildOutput = _expandArchsNativeCodeAssets(buildOutput); hookResult = hookResult.copyAdd(buildOutput, packageSuccess); @@ -427,16 +460,33 @@ class NativeAssetsBuildRunner { Uri? resources, ) async { final outDir = config.outputDirectory; + final ( + compileSuccess, + hookKernelFile, + hookLastSourceChange, + ) = await _compileHookForPackageCached( + config, + packageConfigUri, + workingDirectory, + includeParentEnvironment, + ); + if (!compileSuccess) { + return (HookOutputImpl(), false); + } final hookOutput = HookOutputImpl.readFromFile(file: config.outputFile); if (hookOutput != null) { final lastBuilt = hookOutput.timestamp.roundDownToSeconds(); - final lastChange = await hookOutput.dependenciesModel.lastModified(); - - if (lastBuilt.isAfter(lastChange)) { - logger - .info('Skipping ${hook.name} for ${config.packageName} in $outDir. ' - 'Last build on $lastBuilt, last input change on $lastChange.'); + final dependenciesLastChange = + await hookOutput.dependenciesModel.lastModified(); + if (lastBuilt.isAfter(dependenciesLastChange) && + lastBuilt.isAfter(hookLastSourceChange)) { + logger.info( + 'Skipping ${hook.name} for ${config.packageName} in $outDir. ' + 'Last build on $lastBuilt. ' + 'Last dependencies change on $dependenciesLastChange. ' + 'Last hook change on $hookLastSourceChange.', + ); // All build flags go into [outDir]. Therefore we do not have to check // here whether the config is equal. return (hookOutput, true); @@ -450,6 +500,7 @@ class NativeAssetsBuildRunner { workingDirectory, includeParentEnvironment, resources, + hookKernelFile, ); } @@ -460,6 +511,7 @@ class NativeAssetsBuildRunner { Uri workingDirectory, bool includeParentEnvironment, Uri? resources, + File hookKernelFile, ) async { final configFile = config.outputDirectory.resolve('../config.json'); final configFileContents = config.toJsonString(); @@ -473,7 +525,7 @@ class NativeAssetsBuildRunner { final arguments = [ '--packages=${packageConfigUri.toFilePath()}', - config.script.toFilePath(), + hookKernelFile.path, '--config=${configFile.toFilePath()}', if (resources != null) resources.toFilePath(), ]; @@ -484,6 +536,7 @@ class NativeAssetsBuildRunner { logger: logger, includeParentEnvironment: includeParentEnvironment, ); + var success = true; if (result.exitCode != 0) { final printWorkingDir = workingDirectory != Directory.current.uri; @@ -542,7 +595,114 @@ ${e.message} } } + /// Compiles the hook to dill and caches the dill. + /// + /// It does not reuse the cached dill for different [config]s, due to + /// reentrancy requirements. For more info see: + /// https://github.com/dart-lang/native/issues/1319 + Future<(bool success, File kernelFile, DateTime lastSourceChange)> + _compileHookForPackageCached( + HookConfigImpl config, + Uri packageConfigUri, + Uri workingDirectory, + bool includeParentEnvironment, + ) async { + final kernelFile = File.fromUri( + config.outputDirectory.resolve('../hook.dill'), + ); + final depFile = File.fromUri( + config.outputDirectory.resolve('../hook.dill.d'), + ); + final bool mustCompile; + final DateTime sourceLastChange; + if (!await depFile.exists()) { + mustCompile = true; + sourceLastChange = DateTime.now(); + } else { + // Format: `path/to/my.dill: path/to/my.dart, path/to/more.dart` + final depFileContents = await depFile.readAsString(); + final dartSourceFiles = depFileContents + .trim() + .split(' ') + .skip(1) // ':' + .map((u) => Uri.file(u).fileSystemEntity) + .toList(); + final dartFilesLastChange = await dartSourceFiles.lastModified(); + final packageConfigLastChange = + await packageConfigUri.fileSystemEntity.lastModified(); + sourceLastChange = packageConfigLastChange.isAfter(dartFilesLastChange) + ? packageConfigLastChange + : dartFilesLastChange; + final dillLastChange = await kernelFile.lastModified(); + mustCompile = sourceLastChange.isAfter(dillLastChange); + } + final bool success; + if (!mustCompile) { + success = true; + } else { + success = await _compileHookForPackage( + config, + packageConfigUri, + workingDirectory, + includeParentEnvironment, + kernelFile, + depFile, + ); + } + return (success, kernelFile, sourceLastChange); + } + + Future _compileHookForPackage( + HookConfigImpl config, + Uri packageConfigUri, + Uri workingDirectory, + bool includeParentEnvironment, + File kernelFile, + File depFile, + ) async { + final compileArguments = [ + 'compile', + 'kernel', + '--packages=${packageConfigUri.toFilePath()}', + '--output=${kernelFile.path}', + '--depfile=${depFile.path}', + config.script.toFilePath(), + ]; + final compileResult = await runProcess( + workingDirectory: workingDirectory, + executable: dartExecutable, + arguments: compileArguments, + logger: logger, + includeParentEnvironment: includeParentEnvironment, + ); + var success = true; + if (compileResult.exitCode != 0) { + final printWorkingDir = workingDirectory != Directory.current.uri; + final commandString = [ + if (printWorkingDir) '(cd ${workingDirectory.toFilePath()};', + dartExecutable.toFilePath(), + ...compileArguments.map((a) => a.contains(' ') ? "'$a'" : a), + if (printWorkingDir) ')', + ].join(' '); + logger.severe( + ''' +Building native assets for package:${config.packageName} failed. +Compilation of hook returned with exit code: ${compileResult.exitCode}. +To reproduce run: +$commandString +stderr: +${compileResult.stderr} +stdout: +${compileResult.stdout} + ''', + ); + success = false; + } + return success; + } + static Future _cliConfigDryRun({ + required Package package, required String packageName, required Uri packageRoot, required OSImpl targetOS, @@ -553,8 +713,16 @@ ${e.message} Iterable? supportedAssetTypes, required bool? linkingEnabled, }) async { - final hookDirName = 'dry_run_${hook.name}_${targetOS}_$linkMode'; - final outDirUri = buildParentDir.resolve('$hookDirName/out/'); + final buildDirName = HookConfigImpl.checksumDryRun( + packageName: package.name, + packageRoot: package.root, + targetOS: targetOS, + linkModePreference: linkMode, + supportedAssetTypes: supportedAssetTypes, + hook: hook, + linkingEnabled: linkingEnabled, + ); + final outDirUri = buildParentDir.resolve('$buildDirName/out/'); final outDir = Directory.fromUri(outDirUri); if (!await outDir.exists()) { await outDir.create(recursive: true); 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 00ca561af..f0c23c9eb 100644 --- a/pkgs/native_assets_builder/lib/src/model/hook_result.dart +++ b/pkgs/native_assets_builder/lib/src/model/hook_result.dart @@ -60,7 +60,7 @@ final class HookResult final oneInTwo = assets2.where((asset) => assets1.contains(asset)); if (twoInOne.isNotEmpty || oneInTwo.isNotEmpty) { throw ArgumentError( - 'Found assets with same IDs, ${[...oneInTwo, ...twoInOne]}'); + 'Found duplicate IDs, ${oneInTwo.map((e) => e.id).toList()}'); } return [ ...assets1, diff --git a/pkgs/native_assets_builder/lib/src/utils/file.dart b/pkgs/native_assets_builder/lib/src/utils/file.dart new file mode 100644 index 000000000..369af758c --- /dev/null +++ b/pkgs/native_assets_builder/lib/src/utils/file.dart @@ -0,0 +1,53 @@ +// 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'; + +extension FileSystemEntityExtension on FileSystemEntity { + Future lastModified() async { + final this_ = this; + if (this_ is Link || await FileSystemEntity.isLink(this_.path)) { + // Don't follow links. + return DateTime.fromMicrosecondsSinceEpoch(0); + } + if (this_ is File) { + if (!await this_.exists()) { + // If the file was deleted, regard it is modified recently. + return DateTime.now(); + } + return await this_.lastModified(); + } + assert(this_ is Directory); + this_ as Directory; + return await this_.lastModified(); + } +} + +extension FileSystemEntityIterable on Iterable { + Future lastModified() async { + var last = DateTime.fromMillisecondsSinceEpoch(0); + for (final entity in this) { + final entityTimestamp = await entity.lastModified(); + if (entityTimestamp.isAfter(last)) { + // print([entity, entityTimestamp]); + last = entityTimestamp; + } + } + return last; + } +} + +extension DirectoryExtension on Directory { + Future lastModified() async { + var last = DateTime.fromMillisecondsSinceEpoch(0); + await for (final entity in list()) { + final entityTimestamp = await entity.lastModified(); + if (entityTimestamp.isAfter(last)) { + // print([this, entityTimestamp]); + last = entityTimestamp; + } + } + return last; + } +} diff --git a/pkgs/native_assets_builder/lib/src/utils/uri.dart b/pkgs/native_assets_builder/lib/src/utils/uri.dart new file mode 100644 index 000000000..95e2274c4 --- /dev/null +++ b/pkgs/native_assets_builder/lib/src/utils/uri.dart @@ -0,0 +1,14 @@ +// 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'; + +extension UriExtension on Uri { + FileSystemEntity get fileSystemEntity { + if (path.endsWith(Platform.pathSeparator) || path.endsWith('/')) { + return Directory.fromUri(this); + } + return File.fromUri(this); + } +} diff --git a/pkgs/native_assets_builder/pubspec.yaml b/pkgs/native_assets_builder/pubspec.yaml index 4eb516b88..f197bd828 100644 --- a/pkgs/native_assets_builder/pubspec.yaml +++ b/pkgs/native_assets_builder/pubspec.yaml @@ -4,7 +4,7 @@ description: >- version: 0.8.1-wip repository: https://github.com/dart-lang/native/tree/main/pkgs/native_assets_builder -# publish_to: none +publish_to: none environment: sdk: '>=3.3.0 <4.0.0' @@ -13,9 +13,9 @@ dependencies: collection: ^1.18.0 graphs: ^2.3.1 logging: ^1.2.0 - native_assets_cli: ^0.7.0 - # native_assets_cli: - # path: ../native_assets_cli/ + # native_assets_cli: ^0.7.0 + native_assets_cli: + path: ../native_assets_cli/ package_config: ^2.1.0 yaml: ^3.1.2 yaml_edit: ^2.1.0 diff --git a/pkgs/native_assets_builder/test/build_runner/build_dependencies_test.dart b/pkgs/native_assets_builder/test/build_runner/build_dependencies_test.dart index 55e1cc93f..20e5b9509 100644 --- a/pkgs/native_assets_builder/test/build_runner/build_dependencies_test.dart +++ b/pkgs/native_assets_builder/test/build_runner/build_dependencies_test.dart @@ -43,9 +43,7 @@ void main() async { expect( result.dependencies, [ - tempUri.resolve('native_add/').resolve('hook/build.dart'), tempUri.resolve('native_add/').resolve('src/native_add.c'), - tempUri.resolve('native_subtract/').resolve('hook/build.dart'), tempUri .resolve('native_subtract/') .resolve('src/native_subtract.c'), 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 index fa3327d6a..bc7a13bbb 100644 --- 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 @@ -54,10 +54,22 @@ void main() async { } } - final dryRunDir = packageUri.resolve( - '.dart_tool/native_assets_builder/dry_run_build_${Target.current.os}_dynamic/'); - expect(File.fromUri(dryRunDir.resolve('config.json')), exists); - expect(File.fromUri(dryRunDir.resolve('out/build_output.json')), exists); + 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_caching_test.dart b/pkgs/native_assets_builder/test/build_runner/build_runner_caching_test.dart index d101d14a9..d42b0e7f5 100644 --- a/pkgs/native_assets_builder/test/build_runner/build_runner_caching_test.dart +++ b/pkgs/native_assets_builder/test/build_runner/build_runner_caching_test.dart @@ -22,6 +22,10 @@ void main() async { workingDirectory: packageUri, logger: logger, ); + // Make sure the first compile is at least one second after the + // package_config.json is written, otherwise dill compilation isn't + // cached. + await Future.delayed(const Duration(seconds: 1)); { final logMessages = []; @@ -37,7 +41,6 @@ void main() async { expect( result.dependencies, [ - packageUri.resolve('hook/build.dart'), packageUri.resolve('src/native_add.c'), ], ); @@ -61,7 +64,6 @@ void main() async { expect( result.dependencies, [ - packageUri.resolve('hook/build.dart'), packageUri.resolve('src/native_add.c'), ], ); @@ -78,6 +80,10 @@ void main() async { workingDirectory: packageUri, logger: logger, ); + // Make sure the first compile is at least one second after the + // package_config.json is written, otherwise dill compilation isn't + // cached. + await Future.delayed(const Duration(seconds: 1)); { final result = await build(packageUri, logger, dartExecutable); @@ -107,6 +113,10 @@ void main() async { final packageUri = tempUri.resolve('native_add/'); await runPubGet(workingDirectory: packageUri, logger: logger); + // Make sure the first compile is at least one second after the + // package_config.json is written, otherwise dill compilation isn't + // cached. + await Future.delayed(const Duration(seconds: 1)); { final result = await build(packageUri, logger, dartExecutable); diff --git a/pkgs/native_assets_builder/test/build_runner/build_runner_failure_test.dart b/pkgs/native_assets_builder/test/build_runner/build_runner_failure_test.dart index af6f235ed..aa1e030ca 100644 --- a/pkgs/native_assets_builder/test/build_runner/build_runner_failure_test.dart +++ b/pkgs/native_assets_builder/test/build_runner/build_runner_failure_test.dart @@ -33,7 +33,6 @@ void main() async { expect( result.dependencies, [ - packageUri.resolve('hook/build.dart'), packageUri.resolve('src/native_add.c'), ], ); @@ -78,7 +77,6 @@ void main() async { expect( result.dependencies, [ - packageUri.resolve('hook/build.dart'), packageUri.resolve('src/native_add.c'), ], ); diff --git a/pkgs/native_assets_builder/test/build_runner/build_runner_non_root_package_test.dart b/pkgs/native_assets_builder/test/build_runner/build_runner_non_root_package_test.dart index 4e16289fa..1df7626a3 100644 --- a/pkgs/native_assets_builder/test/build_runner/build_runner_non_root_package_test.dart +++ b/pkgs/native_assets_builder/test/build_runner/build_runner_non_root_package_test.dart @@ -48,7 +48,6 @@ void main() async { expect( result.dependencies, [ - packageUri.resolve('hook/build.dart'), packageUri.resolve('src/native_add.c'), ], ); diff --git a/pkgs/native_assets_builder/test_data/add_asset_link/hook/build.dart b/pkgs/native_assets_builder/test_data/add_asset_link/hook/build.dart index 42f8cecb3..c08c9dbd1 100644 --- a/pkgs/native_assets_builder/test_data/add_asset_link/hook/build.dart +++ b/pkgs/native_assets_builder/test_data/add_asset_link/hook/build.dart @@ -22,7 +22,6 @@ void main(List arguments) async { sources: [ 'src/native_add.c', ], - dartBuildFiles: ['hook/build.dart'], linkModePreference: LinkModePreference.dynamic, ).run( config: config, diff --git a/pkgs/native_assets_builder/test_data/add_asset_link/pubspec.yaml b/pkgs/native_assets_builder/test_data/add_asset_link/pubspec.yaml index 45a28d724..77d9c7bee 100644 --- a/pkgs/native_assets_builder/test_data/add_asset_link/pubspec.yaml +++ b/pkgs/native_assets_builder/test_data/add_asset_link/pubspec.yaml @@ -10,12 +10,12 @@ environment: dependencies: logging: ^1.1.1 meta: ^1.12.0 - native_assets_cli: ^0.7.0 - # native_assets_cli: - # path: ../../../native_assets_cli/ - native_toolchain_c: ^0.5.1 - # native_toolchain_c: - # path: ../../../native_toolchain_c/ + # native_assets_cli: ^0.7.0 + native_assets_cli: + path: ../../../native_assets_cli/ + # native_toolchain_c: ^0.5.1 + native_toolchain_c: + path: ../../../native_toolchain_c/ dev_dependencies: lints: ^3.0.0 diff --git a/pkgs/native_assets_builder/test_data/complex_link/pubspec.yaml b/pkgs/native_assets_builder/test_data/complex_link/pubspec.yaml index 82c0d8f68..32b4c929a 100644 --- a/pkgs/native_assets_builder/test_data/complex_link/pubspec.yaml +++ b/pkgs/native_assets_builder/test_data/complex_link/pubspec.yaml @@ -12,9 +12,9 @@ dependencies: complex_link_helper: path: ../complex_link_helper/ logging: ^1.1.1 - native_assets_cli: ^0.7.0 - # native_assets_cli: - # path: ../../../native_assets_cli/ + # native_assets_cli: ^0.7.0 + native_assets_cli: + path: ../../../native_assets_cli/ dev_dependencies: lints: ^3.0.0 diff --git a/pkgs/native_assets_builder/test_data/complex_link_helper/pubspec.yaml b/pkgs/native_assets_builder/test_data/complex_link_helper/pubspec.yaml index de4d2eca6..26abcf629 100644 --- a/pkgs/native_assets_builder/test_data/complex_link_helper/pubspec.yaml +++ b/pkgs/native_assets_builder/test_data/complex_link_helper/pubspec.yaml @@ -10,9 +10,9 @@ environment: dependencies: cli_config: ^0.2.0 logging: ^1.1.1 - native_assets_cli: ^0.7.0 - # native_assets_cli: - # path: ../../../native_assets_cli/ + # native_assets_cli: ^0.7.0 + native_assets_cli: + path: ../../../native_assets_cli/ dev_dependencies: lints: ^3.0.0 diff --git a/pkgs/native_assets_builder/test_data/cyclic_package_1/pubspec.yaml b/pkgs/native_assets_builder/test_data/cyclic_package_1/pubspec.yaml index ba65b33d3..d2293bb4d 100644 --- a/pkgs/native_assets_builder/test_data/cyclic_package_1/pubspec.yaml +++ b/pkgs/native_assets_builder/test_data/cyclic_package_1/pubspec.yaml @@ -10,9 +10,9 @@ environment: dependencies: cyclic_package_2: path: ../cyclic_package_2 - native_assets_cli: ^0.7.0 - # native_assets_cli: - # path: ../../../native_assets_cli/ + # native_assets_cli: ^0.7.0 + native_assets_cli: + path: ../../../native_assets_cli/ yaml: ^3.1.1 yaml_edit: ^2.1.0 diff --git a/pkgs/native_assets_builder/test_data/cyclic_package_2/pubspec.yaml b/pkgs/native_assets_builder/test_data/cyclic_package_2/pubspec.yaml index ec6739eb9..2005cf487 100644 --- a/pkgs/native_assets_builder/test_data/cyclic_package_2/pubspec.yaml +++ b/pkgs/native_assets_builder/test_data/cyclic_package_2/pubspec.yaml @@ -10,9 +10,9 @@ environment: dependencies: cyclic_package_1: path: ../cyclic_package_1 - native_assets_cli: ^0.7.0 - # native_assets_cli: - # path: ../../../native_assets_cli/ + # native_assets_cli: ^0.7.0 + native_assets_cli: + path: ../../../native_assets_cli/ yaml: ^3.1.1 yaml_edit: ^2.1.0 diff --git a/pkgs/native_assets_builder/test_data/drop_dylib_link/hook/build.dart b/pkgs/native_assets_builder/test_data/drop_dylib_link/hook/build.dart index 9c5e40c41..f56a29b5d 100644 --- a/pkgs/native_assets_builder/test_data/drop_dylib_link/hook/build.dart +++ b/pkgs/native_assets_builder/test_data/drop_dylib_link/hook/build.dart @@ -22,7 +22,6 @@ void main(List arguments) async { sources: [ 'src/native_add.c', ], - dartBuildFiles: ['hook/build.dart'], linkModePreference: LinkModePreference.dynamic, ).run( config: config, @@ -37,7 +36,6 @@ void main(List arguments) async { sources: [ 'src/native_multiply.c', ], - dartBuildFiles: ['hook/build.dart'], linkModePreference: LinkModePreference.dynamic, ).run( config: config, diff --git a/pkgs/native_assets_builder/test_data/drop_dylib_link/pubspec.yaml b/pkgs/native_assets_builder/test_data/drop_dylib_link/pubspec.yaml index d48b39f42..302f99453 100644 --- a/pkgs/native_assets_builder/test_data/drop_dylib_link/pubspec.yaml +++ b/pkgs/native_assets_builder/test_data/drop_dylib_link/pubspec.yaml @@ -10,12 +10,12 @@ environment: dependencies: logging: ^1.1.1 meta: ^1.12.0 - native_assets_cli: ^0.7.0 - # native_assets_cli: - # path: ../../../native_assets_cli/ - native_toolchain_c: ^0.5.1 - # native_toolchain_c: - # path: ../../../native_toolchain_c/ + # native_assets_cli: ^0.7.0 + native_assets_cli: + path: ../../../native_assets_cli/ + # native_toolchain_c: ^0.5.1 + native_toolchain_c: + path: ../../../native_toolchain_c/ dev_dependencies: lints: ^3.0.0 diff --git a/pkgs/native_assets_builder/test_data/fail_on_os_sdk_version/pubspec.yaml b/pkgs/native_assets_builder/test_data/fail_on_os_sdk_version/pubspec.yaml index 3f6577846..5d213552d 100644 --- a/pkgs/native_assets_builder/test_data/fail_on_os_sdk_version/pubspec.yaml +++ b/pkgs/native_assets_builder/test_data/fail_on_os_sdk_version/pubspec.yaml @@ -8,9 +8,9 @@ environment: sdk: '>=3.3.0 <4.0.0' dependencies: - native_assets_cli: ^0.7.0 - # native_assets_cli: - # path: ../../../native_assets_cli/ + # native_assets_cli: ^0.7.0 + native_assets_cli: + path: ../../../native_assets_cli/ dev_dependencies: ffigen: ^8.0.2 diff --git a/pkgs/native_assets_builder/test_data/fail_on_os_sdk_version_link/pubspec.yaml b/pkgs/native_assets_builder/test_data/fail_on_os_sdk_version_link/pubspec.yaml index 07d25c00f..c47dbdcc0 100644 --- a/pkgs/native_assets_builder/test_data/fail_on_os_sdk_version_link/pubspec.yaml +++ b/pkgs/native_assets_builder/test_data/fail_on_os_sdk_version_link/pubspec.yaml @@ -10,9 +10,9 @@ environment: dependencies: fail_on_os_sdk_version_linker: path: ../fail_on_os_sdk_version_linker/ - native_assets_cli: ^0.7.0 - # native_assets_cli: - # path: ../../../native_assets_cli/ + # native_assets_cli: ^0.7.0 + native_assets_cli: + path: ../../../native_assets_cli/ dev_dependencies: ffigen: ^8.0.2 diff --git a/pkgs/native_assets_builder/test_data/fail_on_os_sdk_version_linker/pubspec.yaml b/pkgs/native_assets_builder/test_data/fail_on_os_sdk_version_linker/pubspec.yaml index 5122ae27d..5bdaa410c 100644 --- a/pkgs/native_assets_builder/test_data/fail_on_os_sdk_version_linker/pubspec.yaml +++ b/pkgs/native_assets_builder/test_data/fail_on_os_sdk_version_linker/pubspec.yaml @@ -8,9 +8,9 @@ environment: sdk: '>=3.3.0 <4.0.0' dependencies: - native_assets_cli: ^0.7.0 - # native_assets_cli: - # path: ../../../native_assets_cli/ + # native_assets_cli: ^0.7.0 + native_assets_cli: + path: ../../../native_assets_cli/ dev_dependencies: ffigen: ^8.0.2 diff --git a/pkgs/native_assets_builder/test_data/native_add/hook/build.dart b/pkgs/native_assets_builder/test_data/native_add/hook/build.dart index 1815ceaaf..8ffbbf003 100644 --- a/pkgs/native_assets_builder/test_data/native_add/hook/build.dart +++ b/pkgs/native_assets_builder/test_data/native_add/hook/build.dart @@ -16,7 +16,6 @@ void main(List arguments) async { sources: [ 'src/$packageName.c', ], - dartBuildFiles: ['hook/build.dart'], ); await cbuilder.run( config: config, diff --git a/pkgs/native_assets_builder/test_data/native_add/pubspec.yaml b/pkgs/native_assets_builder/test_data/native_add/pubspec.yaml index f3c7f4b5f..03299d2e7 100644 --- a/pkgs/native_assets_builder/test_data/native_add/pubspec.yaml +++ b/pkgs/native_assets_builder/test_data/native_add/pubspec.yaml @@ -9,12 +9,12 @@ environment: dependencies: logging: ^1.1.1 - native_assets_cli: ^0.7.0 - # native_assets_cli: - # path: ../../../native_assets_cli/ - native_toolchain_c: ^0.5.1 - # native_toolchain_c: - # path: ../../../native_toolchain_c/ + # native_assets_cli: ^0.7.0 + native_assets_cli: + path: ../../../native_assets_cli/ + # native_toolchain_c: ^0.5.1 + native_toolchain_c: + path: ../../../native_toolchain_c/ dev_dependencies: ffigen: ^8.0.2 diff --git a/pkgs/native_assets_builder/test_data/native_add_add_source/hook/build.dart b/pkgs/native_assets_builder/test_data/native_add_add_source/hook/build.dart index 74433d1d2..2f1dd9b4c 100644 --- a/pkgs/native_assets_builder/test_data/native_add_add_source/hook/build.dart +++ b/pkgs/native_assets_builder/test_data/native_add_add_source/hook/build.dart @@ -17,7 +17,6 @@ void main(List arguments) async { 'src/$packageName.c', 'src/native_multiply.c', ], - dartBuildFiles: ['hook/build.dart'], ); await cbuilder.run( config: config, diff --git a/pkgs/native_assets_builder/test_data/native_add_add_source/pubspec.yaml b/pkgs/native_assets_builder/test_data/native_add_add_source/pubspec.yaml index 495bdacb5..a16b199fd 100644 --- a/pkgs/native_assets_builder/test_data/native_add_add_source/pubspec.yaml +++ b/pkgs/native_assets_builder/test_data/native_add_add_source/pubspec.yaml @@ -9,12 +9,12 @@ environment: dependencies: logging: ^1.1.1 - native_assets_cli: ^0.7.0 - # native_assets_cli: - # path: ../../../native_assets_cli/ - native_toolchain_c: ^0.5.1 - # native_toolchain_c: - # path: ../../../native_toolchain_c/ + # native_assets_cli: ^0.7.0 + native_assets_cli: + path: ../../../native_assets_cli/ + # native_toolchain_c: ^0.5.1 + native_toolchain_c: + path: ../../../native_toolchain_c/ dev_dependencies: ffigen: ^8.0.2 diff --git a/pkgs/native_assets_builder/test_data/native_subtract/hook/build.dart b/pkgs/native_assets_builder/test_data/native_subtract/hook/build.dart index f01062863..a4add1e0a 100644 --- a/pkgs/native_assets_builder/test_data/native_subtract/hook/build.dart +++ b/pkgs/native_assets_builder/test_data/native_subtract/hook/build.dart @@ -16,7 +16,6 @@ void main(List arguments) async { sources: [ 'src/$packageName.c', ], - dartBuildFiles: ['hook/build.dart'], ); await cbuilder.run( config: config, diff --git a/pkgs/native_assets_builder/test_data/native_subtract/pubspec.yaml b/pkgs/native_assets_builder/test_data/native_subtract/pubspec.yaml index ef8342167..4e3137632 100644 --- a/pkgs/native_assets_builder/test_data/native_subtract/pubspec.yaml +++ b/pkgs/native_assets_builder/test_data/native_subtract/pubspec.yaml @@ -9,12 +9,12 @@ environment: dependencies: logging: ^1.1.1 - native_assets_cli: ^0.7.0 - # native_assets_cli: - # path: ../../../native_assets_cli/ - native_toolchain_c: ^0.5.1 - # native_toolchain_c: - # path: ../../../native_toolchain_c/ + # native_assets_cli: ^0.7.0 + native_assets_cli: + path: ../../../native_assets_cli/ + # native_toolchain_c: ^0.5.1 + native_toolchain_c: + path: ../../../native_toolchain_c/ dev_dependencies: ffigen: ^8.0.2 diff --git a/pkgs/native_assets_builder/test_data/no_asset_for_link/pubspec.yaml b/pkgs/native_assets_builder/test_data/no_asset_for_link/pubspec.yaml index 3925d2910..3db1cbd0e 100644 --- a/pkgs/native_assets_builder/test_data/no_asset_for_link/pubspec.yaml +++ b/pkgs/native_assets_builder/test_data/no_asset_for_link/pubspec.yaml @@ -10,9 +10,9 @@ environment: dependencies: logging: ^1.1.1 meta: ^1.12.0 - native_assets_cli: ^0.7.0 - # native_assets_cli: - # path: ../../../native_assets_cli/ + # native_assets_cli: ^0.7.0 + native_assets_cli: + path: ../../../native_assets_cli/ dev_dependencies: lints: ^3.0.0 diff --git a/pkgs/native_assets_builder/test_data/package_reading_metadata/pubspec.yaml b/pkgs/native_assets_builder/test_data/package_reading_metadata/pubspec.yaml index f5992dcde..2e104d49f 100644 --- a/pkgs/native_assets_builder/test_data/package_reading_metadata/pubspec.yaml +++ b/pkgs/native_assets_builder/test_data/package_reading_metadata/pubspec.yaml @@ -8,9 +8,9 @@ environment: sdk: '>=3.3.0 <4.0.0' dependencies: - native_assets_cli: ^0.7.0 - # native_assets_cli: - # path: ../../../native_assets_cli/ + # native_assets_cli: ^0.7.0 + native_assets_cli: + path: ../../../native_assets_cli/ package_with_metadata: path: ../package_with_metadata/ yaml: ^3.1.1 diff --git a/pkgs/native_assets_builder/test_data/package_with_metadata/pubspec.yaml b/pkgs/native_assets_builder/test_data/package_with_metadata/pubspec.yaml index 1a6b93286..fb08a5a3b 100644 --- a/pkgs/native_assets_builder/test_data/package_with_metadata/pubspec.yaml +++ b/pkgs/native_assets_builder/test_data/package_with_metadata/pubspec.yaml @@ -8,9 +8,9 @@ environment: sdk: '>=3.3.0 <4.0.0' dependencies: - native_assets_cli: ^0.7.0 - # native_assets_cli: - # path: ../../../native_assets_cli/ + # native_assets_cli: ^0.7.0 + native_assets_cli: + path: ../../../native_assets_cli/ yaml: ^3.1.1 yaml_edit: ^2.1.0 diff --git a/pkgs/native_assets_builder/test_data/simple_data_asset/pubspec.yaml b/pkgs/native_assets_builder/test_data/simple_data_asset/pubspec.yaml index 43f421e3b..91097c888 100644 --- a/pkgs/native_assets_builder/test_data/simple_data_asset/pubspec.yaml +++ b/pkgs/native_assets_builder/test_data/simple_data_asset/pubspec.yaml @@ -9,9 +9,9 @@ environment: dependencies: logging: ^1.1.1 - native_assets_cli: ^0.7.0 - # native_assets_cli: - # path: ../../../native_assets_cli/ + # native_assets_cli: ^0.7.0 + native_assets_cli: + path: ../../../native_assets_cli/ dev_dependencies: lints: ^3.0.0 diff --git a/pkgs/native_assets_builder/test_data/simple_link/pubspec.yaml b/pkgs/native_assets_builder/test_data/simple_link/pubspec.yaml index 3c9a99656..6a3b838f5 100644 --- a/pkgs/native_assets_builder/test_data/simple_link/pubspec.yaml +++ b/pkgs/native_assets_builder/test_data/simple_link/pubspec.yaml @@ -10,9 +10,9 @@ environment: dependencies: cli_config: ^0.2.0 logging: ^1.1.1 - native_assets_cli: ^0.7.0 - # native_assets_cli: - # path: ../../../native_assets_cli/ + # native_assets_cli: ^0.7.0 + native_assets_cli: + path: ../../../native_assets_cli/ dev_dependencies: lints: ^3.0.0 diff --git a/pkgs/native_assets_builder/test_data/wrong_build_output/pubspec.yaml b/pkgs/native_assets_builder/test_data/wrong_build_output/pubspec.yaml index c1b34ea0c..75568f590 100644 --- a/pkgs/native_assets_builder/test_data/wrong_build_output/pubspec.yaml +++ b/pkgs/native_assets_builder/test_data/wrong_build_output/pubspec.yaml @@ -8,9 +8,9 @@ environment: sdk: '>=3.3.0 <4.0.0' dependencies: - native_assets_cli: ^0.7.0 - # native_assets_cli: - # path: ../../../native_assets_cli/ + # native_assets_cli: ^0.7.0 + native_assets_cli: + path: ../../../native_assets_cli/ yaml: ^3.1.1 yaml_edit: ^2.1.0 diff --git a/pkgs/native_assets_builder/test_data/wrong_build_output_2/pubspec.yaml b/pkgs/native_assets_builder/test_data/wrong_build_output_2/pubspec.yaml index d1413da34..aedae131a 100644 --- a/pkgs/native_assets_builder/test_data/wrong_build_output_2/pubspec.yaml +++ b/pkgs/native_assets_builder/test_data/wrong_build_output_2/pubspec.yaml @@ -8,9 +8,9 @@ environment: sdk: '>=3.3.0 <4.0.0' dependencies: - native_assets_cli: ^0.7.0 - # native_assets_cli: - # path: ../../../native_assets_cli/ + # native_assets_cli: ^0.7.0 + native_assets_cli: + path: ../../../native_assets_cli/ yaml: ^3.1.1 yaml_edit: ^2.1.0 diff --git a/pkgs/native_assets_builder/test_data/wrong_build_output_3/pubspec.yaml b/pkgs/native_assets_builder/test_data/wrong_build_output_3/pubspec.yaml index 910e37b0c..69601bac1 100644 --- a/pkgs/native_assets_builder/test_data/wrong_build_output_3/pubspec.yaml +++ b/pkgs/native_assets_builder/test_data/wrong_build_output_3/pubspec.yaml @@ -8,9 +8,9 @@ environment: sdk: '>=3.3.0 <4.0.0' dependencies: - native_assets_cli: ^0.7.0 - # native_assets_cli: - # path: ../../../native_assets_cli/ + # native_assets_cli: ^0.7.0 + native_assets_cli: + path: ../../../native_assets_cli/ yaml: ^3.1.1 yaml_edit: ^2.1.0 diff --git a/pkgs/native_assets_builder/test_data/wrong_namespace_asset/pubspec.yaml b/pkgs/native_assets_builder/test_data/wrong_namespace_asset/pubspec.yaml index fdfc94feb..b84dace74 100644 --- a/pkgs/native_assets_builder/test_data/wrong_namespace_asset/pubspec.yaml +++ b/pkgs/native_assets_builder/test_data/wrong_namespace_asset/pubspec.yaml @@ -8,9 +8,9 @@ environment: sdk: '>=3.3.0 <4.0.0' dependencies: - native_assets_cli: ^0.7.0 - # native_assets_cli: - # path: ../../../native_assets_cli/ + # native_assets_cli: ^0.7.0 + native_assets_cli: + path: ../../../native_assets_cli/ yaml: ^3.1.1 yaml_edit: ^2.1.0 diff --git a/pkgs/native_assets_cli/CHANGELOG.md b/pkgs/native_assets_cli/CHANGELOG.md index 769d24acd..20cbd656c 100644 --- a/pkgs/native_assets_cli/CHANGELOG.md +++ b/pkgs/native_assets_cli/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.7.1-wip + +- `BuildConfig.dependencies` and `LinkConfig.dependencies` no longer have to + specify Dart sources. + ## 0.7.0 - `BuildConfig` constructors now have a required `linkingEnabled` parameter. diff --git a/pkgs/native_assets_cli/example/build/local_asset/pubspec.yaml b/pkgs/native_assets_cli/example/build/local_asset/pubspec.yaml index f0c1d95cd..0e44ca767 100644 --- a/pkgs/native_assets_cli/example/build/local_asset/pubspec.yaml +++ b/pkgs/native_assets_cli/example/build/local_asset/pubspec.yaml @@ -10,9 +10,9 @@ environment: dependencies: logging: ^1.1.1 - native_assets_cli: ^0.7.0 - # native_assets_cli: - # path: ../../../../native_assets_cli/ + # native_assets_cli: ^0.7.0 + native_assets_cli: + path: ../../../../native_assets_cli/ dev_dependencies: ffigen: ^8.0.2 diff --git a/pkgs/native_assets_cli/example/build/native_add_library/hook/build.dart b/pkgs/native_assets_cli/example/build/native_add_library/hook/build.dart index c262e0667..1aef62bb1 100644 --- a/pkgs/native_assets_cli/example/build/native_add_library/hook/build.dart +++ b/pkgs/native_assets_cli/example/build/native_add_library/hook/build.dart @@ -15,7 +15,6 @@ void main(List args) async { sources: [ 'src/$packageName.c', ], - dartBuildFiles: ['hook/build.dart'], ); await cbuilder.run( config: config, diff --git a/pkgs/native_assets_cli/example/build/native_add_library/pubspec.yaml b/pkgs/native_assets_cli/example/build/native_add_library/pubspec.yaml index 2ff2c78c3..c463a230f 100644 --- a/pkgs/native_assets_cli/example/build/native_add_library/pubspec.yaml +++ b/pkgs/native_assets_cli/example/build/native_add_library/pubspec.yaml @@ -10,12 +10,12 @@ environment: dependencies: logging: ^1.1.1 - native_assets_cli: ^0.7.0 - # native_assets_cli: - # path: ../../../../native_assets_cli/ - native_toolchain_c: ^0.5.1 - # native_toolchain_c: - # path: ../../../../native_toolchain_c/ + # native_assets_cli: ^0.7.0 + native_assets_cli: + path: ../../../../native_assets_cli/ + # native_toolchain_c: ^0.5.1 + native_toolchain_c: + path: ../../../../native_toolchain_c/ dev_dependencies: ffigen: ^8.0.2 diff --git a/pkgs/native_assets_cli/example/build/use_dart_api/hook/build.dart b/pkgs/native_assets_cli/example/build/use_dart_api/hook/build.dart index 039a93028..0cac7e6ff 100644 --- a/pkgs/native_assets_cli/example/build/use_dart_api/hook/build.dart +++ b/pkgs/native_assets_cli/example/build/use_dart_api/hook/build.dart @@ -17,7 +17,6 @@ void main(List arguments) async { 'src/$packageName.c', 'src/dart_api_dl.c', ], - dartBuildFiles: ['hook/build.dart'], ); await cbuilder.run( config: config, diff --git a/pkgs/native_assets_cli/example/build/use_dart_api/pubspec.yaml b/pkgs/native_assets_cli/example/build/use_dart_api/pubspec.yaml index 1f0d0c41b..998ab1b0e 100644 --- a/pkgs/native_assets_cli/example/build/use_dart_api/pubspec.yaml +++ b/pkgs/native_assets_cli/example/build/use_dart_api/pubspec.yaml @@ -9,12 +9,12 @@ environment: dependencies: logging: ^1.1.1 - native_assets_cli: ^0.7.0 - # native_assets_cli: - # path: ../../../../native_assets_cli/ - native_toolchain_c: ^0.5.1 - # native_toolchain_c: - # path: ../../../../native_toolchain_c/ + # native_assets_cli: ^0.7.0 + native_assets_cli: + path: ../../../../native_assets_cli/ + # native_toolchain_c: ^0.5.1 + native_toolchain_c: + path: ../../../../native_toolchain_c/ dev_dependencies: ffigen: ^10.0.0 diff --git a/pkgs/native_assets_cli/example/link/package_with_assets/pubspec.yaml b/pkgs/native_assets_cli/example/link/package_with_assets/pubspec.yaml index 6ff75c6e3..a38635565 100644 --- a/pkgs/native_assets_cli/example/link/package_with_assets/pubspec.yaml +++ b/pkgs/native_assets_cli/example/link/package_with_assets/pubspec.yaml @@ -11,9 +11,9 @@ environment: dependencies: logging: ^1.1.1 meta: ^1.12.0 - native_assets_cli: ^0.7.0 - # native_assets_cli: - # path: ../../../../native_assets_cli/ + # native_assets_cli: ^0.7.0 + native_assets_cli: + path: ../../../../native_assets_cli/ dev_dependencies: lints: ^3.0.0 diff --git a/pkgs/native_assets_cli/lib/src/api/build_output.dart b/pkgs/native_assets_cli/lib/src/api/build_output.dart index b3c116680..f9acbb17e 100644 --- a/pkgs/native_assets_cli/lib/src/api/build_output.dart +++ b/pkgs/native_assets_cli/lib/src/api/build_output.dart @@ -67,6 +67,11 @@ abstract final class BuildOutput { /// /// If any of the files in [dependencies] are modified after [timestamp], the /// build will be re-run. + /// + /// The (transitive) Dart sources do not have to be added to these + /// dependencies, only non-Dart files. (Note that old Dart and Flutter SDKs + /// do not automatically add the Dart sources. So builds get wrongly cached, + /// try updating to the latest release.) Iterable get dependencies; /// Create a build output. diff --git a/pkgs/native_assets_cli/lib/src/model/build_config_CHANGELOG.md b/pkgs/native_assets_cli/lib/src/model/build_config_CHANGELOG.md index 34cd84ed3..0e4fce0d5 100644 --- a/pkgs/native_assets_cli/lib/src/model/build_config_CHANGELOG.md +++ b/pkgs/native_assets_cli/lib/src/model/build_config_CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.5.0 + +- No changes, but rev version due to BuildOutput change. + ## 1.4.0 - Link hooks are not always run. `BuildConfig.linkingEnabled` communicates diff --git a/pkgs/native_assets_cli/lib/src/model/build_output_CHANGELOG.md b/pkgs/native_assets_cli/lib/src/model/build_output_CHANGELOG.md index 0cfe00c0c..4d825e062 100644 --- a/pkgs/native_assets_cli/lib/src/model/build_output_CHANGELOG.md +++ b/pkgs/native_assets_cli/lib/src/model/build_output_CHANGELOG.md @@ -1,6 +1,13 @@ +## 1.5.0 + +- BuildOutput.dependencies no longer have to list Dart dependencies. + Backwards compatibility older SDKs: The caching will break. + Backwards compatibility older hooks: The Dart sources will be both in the + dependencies and in the native_assets_builder dependencies, which is fine. + ## 1.4.0 -- No changes yet, but rev version due to BuildConfig change. +- No changes, but rev version due to BuildConfig change. ## 1.3.0 diff --git a/pkgs/native_assets_cli/lib/src/model/hook_config.dart b/pkgs/native_assets_cli/lib/src/model/hook_config.dart index 46506fd50..f6ce8a1c6 100644 --- a/pkgs/native_assets_cli/lib/src/model/hook_config.dart +++ b/pkgs/native_assets_cli/lib/src/model/hook_config.dart @@ -547,6 +547,33 @@ can _only_ depend on OS.'''); return sha256String.substring(0, nameLength); } + static String checksumDryRun({ + required String packageName, + required Uri packageRoot, + required OSImpl targetOS, + required LinkModePreferenceImpl linkModePreference, + Version? version, + Iterable? supportedAssetTypes, + required Hook hook, + required bool? linkingEnabled, + }) { + final input = [ + version ?? latestVersion, + packageName, + targetOS.toString(), + linkModePreference.toString(), + ...supportedAssetTypes ?? [NativeCodeAsset.type], + hook.name, + linkingEnabled, + ].join('###'); + final sha256String = sha256.convert(utf8.encode(input)).toString(); + // 256 bit hashes lead to 64 hex character strings. + // To avoid overflowing file paths limits, only use 32. + // Using 16 hex characters would also be unlikely to have collisions. + const nameLength = 32; + return sha256String.substring(0, nameLength); + } + /// The version of [HookConfigImpl]. /// /// This class is used in the protocol between the Dart and Flutter SDKs @@ -555,5 +582,5 @@ can _only_ depend on OS.'''); /// If we ever were to make breaking changes, it would be useful to give /// proper error messages rather than just fail to parse the JSON /// representation in the protocol. - static Version latestVersion = Version(1, 4, 0); + static Version latestVersion = Version(1, 5, 0); } diff --git a/pkgs/native_assets_cli/pubspec.yaml b/pkgs/native_assets_cli/pubspec.yaml index 7db065a45..f6781e0a9 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.7.0 +version: 0.7.1-wip repository: https://github.com/dart-lang/native/tree/main/pkgs/native_assets_cli topics: diff --git a/pkgs/native_assets_cli/test/example/native_add_library_test.dart b/pkgs/native_assets_cli/test/example/native_add_library_test.dart index 263872d5f..7dfcff088 100644 --- a/pkgs/native_assets_cli/test/example/native_add_library_test.dart +++ b/pkgs/native_assets_cli/test/example/native_add_library_test.dart @@ -82,7 +82,6 @@ void main() async { dependencies, [ testPackageUri.resolve('src/$name.c'), - testPackageUri.resolve('hook/build.dart'), ], ); } diff --git a/pkgs/native_assets_cli/test/model/checksum_test.dart b/pkgs/native_assets_cli/test/model/checksum_test.dart index 02b901ff4..35e3c7b58 100644 --- a/pkgs/native_assets_cli/test/model/checksum_test.dart +++ b/pkgs/native_assets_cli/test/model/checksum_test.dart @@ -32,7 +32,7 @@ void main() { ); // Using the checksum for a build folder should be stable. - expect(name1, '32727df17e2a456516a3301d9fa0a9e4'); + expect(name1, '8780162e48a4539f01ea483fda6c1efc'); // Build folder different due to metadata. final name2 = HookConfigImpl.checksum( diff --git a/pkgs/native_toolchain_c/CHANGELOG.md b/pkgs/native_toolchain_c/CHANGELOG.md index d2961d367..b19551532 100644 --- a/pkgs/native_toolchain_c/CHANGELOG.md +++ b/pkgs/native_toolchain_c/CHANGELOG.md @@ -1,3 +1,9 @@ +## 0.5.2 + +- Deprecated `CBuilder`'s constructors `dartBuildFiles`. The Dart sources are + automatically used for determining whether hooks need to be rerun by newer + Dart and Flutter SDKs. + ## 0.5.1 - Bump `package:native_assets_cli` to 0.7.0. diff --git a/pkgs/native_toolchain_c/lib/src/cbuilder/cbuilder.dart b/pkgs/native_toolchain_c/lib/src/cbuilder/cbuilder.dart index b88ffe7c3..6a9e3737b 100644 --- a/pkgs/native_toolchain_c/lib/src/cbuilder/cbuilder.dart +++ b/pkgs/native_toolchain_c/lib/src/cbuilder/cbuilder.dart @@ -89,6 +89,10 @@ class CBuilder implements Builder { /// Resolved against [BuildConfig.packageRoot]. /// /// Used to output the [BuildOutput.dependencies]. + @Deprecated( + 'Newer Dart and Flutter SDKs automatically add the Dart hook ' + 'sources as dependencies.', + ) final List dartBuildFiles; /// TODO(https://github.com/dart-lang/native/issues/54): Move to [BuildConfig] @@ -177,7 +181,11 @@ class CBuilder implements Builder { this.sources = const [], this.includes = const [], this.frameworks = _defaultFrameworks, - required this.dartBuildFiles, + @Deprecated( + 'Newer Dart and Flutter SDKs automatically add the Dart hook ' + 'sources as dependencies.', + ) + this.dartBuildFiles = const [], @visibleForTesting this.installName, this.flags = const [], this.defines = const {}, @@ -195,7 +203,11 @@ class CBuilder implements Builder { this.sources = const [], this.includes = const [], this.frameworks = _defaultFrameworks, - required this.dartBuildFiles, + @Deprecated( + 'Newer Dart and Flutter SDKs automatically add the Dart hook ' + 'sources as dependencies.', + ) + this.dartBuildFiles = const [], this.flags = const [], this.defines = const {}, this.buildModeDefine = true, @@ -240,6 +252,7 @@ class CBuilder implements Builder { packageRoot.resolveUri(Uri.file(directory)), ]; final dartBuildFiles = [ + // ignore: deprecated_member_use_from_same_package for (final source in this.dartBuildFiles) packageRoot.resolve(source), ]; if (!config.dryRun) { diff --git a/pkgs/native_toolchain_c/pubspec.yaml b/pkgs/native_toolchain_c/pubspec.yaml index 4ae295ec2..c4f52d4f9 100644 --- a/pkgs/native_toolchain_c/pubspec.yaml +++ b/pkgs/native_toolchain_c/pubspec.yaml @@ -1,10 +1,10 @@ name: native_toolchain_c description: >- A library to invoke the native C compiler installed on the host machine. -version: 0.5.1 +version: 0.5.2-wip repository: https://github.com/dart-lang/native/tree/main/pkgs/native_toolchain_c -# publish_to: none +publish_to: none topics: - compiler @@ -20,9 +20,9 @@ dependencies: glob: ^2.1.1 logging: ^1.1.1 meta: ^1.9.1 - native_assets_cli: ^0.7.0 - # native_assets_cli: - # path: ../native_assets_cli/ + # native_assets_cli: ^0.7.0 + native_assets_cli: + path: ../native_assets_cli/ pub_semver: ^2.1.3 dev_dependencies: diff --git a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_build_failure_test.dart b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_build_failure_test.dart index 540b2f269..767b1bf0f 100644 --- a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_build_failure_test.dart +++ b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_build_failure_test.dart @@ -50,7 +50,6 @@ void main() { sources: [addCUri.toFilePath()], name: name, assetName: name, - dartBuildFiles: ['hook/build.dart'], ); expect( () => cbuilder.run( diff --git a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_android_test.dart b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_android_test.dart index bd24e0614..2972af5f3 100644 --- a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_android_test.dart +++ b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_android_test.dart @@ -143,7 +143,6 @@ Future buildLib( name: name, assetName: name, sources: [addCUri.toFilePath()], - dartBuildFiles: ['hook/build.dart'], ); await cbuilder.run( config: buildConfig, diff --git a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_ios_test.dart b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_ios_test.dart index 736fe7cbe..5b67876f2 100644 --- a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_ios_test.dart +++ b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_ios_test.dart @@ -82,7 +82,6 @@ void main() { assetName: name, sources: [sourceUri.toFilePath()], installName: installName, - dartBuildFiles: ['hook/build.dart'], language: language, ); await cbuilder.run( @@ -218,7 +217,6 @@ Future buildLib( name: name, assetName: name, sources: [addCUri.toFilePath()], - dartBuildFiles: ['hook/build.dart'], ); await cbuilder.run( config: buildConfig, diff --git a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_linux_host_test.dart b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_linux_host_test.dart index efed28c87..1bb3eb510 100644 --- a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_linux_host_test.dart +++ b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_linux_host_test.dart @@ -62,7 +62,6 @@ void main() { name: name, assetName: name, sources: [addCUri.toFilePath()], - dartBuildFiles: ['hook/build.dart'], ); await cbuilder.run( config: buildConfig, diff --git a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_macos_host_test.dart b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_macos_host_test.dart index d6da1717f..6856d334b 100644 --- a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_macos_host_test.dart +++ b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_macos_host_test.dart @@ -66,7 +66,6 @@ void main() { name: name, assetName: name, sources: [sourceUri.toFilePath()], - dartBuildFiles: ['hook/build.dart'], language: language, ); await cbuilder.run( @@ -147,7 +146,6 @@ Future buildLib( name: name, assetName: name, sources: [addCUri.toFilePath()], - dartBuildFiles: ['hook/build.dart'], ); await cbuilder.run( config: buildConfig, diff --git a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_windows_host_test.dart b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_windows_host_test.dart index 2b1af278c..0af64e8c9 100644 --- a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_windows_host_test.dart +++ b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_windows_host_test.dart @@ -72,7 +72,6 @@ void main() { name: name, assetName: name, sources: [addCUri.toFilePath()], - dartBuildFiles: ['hook/build.dart'], ); await cbuilder.run( config: buildConfig, diff --git a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_test.dart b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_test.dart index 4d440085c..495e6091d 100644 --- a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_test.dart +++ b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_test.dart @@ -64,7 +64,6 @@ void main() { name: name, sources: [helloWorldCUri.toFilePath()], pie: pic, - dartBuildFiles: ['hook/build.dart'], ); await cbuilder.run( config: buildConfig, @@ -147,7 +146,6 @@ void main() { name: name, assetName: name, pic: pic, - dartBuildFiles: ['hook/build.dart'], ); await cbuilder.run( config: buildConfig, @@ -246,7 +244,6 @@ void main() { name: name, sources: [definesCUri.toFilePath()], flags: [flag], - dartBuildFiles: ['hook/build.dart'], ); await cbuilder.run( config: buildConfig, @@ -301,7 +298,6 @@ void main() { assetName: name, includes: [includeDirectoryUri.toFilePath()], sources: [includesCUri.toFilePath()], - dartBuildFiles: ['hook/build.dart'], ); await cbuilder.run( config: buildConfig, @@ -353,7 +349,6 @@ void main() { name: name, assetName: name, std: std, - dartBuildFiles: ['hook/build.dart'], ); await cbuilder.run( config: buildConfig, @@ -415,7 +410,6 @@ void main() { name: name, sources: [helloWorldCppUri.toFilePath()], language: Language.cpp, - dartBuildFiles: ['hook/build.dart'], ); await cbuilder.run( config: buildConfig, @@ -474,7 +468,6 @@ void main() { sources: [helloWorldCppUri.toFilePath()], language: Language.cpp, cppLinkStdLib: 'stdc++', - dartBuildFiles: ['hook/build.dart'], ); if (buildConfig.targetOS == OS.windows) { @@ -551,7 +544,6 @@ Future testDefines({ }, buildModeDefine: buildModeDefine, ndebugDefine: ndebugDefine, - dartBuildFiles: ['hook/build.dart'], ); await cbuilder.run( config: buildConfig, diff --git a/pkgs/native_toolchain_c/test/cbuilder/objective_c_test.dart b/pkgs/native_toolchain_c/test/cbuilder/objective_c_test.dart index c76ac14d2..63cbb6b4d 100644 --- a/pkgs/native_toolchain_c/test/cbuilder/objective_c_test.dart +++ b/pkgs/native_toolchain_c/test/cbuilder/objective_c_test.dart @@ -57,7 +57,6 @@ void main() { assetName: name, sources: [addMUri.toFilePath()], language: Language.objectiveC, - dartBuildFiles: ['hook/build.dart'], ); await cbuilder.run( config: buildConfig,