@@ -53,35 +53,31 @@ class CodeConfig {
53
53
54
54
CodeConfig (HookConfig config)
55
55
: linkModePreference = LinkModePreference .fromString (
56
- config.json.string (linkModePreferenceKey )),
56
+ config.json.string (_linkModePreferenceKey )),
57
57
// ignore: deprecated_member_use_from_same_package
58
58
_targetArchitecture = (config is BuildConfig && config.dryRun)
59
59
? null
60
- : Architecture .fromString (config.json.string (targetArchitectureKey ,
60
+ : Architecture .fromString (config.json.string (_targetArchitectureKey ,
61
61
validValues: Architecture .values.map ((a) => a.name))),
62
- targetOS = OS .fromString (config.json.string (targetOSConfigKey )),
63
- cCompiler = switch (config.json.optionalMap (compilerKey )) {
62
+ targetOS = OS .fromString (config.json.string (_targetOSConfigKey )),
63
+ cCompiler = switch (config.json.optionalMap (_compilerKey )) {
64
64
final Map <String , Object ?> map => CCompilerConfig .fromJson (map),
65
65
null => null ,
66
66
} {
67
67
// ignore: deprecated_member_use_from_same_package
68
- _iOSConfig = (config is BuildConfig && config.dryRun)
68
+ _iOSConfig = (config is BuildConfig && config.dryRun) || targetOS != OS .iOS
69
69
? null
70
- : targetOS == OS .iOS
71
- ? IOSConfig .fromHookConfig (config)
72
- : null ;
73
- // ignore: deprecated_member_use_from_same_package
74
- _androidConfig = (config is BuildConfig && config.dryRun)
75
- ? null
76
- : targetOS == OS .android
77
- ? AndroidConfig .fromHookConfig (config)
78
- : null ;
79
- // ignore: deprecated_member_use_from_same_package
80
- _macOSConfig = (config is BuildConfig && config.dryRun)
81
- ? null
82
- : targetOS == OS .macOS
83
- ? MacOSConfig .fromHookConfig (config)
84
- : null ;
70
+ : IOSConfig .fromHookConfig (config);
71
+ _androidConfig =
72
+ // ignore: deprecated_member_use_from_same_package
73
+ (config is BuildConfig && config.dryRun) || targetOS != OS .android
74
+ ? null
75
+ : AndroidConfig .fromHookConfig (config);
76
+ _macOSConfig =
77
+ // ignore: deprecated_member_use_from_same_package
78
+ (config is BuildConfig && config.dryRun) || targetOS != OS .macOS
79
+ ? null
80
+ : MacOSConfig .fromHookConfig (config);
85
81
}
86
82
87
83
Architecture get targetArchitecture {
@@ -121,46 +117,71 @@ class CodeConfig {
121
117
/// Configuration provided when [CodeConfig.targetOS] is [OS.iOS] .
122
118
class IOSConfig {
123
119
/// Whether to target device or simulator.
124
- final IOSSdk targetSdk;
120
+ IOSSdk get targetSdk => _targetSdk! ;
121
+
122
+ final IOSSdk ? _targetSdk;
125
123
126
124
/// The lowest iOS version that the compiled code will be compatible with.
127
- final int targetVersion;
125
+ int get targetVersion => _targetVersion! ;
126
+
127
+ final int ? _targetVersion;
128
128
129
129
IOSConfig ({
130
- required this .targetSdk,
131
- required this .targetVersion,
132
- });
130
+ required IOSSdk targetSdk,
131
+ required int targetVersion,
132
+ }) : _targetSdk = targetSdk,
133
+ _targetVersion = targetVersion;
133
134
134
135
IOSConfig .fromHookConfig (HookConfig config)
135
- : targetVersion = config.json.int (targetIOSVersionKey),
136
- targetSdk = IOSSdk .fromString (config.json.string (targetIOSSdkKey));
136
+ : _targetVersion = config.json.optionalInt (_targetIOSVersionKey),
137
+ _targetSdk = switch (config.json.optionalString (_targetIOSSdkKey)) {
138
+ null => null ,
139
+ String e => IOSSdk .fromString (e)
140
+ };
141
+ }
142
+
143
+ extension IOSConfigSyntactic on IOSConfig {
144
+ IOSSdk ? get targetSdkSyntactic => _targetSdk;
145
+ int ? get targetVersionSyntactic => _targetVersion;
137
146
}
138
147
139
148
/// Configuration provided when [CodeConfig.targetOS] is [OS.macOS] .
140
149
class AndroidConfig {
141
150
/// The minimum Android SDK API version to that the compiled code will be
142
151
/// compatible with.
143
- final int targetNdkApi;
152
+ int get targetNdkApi => _targetNdkApi! ;
153
+
154
+ final int ? _targetNdkApi;
144
155
145
156
AndroidConfig ({
146
- required this . targetNdkApi,
147
- });
157
+ required int targetNdkApi,
158
+ }) : _targetNdkApi = targetNdkApi ;
148
159
149
160
AndroidConfig .fromHookConfig (HookConfig config)
150
- : targetNdkApi = config.json.int (targetAndroidNdkApiKey);
161
+ : _targetNdkApi = config.json.optionalInt (_targetAndroidNdkApiKey);
162
+ }
163
+
164
+ extension AndroidConfigSyntactic on AndroidConfig {
165
+ int ? get targetNdkApiSyntactic => _targetNdkApi;
151
166
}
152
167
153
168
//// Configuration provided when [CodeConfig.targetOS] is [OS.macOS] .
154
169
class MacOSConfig {
155
170
/// The lowest MacOS version that the compiled code will be compatible with.
156
- final int targetVersion;
171
+ int get targetVersion => _targetVersion! ;
172
+
173
+ final int ? _targetVersion;
157
174
158
175
MacOSConfig ({
159
- required this . targetVersion,
160
- });
176
+ required int targetVersion,
177
+ }) : _targetVersion = targetVersion ;
161
178
162
179
MacOSConfig .fromHookConfig (HookConfig config)
163
- : targetVersion = config.json.int (targetMacOSVersionKey);
180
+ : _targetVersion = config.json.optionalInt (_targetMacOSVersionKey);
181
+ }
182
+
183
+ extension MacOSConfigSyntactic on MacOSConfig {
184
+ int ? get targetVersionSyntactic => _targetVersion;
164
185
}
165
186
166
187
/// Extension to the [BuildOutputBuilder] providing access to emitting code
@@ -216,32 +237,23 @@ extension CodeAssetBuildConfigBuilder on HookConfigBuilder {
216
237
MacOSConfig ? macOSConfig,
217
238
}) {
218
239
if (targetArchitecture != null ) {
219
- json[targetArchitectureKey ] = targetArchitecture.toString ();
240
+ json[_targetArchitectureKey ] = targetArchitecture.toString ();
220
241
}
221
- json[targetOSConfigKey ] = targetOS.toString ();
222
- json[linkModePreferenceKey ] = linkModePreference.toString ();
242
+ json[_targetOSConfigKey ] = targetOS.toString ();
243
+ json[_linkModePreferenceKey ] = linkModePreference.toString ();
223
244
if (cCompilerConfig != null ) {
224
- json[compilerKey ] = cCompilerConfig.toJson ();
245
+ json[_compilerKey ] = cCompilerConfig.toJson ();
225
246
}
226
247
227
- // Note, using ?. instead of !. enables using this in tests to write wrong
228
- // invalid configs. Is this a good idea? The setup methods only create the
229
- // JSON now, but don't enable creating all forms of wrong JSON. For example
230
- // `IOSConfig` either has both fields or none.
231
- // Maybe the builders should be more construct by construction, and the
232
- // validator tests should be on the JSON. This requires duplicating JSON
233
- // serialization logic in the tests though.
234
- // This PR already duplicates deserialization logic in the validator and
235
- // `Config`s. The configs classes need to provide non-nullable accessors, so
236
- // they cannot be used inside the validators to check for invalid null
237
- // values.
248
+ // Note, using ?. instead of !. makes missing data be a semantic error
249
+ // rather than a syntactic error to be caught in the validation.
238
250
if (targetOS == OS .android) {
239
- json[targetAndroidNdkApiKey ] = androidConfig? .targetNdkApi;
251
+ json[_targetAndroidNdkApiKey ] = androidConfig? .targetNdkApi;
240
252
} else if (targetOS == OS .iOS) {
241
- json[targetIOSSdkKey ] = iOSConfig? .targetSdk.toString ();
242
- json[targetIOSVersionKey ] = iOSConfig? .targetVersion;
253
+ json[_targetIOSSdkKey ] = iOSConfig? .targetSdk.toString ();
254
+ json[_targetIOSVersionKey ] = iOSConfig? .targetVersion;
243
255
} else if (targetOS == OS .macOS) {
244
- json[targetMacOSVersionKey ] = macOSConfig? .targetVersion;
256
+ json[_targetMacOSVersionKey ] = macOSConfig? .targetVersion;
245
257
}
246
258
}
247
259
}
@@ -264,11 +276,11 @@ extension CodeAssetLinkOutput on LinkOutput {
264
276
.toList ();
265
277
}
266
278
267
- const String compilerKey = 'c_compiler' ;
268
- const String linkModePreferenceKey = 'link_mode_preference' ;
269
- const String targetAndroidNdkApiKey = 'target_android_ndk_api' ;
270
- const String targetArchitectureKey = 'target_architecture' ;
271
- const String targetIOSSdkKey = 'target_ios_sdk' ;
272
- const String targetIOSVersionKey = 'target_ios_version' ;
273
- const String targetMacOSVersionKey = 'target_macos_version' ;
274
- const String targetOSConfigKey = 'target_os' ;
279
+ const String _compilerKey = 'c_compiler' ;
280
+ const String _linkModePreferenceKey = 'link_mode_preference' ;
281
+ const String _targetAndroidNdkApiKey = 'target_android_ndk_api' ;
282
+ const String _targetArchitectureKey = 'target_architecture' ;
283
+ const String _targetIOSSdkKey = 'target_ios_sdk' ;
284
+ const String _targetIOSVersionKey = 'target_ios_version' ;
285
+ const String _targetMacOSVersionKey = 'target_macos_version' ;
286
+ const String _targetOSConfigKey = 'target_os' ;
0 commit comments