From 6ee53b3b49c12410711ecb070547366da9505a40 Mon Sep 17 00:00:00 2001 From: Martin Kustermann Date: Thu, 26 Sep 2024 20:51:02 +0200 Subject: [PATCH] Also CCompilerConfig{,Impl} -> CCompilerConfig (now that CCompilerConfig is a plain data class) --- .../lib/src/build_runner/build_runner.dart | 20 ++-- .../build_runner_run_in_isolation_test.dart | 12 +-- .../test/build_runner/helpers.dart | 10 +- pkgs/native_assets_builder/test/helpers.dart | 12 +-- .../lib/native_assets_cli.dart | 3 +- .../lib/native_assets_cli_internal.dart | 2 +- .../lib/src/api/build_config.dart | 5 +- .../lib/src/api/c_compiler_config.dart | 32 ------- .../lib/src/api/hook_config.dart | 1 + .../lib/src/api/link_config.dart | 3 +- pkgs/native_assets_cli/lib/src/api/test.dart | 1 + .../lib/src/model/c_compiler_config.dart | 95 ------------------- .../lib/src/model/hook_config.dart | 59 +++--------- pkgs/native_assets_cli/test/helpers.dart | 12 +-- .../test/model/build_config_test.dart | 10 +- .../test/model/checksum_test.dart | 4 +- .../test/model/link_config_test.dart | 8 +- 17 files changed, 66 insertions(+), 223 deletions(-) delete mode 100644 pkgs/native_assets_cli/lib/src/api/c_compiler_config.dart delete mode 100644 pkgs/native_assets_cli/lib/src/model/c_compiler_config.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 65a6bcfe2..5efc7c81d 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 @@ -59,7 +59,7 @@ class NativeAssetsBuildRunner { required Target target, required Uri workingDirectory, required BuildMode buildMode, - CCompilerConfigImpl? cCompilerConfig, + CCompilerConfig? cCompilerConfig, IOSSdk? targetIOSSdk, int? targetIOSVersion, int? targetMacOSVersion, @@ -104,7 +104,7 @@ class NativeAssetsBuildRunner { required Target target, required Uri workingDirectory, required BuildMode buildMode, - CCompilerConfigImpl? cCompilerConfig, + CCompilerConfig? cCompilerConfig, IOSSdk? targetIOSSdk, int? targetIOSVersion, int? targetMacOSVersion, @@ -142,7 +142,7 @@ class NativeAssetsBuildRunner { required Target target, required Uri workingDirectory, required BuildMode buildMode, - CCompilerConfigImpl? cCompilerConfig, + CCompilerConfig? cCompilerConfig, IOSSdk? targetIOSSdk, int? targetIOSVersion, int? targetMacOSVersion, @@ -167,12 +167,12 @@ class NativeAssetsBuildRunner { final env = Platform.environment; String? lookup(String key) => env[unparseKey(key)]; - final cc = lookup(CCompilerConfigImpl.ccConfigKeyFull); - final ar = lookup(CCompilerConfigImpl.arConfigKeyFull); - final ld = lookup(CCompilerConfigImpl.ldConfigKeyFull); - final envScript = lookup(CCompilerConfigImpl.envScriptConfigKeyFull); + final cc = lookup(CCompilerConfig.ccConfigKeyFull); + final ar = lookup(CCompilerConfig.arConfigKeyFull); + final ld = lookup(CCompilerConfig.ldConfigKeyFull); + final envScript = lookup(CCompilerConfig.envScriptConfigKeyFull); final envScriptArgs = - lookup(CCompilerConfigImpl.envScriptArgsConfigKeyFull) + lookup(CCompilerConfig.envScriptArgsConfigKeyFull) ?.split(' ') .map((arg) => arg.trim()) .where((arg) => arg.isNotEmpty) @@ -185,7 +185,7 @@ class NativeAssetsBuildRunner { ld != null || envScript != null || hasEnvScriptArgs) { - cCompilerConfig = CCompilerConfigImpl( + cCompilerConfig = CCompilerConfig( archiver: ar != null ? Uri.file(ar) : null, compiler: cc != null ? Uri.file(cc) : null, envScript: envScript != null ? Uri.file(envScript) : null, @@ -273,7 +273,7 @@ class NativeAssetsBuildRunner { LinkModePreference linkModePreference, DependencyMetadata? dependencyMetadata, bool? linkingEnabled, - CCompilerConfigImpl? cCompilerConfig, + CCompilerConfig? cCompilerConfig, IOSSdk? targetIOSSdk, int? targetAndroidNdkApi, int? targetIOSVersion, diff --git a/pkgs/native_assets_builder/test/build_runner/build_runner_run_in_isolation_test.dart b/pkgs/native_assets_builder/test/build_runner/build_runner_run_in_isolation_test.dart index ecfa8b28b..0047e08bc 100644 --- a/pkgs/native_assets_builder/test/build_runner/build_runner_run_in_isolation_test.dart +++ b/pkgs/native_assets_builder/test/build_runner/build_runner_run_in_isolation_test.dart @@ -16,12 +16,12 @@ void main() async { String unparseKey(String key) => 'DART_HOOK_TESTING_${key.replaceAll('.', '__').toUpperCase()}'; - final arKey = unparseKey(CCompilerConfigImpl.arConfigKeyFull); - final ccKey = unparseKey(CCompilerConfigImpl.ccConfigKeyFull); - final ldKey = unparseKey(CCompilerConfigImpl.ldConfigKeyFull); - final envScriptKey = unparseKey(CCompilerConfigImpl.envScriptConfigKeyFull); + final arKey = unparseKey(CCompilerConfig.arConfigKeyFull); + final ccKey = unparseKey(CCompilerConfig.ccConfigKeyFull); + final ldKey = unparseKey(CCompilerConfig.ldConfigKeyFull); + final envScriptKey = unparseKey(CCompilerConfig.envScriptConfigKeyFull); final envScriptArgsKey = - unparseKey(CCompilerConfigImpl.envScriptArgsConfigKeyFull); + unparseKey(CCompilerConfig.envScriptArgsConfigKeyFull); final cc = Platform.environment[ccKey]?.fileUri; @@ -54,7 +54,7 @@ void main() async { logger, dartExecutable, // Manually pass in a compiler. - cCompilerConfig: CCompilerConfigImpl( + cCompilerConfig: CCompilerConfig( archiver: Platform.environment[arKey]?.fileUri, compiler: cc, envScript: Platform.environment[envScriptKey]?.fileUri, diff --git a/pkgs/native_assets_builder/test/build_runner/helpers.dart b/pkgs/native_assets_builder/test/build_runner/helpers.dart index 32311d4ac..b5fb3a89b 100644 --- a/pkgs/native_assets_builder/test/build_runner/helpers.dart +++ b/pkgs/native_assets_builder/test/build_runner/helpers.dart @@ -36,7 +36,7 @@ Future build( Logger logger, Uri dartExecutable, { LinkModePreference linkModePreference = LinkModePreference.dynamic, - CCompilerConfigImpl? cCompilerConfig, + CCompilerConfig? cCompilerConfig, bool includeParentEnvironment = true, List? capturedLogs, PackageLayout? packageLayout, @@ -85,7 +85,7 @@ Future link( Logger logger, Uri dartExecutable, { LinkModePreference linkModePreference = LinkModePreference.dynamic, - CCompilerConfigImpl? cCompilerConfig, + CCompilerConfig? cCompilerConfig, bool includeParentEnvironment = true, List? capturedLogs, PackageLayout? packageLayout, @@ -131,7 +131,7 @@ Future<(BuildResult, LinkResult)> buildAndLink( Logger logger, Uri dartExecutable, { LinkModePreference linkModePreference = LinkModePreference.dynamic, - CCompilerConfigImpl? cCompilerConfig, + CCompilerConfig? cCompilerConfig, bool includeParentEnvironment = true, List? capturedLogs, PackageLayout? packageLayout, @@ -223,7 +223,7 @@ Future buildDryRun( Logger logger, Uri dartExecutable, { LinkModePreference linkModePreference = LinkModePreference.dynamic, - CCompilerConfigImpl? cCompilerConfig, + CCompilerConfig? cCompilerConfig, bool includeParentEnvironment = true, List? capturedLogs, PackageLayout? packageLayout, @@ -251,7 +251,7 @@ Future linkDryRun( Logger logger, Uri dartExecutable, { LinkModePreference linkModePreference = LinkModePreference.dynamic, - CCompilerConfigImpl? cCompilerConfig, + CCompilerConfig? cCompilerConfig, bool includeParentEnvironment = true, List? capturedLogs, PackageLayout? packageLayout, diff --git a/pkgs/native_assets_builder/test/helpers.dart b/pkgs/native_assets_builder/test/helpers.dart index fa6fc9638..99a2adfb6 100644 --- a/pkgs/native_assets_builder/test/helpers.dart +++ b/pkgs/native_assets_builder/test/helpers.dart @@ -130,41 +130,41 @@ String unparseKey(String key) => /// /// Provided on Dart CI. final Uri? _ar = Platform - .environment[unparseKey(internal.CCompilerConfigImpl.arConfigKeyFull)] + .environment[unparseKey(internal.CCompilerConfig.arConfigKeyFull)] ?.asFileUri(); /// Compiler provided by the environment. /// /// Provided on Dart CI. final Uri? _cc = Platform - .environment[unparseKey(internal.CCompilerConfigImpl.ccConfigKeyFull)] + .environment[unparseKey(internal.CCompilerConfig.ccConfigKeyFull)] ?.asFileUri(); /// Linker provided by the environment. /// /// Provided on Dart CI. final Uri? _ld = Platform - .environment[unparseKey(internal.CCompilerConfigImpl.ldConfigKeyFull)] + .environment[unparseKey(internal.CCompilerConfig.ldConfigKeyFull)] ?.asFileUri(); /// Path to script that sets environment variables for [_cc], [_ld], and [_ar]. /// /// Provided on Dart CI. final Uri? _envScript = Platform.environment[ - unparseKey(internal.CCompilerConfigImpl.envScriptConfigKeyFull)] + unparseKey(internal.CCompilerConfig.envScriptConfigKeyFull)] ?.asFileUri(); /// Arguments for [_envScript] provided by environment. /// /// Provided on Dart CI. final List? _envScriptArgs = Platform.environment[ - unparseKey(internal.CCompilerConfigImpl.envScriptArgsConfigKeyFull)] + unparseKey(internal.CCompilerConfig.envScriptArgsConfigKeyFull)] ?.split(' '); /// Configuration for the native toolchain. /// /// Provided on Dart CI. -final cCompiler = internal.CCompilerConfigImpl( +final cCompiler = internal.CCompilerConfig( compiler: _cc, archiver: _ar, linker: _ld, diff --git a/pkgs/native_assets_cli/lib/native_assets_cli.dart b/pkgs/native_assets_cli/lib/native_assets_cli.dart index 4c9b2fcaf..610159c08 100644 --- a/pkgs/native_assets_cli/lib/native_assets_cli.dart +++ b/pkgs/native_assets_cli/lib/native_assets_cli.dart @@ -9,7 +9,7 @@ library native_assets_cli; export 'src/api/asset.dart' show Asset, DataAsset, NativeCodeAsset, OSLibraryNaming; export 'src/api/build.dart' show build; -export 'src/api/build_config.dart' show BuildConfig, CCompilerConfig; +export 'src/api/build_config.dart' show BuildConfig; export 'src/api/build_output.dart' show BuildOutput, LinkOutput; export 'src/api/builder.dart' show Builder; export 'src/api/hook_config.dart' show HookConfig; @@ -18,6 +18,7 @@ export 'src/api/link_config.dart' show LinkConfig; export 'src/api/linker.dart' show Linker; export 'src/architecture.dart' show Architecture; export 'src/build_mode.dart' show BuildMode; +export 'src/c_compiler_config.dart' show CCompilerConfig; export 'src/ios_sdk.dart' show IOSSdk; export 'src/link_mode.dart' show diff --git a/pkgs/native_assets_cli/lib/native_assets_cli_internal.dart b/pkgs/native_assets_cli/lib/native_assets_cli_internal.dart index 9e3e180be..fbb4ad9a3 100644 --- a/pkgs/native_assets_cli/lib/native_assets_cli_internal.dart +++ b/pkgs/native_assets_cli/lib/native_assets_cli_internal.dart @@ -18,7 +18,7 @@ library native_assets_cli_internal; export 'native_assets_cli.dart' hide build, link; export 'src/api/asset.dart' show AssetImpl, DataAssetImpl, NativeCodeAssetImpl; -export 'src/api/build_config.dart' show BuildConfigImpl, CCompilerConfigImpl; +export 'src/api/build_config.dart' show BuildConfigImpl; export 'src/api/build_output.dart' show HookOutputImpl; export 'src/api/hook_config.dart' show HookConfigImpl; export 'src/api/link_config.dart' show LinkConfigImpl; diff --git a/pkgs/native_assets_cli/lib/src/api/build_config.dart b/pkgs/native_assets_cli/lib/src/api/build_config.dart index ccfed9623..557651ca7 100644 --- a/pkgs/native_assets_cli/lib/src/api/build_config.dart +++ b/pkgs/native_assets_cli/lib/src/api/build_config.dart @@ -11,6 +11,7 @@ import 'package:pub_semver/pub_semver.dart'; import '../architecture.dart'; import '../args_parser.dart'; import '../build_mode.dart'; +import '../c_compiler_config.dart'; import '../ios_sdk.dart'; import '../json_utils.dart'; import '../link_mode_preference.dart'; @@ -26,8 +27,6 @@ import 'deprecation_messages.dart'; import 'hook_config.dart'; part '../model/build_config.dart'; -part '../model/c_compiler_config.dart'; -part 'c_compiler_config.dart'; /// The configuration for a build hook (`hook/build.dart`) invocation. /// @@ -143,7 +142,7 @@ abstract final class BuildConfig implements HookConfig { targetIOSVersion: targetIOSVersion, targetMacOSVersion: targetMacOSVersion, targetAndroidNdkApi: targetAndroidNdkApi, - cCompiler: cCompiler as CCompilerConfigImpl?, + cCompiler: cCompiler, linkModePreference: linkModePreference, dependencyMetadata: dependencyMetadata != null ? { diff --git a/pkgs/native_assets_cli/lib/src/api/c_compiler_config.dart b/pkgs/native_assets_cli/lib/src/api/c_compiler_config.dart deleted file mode 100644 index 30dc67ac4..000000000 --- a/pkgs/native_assets_cli/lib/src/api/c_compiler_config.dart +++ /dev/null @@ -1,32 +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. - -part of 'build_config.dart'; - -/// The configuration for a C toolchain. -abstract final class CCompilerConfig { - /// Path to a C compiler. - Uri? get compiler; - - /// Path to a native linker. - Uri? get linker; - - /// Path to a native archiver. - Uri? get archiver; - - /// Path to script that sets environment variables for [compiler], [linker], - /// and [archiver]. - Uri? get envScript; - - /// Arguments for [envScript]. - List? get envScriptArgs; - - factory CCompilerConfig({ - Uri? archiver, - Uri? compiler, - Uri? linker, - Uri? envScript, - List? envScriptArgs, - }) = CCompilerConfigImpl; -} diff --git a/pkgs/native_assets_cli/lib/src/api/hook_config.dart b/pkgs/native_assets_cli/lib/src/api/hook_config.dart index 4687d268c..64271462b 100644 --- a/pkgs/native_assets_cli/lib/src/api/hook_config.dart +++ b/pkgs/native_assets_cli/lib/src/api/hook_config.dart @@ -11,6 +11,7 @@ import 'package:pub_semver/pub_semver.dart'; import '../architecture.dart'; import '../build_mode.dart'; +import '../c_compiler_config.dart'; import '../ios_sdk.dart'; import '../json_utils.dart'; import '../link_mode.dart'; diff --git a/pkgs/native_assets_cli/lib/src/api/link_config.dart b/pkgs/native_assets_cli/lib/src/api/link_config.dart index 26dcdbd1e..318298046 100644 --- a/pkgs/native_assets_cli/lib/src/api/link_config.dart +++ b/pkgs/native_assets_cli/lib/src/api/link_config.dart @@ -11,6 +11,7 @@ import 'package:pub_semver/pub_semver.dart'; import '../architecture.dart'; import '../args_parser.dart'; import '../build_mode.dart'; +import '../c_compiler_config.dart'; import '../ios_sdk.dart'; import '../json_utils.dart'; import '../link_mode_preference.dart'; @@ -68,7 +69,7 @@ abstract class LinkConfig implements HookConfig { packageName: packageName, packageRoot: packageRoot, buildMode: buildMode, - cCompiler: cCompiler as CCompilerConfigImpl?, + cCompiler: cCompiler, targetAndroidNdkApi: targetAndroidNdkApi, targetArchitecture: targetArchitecture, targetIOSSdk: targetIOSSdk, diff --git a/pkgs/native_assets_cli/lib/src/api/test.dart b/pkgs/native_assets_cli/lib/src/api/test.dart index 12c4077a6..167a248fd 100644 --- a/pkgs/native_assets_cli/lib/src/api/test.dart +++ b/pkgs/native_assets_cli/lib/src/api/test.dart @@ -10,6 +10,7 @@ import 'package:yaml/yaml.dart'; import '../architecture.dart'; import '../build_mode.dart'; +import '../c_compiler_config.dart'; import '../ios_sdk.dart'; import '../link_mode_preference.dart'; import '../os.dart'; diff --git a/pkgs/native_assets_cli/lib/src/model/c_compiler_config.dart b/pkgs/native_assets_cli/lib/src/model/c_compiler_config.dart deleted file mode 100644 index 1dc496c0a..000000000 --- a/pkgs/native_assets_cli/lib/src/model/c_compiler_config.dart +++ /dev/null @@ -1,95 +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. - -part of '../api/build_config.dart'; - -final class CCompilerConfigImpl implements CCompilerConfig { - /// Path to a C compiler. - @override - Uri? get compiler => _compiler; - late final Uri? _compiler; - - /// Path to a native linker. - @override - Uri? get linker => _linker; - late final Uri? _linker; - - /// Path to a native archiver. - @override - Uri? get archiver => _archiver; - late final Uri? _archiver; - - /// Path to script that sets environment variables for [compiler], [linker], - /// and [archiver]. - @override - Uri? get envScript => _envScript; - late final Uri? _envScript; - - /// Arguments for [envScript]. - @override - List? get envScriptArgs => _envScriptArgs; - late final List? _envScriptArgs; - - factory CCompilerConfigImpl({ - Uri? archiver, - Uri? compiler, - Uri? linker, - Uri? envScript, - List? envScriptArgs, - }) => - CCompilerConfigImpl._() - .._archiver = archiver - .._compiler = compiler - .._linker = linker - .._envScript = envScript - .._envScriptArgs = envScriptArgs; - - CCompilerConfigImpl._(); - - static const configKey = 'c_compiler'; - static const arConfigKey = 'ar'; - static const arConfigKeyFull = '$configKey.$arConfigKey'; - static const ccConfigKey = 'cc'; - static const ccConfigKeyFull = '$configKey.$ccConfigKey'; - static const ldConfigKey = 'ld'; - static const ldConfigKeyFull = '$configKey.$ldConfigKey'; - static const envScriptConfigKey = 'env_script'; - static const envScriptConfigKeyFull = '$configKey.$envScriptConfigKey'; - static const envScriptArgsConfigKey = 'env_script_arguments'; - static const envScriptArgsConfigKeyFull = - '$configKey.$envScriptArgsConfigKey'; - - Map toJson() => { - if (_archiver != null) arConfigKey: _archiver.toFilePath(), - if (_compiler != null) ccConfigKey: _compiler.toFilePath(), - if (_linker != null) ldConfigKey: _linker.toFilePath(), - if (_envScript != null) envScriptConfigKey: _envScript.toFilePath(), - if (_envScriptArgs != null) envScriptArgsConfigKey: _envScriptArgs, - }.sortOnKey(); - - @override - bool operator ==(Object other) { - if (other is! CCompilerConfigImpl) { - return false; - } - if (other.archiver != archiver) return false; - if (other.compiler != compiler) return false; - if (other.linker != linker) return false; - if (other.envScript != envScript) return false; - if (!const ListEquality() - .equals(other.envScriptArgs, envScriptArgs)) { - return false; - } - return true; - } - - @override - int get hashCode => Object.hash( - _archiver, - _compiler, - _linker, - _envScript, - const ListEquality().hash(envScriptArgs), - ); -} 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 c3bcaf2d1..37f867b65 100644 --- a/pkgs/native_assets_cli/lib/src/model/hook_config.dart +++ b/pkgs/native_assets_cli/lib/src/model/hook_config.dart @@ -29,10 +29,10 @@ abstract class HookConfigImpl implements HookConfig { return _buildMode!; } - final CCompilerConfigImpl _cCompiler; + final CCompilerConfig _cCompiler; @override - CCompilerConfigImpl get cCompiler { + CCompilerConfig get cCompiler { ensureNotDryRun(dryRun); return _cCompiler; } @@ -112,7 +112,7 @@ abstract class HookConfigImpl implements HookConfig { required this.packageRoot, required this.version, required BuildMode? buildMode, - required CCompilerConfigImpl? cCompiler, + required CCompilerConfig? cCompiler, required this.supportedAssetTypes, required int? targetAndroidNdkApi, required this.targetArchitecture, @@ -127,7 +127,7 @@ abstract class HookConfigImpl implements HookConfig { _targetIOSVersion = targetIOSVersion, _targetMacOSVersion = targetMacOSVersion, _buildMode = buildMode, - _cCompiler = cCompiler ?? CCompilerConfigImpl(), + _cCompiler = cCompiler ?? CCompilerConfig(), dryRun = dryRun ?? false; HookConfigImpl.dryRun({ @@ -140,7 +140,7 @@ abstract class HookConfigImpl implements HookConfig { required this.supportedAssetTypes, required this.linkModePreference, required this.targetOS, - }) : _cCompiler = CCompilerConfigImpl(), + }) : _cCompiler = CCompilerConfig(), dryRun = true, targetArchitecture = null, _buildMode = null, @@ -197,8 +197,7 @@ abstract class HookConfigImpl implements HookConfig { targetMacOSVersionConfigKey: targetMacOSVersion!, if (targetAndroidNdkApi != null) targetAndroidNdkApiConfigKey: targetAndroidNdkApi!, - if (cCompilerJson.isNotEmpty) - CCompilerConfigImpl.configKey: cCompilerJson, + if (cCompilerJson.isNotEmpty) CCompilerConfig.configKey: cCompilerJson, }, _linkModePreferenceConfigKey: linkModePreference.toString(), }.sortOnKey(); @@ -367,53 +366,21 @@ abstract class HookConfigImpl implements HookConfig { } } - static Uri? _parseArchiver(Map config) => - config.optionalPath( - CCompilerConfigImpl.arConfigKey, - mustExist: true, - ); - - static Uri? _parseCompiler(Map config) => - config.optionalPath( - CCompilerConfigImpl.ccConfigKey, - mustExist: true, - ); - - static Uri? _parseLinker(Map config) => config.optionalPath( - CCompilerConfigImpl.ldConfigKey, - mustExist: true, - ); - - static Uri? _parseEnvScript(Map config, Uri? compiler) => - (compiler != null && compiler.toFilePath().endsWith('cl.exe')) - ? config.path(CCompilerConfigImpl.envScriptConfigKey, mustExist: true) - : null; - - static List? _parseEnvScriptArgs(Map config) => - config.optionalStringList(CCompilerConfigImpl.envScriptArgsConfigKey); - static List parseSupportedAssetTypes(Map config) => config.optionalStringList(supportedAssetTypesKey) ?? [NativeCodeAsset.type]; - static CCompilerConfigImpl parseCCompiler( + static CCompilerConfig parseCCompiler( Map config, bool dryRun) { if (dryRun) { - _throwIfNotNullInDryRun(config, CCompilerConfigImpl.configKey); + _throwIfNotNullInDryRun(config, CCompilerConfig.configKey); } final cCompilerJson = - config.getOptional>(CCompilerConfigImpl.configKey); - if (cCompilerJson == null) return CCompilerConfigImpl(); - - final compiler = _parseCompiler(cCompilerJson); - return CCompilerConfigImpl( - archiver: _parseArchiver(cCompilerJson), - compiler: compiler, - envScript: _parseEnvScript(cCompilerJson, compiler), - envScriptArgs: _parseEnvScriptArgs(cCompilerJson), - linker: _parseLinker(cCompilerJson), - ); + config.getOptional>(CCompilerConfig.configKey); + if (cCompilerJson == null) return CCompilerConfig(); + + return CCompilerConfig.fromJson(cCompilerJson); } static void _throwIfNotNullInDryRun( @@ -497,7 +464,7 @@ can _only_ depend on OS.'''); required BuildMode buildMode, IOSSdk? targetIOSSdk, int? targetAndroidNdkApi, - CCompilerConfigImpl? cCompiler, + CCompilerConfig? cCompiler, required LinkModePreference linkModePreference, Map? dependencyMetadata, Iterable? supportedAssetTypes, diff --git a/pkgs/native_assets_cli/test/helpers.dart b/pkgs/native_assets_cli/test/helpers.dart index d3771ed9e..d9efcc157 100644 --- a/pkgs/native_assets_cli/test/helpers.dart +++ b/pkgs/native_assets_cli/test/helpers.dart @@ -87,41 +87,41 @@ String unparseKey(String key) => /// /// Provided on Dart CI. final Uri? _ar = Platform - .environment[unparseKey(internal.CCompilerConfigImpl.arConfigKeyFull)] + .environment[unparseKey(internal.CCompilerConfig.arConfigKeyFull)] ?.asFileUri(); /// Compiler provided by the environment. /// /// Provided on Dart CI. final Uri? _cc = Platform - .environment[unparseKey(internal.CCompilerConfigImpl.ccConfigKeyFull)] + .environment[unparseKey(internal.CCompilerConfig.ccConfigKeyFull)] ?.asFileUri(); /// Linker provided by the environment. /// /// Provided on Dart CI. final Uri? _ld = Platform - .environment[unparseKey(internal.CCompilerConfigImpl.ldConfigKeyFull)] + .environment[unparseKey(internal.CCompilerConfig.ldConfigKeyFull)] ?.asFileUri(); /// Path to script that sets environment variables for [_cc], [_ld], and [_ar]. /// /// Provided on Dart CI. final Uri? _envScript = Platform.environment[ - unparseKey(internal.CCompilerConfigImpl.envScriptConfigKeyFull)] + unparseKey(internal.CCompilerConfig.envScriptConfigKeyFull)] ?.asFileUri(); /// Arguments for [_envScript] provided by environment. /// /// Provided on Dart CI. final List? _envScriptArgs = Platform.environment[ - unparseKey(internal.CCompilerConfigImpl.envScriptArgsConfigKeyFull)] + unparseKey(internal.CCompilerConfig.envScriptArgsConfigKeyFull)] ?.split(' '); /// Configuration for the native toolchain. /// /// Provided on Dart CI. -final cCompiler = internal.CCompilerConfigImpl( +final cCompiler = internal.CCompilerConfig( compiler: _cc, archiver: _ar, linker: _ld, diff --git a/pkgs/native_assets_cli/test/model/build_config_test.dart b/pkgs/native_assets_cli/test/model/build_config_test.dart index 884e0e498..c41d6cce6 100644 --- a/pkgs/native_assets_cli/test/model/build_config_test.dart +++ b/pkgs/native_assets_cli/test/model/build_config_test.dart @@ -58,7 +58,7 @@ void main() async { targetArchitecture: Architecture.arm64, targetOS: OS.iOS, targetIOSSdk: IOSSdk.iPhoneOS, - cCompiler: CCompilerConfigImpl( + cCompiler: CCompilerConfig( compiler: fakeClang, linker: fakeLd, archiver: fakeAr, @@ -169,7 +169,7 @@ void main() async { targetArchitecture: Architecture.arm64, targetOS: OS.iOS, targetIOSSdk: IOSSdk.iPhoneOS, - cCompiler: CCompilerConfigImpl( + cCompiler: CCompilerConfig( compiler: fakeClang, linker: fakeLd, ), @@ -242,7 +242,7 @@ void main() async { targetArchitecture: Architecture.arm64, targetOS: OS.iOS, targetIOSSdk: IOSSdk.iPhoneOS, - cCompiler: CCompilerConfigImpl( + cCompiler: CCompilerConfig( compiler: fakeClang, linker: fakeLd, ), @@ -379,7 +379,7 @@ void main() async { targetArchitecture: Architecture.arm64, targetOS: OS.iOS, targetIOSSdk: IOSSdk.iPhoneOS, - cCompiler: CCompilerConfigImpl( + cCompiler: CCompilerConfig( compiler: fakeClang, linker: fakeLd, ), @@ -422,7 +422,7 @@ void main() async { packageRoot: packageRootUri, targetArchitecture: Architecture.x64, targetOS: OS.windows, - cCompiler: CCompilerConfigImpl( + cCompiler: CCompilerConfig( compiler: fakeCl, envScript: fakeVcVars, envScriptArgs: ['x64'], diff --git a/pkgs/native_assets_cli/test/model/checksum_test.dart b/pkgs/native_assets_cli/test/model/checksum_test.dart index be8e4a4d3..140689cf4 100644 --- a/pkgs/native_assets_cli/test/model/checksum_test.dart +++ b/pkgs/native_assets_cli/test/model/checksum_test.dart @@ -59,7 +59,7 @@ void main() { targetOS: OS.linux, buildMode: BuildMode.release, linkModePreference: LinkModePreference.dynamic, - cCompiler: CCompilerConfigImpl( + cCompiler: CCompilerConfig( compiler: fakeClangUri, ), hook: Hook.build, @@ -77,7 +77,7 @@ void main() { targetOS: OS.linux, buildMode: BuildMode.release, linkModePreference: LinkModePreference.dynamic, - cCompiler: CCompilerConfigImpl( + cCompiler: CCompilerConfig( compiler: fakeClangUri, ), hook: Hook.link, diff --git a/pkgs/native_assets_cli/test/model/link_config_test.dart b/pkgs/native_assets_cli/test/model/link_config_test.dart index 0cda6f803..8339f2ffe 100644 --- a/pkgs/native_assets_cli/test/model/link_config_test.dart +++ b/pkgs/native_assets_cli/test/model/link_config_test.dart @@ -76,7 +76,7 @@ void main() async { targetArchitecture: Architecture.arm64, targetOS: OS.iOS, targetIOSSdk: IOSSdk.iPhoneOS, - cCompiler: CCompilerConfigImpl( + cCompiler: CCompilerConfig( compiler: fakeClang, linker: fakeLd, archiver: fakeAr, @@ -188,7 +188,7 @@ void main() async { targetArchitecture: Architecture.arm64, targetOS: OS.iOS, targetIOSSdk: IOSSdk.iPhoneOS, - cCompiler: CCompilerConfigImpl( + cCompiler: CCompilerConfig( compiler: fakeClang, linker: fakeLd, ), @@ -212,7 +212,7 @@ void main() async { targetArchitecture: Architecture.arm64, targetOS: OS.iOS, targetIOSSdk: IOSSdk.iPhoneOS, - cCompiler: CCompilerConfigImpl( + cCompiler: CCompilerConfig( compiler: fakeClang, linker: fakeLd, ), @@ -325,7 +325,7 @@ void main() async { targetArchitecture: Architecture.arm64, targetOS: OS.iOS, targetIOSSdk: IOSSdk.iPhoneOS, - cCompiler: CCompilerConfigImpl( + cCompiler: CCompilerConfig( compiler: fakeClang, linker: fakeLd, ),