Skip to content

Commit 562159d

Browse files
committed
[test] Transform Swift Features.def into Lit available features
Take the `Features.def` file used in other parts of the code and create a file that can be used from the LLVM Lit configuration files to add new available features that can be checked from the tests with `REQUIRES` and others. The file `lit.swift-features.cfg.inc` is preprocessed by Clang and generates a file with Python syntax that can be loaded from both `lit.site.cfg.in` files. The preprocessing output is copied into the different test directories in the build directory, and added it is added as a dependency of them, so it will be generate when the test run or when `Features.def` changes. `EXPERIMENTAL_FEATURES` are only enabled if they are available in production or the compiler is being built with assertions, while `UPCOMING_FEATURES` and the rest of the `LANGUAGE_FEATURES` are always available.
1 parent 96143db commit 562159d

File tree

4 files changed

+80
-0
lines changed

4 files changed

+80
-0
lines changed

test/CMakeLists.txt

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,16 @@ if(NOT "${COVERAGE_DB}" STREQUAL "")
253253
COMMENT "Touching covering tests")
254254
endif()
255255

256+
if(SWIFT_COMPILER_IS_MSVC_LIKE)
257+
set(C_PREPROCESSOR_COMMAND
258+
"${CMAKE_C_COMPILER}" "/P" "/EP" "/I" "${SWIFT_MAIN_INCLUDE_DIR}" "/TC"
259+
"/Fi<<<OUTPUT_FILE>>>")
260+
else()
261+
set(C_PREPROCESSOR_COMMAND
262+
"${CMAKE_C_COMPILER}" "-E" "-P" "-I${SWIFT_MAIN_INCLUDE_DIR}" "-x" "c" "-o"
263+
"<<<OUTPUT_FILE>>>")
264+
endif()
265+
256266
foreach(SDK ${SWIFT_SDKS})
257267
foreach(ARCH ${SWIFT_SDK_${SDK}_ARCHITECTURES})
258268
# macCatalyst needs to run two sets of tests: one with the normal macosx target triple
@@ -301,6 +311,38 @@ foreach(SDK ${SWIFT_SDKS})
301311
"${validation_test_bin_dir}/lit.site.cfg"
302312
"validation-test${VARIANT_SUFFIX}.lit.site.cfg")
303313

314+
set(test_lit_swift_features_cmd ${C_PREPROCESSOR_COMMAND})
315+
list(
316+
TRANSFORM test_lit_swift_features_cmd
317+
REPLACE "<<<OUTPUT_FILE>>>" "${test_bin_dir}/lit.swift-features.cfg")
318+
add_custom_command(
319+
OUTPUT "${test_bin_dir}/lit.swift-features.cfg"
320+
COMMAND
321+
${test_lit_swift_features_cmd}
322+
"${CMAKE_CURRENT_SOURCE_DIR}/lit.swift-features.cfg.inc"
323+
DEPENDS
324+
"lit.swift-features.cfg.inc"
325+
"${SWIFT_MAIN_INCLUDE_DIR}/swift/Basic/Features.def"
326+
)
327+
328+
set(validation_test_lit_swift_features_cmd ${C_PREPROCESSOR_COMMAND})
329+
list(
330+
TRANSFORM validation_test_lit_swift_features_cmd
331+
REPLACE "<<<OUTPUT_FILE>>>" "${validation_test_bin_dir}/lit.swift-features.cfg")
332+
add_custom_command(
333+
OUTPUT "${validation_test_bin_dir}/lit.swift-features.cfg"
334+
COMMAND
335+
${validation_test_lit_swift_features_cmd}
336+
"${CMAKE_CURRENT_SOURCE_DIR}/lit.swift-features.cfg.inc"
337+
DEPENDS
338+
"lit.swift-features.cfg.inc"
339+
"${SWIFT_MAIN_INCLUDE_DIR}/swift/Basic/Features.def"
340+
)
341+
add_custom_target(lit_swift_features_cfg_${VARIANT_SUFFIX}
342+
DEPENDS
343+
"${test_bin_dir}/lit.swift-features.cfg"
344+
"${validation_test_bin_dir}/lit.swift-features.cfg")
345+
304346
set(test_dependencies)
305347
get_test_dependencies("${SDK}" test_dependencies)
306348

@@ -338,6 +380,9 @@ foreach(SDK ${SWIFT_SDKS})
338380

339381
set(validation_test_dependencies)
340382

383+
list(APPEND test_dependencies lit_swift_features_cfg_${VARIANT_SUFFIX})
384+
list(APPEND validation_test_dependencies lit_swift_features_cfg_${VARIANT_SUFFIX})
385+
341386
set(command_upload_stdlib)
342387
set(command_upload_swift_reflection_test)
343388
if("${SDK}" STREQUAL "IOS" OR "${SDK}" STREQUAL "TVOS" OR "${SDK}" STREQUAL "WATCHOS" OR "${SDK}" STREQUAL "XROS")

test/lit.site.cfg.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,5 +180,6 @@ if '@SWIFT_BUILD_SWIFT_SYNTAX@' == 'TRUE':
180180
# Let the main config do the real work.
181181
if config.test_exec_root is None:
182182
config.test_exec_root = os.path.dirname(lit.util.abs_path_preserve_drive(__file__))
183+
lit_config.load_config(config, os.path.join(config.test_exec_root, "lit.swift-features.cfg"))
183184
lit_config.load_config(
184185
config, os.path.join(config.swift_src_root, "test", "lit.cfg"))

test/lit.swift-features.cfg.inc

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/* lit.swift-feature.cfg.inc - Config for Swift features for 'lit' test runner */
2+
3+
/*
4+
* This source file is part of the Swift.org open source project
5+
*
6+
* Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors
7+
* Licensed under Apache License v2.0 with Runtime Library Exception
8+
*
9+
* See https://swift.org/LICENSE.txt for license information
10+
* See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
11+
*/
12+
13+
/*
14+
* This is a configuration file for the 'lit' test runner. It takes the
15+
* Features.def for the language and creates 'lit' features associated with
16+
* them when the Swift feature is available. It allows using
17+
* `REQUIRES: FeatureName` instead of `REQUIRES: asserts`, which tend to be
18+
* left behind when the Swift feature becomes non-experimental.
19+
*
20+
* This file is preprocessed the Clang preprocessor and generates Python files.
21+
* C comments are possible, but not Python comments (they look like preprocessor
22+
* statements).
23+
*/
24+
25+
def language_feature(feature_name, enabled):
26+
if enabled or "asserts" in config.available_features:
27+
config.available_features.add(feature_name)
28+
29+
#define UPCOMING_FEATURE(FeatureName, SENumber, Version) language_feature("swift_feature_" # FeatureName, True)
30+
#define EXPERIMENTAL_FEATURE(FeatureName, AvailableInProd) language_feature("swift_feature_" # FeatureName, #AvailableInProd == "true")
31+
#define LANGUAGE_FEATURE(FeatureName, SENumber, Description) language_feature("swift_feature_" # FeatureName, True)
32+
33+
#include <swift/Basic/Features.def>

validation-test/lit.site.cfg.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,5 @@ config.freestanding_sdk_name = "@SWIFT_SDK_FREESTANDING_LIB_SUBDIR@"
145145

146146
# Let the main config do the real work.
147147
config.test_exec_root = os.path.dirname(os.path.realpath(__file__))
148+
lit_config.load_config(config, os.path.join(config.test_exec_root, "lit.swift-features.cfg"))
148149
lit_config.load_config(config, "@SWIFT_SOURCE_DIR@/validation-test/lit.cfg")

0 commit comments

Comments
 (0)