Skip to content

Commit

Permalink
remove target os and target arch toplevel
Browse files Browse the repository at this point in the history
  • Loading branch information
dcharkes committed Feb 18, 2025
1 parent 678a7d1 commit c366cdd
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 51 deletions.
50 changes: 16 additions & 34 deletions pkgs/native_assets_cli/lib/src/code_assets/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,12 @@ class CodeConfig {
json.code!.string(_linkModePreferenceKey),
);
final targetArchitecture = Architecture.fromString(
json.code?.optionalString(
_targetArchitectureKey,
validValues: Architecture.values.map((a) => a.name),
) ??
json.string(
_targetArchitectureKey,
validValues: Architecture.values.map((a) => a.name),
),
);
final targetOS = OS.fromString(
json.code?.optionalString(_targetOSConfigKey) ??
json.string(_targetOSConfigKey),
json.code!.string(
_targetArchitectureKey,
validValues: Architecture.values.map((a) => a.name),
),
);
final targetOS = OS.fromString(json.code!.string(_targetOSConfigKey));
final cCompiler = switch (json.code?.optionalMap(_compilerKey)) {
final Map<String, Object?> map => CCompilerConfig.fromJson(map),
null => null,
Expand Down Expand Up @@ -153,13 +146,12 @@ class IOSCodeConfig {
_targetVersion = targetVersion;

IOSCodeConfig.fromJson(Map<String, Object?> json)
: _targetVersion =
json.code?.optionalMap(_iosKey)?.optionalInt(_targetVersionKey) ??
json.optionalInt(_targetIOSVersionKeyDeprecated),
: _targetVersion = json.code
?.optionalMap(_iosKey)
?.optionalInt(_targetVersionKey),
_targetSdk = switch (json.code
?.optionalMap(_iosKey)
?.optionalString(_targetSdkKey) ??
json.optionalString(_targetIOSSdkKeyDeprecated)) {
?.optionalMap(_iosKey)
?.optionalString(_targetSdkKey)) {
null => null,
String e => IOSSdk.fromString(e),
};
Expand All @@ -181,9 +173,9 @@ class AndroidCodeConfig {
AndroidCodeConfig({required int targetNdkApi}) : _targetNdkApi = targetNdkApi;

AndroidCodeConfig.fromJson(Map<String, Object?> json)
: _targetNdkApi =
json.code?.optionalMap(_androidKey)?.optionalInt(_targetNdkApiKey) ??
json.optionalInt(_targetAndroidNdkApiKeyDeprecated);
: _targetNdkApi = json.code
?.optionalMap(_androidKey)
?.optionalInt(_targetNdkApiKey);
}

extension AndroidConfigSyntactic on AndroidCodeConfig {
Expand All @@ -201,9 +193,9 @@ class MacOSCodeConfig {
: _targetVersion = targetVersion;

MacOSCodeConfig.fromJson(Map<String, Object?> json)
: _targetVersion =
json.code?.optionalMap(_macosKey)?.optionalInt(_targetVersionKey) ??
json.optionalInt(_targetMacOSVersionKeyDeprecated);
: _targetVersion = json.code
?.optionalMap(_macosKey)
?.optionalInt(_targetVersionKey);
}

extension MacOSConfigSyntactic on MacOSCodeConfig {
Expand Down Expand Up @@ -267,14 +259,12 @@ extension CodeAssetBuildInputBuilder on HookConfigBuilder {
MacOSCodeConfig? macOS,
}) {
if (targetArchitecture != null) {
json[_targetArchitectureKey] = targetArchitecture.toString();
json.setNested([
_configKey,
_codeKey,
_targetArchitectureKey,
], targetArchitecture.toString());
}
json[_targetOSConfigKey] = targetOS.toString();
json.setNested([
_configKey,
_codeKey,
Expand All @@ -292,16 +282,13 @@ extension CodeAssetBuildInputBuilder on HookConfigBuilder {
// Note, using ?. instead of !. makes missing data be a semantic error
// rather than a syntactic error to be caught in the validation.
if (targetOS == OS.android) {
json[_targetAndroidNdkApiKeyDeprecated] = android?.targetNdkApi;
json.setNested([
_configKey,
_codeKey,
_androidKey,
_targetNdkApiKey,
], android?.targetNdkApi);
} else if (targetOS == OS.iOS) {
json[_targetIOSSdkKeyDeprecated] = iOS?.targetSdk.toString();
json[_targetIOSVersionKeyDeprecated] = iOS?.targetVersion;
json.setNested([
_configKey,
_codeKey,
Expand All @@ -315,7 +302,6 @@ extension CodeAssetBuildInputBuilder on HookConfigBuilder {
_targetVersionKey,
], iOS?.targetVersion);
} else if (targetOS == OS.macOS) {
json[_targetMacOSVersionKeyDeprecated] = macOS?.targetVersion;
json.setNested([
_configKey,
_codeKey,
Expand Down Expand Up @@ -349,13 +335,9 @@ extension CodeAssetLinkOutput on LinkOutputAssets {
const String _compilerKey = 'c_compiler';
const String _linkModePreferenceKey = 'link_mode_preference';
const String _targetNdkApiKey = 'target_ndk_api';
const String _targetAndroidNdkApiKeyDeprecated = 'target_android_ndk_api';
const String _targetArchitectureKey = 'target_architecture';
const String _targetSdkKey = 'target_sdk';
const String _targetIOSSdkKeyDeprecated = 'target_ios_sdk';
const String _targetVersionKey = 'target_version';
const String _targetIOSVersionKeyDeprecated = 'target_ios_version';
const String _targetMacOSVersionKeyDeprecated = 'target_macos_version';
const String _targetOSConfigKey = 'target_os';

const _configKey = 'config';
Expand Down
4 changes: 2 additions & 2 deletions pkgs/native_assets_cli/test/build_config_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ void main() async {
'config': {
'build_asset_types': ['my-asset-type'],
'linking_enabled': false,
'target_os': 'linux',
'link_mode_preference': 'prefer-static',
},
'link_mode_preference': 'prefer-static',
'out_dir': outDir.toFilePath(),
'out_dir_shared': outputDirectoryShared.toFilePath(),
'out_file': outFile.toFilePath(),
'package_root': packageRootUri.toFilePath(),
'target_os': 'linux',
'version': version,
'package_name': packageName,
};
Expand Down
24 changes: 12 additions & 12 deletions pkgs/native_assets_cli/test/code_assets/config_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,6 @@ void main() async {
'out_file': outFile.toFilePath(),
'package_name': packageName,
'package_root': packageRootUri.toFilePath(),
if (includeDeprecated && targetOS == OS.android)
'target_android_ndk_api': 30,
if (includeDeprecated) 'target_architecture': 'arm64',
if (includeDeprecated) 'target_os': targetOS.name,
'version': '1.9.0',
};

Expand Down Expand Up @@ -227,17 +223,19 @@ void main() async {
test('BuildInput.config.code: invalid architecture', () {
final input = {
'config': {
'code': {'link_mode_preference': 'prefer-static'},
'code': {
'link_mode_preference': 'prefer-static',
'android': {'target_ndk_api': 30},
'target_architecture': 'invalid_architecture',
'target_os': 'android',
},
'linking_enabled': false,
},
'out_dir': outDirUri.toFilePath(),
'out_dir_shared': outputDirectoryShared.toFilePath(),
'out_file': outFile.toFilePath(),
'package_name': packageName,
'package_root': packageRootUri.toFilePath(),
'target_android_ndk_api': 30,
'target_architecture': 'invalid_architecture',
'target_os': 'android',
'version': latestVersion.toString(),
};
expect(() => BuildInput(input).config.code, throwsFormatException);
Expand All @@ -246,16 +244,18 @@ void main() async {
test('LinkInput.config.code: invalid architecture', () {
final input = {
'config': {
'code': {'link_mode_preference': 'prefer-static'},
'code': {
'link_mode_preference': 'prefer-static',
'android': {'target_ndk_api': 30},
'target_architecture': 'invalid_architecture',
'target_os': 'android',
},
},
'out_dir': outDirUri.toFilePath(),
'out_dir_shared': outputDirectoryShared.toFilePath(),
'out_file': outFile.toFilePath(),
'package_name': packageName,
'package_root': packageRootUri.toFilePath(),
'target_android_ndk_api': 30,
'target_architecture': 'invalid_architecture',
'target_os': 'android',
'version': latestVersion.toString(),
};
expect(() => LinkInput(input).config.code, throwsFormatException);
Expand Down
3 changes: 0 additions & 3 deletions pkgs/native_assets_cli/test/link_config_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ void main() async {
'out_dir_shared': outputDirectoryShared.toFilePath(),
'out_file': outFile.toFilePath(),
'package_root': packageRootUri.toFilePath(),
'target_os': 'linux',
'version': version,
'package_name': packageName,
};
Expand Down Expand Up @@ -112,7 +111,6 @@ void main() async {
'version': latestVersion.toString(),
'package_name': packageName,
'package_root': packageRootUri.toFilePath(),
'target_os': 'android',
'assets': <String>[],
}),
throwsA(
Expand All @@ -133,7 +131,6 @@ void main() async {
'out_file': outFile.toFilePath(),
'package_name': packageName,
'package_root': packageRootUri.toFilePath(),
'target_os': 'android',
'assets': 'astring',
}),
throwsA(
Expand Down

0 comments on commit c366cdd

Please sign in to comment.