Skip to content
Merged
7 changes: 0 additions & 7 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -470,20 +470,13 @@ 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"))
}
} 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)""#))
}

Expand Down
1 change: 0 additions & 1 deletion Sources/_TestingInternals/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
set(CMAKE_CXX_SCAN_FOR_MODULES 0)

include(GitCommit)
include(LibraryVersion)
include(TargetTriple)
add_library(_TestingInternals STATIC
Discovery.cpp
Expand Down
28 changes: 27 additions & 1 deletion Sources/_TestingInternals/Versions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,37 @@

#include "Versions.h"

#include <array>
#include <algorithm>
#include <iterator>

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<char, std::size(version) + 1> 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
}
Expand Down
1 change: 1 addition & 0 deletions VERSION.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6.3-dev
11 changes: 3 additions & 8 deletions cmake/modules/LibraryVersion.cmake
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
# 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 http://swift.org/LICENSE.txt for license information
# See http://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(
"$<$<COMPILE_LANGUAGE:CXX>: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.