Skip to content

Commit da74dbc

Browse files
committed
Move the package version to version.txt.
This change moves the definition of Swift Testing's version to a new file, version.txt. This file doesn't represent a standard, _per se_, but it is common for open-source projects to list their version info in such a file. And by putting our version info in this file, we can share it between package builds and CMake builds.
1 parent b4abd32 commit da74dbc

File tree

5 files changed

+35
-16
lines changed

5 files changed

+35
-16
lines changed

Package.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -470,12 +470,6 @@ extension Array where Element == PackageDescription.CXXSetting {
470470

471471
// Capture the testing library's commit info as C++ constants.
472472
if let git {
473-
if let tag = git.currentTag {
474-
result.append(.define("SWT_TESTING_LIBRARY_VERSION", to: #""\#(tag)""#))
475-
} else {
476-
result.append(.define("SWT_TESTING_LIBRARY_VERSION", to: "0"))
477-
}
478-
479473
result.append(.define("SWT_TESTING_LIBRARY_COMMIT_HASH", to: #""\#(git.currentCommit)""#))
480474
if git.hasUncommittedChanges {
481475
result.append(.define("SWT_TESTING_LIBRARY_COMMIT_MODIFIED", to: "1"))

Sources/_TestingInternals/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
set(CMAKE_CXX_SCAN_FOR_MODULES 0)
1010

1111
include(GitCommit)
12-
include(LibraryVersion)
1312
include(TargetTriple)
1413
add_library(_TestingInternals STATIC
1514
Discovery.cpp

Sources/_TestingInternals/Versions.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,33 @@
1010

1111
#include "Versions.h"
1212

13+
#include <mutex>
14+
1315
const char *swt_getTestingLibraryVersion(void) {
1416
#if defined(SWT_TESTING_LIBRARY_VERSION)
17+
// The current environment explicitly specifies a version string to return.
1518
return SWT_TESTING_LIBRARY_VERSION;
19+
#elif __has_embed("../../version.txt")
20+
// Read the version from version.txt at the root of the package's repository.
21+
static char version[] = {
22+
#pragma clang diagnostic push
23+
#pragma clang diagnostic ignored "-Wc23-extensions"
24+
#embed "../../version.txt" suffix(, '\0')
25+
#pragma clang diagnostic pop
26+
};
27+
28+
// Trim any trailing whitespace.
29+
static std::once_flag once;
30+
std::call_once(once, [] {
31+
auto i = std::find_if(std::begin(version), std::end(version), std::isspace);
32+
if (i != std::end(version)) {
33+
*i = '\0';
34+
}
35+
});
36+
37+
return version;
1638
#else
17-
#warning SWT_TESTING_LIBRARY_VERSION not defined: testing library version is unavailable
39+
#warning SWT_TESTING_LIBRARY_VERSION not defined and version.txt not found: testing library version is unavailable
1840
return nullptr;
1941
#endif
2042
}

cmake/modules/LibraryVersion.cmake

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
# This source file is part of the Swift.org open source project
22
#
3-
# Copyright (c) 2024 Apple Inc. and the Swift project authors
3+
# Copyright (c) 2024–2025 Apple Inc. and the Swift project authors
44
# Licensed under Apache License v2.0 with Runtime Library Exception
55
#
66
# See http://swift.org/LICENSE.txt for license information
77
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
88

9-
# The current version of the Swift Testing release. For release branches,
10-
# remember to remove -dev.
11-
set(SWT_TESTING_LIBRARY_VERSION "6.3-dev")
12-
13-
message(STATUS "Swift Testing version: ${SWT_TESTING_LIBRARY_VERSION}")
14-
add_compile_definitions(
15-
"$<$<COMPILE_LANGUAGE:CXX>:SWT_TESTING_LIBRARY_VERSION=\"${SWT_TESTING_LIBRARY_VERSION}\">")
9+
# The library version is now tracked in version.txt at the root directory of the
10+
# repository. This file will be removed in a future commit.

version.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
6.3-dev
2+
3+
# This source file is part of the Swift.org open source project
4+
#
5+
# Copyright (c) 2025 Apple Inc. and the Swift project authors
6+
# Licensed under Apache License v2.0 with Runtime Library Exception
7+
#
8+
# See http://swift.org/LICENSE.txt for license information
9+
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors

0 commit comments

Comments
 (0)