Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions pkgs/native_assets_cli/lib/src/code_assets/architecture.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ extension ArchitectureSyntax on Architecture {

syntax.Architecture toSyntax() => _toSyntax[this]!;

static Architecture fromSyntax(
syntax.Architecture syntax,
) => switch (_fromSyntax[syntax]) {
null =>
throw FormatException('The architecture "${syntax.name}" is not known'),
final arch => arch,
};
static Architecture fromSyntax(syntax.Architecture syntax) =>
switch (_fromSyntax[syntax]) {
null => throw FormatException(
'The architecture "${syntax.name}" is not known',
),
final arch => arch,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ final class CCompilerConfig {

/// Configuration provided when [CodeConfig.targetOS] is [OS.windows].
WindowsCCompilerConfig get windows => switch (_windows) {
null =>
throw StateError(
'Cannot access windows if CodeConfig.targetOS is not Windows',
),
null => throw StateError(
'Cannot access windows if CodeConfig.targetOS is not Windows',
),
final c => c,
};

Expand Down
37 changes: 17 additions & 20 deletions pkgs/native_assets_cli/lib/src/code_assets/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ extension CodeAssetHookConfig on HookConfig {
/// Code asset specific configuration.
CodeConfig get code => CodeConfig._fromJson(json, path);

bool get buildCodeAssets =>
buildAssetTypes
.where((e) => CodeAssetType.typesForBuildAssetTypes.contains(e))
.isNotEmpty;
bool get buildCodeAssets => buildAssetTypes
.where((e) => CodeAssetType.typesForBuildAssetTypes.contains(e))
.isNotEmpty;
}

/// Extension to the [LinkInput] providing access to configuration specific to
Expand Down Expand Up @@ -78,17 +77,17 @@ class CodeConfig {

/// Configuration provided when [CodeConfig.targetOS] is [OS.android].
AndroidCodeConfig get android => switch (_syntax.android) {
null =>
throw StateError(
'Cannot access androidConfig if targetOS is not android.',
),
null => throw StateError(
'Cannot access androidConfig if targetOS is not android.',
),
final c => AndroidCodeConfig._(c),
};

/// Configuration provided when [CodeConfig.targetOS] is [OS.macOS].
MacOSCodeConfig get macOS => switch (_syntax.macOS) {
null =>
throw StateError('Cannot access macOSConfig if targetOS is not MacOS.'),
null => throw StateError(
'Cannot access macOSConfig if targetOS is not MacOS.',
),
final c => MacOSCodeConfig._(c),
};
}
Expand Down Expand Up @@ -217,21 +216,19 @@ extension CodeAssetBuildInputBuilder on HookConfigBuilder {
/// Provides access to [CodeAsset]s from a build hook output.
extension CodeAssetBuildOutput on BuildOutputAssets {
/// The code assets emitted by the build hook.
List<CodeAsset> get code =>
encodedAssets
.where((asset) => asset.isCodeAsset)
.map(CodeAsset.fromEncoded)
.toList();
List<CodeAsset> get code => encodedAssets
.where((asset) => asset.isCodeAsset)
.map(CodeAsset.fromEncoded)
.toList();
}

/// Provides access to [CodeAsset]s from a link hook output.
extension CodeAssetLinkOutput on LinkOutputAssets {
/// The code assets emitted by the link hook.
List<CodeAsset> get code =>
encodedAssets
.where((asset) => asset.isCodeAsset)
.map(CodeAsset.fromEncoded)
.toList();
List<CodeAsset> get code => encodedAssets
.where((asset) => asset.isCodeAsset)
.map(CodeAsset.fromEncoded)
.toList();
}

extension MacOSCodeConfigSyntax on MacOSCodeConfig {
Expand Down
27 changes: 12 additions & 15 deletions pkgs/native_assets_cli/lib/src/code_assets/testing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,18 @@ Future<void> testCodeBuildHook({
cCompiler: cCompiler,
targetArchitecture: targetArchitecture ?? Architecture.current,
targetOS: targetOS ?? OS.current,
iOS:
targetOS == OS.iOS
? IOSCodeConfig(
targetSdk: targetIOSSdk!,
targetVersion: targetIOSVersion!,
)
: null,
macOS:
targetOS == OS.macOS
? MacOSCodeConfig(targetVersion: targetMacOSVersion!)
: null,
android:
targetOS == OS.android
? AndroidCodeConfig(targetNdkApi: targetAndroidNdkApi!)
: null,
iOS: targetOS == OS.iOS
? IOSCodeConfig(
targetSdk: targetIOSSdk!,
targetVersion: targetIOSVersion!,
)
: null,
macOS: targetOS == OS.macOS
? MacOSCodeConfig(targetVersion: targetMacOSVersion!)
: null,
android: targetOS == OS.android
? AndroidCodeConfig(targetNdkApi: targetAndroidNdkApi!)
: null,
);
await testBuildHook(
mainMethod: mainMethod,
Expand Down
44 changes: 21 additions & 23 deletions pkgs/native_assets_cli/lib/src/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,9 @@ extension type HookInputUserDefines._(HookInput _input) {
}

sealed class HookInputBuilder {
final _syntax =
syntax.HookInput.fromJson({})
..version = latestVersion.toString()
..config = syntax.Config(buildAssetTypes: [], extensions: null);
final _syntax = syntax.HookInput.fromJson({})
..version = latestVersion.toString()
..config = syntax.Config(buildAssetTypes: [], extensions: null);

Map<String, Object?> get json => _syntax.json;

Expand All @@ -129,8 +128,9 @@ sealed class HookInputBuilder {
_syntax.outDir = outputDirectory;
_syntax.outDirShared = outputDirectoryShared;
_syntax.outFile = outputFile;
_syntax.userDefines =
userDefines == null ? null : syntax.JsonObject.fromJson(userDefines);
_syntax.userDefines = userDefines == null
? null
: syntax.JsonObject.fromJson(userDefines);
}

/// Constructs a checksum for a [BuildInput].
Expand Down Expand Up @@ -237,16 +237,15 @@ final class BuildInputBuilder extends HookInputBuilder {
dependencyMetadata: {
for (final key in metadata.keys) key: metadata[key]!.toJson(),
},
assets:
assets == null
? null
: {
for (final MapEntry(:key, :value) in assets.entries)
key: [
for (final asset in value)
syntax.Asset.fromJson(asset.toJson()),
],
},
assets: assets == null
? null
: {
for (final MapEntry(:key, :value) in assets.entries)
key: [
for (final asset in value)
syntax.Asset.fromJson(asset.toJson()),
],
},
);
}

Expand Down Expand Up @@ -332,13 +331,12 @@ final class LinkInputBuilder extends HookInputBuilder {
extension.setupLinkInput(this);
}

List<EncodedAsset> _parseAssets(List<syntax.Asset>? assets) =>
assets == null
? []
: [
for (final asset in assets)
EncodedAsset.fromJson(asset.json, asset.path),
];
List<EncodedAsset> _parseAssets(List<syntax.Asset>? assets) => assets == null
? []
: [
for (final asset in assets)
EncodedAsset.fromJson(asset.json, asset.path),
];

sealed class HookOutput {
/// The underlying json configuration of this [HookOutput].
Expand Down
25 changes: 11 additions & 14 deletions pkgs/native_assets_cli/lib/src/data_assets/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,9 @@ extension AddDataAssetsDirectory on BuildOutputBuilder {
/// Extension to the [HookConfig] providing access to configuration specific
/// to data assets.
extension DataAssetHookConfig on HookConfig {
bool get buildDataAssets =>
buildAssetTypes
.where((e) => DataAssetType.typesForBuildAssetTypes.contains(e))
.isNotEmpty;
bool get buildDataAssets => buildAssetTypes
.where((e) => DataAssetType.typesForBuildAssetTypes.contains(e))
.isNotEmpty;
}

/// Extension to initialize data specific configuration on link/build inputs.
Expand Down Expand Up @@ -149,18 +148,16 @@ extension type DataAssetLinkOutputBuilderAdd(

/// Provides access to [DataAsset]s from a build hook output.
extension DataAssetBuildOutput on BuildOutputAssets {
List<DataAsset> get data =>
encodedAssets
.where((asset) => asset.isDataAsset)
.map<DataAsset>(DataAsset.fromEncoded)
.toList();
List<DataAsset> get data => encodedAssets
.where((asset) => asset.isDataAsset)
.map<DataAsset>(DataAsset.fromEncoded)
.toList();
}

/// Provides access to [DataAsset]s from a link hook output.
extension DataAssetLinkOutput on LinkOutputAssets {
List<DataAsset> get data =>
encodedAssets
.where((asset) => asset.isDataAsset)
.map<DataAsset>(DataAsset.fromEncoded)
.toList();
List<DataAsset> get data => encodedAssets
.where((asset) => asset.isDataAsset)
.map<DataAsset>(DataAsset.fromEncoded)
.toList();
}
17 changes: 8 additions & 9 deletions pkgs/native_assets_cli/lib/src/encoded_asset.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,14 @@ final class EncodedAsset {
]) {
final syntax_ = syntax.Asset.fromJson(json, path: path ?? []);
final encodingSyntax = syntax_.encoding;
final encoding =
encodingSyntax != null
// If 'encoding' is provided, copy that.
? Map.of(encodingSyntax.json)
// Otherwise, fall back to copying the keys except for 'type'.
: {
for (final key in json.keys)
if (key != _typeKey) key: json[key],
};
final encoding = encodingSyntax != null
// If 'encoding' is provided, copy that.
? Map.of(encodingSyntax.json)
// Otherwise, fall back to copying the keys except for 'type'.
: {
for (final key in json.keys)
if (key != _typeKey) key: json[key],
};
final path_ = encodingSyntax != null ? [...?path, 'encoding'] : path;

return EncodedAsset._(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ class ResourceIdentifiers {
factory ResourceIdentifiers.fromFileContents(String fileContents) {
final fileJson = (jsonDecode(fileContents) as Map)['identifiers'] as List;
return ResourceIdentifiers(
identifiers:
fileJson
.map((e) => e as Map<String, Object?>)
.map(Identifier.fromJson)
.toList(),
identifiers: fileJson
.map((e) => e as Map<String, Object?>)
.map(Identifier.fromJson)
.toList(),
);
}

Expand Down
66 changes: 32 additions & 34 deletions pkgs/native_assets_cli/lib/src/target.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,30 +114,29 @@ final class Target implements Comparable<Target> {

Architecture get architecture => Architecture.fromAbi(abi);

OS get os =>
{
Abi.androidArm: OS.android,
Abi.androidArm64: OS.android,
Abi.androidIA32: OS.android,
Abi.androidX64: OS.android,
Abi.androidRiscv64: OS.android,
Abi.fuchsiaArm64: OS.fuchsia,
Abi.fuchsiaX64: OS.fuchsia,
Abi.iosArm: OS.iOS,
Abi.iosArm64: OS.iOS,
Abi.iosX64: OS.iOS,
Abi.linuxArm: OS.linux,
Abi.linuxArm64: OS.linux,
Abi.linuxIA32: OS.linux,
Abi.linuxRiscv32: OS.linux,
Abi.linuxRiscv64: OS.linux,
Abi.linuxX64: OS.linux,
Abi.macosArm64: OS.macOS,
Abi.macosX64: OS.macOS,
Abi.windowsArm64: OS.windows,
Abi.windowsIA32: OS.windows,
Abi.windowsX64: OS.windows,
}[abi]!;
OS get os => {
Abi.androidArm: OS.android,
Abi.androidArm64: OS.android,
Abi.androidIA32: OS.android,
Abi.androidX64: OS.android,
Abi.androidRiscv64: OS.android,
Abi.fuchsiaArm64: OS.fuchsia,
Abi.fuchsiaX64: OS.fuchsia,
Abi.iosArm: OS.iOS,
Abi.iosArm64: OS.iOS,
Abi.iosX64: OS.iOS,
Abi.linuxArm: OS.linux,
Abi.linuxArm64: OS.linux,
Abi.linuxIA32: OS.linux,
Abi.linuxRiscv32: OS.linux,
Abi.linuxRiscv64: OS.linux,
Abi.linuxX64: OS.linux,
Abi.macosArm64: OS.macOS,
Abi.macosX64: OS.macOS,
Abi.windowsArm64: OS.windows,
Abi.windowsIA32: OS.windows,
Abi.windowsX64: OS.windows,
}[abi]!;

@override
String toString() => dartVMToString();
Expand All @@ -154,16 +153,15 @@ final class Target implements Comparable<Target> {
/// A list of supported target [Target]s from this host [os].
List<Target> supportedTargetTargets({
Map<OS, List<OS>> osCrossCompilation = OS.osCrossCompilationDefault,
}) =>
Target.values
.where(
(target) =>
// Only valid cross compilation.
osCrossCompilation[os]!.contains(target.os) &&
// And no deprecated architectures.
target != Target.iOSArm,
)
.sorted;
}) => Target.values
.where(
(target) =>
// Only valid cross compilation.
osCrossCompilation[os]!.contains(target.os) &&
// And no deprecated architectures.
target != Target.iOSArm,
)
.sorted;
}

/// Common methods for manipulating iterables of [Target]s.
Expand Down
5 changes: 3 additions & 2 deletions pkgs/native_assets_cli/lib/test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ Future<void> testBuildHook({

try {
// Deal with Windows temp folder aliases.
final tempUri =
Directory(await tempDir.resolveSymbolicLinks()).uri.normalizePath();
final tempUri = Directory(
await tempDir.resolveSymbolicLinks(),
).uri.normalizePath();
final outputDirectory = tempUri.resolve('output/');
final outputDirectoryShared = tempUri.resolve('output_shared/');
final outputFile = tempUri.resolve('output.json');
Expand Down
Loading
Loading