21
21
#include < string.h>
22
22
#include < inttypes.h>
23
23
24
+ #if defined(__ANDROID__)
25
+ #include < sys/system_properties.h>
26
+ #endif
27
+
24
28
using namespace swift ;
25
29
26
30
namespace {
@@ -187,9 +191,32 @@ extern "C" char **_environ;
187
191
#endif
188
192
#endif
189
193
194
+ #if defined(__ANDROID__)
195
+ // On Android, also try loading runtime debug env variables from system props.
196
+ static void platformInitialize (void *context) {
197
+ (void )context;
198
+ #define SYSPROP_PREFIX " debug.swift.runtime."
199
+ #define VARIABLE (name, type, defaultValue, help ) \
200
+ do { \
201
+ char name##_string[PROP_VALUE_MAX] = " " ; \
202
+ if (__system_property_get (SYSPROP_PREFIX #name, name##_string) > 0 ) { \
203
+ swift::runtime::environment::name##_isSet_variable = true ; \
204
+ swift::runtime::environment::name##_variable = \
205
+ parse_##type (#name, name##_string, defaultValue); \
206
+ } \
207
+ } while (0 );
208
+ #include " EnvironmentVariables.def"
209
+ #undef VARIABLE
210
+ }
211
+ #else
212
+ static void platformInitialize (void *context) {
213
+ (void )context;
214
+ }
215
+ #endif
216
+
190
217
#if !SWIFT_STDLIB_HAS_ENVIRON
191
218
void swift::runtime::environment::initialize (void *context) {
192
- ( void ) context;
219
+ platformInitialize ( context) ;
193
220
}
194
221
#elif defined(ENVIRON)
195
222
void swift::runtime::environment::initialize (void *context) {
@@ -242,6 +269,8 @@ void swift::runtime::environment::initialize(void *context) {
242
269
}
243
270
}
244
271
272
+ platformInitialize (context);
273
+
245
274
if (SWIFT_DEBUG_HELP_variable)
246
275
printHelp (nullptr );
247
276
}
@@ -258,6 +287,8 @@ void swift::runtime::environment::initialize(void *context) {
258
287
} while (0 );
259
288
#include " EnvironmentVariables.def"
260
289
290
+ platformInitialize (context);
291
+
261
292
// Print help if requested.
262
293
if (parse_bool (" SWIFT_DEBUG_HELP" , getenv (" SWIFT_DEBUG_HELP" ), false ))
263
294
printHelp (" Using getenv to read variables. Unknown SWIFT_DEBUG_ variables "
0 commit comments