Skip to content

Commit 9c551c1

Browse files
authored
[native_assets_cli] Format with Dart 3.8 (#2195)
The CI will be red soon because `package:native_assets_cli` is opted in to a Dart 3.8 dev release. When the CI will be red, we should land this PR to make it green again. The PR will be red before a new dart dev release is cut. (Tuesday?) Bug: #2194
1 parent a95c6c4 commit 9c551c1

22 files changed

+393
-434
lines changed

pkgs/native_assets_cli/lib/src/code_assets/architecture.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,11 @@ extension ArchitectureSyntax on Architecture {
100100

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

103-
static Architecture fromSyntax(
104-
syntax.Architecture syntax,
105-
) => switch (_fromSyntax[syntax]) {
106-
null =>
107-
throw FormatException('The architecture "${syntax.name}" is not known'),
108-
final arch => arch,
109-
};
103+
static Architecture fromSyntax(syntax.Architecture syntax) =>
104+
switch (_fromSyntax[syntax]) {
105+
null => throw FormatException(
106+
'The architecture "${syntax.name}" is not known',
107+
),
108+
final arch => arch,
109+
};
110110
}

pkgs/native_assets_cli/lib/src/code_assets/c_compiler_config.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@ final class CCompilerConfig {
2222

2323
/// Configuration provided when [CodeConfig.targetOS] is [OS.windows].
2424
WindowsCCompilerConfig get windows => switch (_windows) {
25-
null =>
26-
throw StateError(
27-
'Cannot access windows if CodeConfig.targetOS is not Windows',
28-
),
25+
null => throw StateError(
26+
'Cannot access windows if CodeConfig.targetOS is not Windows',
27+
),
2928
final c => c,
3029
};
3130

pkgs/native_assets_cli/lib/src/code_assets/config.dart

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@ extension CodeAssetHookConfig on HookConfig {
1818
/// Code asset specific configuration.
1919
CodeConfig get code => CodeConfig._fromJson(json, path);
2020

21-
bool get buildCodeAssets =>
22-
buildAssetTypes
23-
.where((e) => CodeAssetType.typesForBuildAssetTypes.contains(e))
24-
.isNotEmpty;
21+
bool get buildCodeAssets => buildAssetTypes
22+
.where((e) => CodeAssetType.typesForBuildAssetTypes.contains(e))
23+
.isNotEmpty;
2524
}
2625

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

7978
/// Configuration provided when [CodeConfig.targetOS] is [OS.android].
8079
AndroidCodeConfig get android => switch (_syntax.android) {
81-
null =>
82-
throw StateError(
83-
'Cannot access androidConfig if targetOS is not android.',
84-
),
80+
null => throw StateError(
81+
'Cannot access androidConfig if targetOS is not android.',
82+
),
8583
final c => AndroidCodeConfig._(c),
8684
};
8785

8886
/// Configuration provided when [CodeConfig.targetOS] is [OS.macOS].
8987
MacOSCodeConfig get macOS => switch (_syntax.macOS) {
90-
null =>
91-
throw StateError('Cannot access macOSConfig if targetOS is not MacOS.'),
88+
null => throw StateError(
89+
'Cannot access macOSConfig if targetOS is not MacOS.',
90+
),
9291
final c => MacOSCodeConfig._(c),
9392
};
9493
}
@@ -217,21 +216,19 @@ extension CodeAssetBuildInputBuilder on HookConfigBuilder {
217216
/// Provides access to [CodeAsset]s from a build hook output.
218217
extension CodeAssetBuildOutput on BuildOutputAssets {
219218
/// The code assets emitted by the build hook.
220-
List<CodeAsset> get code =>
221-
encodedAssets
222-
.where((asset) => asset.isCodeAsset)
223-
.map(CodeAsset.fromEncoded)
224-
.toList();
219+
List<CodeAsset> get code => encodedAssets
220+
.where((asset) => asset.isCodeAsset)
221+
.map(CodeAsset.fromEncoded)
222+
.toList();
225223
}
226224

227225
/// Provides access to [CodeAsset]s from a link hook output.
228226
extension CodeAssetLinkOutput on LinkOutputAssets {
229227
/// The code assets emitted by the link hook.
230-
List<CodeAsset> get code =>
231-
encodedAssets
232-
.where((asset) => asset.isCodeAsset)
233-
.map(CodeAsset.fromEncoded)
234-
.toList();
228+
List<CodeAsset> get code => encodedAssets
229+
.where((asset) => asset.isCodeAsset)
230+
.map(CodeAsset.fromEncoded)
231+
.toList();
235232
}
236233

237234
extension MacOSCodeConfigSyntax on MacOSCodeConfig {

pkgs/native_assets_cli/lib/src/code_assets/testing.dart

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,18 @@ Future<void> testCodeBuildHook({
3939
cCompiler: cCompiler,
4040
targetArchitecture: targetArchitecture ?? Architecture.current,
4141
targetOS: targetOS ?? OS.current,
42-
iOS:
43-
targetOS == OS.iOS
44-
? IOSCodeConfig(
45-
targetSdk: targetIOSSdk!,
46-
targetVersion: targetIOSVersion!,
47-
)
48-
: null,
49-
macOS:
50-
targetOS == OS.macOS
51-
? MacOSCodeConfig(targetVersion: targetMacOSVersion!)
52-
: null,
53-
android:
54-
targetOS == OS.android
55-
? AndroidCodeConfig(targetNdkApi: targetAndroidNdkApi!)
56-
: null,
42+
iOS: targetOS == OS.iOS
43+
? IOSCodeConfig(
44+
targetSdk: targetIOSSdk!,
45+
targetVersion: targetIOSVersion!,
46+
)
47+
: null,
48+
macOS: targetOS == OS.macOS
49+
? MacOSCodeConfig(targetVersion: targetMacOSVersion!)
50+
: null,
51+
android: targetOS == OS.android
52+
? AndroidCodeConfig(targetNdkApi: targetAndroidNdkApi!)
53+
: null,
5754
);
5855
await testBuildHook(
5956
mainMethod: mainMethod,

pkgs/native_assets_cli/lib/src/config.dart

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,9 @@ extension type HookInputUserDefines._(HookInput _input) {
103103
}
104104

105105
sealed class HookInputBuilder {
106-
final _syntax =
107-
syntax.HookInput.fromJson({})
108-
..version = latestVersion.toString()
109-
..config = syntax.Config(buildAssetTypes: [], extensions: null);
106+
final _syntax = syntax.HookInput.fromJson({})
107+
..version = latestVersion.toString()
108+
..config = syntax.Config(buildAssetTypes: [], extensions: null);
110109

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

@@ -129,8 +128,9 @@ sealed class HookInputBuilder {
129128
_syntax.outDir = outputDirectory;
130129
_syntax.outDirShared = outputDirectoryShared;
131130
_syntax.outFile = outputFile;
132-
_syntax.userDefines =
133-
userDefines == null ? null : syntax.JsonObject.fromJson(userDefines);
131+
_syntax.userDefines = userDefines == null
132+
? null
133+
: syntax.JsonObject.fromJson(userDefines);
134134
}
135135

136136
/// Constructs a checksum for a [BuildInput].
@@ -237,16 +237,15 @@ final class BuildInputBuilder extends HookInputBuilder {
237237
dependencyMetadata: {
238238
for (final key in metadata.keys) key: metadata[key]!.toJson(),
239239
},
240-
assets:
241-
assets == null
242-
? null
243-
: {
244-
for (final MapEntry(:key, :value) in assets.entries)
245-
key: [
246-
for (final asset in value)
247-
syntax.Asset.fromJson(asset.toJson()),
248-
],
249-
},
240+
assets: assets == null
241+
? null
242+
: {
243+
for (final MapEntry(:key, :value) in assets.entries)
244+
key: [
245+
for (final asset in value)
246+
syntax.Asset.fromJson(asset.toJson()),
247+
],
248+
},
250249
);
251250
}
252251

@@ -332,13 +331,12 @@ final class LinkInputBuilder extends HookInputBuilder {
332331
extension.setupLinkInput(this);
333332
}
334333

335-
List<EncodedAsset> _parseAssets(List<syntax.Asset>? assets) =>
336-
assets == null
337-
? []
338-
: [
339-
for (final asset in assets)
340-
EncodedAsset.fromJson(asset.json, asset.path),
341-
];
334+
List<EncodedAsset> _parseAssets(List<syntax.Asset>? assets) => assets == null
335+
? []
336+
: [
337+
for (final asset in assets)
338+
EncodedAsset.fromJson(asset.json, asset.path),
339+
];
342340

343341
sealed class HookOutput {
344342
/// The underlying json configuration of this [HookOutput].

pkgs/native_assets_cli/lib/src/data_assets/config.dart

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,9 @@ extension AddDataAssetsDirectory on BuildOutputBuilder {
8181
/// Extension to the [HookConfig] providing access to configuration specific
8282
/// to data assets.
8383
extension DataAssetHookConfig on HookConfig {
84-
bool get buildDataAssets =>
85-
buildAssetTypes
86-
.where((e) => DataAssetType.typesForBuildAssetTypes.contains(e))
87-
.isNotEmpty;
84+
bool get buildDataAssets => buildAssetTypes
85+
.where((e) => DataAssetType.typesForBuildAssetTypes.contains(e))
86+
.isNotEmpty;
8887
}
8988

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

150149
/// Provides access to [DataAsset]s from a build hook output.
151150
extension DataAssetBuildOutput on BuildOutputAssets {
152-
List<DataAsset> get data =>
153-
encodedAssets
154-
.where((asset) => asset.isDataAsset)
155-
.map<DataAsset>(DataAsset.fromEncoded)
156-
.toList();
151+
List<DataAsset> get data => encodedAssets
152+
.where((asset) => asset.isDataAsset)
153+
.map<DataAsset>(DataAsset.fromEncoded)
154+
.toList();
157155
}
158156

159157
/// Provides access to [DataAsset]s from a link hook output.
160158
extension DataAssetLinkOutput on LinkOutputAssets {
161-
List<DataAsset> get data =>
162-
encodedAssets
163-
.where((asset) => asset.isDataAsset)
164-
.map<DataAsset>(DataAsset.fromEncoded)
165-
.toList();
159+
List<DataAsset> get data => encodedAssets
160+
.where((asset) => asset.isDataAsset)
161+
.map<DataAsset>(DataAsset.fromEncoded)
162+
.toList();
166163
}

pkgs/native_assets_cli/lib/src/encoded_asset.dart

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,14 @@ final class EncodedAsset {
3636
]) {
3737
final syntax_ = syntax.Asset.fromJson(json, path: path ?? []);
3838
final encodingSyntax = syntax_.encoding;
39-
final encoding =
40-
encodingSyntax != null
41-
// If 'encoding' is provided, copy that.
42-
? Map.of(encodingSyntax.json)
43-
// Otherwise, fall back to copying the keys except for 'type'.
44-
: {
45-
for (final key in json.keys)
46-
if (key != _typeKey) key: json[key],
47-
};
39+
final encoding = encodingSyntax != null
40+
// If 'encoding' is provided, copy that.
41+
? Map.of(encodingSyntax.json)
42+
// Otherwise, fall back to copying the keys except for 'type'.
43+
: {
44+
for (final key in json.keys)
45+
if (key != _typeKey) key: json[key],
46+
};
4847
final path_ = encodingSyntax != null ? [...?path, 'encoding'] : path;
4948

5049
return EncodedAsset._(

pkgs/native_assets_cli/lib/src/model/resource_identifiers.dart

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@ class ResourceIdentifiers {
2020
factory ResourceIdentifiers.fromFileContents(String fileContents) {
2121
final fileJson = (jsonDecode(fileContents) as Map)['identifiers'] as List;
2222
return ResourceIdentifiers(
23-
identifiers:
24-
fileJson
25-
.map((e) => e as Map<String, Object?>)
26-
.map(Identifier.fromJson)
27-
.toList(),
23+
identifiers: fileJson
24+
.map((e) => e as Map<String, Object?>)
25+
.map(Identifier.fromJson)
26+
.toList(),
2827
);
2928
}
3029

pkgs/native_assets_cli/lib/src/target.dart

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -114,30 +114,29 @@ final class Target implements Comparable<Target> {
114114

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

117-
OS get os =>
118-
{
119-
Abi.androidArm: OS.android,
120-
Abi.androidArm64: OS.android,
121-
Abi.androidIA32: OS.android,
122-
Abi.androidX64: OS.android,
123-
Abi.androidRiscv64: OS.android,
124-
Abi.fuchsiaArm64: OS.fuchsia,
125-
Abi.fuchsiaX64: OS.fuchsia,
126-
Abi.iosArm: OS.iOS,
127-
Abi.iosArm64: OS.iOS,
128-
Abi.iosX64: OS.iOS,
129-
Abi.linuxArm: OS.linux,
130-
Abi.linuxArm64: OS.linux,
131-
Abi.linuxIA32: OS.linux,
132-
Abi.linuxRiscv32: OS.linux,
133-
Abi.linuxRiscv64: OS.linux,
134-
Abi.linuxX64: OS.linux,
135-
Abi.macosArm64: OS.macOS,
136-
Abi.macosX64: OS.macOS,
137-
Abi.windowsArm64: OS.windows,
138-
Abi.windowsIA32: OS.windows,
139-
Abi.windowsX64: OS.windows,
140-
}[abi]!;
117+
OS get os => {
118+
Abi.androidArm: OS.android,
119+
Abi.androidArm64: OS.android,
120+
Abi.androidIA32: OS.android,
121+
Abi.androidX64: OS.android,
122+
Abi.androidRiscv64: OS.android,
123+
Abi.fuchsiaArm64: OS.fuchsia,
124+
Abi.fuchsiaX64: OS.fuchsia,
125+
Abi.iosArm: OS.iOS,
126+
Abi.iosArm64: OS.iOS,
127+
Abi.iosX64: OS.iOS,
128+
Abi.linuxArm: OS.linux,
129+
Abi.linuxArm64: OS.linux,
130+
Abi.linuxIA32: OS.linux,
131+
Abi.linuxRiscv32: OS.linux,
132+
Abi.linuxRiscv64: OS.linux,
133+
Abi.linuxX64: OS.linux,
134+
Abi.macosArm64: OS.macOS,
135+
Abi.macosX64: OS.macOS,
136+
Abi.windowsArm64: OS.windows,
137+
Abi.windowsIA32: OS.windows,
138+
Abi.windowsX64: OS.windows,
139+
}[abi]!;
141140

142141
@override
143142
String toString() => dartVMToString();
@@ -154,16 +153,15 @@ final class Target implements Comparable<Target> {
154153
/// A list of supported target [Target]s from this host [os].
155154
List<Target> supportedTargetTargets({
156155
Map<OS, List<OS>> osCrossCompilation = OS.osCrossCompilationDefault,
157-
}) =>
158-
Target.values
159-
.where(
160-
(target) =>
161-
// Only valid cross compilation.
162-
osCrossCompilation[os]!.contains(target.os) &&
163-
// And no deprecated architectures.
164-
target != Target.iOSArm,
165-
)
166-
.sorted;
156+
}) => Target.values
157+
.where(
158+
(target) =>
159+
// Only valid cross compilation.
160+
osCrossCompilation[os]!.contains(target.os) &&
161+
// And no deprecated architectures.
162+
target != Target.iOSArm,
163+
)
164+
.sorted;
167165
}
168166

169167
/// Common methods for manipulating iterables of [Target]s.

pkgs/native_assets_cli/lib/test.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ Future<void> testBuildHook({
3636

3737
try {
3838
// Deal with Windows temp folder aliases.
39-
final tempUri =
40-
Directory(await tempDir.resolveSymbolicLinks()).uri.normalizePath();
39+
final tempUri = Directory(
40+
await tempDir.resolveSymbolicLinks(),
41+
).uri.normalizePath();
4142
final outputDirectory = tempUri.resolve('output/');
4243
final outputDirectoryShared = tempUri.resolve('output_shared/');
4344
final outputFile = tempUri.resolve('output.json');

0 commit comments

Comments
 (0)