mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[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.
This commit is contained in:
@@ -253,6 +253,16 @@ if(NOT "${COVERAGE_DB}" STREQUAL "")
|
||||
COMMENT "Touching covering tests")
|
||||
endif()
|
||||
|
||||
if(SWIFT_COMPILER_IS_MSVC_LIKE)
|
||||
set(C_PREPROCESSOR_COMMAND
|
||||
"${CMAKE_C_COMPILER}" "/P" "/EP" "/I" "${SWIFT_MAIN_INCLUDE_DIR}" "/TC"
|
||||
"/Fi<<<OUTPUT_FILE>>>")
|
||||
else()
|
||||
set(C_PREPROCESSOR_COMMAND
|
||||
"${CMAKE_C_COMPILER}" "-E" "-P" "-I${SWIFT_MAIN_INCLUDE_DIR}" "-x" "c" "-o"
|
||||
"<<<OUTPUT_FILE>>>")
|
||||
endif()
|
||||
|
||||
foreach(SDK ${SWIFT_SDKS})
|
||||
foreach(ARCH ${SWIFT_SDK_${SDK}_ARCHITECTURES})
|
||||
# macCatalyst needs to run two sets of tests: one with the normal macosx target triple
|
||||
@@ -304,6 +314,38 @@ foreach(SDK ${SWIFT_SDKS})
|
||||
"${validation_test_bin_dir}/lit.site.cfg"
|
||||
"validation-test${VARIANT_SUFFIX}.lit.site.cfg")
|
||||
|
||||
set(test_lit_swift_features_cmd ${C_PREPROCESSOR_COMMAND})
|
||||
list(
|
||||
TRANSFORM test_lit_swift_features_cmd
|
||||
REPLACE "<<<OUTPUT_FILE>>>" "${test_bin_dir}/lit.swift-features.cfg")
|
||||
add_custom_command(
|
||||
OUTPUT "${test_bin_dir}/lit.swift-features.cfg"
|
||||
COMMAND
|
||||
${test_lit_swift_features_cmd}
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/lit.swift-features.cfg.inc"
|
||||
DEPENDS
|
||||
"lit.swift-features.cfg.inc"
|
||||
"${SWIFT_MAIN_INCLUDE_DIR}/swift/Basic/Features.def"
|
||||
)
|
||||
|
||||
set(validation_test_lit_swift_features_cmd ${C_PREPROCESSOR_COMMAND})
|
||||
list(
|
||||
TRANSFORM validation_test_lit_swift_features_cmd
|
||||
REPLACE "<<<OUTPUT_FILE>>>" "${validation_test_bin_dir}/lit.swift-features.cfg")
|
||||
add_custom_command(
|
||||
OUTPUT "${validation_test_bin_dir}/lit.swift-features.cfg"
|
||||
COMMAND
|
||||
${validation_test_lit_swift_features_cmd}
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/lit.swift-features.cfg.inc"
|
||||
DEPENDS
|
||||
"lit.swift-features.cfg.inc"
|
||||
"${SWIFT_MAIN_INCLUDE_DIR}/swift/Basic/Features.def"
|
||||
)
|
||||
add_custom_target(lit_swift_features_cfg_${VARIANT_SUFFIX}
|
||||
DEPENDS
|
||||
"${test_bin_dir}/lit.swift-features.cfg"
|
||||
"${validation_test_bin_dir}/lit.swift-features.cfg")
|
||||
|
||||
set(test_dependencies)
|
||||
get_test_dependencies("${SDK}" test_dependencies)
|
||||
|
||||
@@ -341,6 +383,9 @@ foreach(SDK ${SWIFT_SDKS})
|
||||
|
||||
set(validation_test_dependencies)
|
||||
|
||||
list(APPEND test_dependencies lit_swift_features_cfg_${VARIANT_SUFFIX})
|
||||
list(APPEND validation_test_dependencies lit_swift_features_cfg_${VARIANT_SUFFIX})
|
||||
|
||||
set(command_upload_stdlib)
|
||||
set(command_upload_swift_reflection_test)
|
||||
if("${SDK}" STREQUAL "IOS" OR "${SDK}" STREQUAL "TVOS" OR "${SDK}" STREQUAL "WATCHOS" OR "${SDK}" STREQUAL "XROS")
|
||||
|
||||
@@ -182,5 +182,6 @@ if '@SWIFT_BUILD_SWIFT_SYNTAX@' == 'TRUE':
|
||||
# Let the main config do the real work.
|
||||
if config.test_exec_root is None:
|
||||
config.test_exec_root = os.path.dirname(lit.util.abs_path_preserve_drive(__file__))
|
||||
lit_config.load_config(config, os.path.join(config.test_exec_root, "lit.swift-features.cfg"))
|
||||
lit_config.load_config(
|
||||
config, os.path.join(config.swift_src_root, "test", "lit.cfg"))
|
||||
|
||||
33
test/lit.swift-features.cfg.inc
Normal file
33
test/lit.swift-features.cfg.inc
Normal file
@@ -0,0 +1,33 @@
|
||||
/* lit.swift-feature.cfg.inc - Config for Swift features for 'lit' test runner */
|
||||
|
||||
/*
|
||||
* This source file is part of the Swift.org open source project
|
||||
*
|
||||
* Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors
|
||||
* Licensed under Apache License v2.0 with Runtime Library Exception
|
||||
*
|
||||
* See https://swift.org/LICENSE.txt for license information
|
||||
* See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
||||
*/
|
||||
|
||||
/*
|
||||
* This is a configuration file for the 'lit' test runner. It takes the
|
||||
* Features.def for the language and creates 'lit' features associated with
|
||||
* them when the Swift feature is available. It allows using
|
||||
* `REQUIRES: FeatureName` instead of `REQUIRES: asserts`, which tend to be
|
||||
* left behind when the Swift feature becomes non-experimental.
|
||||
*
|
||||
* This file is preprocessed the Clang preprocessor and generates Python files.
|
||||
* C comments are possible, but not Python comments (they look like preprocessor
|
||||
* statements).
|
||||
*/
|
||||
|
||||
def language_feature(feature_name, enabled):
|
||||
if enabled or "asserts" in config.available_features:
|
||||
config.available_features.add(feature_name)
|
||||
|
||||
#define UPCOMING_FEATURE(FeatureName, SENumber, Version) language_feature("swift_feature_" # FeatureName, True)
|
||||
#define EXPERIMENTAL_FEATURE(FeatureName, AvailableInProd) language_feature("swift_feature_" # FeatureName, #AvailableInProd == "true")
|
||||
#define LANGUAGE_FEATURE(FeatureName, SENumber, Description) language_feature("swift_feature_" # FeatureName, True)
|
||||
|
||||
#include <swift/Basic/Features.def>
|
||||
@@ -145,4 +145,5 @@ config.freestanding_sdk_name = "@SWIFT_SDK_FREESTANDING_LIB_SUBDIR@"
|
||||
|
||||
# Let the main config do the real work.
|
||||
config.test_exec_root = os.path.dirname(os.path.realpath(__file__))
|
||||
lit_config.load_config(config, os.path.join(config.test_exec_root, "lit.swift-features.cfg"))
|
||||
lit_config.load_config(config, "@SWIFT_SOURCE_DIR@/validation-test/lit.cfg")
|
||||
|
||||
Reference in New Issue
Block a user