[libcxx-commits] [libcxx] f2d957f - [libc++] Allow specifying conditional compile flags dependent on basic Lit features

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Thu Aug 25 14:33:54 PDT 2022


Author: Louis Dionne
Date: 2022-08-25T17:33:44-04:00
New Revision: f2d957f03634c4e90c9847b92f197dff6e5aa315

URL: https://github.com/llvm/llvm-project/commit/f2d957f03634c4e90c9847b92f197dff6e5aa315
DIFF: https://github.com/llvm/llvm-project/commit/f2d957f03634c4e90c9847b92f197dff6e5aa315.diff

LOG: [libc++] Allow specifying conditional compile flags dependent on basic Lit features

This patch adds support for passing basic Lit features to the
ADDITIONAL_COMPILE_FLAGS keyword by enclosing them in parentheses.
This is done to support https://llvm.org/D131836.

In the future, we should instead add proper support for conditional
keywords in Lit, so that we can evaluate arbitrary Lit boolean
expressions such as `ADDITIONAL_COMPILE_FLAGS(x && !y): -flag`.

Note that I can see this being exceptionally useful when combined
with RUN commands, which would allow using different commands on
different systems. For example:

     RUN(!buildhost=windows): something
     RUN(buildhost=windows): something-else

Differential Revision: https://reviews.llvm.org/D132575

Added: 
    libcxx/test/libcxx/selftest/additional_compile_flags/conditional-compile-flags.sh.cpp
    libcxx/test/libcxx/selftest/additional_compile_flags/lit.local.cfg

Modified: 
    libcxx/utils/libcxx/test/format.py

Removed: 
    


################################################################################
diff  --git a/libcxx/test/libcxx/selftest/additional_compile_flags/conditional-compile-flags.sh.cpp b/libcxx/test/libcxx/selftest/additional_compile_flags/conditional-compile-flags.sh.cpp
new file mode 100644
index 0000000000000..2c63cb2b12892
--- /dev/null
+++ b/libcxx/test/libcxx/selftest/additional_compile_flags/conditional-compile-flags.sh.cpp
@@ -0,0 +1,14 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// This test ensures that we can add compile flags that are conditional on Lit features.
+
+// ADDITIONAL_COMPILE_FLAGS(some-defined-feature): -this-flag-should-be-added
+// ADDITIONAL_COMPILE_FLAGS(some-undefined-feature): -this-flag-should-not-be-added
+// RUN: echo "%{compile_flags}" | grep -e '-this-flag-should-be-added'
+// RUN: echo "%{compile_flags}" | grep -v -e '-this-flag-should-not-be-added'

diff  --git a/libcxx/test/libcxx/selftest/additional_compile_flags/lit.local.cfg b/libcxx/test/libcxx/selftest/additional_compile_flags/lit.local.cfg
new file mode 100644
index 0000000000000..44618debaa4ed
--- /dev/null
+++ b/libcxx/test/libcxx/selftest/additional_compile_flags/lit.local.cfg
@@ -0,0 +1,2 @@
+# Add a Lit feature so we can test conditional addition of compile flags.
+config.available_features.add('some-defined-feature')

diff  --git a/libcxx/utils/libcxx/test/format.py b/libcxx/utils/libcxx/test/format.py
index 1892c5fcd3710..6860f8d3cf2fd 100644
--- a/libcxx/utils/libcxx/test/format.py
+++ b/libcxx/utils/libcxx/test/format.py
@@ -67,6 +67,15 @@ def parseScript(test, preamble):
                                                    initial_value=additionalCompileFlags)
     ]
 
+    # Add conditional parsers for ADDITIONAL_COMPILE_FLAGS. This should be replaced by first
+    # class support for conditional keywords in Lit, which would allow evaluating arbitrary
+    # Lit boolean expressions instead.
+    for feature in test.config.available_features:
+        parser = lit.TestRunner.IntegratedTestKeywordParser('ADDITIONAL_COMPILE_FLAGS({}):'.format(feature),
+                                                            lit.TestRunner.ParserKind.LIST,
+                                                            initial_value=additionalCompileFlags)
+        parsers.append(parser)
+
     scriptInTest = lit.TestRunner.parseIntegratedTestScript(test, additional_parsers=parsers,
                                                             require_script=not preamble)
     if isinstance(scriptInTest, lit.Test.Result):


        


More information about the libcxx-commits mailing list