Skip to content

Commit 0192aa4

Browse files
committed
[android] also load debug env vars from system properties
1 parent 283ce7f commit 0192aa4

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

stdlib/public/runtime/EnvironmentVariables.cpp

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
#include <string.h>
2222
#include <inttypes.h>
2323

24+
#if defined(__ANDROID__)
25+
#include <sys/system_properties.h>
26+
#endif
27+
2428
using namespace swift;
2529

2630
namespace {
@@ -187,9 +191,32 @@ extern "C" char **_environ;
187191
#endif
188192
#endif
189193

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+
190217
#if !SWIFT_STDLIB_HAS_ENVIRON
191218
void swift::runtime::environment::initialize(void *context) {
192-
(void)context;
219+
platformInitialize(context);
193220
}
194221
#elif defined(ENVIRON)
195222
void swift::runtime::environment::initialize(void *context) {
@@ -242,6 +269,8 @@ void swift::runtime::environment::initialize(void *context) {
242269
}
243270
}
244271

272+
platformInitialize(context);
273+
245274
if (SWIFT_DEBUG_HELP_variable)
246275
printHelp(nullptr);
247276
}
@@ -258,6 +287,8 @@ void swift::runtime::environment::initialize(void *context) {
258287
} while (0);
259288
#include "EnvironmentVariables.def"
260289

290+
platformInitialize(context);
291+
261292
// Print help if requested.
262293
if (parse_bool("SWIFT_DEBUG_HELP", getenv("SWIFT_DEBUG_HELP"), false))
263294
printHelp("Using getenv to read variables. Unknown SWIFT_DEBUG_ variables "

0 commit comments

Comments
 (0)