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

Louis Dionne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Wed Aug 24 10:30:16 PDT 2022


ldionne created this revision.
ldionne added a reviewer: Mordante.
Herald added a subscriber: arichardson.
Herald added a project: All.
ldionne requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D132575

Files:
  libcxx/test/libcxx/selftest/additional_compile_flags/conditional-compile-flags.sh.cpp
  libcxx/test/libcxx/selftest/additional_compile_flags/lit.local.cfg
  libcxx/utils/libcxx/test/format.py


Index: libcxx/utils/libcxx/test/format.py
===================================================================
--- libcxx/utils/libcxx/test/format.py
+++ libcxx/utils/libcxx/test/format.py
@@ -67,6 +67,15 @@
                                                    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):
Index: libcxx/test/libcxx/selftest/additional_compile_flags/lit.local.cfg
===================================================================
--- /dev/null
+++ 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')
Index: libcxx/test/libcxx/selftest/additional_compile_flags/conditional-compile-flags.sh.cpp
===================================================================
--- /dev/null
+++ 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 --invert-match -e '-this-flag-should-not-be-added'


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132575.455280.patch
Type: text/x-patch
Size: 2609 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20220824/f12eccee/attachment.bin>


More information about the libcxx-commits mailing list