Skip to content

Commit 5c87ccc

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 cd6864a commit 5c87ccc

File tree

4 files changed

+72
-0
lines changed

4 files changed

+72
-0
lines changed

test/CMakeLists.txt

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,14 @@ 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" "/Fi")
259+
else()
260+
set(C_PREPROCESSOR_COMMAND
261+
"${CMAKE_C_COMPILER}" "-E" "-P" "-I${SWIFT_MAIN_INCLUDE_DIR}" "-x" "c" "-o")
262+
endif()
263+
256264
foreach(SDK ${SWIFT_SDKS})
257265
foreach(ARCH ${SWIFT_SDK_${SDK}_ARCHITECTURES})
258266
# macCatalyst needs to run two sets of tests: one with the normal macosx target triple
@@ -301,6 +309,32 @@ foreach(SDK ${SWIFT_SDKS})
301309
"${validation_test_bin_dir}/lit.site.cfg"
302310
"validation-test${VARIANT_SUFFIX}.lit.site.cfg")
303311

312+
add_custom_command(
313+
OUTPUT "${test_bin_dir}/lit.swift-features.cfg"
314+
COMMAND
315+
${C_PREPROCESSOR_COMMAND}
316+
"${test_bin_dir}/lit.swift-features.cfg"
317+
"${CMAKE_CURRENT_SOURCE_DIR}/lit.swift-features.cfg.inc"
318+
DEPENDS
319+
"lit.swift-features.cfg.inc"
320+
"${SWIFT_MAIN_INCLUDE_DIR}/swift/Basic/Features.def"
321+
)
322+
323+
add_custom_command(
324+
OUTPUT "${validation_test_bin_dir}/lit.swift-features.cfg"
325+
COMMAND
326+
${C_PREPROCESSOR_COMMAND}
327+
"${validation_test_bin_dir}/lit.swift-features.cfg"
328+
"${CMAKE_CURRENT_SOURCE_DIR}/lit.swift-features.cfg.inc"
329+
DEPENDS
330+
"lit.swift-features.cfg.inc"
331+
"${SWIFT_MAIN_INCLUDE_DIR}/swift/Basic/Features.def"
332+
)
333+
add_custom_target(lit_swift_features_cfg_${VARIANT_SUFFIX}
334+
DEPENDS
335+
"${test_bin_dir}/lit.swift-features.cfg"
336+
"${validation_test_bin_dir}/lit.swift-features.cfg")
337+
304338
set(test_dependencies)
305339
get_test_dependencies("${SDK}" test_dependencies)
306340

@@ -338,6 +372,9 @@ foreach(SDK ${SWIFT_SDKS})
338372

339373
set(validation_test_dependencies)
340374

375+
list(APPEND test_dependencies lit_swift_features_cfg_${VARIANT_SUFFIX})
376+
list(APPEND validation_test_dependencies lit_swift_features_cfg_${VARIANT_SUFFIX})
377+
341378
set(command_upload_stdlib)
342379
set(command_upload_swift_reflection_test)
343380
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)