diff --git a/Package.swift b/Package.swift index 840541887..e387f1453 100644 --- a/Package.swift +++ b/Package.swift @@ -470,12 +470,6 @@ extension Array where Element == PackageDescription.CXXSetting { // Capture the testing library's commit info as C++ constants. if let git { - if let tag = git.currentTag { - result.append(.define("SWT_TESTING_LIBRARY_VERSION", to: #""\#(tag)""#)) - } else { - result.append(.define("SWT_TESTING_LIBRARY_VERSION", to: "0")) - } - result.append(.define("SWT_TESTING_LIBRARY_COMMIT_HASH", to: #""\#(git.currentCommit)""#)) if git.hasUncommittedChanges { result.append(.define("SWT_TESTING_LIBRARY_COMMIT_MODIFIED", to: "1")) @@ -483,7 +477,6 @@ extension Array where Element == PackageDescription.CXXSetting { } else if let gitHubSHA = Context.environment["GITHUB_SHA"] { // When building in GitHub Actions, the git command may fail to get us the // commit hash, so check if GitHub shared it with us instead. - result.append(.define("SWT_TESTING_LIBRARY_VERSION", to: "0")) result.append(.define("SWT_TESTING_LIBRARY_COMMIT_HASH", to: #""\#(gitHubSHA)""#)) } diff --git a/Sources/_TestingInternals/CMakeLists.txt b/Sources/_TestingInternals/CMakeLists.txt index 90ad424e9..a951c7d4b 100644 --- a/Sources/_TestingInternals/CMakeLists.txt +++ b/Sources/_TestingInternals/CMakeLists.txt @@ -9,7 +9,6 @@ set(CMAKE_CXX_SCAN_FOR_MODULES 0) include(GitCommit) -include(LibraryVersion) include(TargetTriple) add_library(_TestingInternals STATIC Discovery.cpp diff --git a/Sources/_TestingInternals/Versions.cpp b/Sources/_TestingInternals/Versions.cpp index 8e85f3d06..bd8f2314a 100644 --- a/Sources/_TestingInternals/Versions.cpp +++ b/Sources/_TestingInternals/Versions.cpp @@ -10,11 +10,37 @@ #include "Versions.h" +#include +#include +#include + const char *swt_getTestingLibraryVersion(void) { #if defined(SWT_TESTING_LIBRARY_VERSION) + // The current environment explicitly specifies a version string to return. return SWT_TESTING_LIBRARY_VERSION; +#elif __has_embed("../../VERSION.txt") + static constinit auto version = [] () constexpr { + // Read the version from version.txt at the root of the package's repo. + char version[] = { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wc23-extensions" +#embed "../../VERSION.txt" +#pragma clang diagnostic pop + }; + + // Copy the first line from the C string into a C array so that we can + // return it from this closure. + std::array result {}; + auto i = std::find_if(std::begin(version), std::end(version), [] (char c) { + return c == '\r' || c == '\n'; + }); + std::copy(std::begin(version), i, result.begin()); + return result; + }(); + + return version.data(); #else -#warning SWT_TESTING_LIBRARY_VERSION not defined: testing library version is unavailable +#warning SWT_TESTING_LIBRARY_VERSION not defined and VERSION.txt not found: testing library version is unavailable return nullptr; #endif } diff --git a/VERSION.txt b/VERSION.txt new file mode 100644 index 000000000..a2b88412f --- /dev/null +++ b/VERSION.txt @@ -0,0 +1 @@ +6.3-dev diff --git a/cmake/modules/LibraryVersion.cmake b/cmake/modules/LibraryVersion.cmake index 72e42e4cb..c5c1d6405 100644 --- a/cmake/modules/LibraryVersion.cmake +++ b/cmake/modules/LibraryVersion.cmake @@ -1,17 +1,12 @@ ## ## This source file is part of the Swift.org open source project ## -## Copyright (c) 2024 Apple Inc. and the Swift project authors +## Copyright (c) 2024–2025 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 Swift project authors ## -# The current version of the Swift Testing release. For release branches, -# remember to remove -dev. -set(SWT_TESTING_LIBRARY_VERSION "6.3-dev") - -message(STATUS "Swift Testing version: ${SWT_TESTING_LIBRARY_VERSION}") -add_compile_definitions( - "$<$:SWT_TESTING_LIBRARY_VERSION=\"${SWT_TESTING_LIBRARY_VERSION}\">") +# The library version is now tracked in VERSION.txt at the root directory of the +# repository. This file will be removed in a future commit.