diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index f95f79cdb2f..d6e8a2151d4 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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<<>>") +else() + set(C_PREPROCESSOR_COMMAND + "${CMAKE_C_COMPILER}" "-E" "-P" "-I${SWIFT_MAIN_INCLUDE_DIR}" "-x" "c" "-o" + "<<>>") +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 "<<>>" "${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 "<<>>" "${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") diff --git a/test/lit.site.cfg.in b/test/lit.site.cfg.in index f92a789336b..2e293658c17 100644 --- a/test/lit.site.cfg.in +++ b/test/lit.site.cfg.in @@ -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")) diff --git a/test/lit.swift-features.cfg.inc b/test/lit.swift-features.cfg.inc new file mode 100644 index 00000000000..263d9d34a8a --- /dev/null +++ b/test/lit.swift-features.cfg.inc @@ -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 diff --git a/validation-test/lit.site.cfg.in b/validation-test/lit.site.cfg.in index 30a5fe11989..22ac7db6f13 100644 --- a/validation-test/lit.site.cfg.in +++ b/validation-test/lit.site.cfg.in @@ -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")