From 2be4014fe6005e310b9e24c88d407c7a14eb625e Mon Sep 17 00:00:00 2001 From: Louis Dionne Date: Wed, 8 Jul 2020 14:04:45 -0400 Subject: [PATCH] [libc++] Reimplement platform detection features without running on the test host It's sufficient to sniff the platform we're running on using the compiler macros -- we don't need to run any code. --- libcxx/utils/libcxx/test/features.py | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/libcxx/utils/libcxx/test/features.py b/libcxx/utils/libcxx/test/features.py index 5229cf6..f3d8e78 100644 --- a/libcxx/utils/libcxx/test/features.py +++ b/libcxx/utils/libcxx/test/features.py @@ -110,22 +110,10 @@ for locale, alts in locales.items(): ] -# Add a feature representing the platform name: darwin, linux, windows, etc... +# Add features representing the platform name: darwin, linux, windows, etc... features += [ - Feature(name=lambda cfg: programOutput(cfg, """ - #include - int main() { - #if defined(__APPLE__) - std::printf("darwin"); - #elif defined(_WIN32) - std::printf("windows"); - #elif defined(__NetBSD__) - std::printf("netbsd"); - #elif defined(__linux__) - std::printf("linux"); - #else - std::printf("unknown-platform"); - #endif - } - """)) + Feature(name='darwin', when=lambda cfg: '__APPLE__' in compilerMacros(cfg)), + Feature(name='windows', when=lambda cfg: '_WIN32' in compilerMacros(cfg)), + Feature(name='linux', when=lambda cfg: '__linux__' in compilerMacros(cfg)), + Feature(name='netbsd', when=lambda cfg: '__NetBSD__' in compilerMacros(cfg)) ] -- 2.7.4