From 251a33445a21df21bd57615ac24deef2687579bb Mon Sep 17 00:00:00 2001 From: Martin Kustermann Date: Fri, 11 Oct 2024 09:01:13 +0200 Subject: [PATCH] Fix some tests --- .../build_runner/concurrency_test_helper.dart | 2 + .../test/build_runner/helpers.dart | 38 +++++- .../lib/src/code_assets/code_asset.dart | 4 +- pkgs/native_assets_cli/lib/src/config.dart | 14 +- .../test/build_config_test.dart | 13 +- .../native_assets_cli/test/checksum_test.dart | 128 +++++++++--------- .../test/link_config_test.dart | 13 +- .../cbuilder_cross_macos_host_test.dart | 2 +- 8 files changed, 125 insertions(+), 89 deletions(-) diff --git a/pkgs/native_assets_builder/test/build_runner/concurrency_test_helper.dart b/pkgs/native_assets_builder/test/build_runner/concurrency_test_helper.dart index 47c80ddba..8aa2746a5 100644 --- a/pkgs/native_assets_builder/test/build_runner/concurrency_test_helper.dart +++ b/pkgs/native_assets_builder/test/build_runner/concurrency_test_helper.dart @@ -6,6 +6,7 @@ import 'package:logging/logging.dart'; import 'package:native_assets_builder/native_assets_builder.dart'; import '../helpers.dart'; +import 'helpers.dart'; // Is invoked concurrently multiple times in separate processes. void main(List args) async { @@ -28,6 +29,7 @@ void main(List args) async { ..setupCodeConfig( targetArchitecture: Architecture.current, linkModePreference: LinkModePreference.dynamic, + cCompilerConfig: dartCICompilerConfig, ), buildMode: BuildMode.release, 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 b40825943..640d8add7 100644 --- a/pkgs/native_assets_builder/test/build_runner/helpers.dart +++ b/pkgs/native_assets_builder/test/build_runner/helpers.dart @@ -57,7 +57,7 @@ Future build( ..setupCodeConfig( targetArchitecture: target?.architecture ?? Architecture.current, linkModePreference: linkModePreference, - cCompilerConfig: cCompilerConfig, + cCompilerConfig: cCompilerConfig ?? dartCICompilerConfig, targetIOSSdk: targetIOSSdk, targetIOSVersion: targetIOSVersion, targetMacOSVersion: targetMacOSVersion, @@ -115,7 +115,7 @@ Future link( ..setupCodeConfig( targetArchitecture: target?.architecture ?? Architecture.current, linkModePreference: linkModePreference, - cCompilerConfig: cCompilerConfig, + cCompilerConfig: cCompilerConfig ?? dartCICompilerConfig, targetIOSSdk: targetIOSSdk, targetIOSVersion: targetIOSVersion, targetMacOSVersion: targetMacOSVersion, @@ -171,7 +171,7 @@ Future<(BuildResult?, LinkResult?)> buildAndLink( ..setupCodeConfig( targetArchitecture: target?.architecture ?? Architecture.current, linkModePreference: linkModePreference, - cCompilerConfig: cCompilerConfig, + cCompilerConfig: cCompilerConfig ?? dartCICompilerConfig, targetIOSSdk: targetIOSSdk, targetIOSVersion: targetIOSVersion, targetMacOSVersion: targetMacOSVersion, @@ -303,3 +303,35 @@ Future expectSymbols({ ); } } + +final CCompilerConfig? dartCICompilerConfig = (() { + // Specifically for running our tests on Dart CI with the test runner, we + // recognize specific variables to setup the C Compiler configuration. + final env = Platform.environment; + final cc = env['DART_HOOK_TESTING_C_COMPILER__CC']; + final ar = env['DART_HOOK_TESTING_C_COMPILER__AR']; + final ld = env['DART_HOOK_TESTING_C_COMPILER__LD']; + final envScript = env['DART_HOOK_TESTING_C_COMPILER__ENV_SCRIPT']; + final envScriptArgs = + env['DART_HOOK_TESTING_C_COMPILER__ENV_SCRIPT_ARGUMENTS'] + ?.split(' ') + .map((arg) => arg.trim()) + .where((arg) => arg.isNotEmpty) + .toList(); + final hasEnvScriptArgs = envScriptArgs != null && envScriptArgs.isNotEmpty; + + if (cc != null || + ar != null || + ld != null || + envScript != null || + hasEnvScriptArgs) { + return CCompilerConfig( + archiver: ar != null ? Uri.file(ar) : null, + compiler: cc != null ? Uri.file(cc) : null, + envScript: envScript != null ? Uri.file(envScript) : null, + envScriptArgs: hasEnvScriptArgs ? envScriptArgs : null, + linker: ld != null ? Uri.file(ld) : null, + ); + } + return null; +})(); diff --git a/pkgs/native_assets_cli/lib/src/code_assets/code_asset.dart b/pkgs/native_assets_cli/lib/src/code_assets/code_asset.dart index c07b91fb7..399175643 100644 --- a/pkgs/native_assets_cli/lib/src/code_assets/code_asset.dart +++ b/pkgs/native_assets_cli/lib/src/code_assets/code_asset.dart @@ -289,8 +289,8 @@ class CodeConfig { config.json.string('link_mode_preference')), _targetArchitecture = (config is BuildConfig && config.dryRun) ? null - : Architecture.fromString( - config.json.string('target_architecture')), + : Architecture.fromString(config.json.string('target_architecture', + validValues: Architecture.values.map((a) => a.name))), cCompiler = (() { final cCompiler = CCompilerConfig( archiver: config.json.optionalPath('c_compiler.ar'), diff --git a/pkgs/native_assets_cli/lib/src/config.dart b/pkgs/native_assets_cli/lib/src/config.dart index 904b36eac..bb370c5ca 100644 --- a/pkgs/native_assets_cli/lib/src/config.dart +++ b/pkgs/native_assets_cli/lib/src/config.dart @@ -77,10 +77,10 @@ sealed class HookConfig { HookConfig(this.json) : version = switch (Version.parse(json.string(_versionKey))) { - final Version version => (version.major != currentVersion.major || - version < currentVersion) + final Version version => (version.major != latestVersion.major || + version < latestVersion) ? throw FormatException( - 'Only compatible versions with $currentVersion are supported ' + 'Only compatible versions with $latestVersion are supported ' '(was: $version).') : version, }, @@ -105,14 +105,11 @@ sealed class HookConfig { @override String toString() => const JsonEncoder.withIndent(' ').convert(json); - - // The latest supported config version. - static Version currentVersion = Version(3, 5, 0); } sealed class HookConfigBuilder { final Map json = { - 'version': HookConfig.currentVersion.toString(), + 'version': latestVersion.toString(), }; void setupHookConfig({ @@ -536,3 +533,6 @@ class LinkOutputBuilder extends HookOutputBuilder { } } } + +// The latest supported config version. +final latestVersion = Version(1, 5, 0); diff --git a/pkgs/native_assets_cli/test/build_config_test.dart b/pkgs/native_assets_cli/test/build_config_test.dart index 85ebf0e6b..3011444b6 100644 --- a/pkgs/native_assets_cli/test/build_config_test.dart +++ b/pkgs/native_assets_cli/test/build_config_test.dart @@ -8,6 +8,7 @@ import 'dart:convert'; import 'dart:io'; import 'package:native_assets_cli/native_assets_cli_internal.dart'; +import 'package:native_assets_cli/src/config.dart' show latestVersion; import 'package:test/test.dart'; //XXX TODO @@ -108,7 +109,7 @@ void main() async { 'target_android_ndk_api': 30, 'target_architecture': 'arm64', 'target_os': 'android', - 'version': HookConfig.currentVersion.toString(), + 'version': latestVersion.toString(), 'c_compiler.ar': fakeAr.toFilePath(), 'c_compiler.ld': fakeLd.toFilePath(), 'c_compiler.cc': fakeClang.toFilePath(), @@ -182,7 +183,7 @@ void main() async { 'package_name': packageName, 'package_root': packageRootUri.toFilePath(), 'target_os': 'android', - 'version': HookConfig.currentVersion.toString(), + 'version': latestVersion.toString(), }; expect(config.json, expectedConfigJson); @@ -232,7 +233,7 @@ void main() async { (e) => e is FormatException && e.message.contains(version) && - e.message.contains(HookConfig.currentVersion.toString()), + e.message.contains(latestVersion.toString()), )), ); }); @@ -251,7 +252,7 @@ void main() async { ); expect( () => BuildConfig({ - 'version': HookConfig.currentVersion.toString(), + 'version': latestVersion.toString(), 'package_name': packageName, 'package_root': packageRootUri.toFilePath(), 'target_architecture': 'arm64', @@ -271,7 +272,7 @@ void main() async { ); expect( () => BuildConfig({ - 'version': HookConfig.currentVersion.toString(), + 'version': latestVersion.toString(), 'out_dir': outDirUri.toFilePath(), 'out_dir_shared': outputDirectoryShared.toFilePath(), 'package_name': packageName, @@ -310,7 +311,7 @@ void main() async { 'target_architecture': 'invalid_architecture', 'target_os': 'android', 'supported_asset_types': [CodeAsset.type], - 'version': HookConfig.currentVersion.toString(), + 'version': latestVersion.toString(), }; expect( () => BuildConfig(config), diff --git a/pkgs/native_assets_cli/test/checksum_test.dart b/pkgs/native_assets_cli/test/checksum_test.dart index 246066ade..680e6da2e 100644 --- a/pkgs/native_assets_cli/test/checksum_test.dart +++ b/pkgs/native_assets_cli/test/checksum_test.dart @@ -38,70 +38,70 @@ void main() { // If format or algorithm for checksumming changes we'd like to know (by // needing to update this list). expect(checksums, [ - '49daf3450cda2d6f703fd1c5615723e1', - '5b071ecc8b32a1dd7ae71cec893da765', - '42e0e9ef9b52243b2a033708c5614692', - '779e7bd31c6671c69c15bffe20b9b882', - 'e1684c0558449dc47dd6e95eed9c8f20', - '42264730ed1bac426fd9b0de85ca355a', - 'fae528a60605783f326c1e61af02a943', - '375be74dab1457c8ba637444654a4a3a', - '390e8e89b417572229bf7f2c02883a3c', - 'd2931555f8c5f3610b45012f63fafae4', - '423dc47a44ce262b6d1d30fd159752fe', - '1616bd24aa7745c19272cb7776c740d8', - '1dfafc3008d703fb5670cae22955e7f0', - '27c8a7891663bdea5791f0a4a0b00f0a', - '33628656d5ba5acff5ba6d672e6266e9', - '6a99fa1285cdbdf07e7f2f16dd9c124f', - '6d6fca403370aa7ea4ae309eb3e19272', - '09aadc73a263858f3b0724c3ca1c886a', - '920c1e3d286c746065652bfd2d740698', - 'cbf2c911f9d3e5b0d644b402d8feebd3', - 'ac36f6d4b530ddbd77d7c9fd93514bfc', - 'a77d9a81e1f66c43ba16743263516fc1', - '7619ec268bb1c4da8116db2605bd2ab8', - '3eaa505790a10afc93b4402799c735d2', - 'c9378ada5a069e0ea1f4906e6e981092', - '2915954b795f02d688269214b3db0cf7', - 'c6c895b2c738ff19eba67044f0dbbbd0', - '953a29fc8f4015a57fb44749dd576837', - '4c6c58417ab2e732e9b2952fedacce68', - '9cfb486089a705226ee8a138d14f7fd7', - '8a9fc2ebf5cc1fa39cd03179a5959fad', - 'b956d47a5613b89e09f00763fc7b30b6', - 'fe690851eb75c9566fbf2060f8b37df9', - 'f29ec64febd078bd188041ccb7d545f7', - '3f54f0ceca274275c71c4fa2ca3ef919', - '9896e8326e43a114ca1fa833a00f0e80', - '8f5c3abb4578159f37a3f585a4e52b62', - 'fd2e5b9cd4ccbe35a7b515f49b44a6f4', - '90d3dfc0dab4617da8b3b261c6d42ed6', - '4491024a82b1ae5545b3bb90f37c47bd', - '491e8c4549b80de2de7366f75deb6fb7', - 'bf8ce548a070836411efc4ffab36f00d', - '5562ecf90c8ea05f8cff98099a16c6bd', - '451b5c9be02a42cb5cf6359355241f6a', - '3b39694a45d1c427dbf24229ad88f969', - 'd4527aec8dc183f1f61819a414fe3a52', - '95ea9db54a39dfc3d7eecbf120b93ee0', - '2ac0ee9854562c6274749fdcc1fb3609', - 'd1ef410112e3f3ed8a98e1dc7e64f653', - '5e05ca0cd3496beebe8f3a3c5dec2e3c', - '3e2febea1b3c111eed26c9a5a6b90ef3', - '969f85ffb945e52278b0b55b895f12a1', - 'd00132dd4a88b01e4071e8b1e1d6cf28', - '5d940c16b18065eb2579a48d12a9cdd0', - '144cbd4cd41f6bf3a3bee7b0776cff40', - '793cd15349782e52b009a5337301c2b9', - '676def9232cfb0ad832311cf6c29defb', - '7010c8c6d8124e35b1c9ad643f219ffd', - 'd0b705242470e18b6caf62dc1765e70f', - 'e0874bd58e0a72f341406fef23979bd0', - '4174d81f0fa117071a58abc5886cce45', - '6221a8463b3978352a1cc6f0b0945f0a', - '154c04f511463b7f73033559561ca88d', - '66fc47c7320a7af96716f17c80b0eb3f', + 'ba2bc300017587a47517a4572526b933', + '26ccc134a7a0dbca796c084da8a8f2ab', + '9353b5a4743d5846966982c617f8c6d3', + '38256f2a773b1d2e4bdc75ae08fc5aca', + '2e7889e3525851cb5f52917c1433f276', + '636c833769cbc78ebe6c50aa143bdb7c', + 'ff5af0c4a25ad97bea69046d90816795', + '6d0d5e14aeeb05df47ac0a609834a919', + '43d41135168d8ddeba8bd75a5ecdd23b', + '5a13ce6c9e3631caf83541d53490503e', + 'b2c53aa181d573f773c531d33a4ecaaa', + '75dcb30bbc0881082c336d94f04ba6cf', + 'c0d52057e60ec03f6e1e353c833cdb58', + '873ffa4c448ba9a4700c7287969265c5', + 'fd5d647936a2359641f005c1f63d6c9b', + 'd6c94a9cc87ceee6bdbddcf6b1a44430', + 'c317380eafe0d801d69ad41527817e4c', + '88e797f27103025280032ea58dfe3286', + '602a6129ed715ef7f0d64f1a3d06c79d', + '35b049dbbfc14eafe6eff9784fbc043c', + 'c7d2dcad8a49fb378c1156bc3e0eb076', + '099bd7788d3d1035a9ef0703bc8c5e3a', + 'b4127e80ac8ff38350c0561219bd4829', + '1e0c648381278c5f8a1e700117b68481', + 'f31b2395ece58f7ce0050401fbfc6ee3', + 'd7e0c607f6c273191935fe3c503f5edc', + 'c764f9a7d1fe73f7e25914785822228f', + '6631019d7da3f4895f73a8552b594ed7', + '3c6e6ae969948fdf2d5483c25cf4de9b', + '453c7605eb2530da9f73370d0b547b74', + '064065551068620fc01871981d7d78be', + '5fb0fef97089d96b73b2e36c472d3ea3', + '5d031c711a4c967d69230300884043b4', + '6766828a69d373a5cca7b8d6ab02de68', + 'e0b5b6179fa12fca7c6c485fff6c9604', + 'e96485164e8cd8cc67786a695aa1ef41', + '54b31167d328cef00adccaa1a58817a2', + '0220c1091cfbffd04c04b7a4c85042f1', + 'b28fa401faa29491a44196d26a97b207', + '361a44ba78a1d1c83a3ac69c54698427', + '1f1d1e5c34e55fc2befd1d9c8406c6e6', + '5a5b2e61f4bd2d6becf09794c076052c', + 'e876ee447141fcf3340fd2be9e0e7150', + 'f39056ec56716ac8126d028f5b173af3', + '9583a43d92f68823bf7ed48cee58a31f', + '55bad15339b118e2a5499d9c6e4d6712', + 'a13a80b07b2652e875ad2d6085c1d18b', + '32c7e1206e515c1d1e70ce377297d54b', + '6a184b55796ea1e881d770e738b7ab50', + 'f8447318c2425bb9b61867b3893c076e', + '3799d315dcd32cb4ef04f7c696864a97', + '03e5f35bbddb6eabb31d204956553929', + '38a184c0de890152e827818d91262a03', + '89712caccd036a44d57532af16b5edac', + '25262ba7da76224ac55b25fc2c0f72e7', + 'b9a88e9fd06e9f5d61f21ff2f2bbb7a1', + 'e13d2a99df2448b3c3dda18ed4e25d10', + 'ef0b2152ae957394bb790cfa253297ad', + '7d64c455ce832456b15c11d363fb78f5', + 'f8f697616faeb8a37c754cb5753b87a9', + 'ebb22b7ebe0e7ac29ce841cc237a941f', + 'b527639217b053dde60a34d7fb0d576b', + '1b5b1ef52b505d5858eb30d86ccd26a2', + 'fc4654d784f30ab97a72f089ad7e5684', ]); }); } diff --git a/pkgs/native_assets_cli/test/link_config_test.dart b/pkgs/native_assets_cli/test/link_config_test.dart index 44440d254..af6dd26a1 100644 --- a/pkgs/native_assets_cli/test/link_config_test.dart +++ b/pkgs/native_assets_cli/test/link_config_test.dart @@ -6,6 +6,7 @@ import 'dart:convert'; import 'dart:io'; import 'package:native_assets_cli/native_assets_cli_internal.dart'; +import 'package:native_assets_cli/src/config.dart' show latestVersion; import 'package:test/test.dart'; void main() async { @@ -83,7 +84,7 @@ void main() async { 'target_android_ndk_api': 30, 'target_architecture': 'arm64', 'target_os': 'android', - 'version': HookConfig.currentVersion.toString(), + 'version': latestVersion.toString(), 'c_compiler.ar': fakeAr.toFilePath(), 'c_compiler.ld': fakeLd.toFilePath(), 'c_compiler.cc': fakeClang.toFilePath(), @@ -132,7 +133,7 @@ void main() async { (e) => e is FormatException && e.message.contains(version) && - e.message.contains(HookConfig.currentVersion.toString()), + e.message.contains(latestVersion.toString()), )), ); }); @@ -151,10 +152,10 @@ void main() async { 'target_android_ndk_api': 30, 'target_architecture': 'invalid_architecture', 'target_os': 'android', - 'version': HookOutput.latestVersion.toString(), + 'version': latestVersion.toString(), }; expect( - () => LinkConfig(config), + () => LinkConfig(config).codeConfig, throwsFormatException, ); }); @@ -170,7 +171,7 @@ void main() async { ); expect( () => LinkConfig({ - 'version': HookConfig.currentVersion.toString(), + 'version': latestVersion.toString(), 'supported_asset_types': [CodeAsset.type], 'package_name': packageName, 'package_root': packageRootUri.toFilePath(), @@ -189,7 +190,7 @@ void main() async { ); expect( () => LinkConfig({ - 'version': HookConfig.currentVersion.toString(), + 'version': latestVersion.toString(), 'supported_asset_types': [CodeAsset.type], 'out_dir': outDirUri.toFilePath(), 'out_dir_shared': outputDirectoryShared.toFilePath(), 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 9a92e3649..17adc1519 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 @@ -154,7 +154,7 @@ Future buildLib( supportedAssetTypes: [CodeAsset.type], packageName: name, packageRoot: tempUri, - targetOS: OS.iOS, + targetOS: OS.macOS, buildMode: BuildMode.release, ) ..setupBuildConfig(