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 --- /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 --- /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 --- a/libcxx/utils/libcxx/test/format.py +++ b/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):