@@ -15,15 +15,15 @@ import 'os.dart';
15
15
/// code assets (only available if code assets are supported).
16
16
extension CodeAssetBuildConfig on BuildConfig {
17
17
/// Code asset specific configuration.
18
- CodeConfig get codeConfig => CodeConfig ( this );
18
+ CodeConfig get codeConfig => CodeConfig . fromJson (json );
19
19
}
20
20
21
21
/// Extension to the [LinkConfig] providing access to configuration specific to
22
22
/// code assets as well as code asset inputs to the linker (only available if
23
23
/// code assets are supported).
24
24
extension CodeAssetLinkConfig on LinkConfig {
25
25
/// Code asset specific configuration.
26
- CodeConfig get codeConfig => CodeConfig ( this );
26
+ CodeConfig get codeConfig => CodeConfig . fromJson (json );
27
27
28
28
// Returns the code assets that were sent to this linker.
29
29
//
@@ -47,37 +47,56 @@ class CodeConfig {
47
47
/// The operating system being compiled for.
48
48
final OS targetOS;
49
49
50
- late final IOSConfig ? _iOSConfig;
51
- late final AndroidConfig ? _androidConfig;
52
- late final MacOSConfig ? _macOSConfig;
53
-
54
- CodeConfig (HookConfig config)
55
- : linkModePreference = LinkModePreference .fromString (
56
- config.json.string (_linkModePreferenceKey)),
57
- // ignore: deprecated_member_use_from_same_package
58
- _targetArchitecture = (config is BuildConfig && config.dryRun)
59
- ? null
60
- : Architecture .fromString (config.json.string (_targetArchitectureKey,
61
- validValues: Architecture .values.map ((a) => a.name))),
62
- targetOS = OS .fromString (config.json.string (_targetOSConfigKey)),
63
- cCompiler = switch (config.json.optionalMap (_compilerKey)) {
64
- final Map <String , Object ?> map => CCompilerConfig .fromJson (map),
65
- null => null ,
66
- } {
67
- // ignore: deprecated_member_use_from_same_package
68
- _iOSConfig = (config is BuildConfig && config.dryRun) || targetOS != OS .iOS
50
+ final IOSConfig ? _iOSConfig;
51
+ final AndroidConfig ? _androidConfig;
52
+ final MacOSConfig ? _macOSConfig;
53
+
54
+ // Should not be made public, class will be replaced as a view on `json`.
55
+ CodeConfig ._({
56
+ required Architecture ? targetArchitecture,
57
+ required this .targetOS,
58
+ required this .linkModePreference,
59
+ CCompilerConfig ? cCompilerConfig,
60
+ AndroidConfig ? androidConfig,
61
+ IOSConfig ? iOSConfig,
62
+ MacOSConfig ? macOSConfig,
63
+ }) : _targetArchitecture = targetArchitecture,
64
+ cCompiler = cCompilerConfig,
65
+ _iOSConfig = iOSConfig,
66
+ _androidConfig = androidConfig,
67
+ _macOSConfig = macOSConfig;
68
+
69
+ factory CodeConfig .fromJson (Map <String , Object ?> json) {
70
+ final dryRun = json.getOptional <bool >(_dryRunConfigKey) ?? false ;
71
+
72
+ final linkModePreference =
73
+ LinkModePreference .fromString (json.string (_linkModePreferenceKey));
74
+ final targetArchitecture = dryRun
69
75
? 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);
76
+ : Architecture .fromString (json.string (_targetArchitectureKey,
77
+ validValues: Architecture .values.map ((a) => a.name)));
78
+ final targetOS = OS .fromString (json.string (_targetOSConfigKey));
79
+ final cCompiler = switch (json.optionalMap (_compilerKey)) {
80
+ final Map <String , Object ?> map => CCompilerConfig .fromJson (map),
81
+ null => null
82
+ };
83
+
84
+ final iOSConfig =
85
+ dryRun || targetOS != OS .iOS ? null : IOSConfig .fromJson (json);
86
+ final androidConfig =
87
+ dryRun || targetOS != OS .android ? null : AndroidConfig .fromJson (json);
88
+ final macOSConfig =
89
+ dryRun || targetOS != OS .macOS ? null : MacOSConfig .fromJson (json);
90
+
91
+ return CodeConfig ._(
92
+ targetArchitecture: targetArchitecture,
93
+ targetOS: targetOS,
94
+ linkModePreference: linkModePreference,
95
+ cCompilerConfig: cCompiler,
96
+ iOSConfig: iOSConfig,
97
+ androidConfig: androidConfig,
98
+ macOSConfig: macOSConfig,
99
+ );
81
100
}
82
101
83
102
Architecture get targetArchitecture {
@@ -132,9 +151,9 @@ class IOSConfig {
132
151
}) : _targetSdk = targetSdk,
133
152
_targetVersion = targetVersion;
134
153
135
- IOSConfig .fromHookConfig ( HookConfig config )
136
- : _targetVersion = config. json.optionalInt (_targetIOSVersionKey),
137
- _targetSdk = switch (config. json.optionalString (_targetIOSSdkKey)) {
154
+ IOSConfig .fromJson ( Map < String , Object ?> json )
155
+ : _targetVersion = json.optionalInt (_targetIOSVersionKey),
156
+ _targetSdk = switch (json.optionalString (_targetIOSSdkKey)) {
138
157
null => null ,
139
158
String e => IOSSdk .fromString (e)
140
159
};
@@ -157,8 +176,8 @@ class AndroidConfig {
157
176
required int targetNdkApi,
158
177
}) : _targetNdkApi = targetNdkApi;
159
178
160
- AndroidConfig .fromHookConfig ( HookConfig config )
161
- : _targetNdkApi = config. json.optionalInt (_targetAndroidNdkApiKey);
179
+ AndroidConfig .fromJson ( Map < String , Object ?> json )
180
+ : _targetNdkApi = json.optionalInt (_targetAndroidNdkApiKey);
162
181
}
163
182
164
183
extension AndroidConfigSyntactic on AndroidConfig {
@@ -176,8 +195,8 @@ class MacOSConfig {
176
195
required int targetVersion,
177
196
}) : _targetVersion = targetVersion;
178
197
179
- MacOSConfig .fromHookConfig ( HookConfig config )
180
- : _targetVersion = config. json.optionalInt (_targetMacOSVersionKey);
198
+ MacOSConfig .fromJson ( Map < String , Object ?> json )
199
+ : _targetVersion = json.optionalInt (_targetMacOSVersionKey);
181
200
}
182
201
183
202
extension MacOSConfigSyntactic on MacOSConfig {
@@ -284,3 +303,5 @@ const String _targetIOSSdkKey = 'target_ios_sdk';
284
303
const String _targetIOSVersionKey = 'target_ios_version' ;
285
304
const String _targetMacOSVersionKey = 'target_macos_version' ;
286
305
const String _targetOSConfigKey = 'target_os' ;
306
+
307
+ const _dryRunConfigKey = 'dry_run' ;
0 commit comments