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,31 @@ 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
+ char buffer[PROP_VALUE_MAX] = " " ;
199
+ // Only system properties prefixed with "debug." can be set without root access.
200
+ #define SYSPROP_PREFIX " debug.org.swift.runtime."
201
+ #define VARIABLE (name, type, defaultValue, help ) \
202
+ if (__system_property_get (SYSPROP_PREFIX #name, buffer)) { \
203
+ swift::runtime::environment::name##_isSet_variable = true ; \
204
+ swift::runtime::environment::name##_variable = \
205
+ parse_##type (#name, buffer, defaultValue); \
206
+ }
207
+ #include " EnvironmentVariables.def"
208
+ #undef VARIABLE
209
+ }
210
+ #else
211
+ static void platformInitialize (void *context) {
212
+ (void )context;
213
+ }
214
+ #endif
215
+
190
216
#if !SWIFT_STDLIB_HAS_ENVIRON
191
217
void swift::runtime::environment::initialize (void *context) {
192
- ( void ) context;
218
+ platformInitialize ( context) ;
193
219
}
194
220
#elif defined(ENVIRON)
195
221
void swift::runtime::environment::initialize (void *context) {
@@ -242,6 +268,8 @@ void swift::runtime::environment::initialize(void *context) {
242
268
}
243
269
}
244
270
271
+ platformInitialize (context);
272
+
245
273
if (SWIFT_DEBUG_HELP_variable)
246
274
printHelp (nullptr );
247
275
}
@@ -258,6 +286,8 @@ void swift::runtime::environment::initialize(void *context) {
258
286
} while (0 );
259
287
#include " EnvironmentVariables.def"
260
288
289
+ platformInitialize (context);
290
+
261
291
// Print help if requested.
262
292
if (parse_bool (" SWIFT_DEBUG_HELP" , getenv (" SWIFT_DEBUG_HELP" ), false ))
263
293
printHelp (" Using getenv to read variables. Unknown SWIFT_DEBUG_ variables "
0 commit comments