[libcxx-commits] [PATCH] D88884: [libc++][dsl] Run checks for locale names aliases using a single %exec

Alexander Richardson via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Oct 6 03:11:15 PDT 2020


arichardson created this revision.
arichardson added reviewers: libc++, ldionne.
Herald added subscribers: libcxx-commits, dexonsmith.
Herald added a project: libc++.
Herald added 1 blocking reviewer(s): libc++.
arichardson requested review of this revision.

This changes the checking for available locales to use one program that
iterates over argv to test multiple locale names instead of checking each
name with a separate executable.

This massively speeds up running individual tests using an SSH executor
(it can take up to 10 seconds to compile and run a single test in some
emulated environments) in case no locales are installed since then all
fallback names are tested idividually. But even on a native machine
this reduces the libc++ lit startup time by ~1-2 second for me on a machine
that does not have locale data installed.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D88884

Files:
  libcxx/utils/libcxx/test/dsl.py
  libcxx/utils/libcxx/test/features.py


Index: libcxx/utils/libcxx/test/features.py
===================================================================
--- libcxx/utils/libcxx/test/features.py
+++ libcxx/utils/libcxx/test/features.py
@@ -107,7 +107,7 @@
   # Note: Using alts directly in the lambda body here will bind it to the value at the
   # end of the loop. Assigning it to a default argument works around this issue.
   DEFAULT_FEATURES.append(Feature(name='locale.{}'.format(locale),
-                                  when=lambda cfg, alts=alts: any(hasLocale(cfg, alt) for alt in alts)))
+                                  when=lambda cfg, name=locale, alts=alts: hasLocale(cfg, name, alts)))
 
 
 # Add features representing the platform name: darwin, linux, windows, etc...
Index: libcxx/utils/libcxx/test/dsl.py
===================================================================
--- libcxx/utils/libcxx/test/dsl.py
+++ libcxx/utils/libcxx/test/dsl.py
@@ -135,9 +135,12 @@
     ])
     return exitCode == 0
 
-def hasLocale(config, locale):
+def hasLocale(config, locale, names):
   """
   Return whether the runtime execution environment supports a given locale.
+  Different systems may use different names for a locale, so this function checks
+  whether any of the passed locale names is supported by setlocale() and returns
+  true if one of them works.
 
   This is done by executing a program that tries to set the given locale using
   %{exec} -- this means that the command may be executed on a remote host
@@ -145,12 +148,20 @@
   """
   program = """
     #include <locale.h>
-    int main(int, char** argv) {
-      if (::setlocale(LC_ALL, argv[1]) != NULL) return 0;
-      else                                      return 1;
+    #include <stdio.h>
+    int main(int argc, char** argv) {
+      // For debugging purposes print which locales are (not) supported.
+      for (int i = 1; i < argc; i++) {
+        if (::setlocale(LC_ALL, argv[i]) != NULL) {
+          printf("%s is supported.\\n", argv[i]);
+          return 0;
+        }
+        printf("%s is not supported.\\n", argv[i]);
+      }
+      return 1;
     }
   """
-  return programOutput(config, program, args=[pipes.quote(locale)],
+  return programOutput(config, program, args=[pipes.quote(l) for l in names],
                        testPrefix="check_locale_" + locale) is not None
 
 def compilerMacros(config, flags=''):


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88884.296401.patch
Type: text/x-patch
Size: 2380 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20201006/34b7db67/attachment.bin>


More information about the libcxx-commits mailing list