Skip to content

Commit 9aa8076

Browse files
authored
[6.0.0] Plumb through the testing library version into a function instead of a C++ macro. (#650)
**Explanation:** Correctly sets the testing library version (it was failing to set on the Swift side.) **Scope:** Building with CMake **Issue:** N/A **Original PR:** #648 **Risk:** Low **Testing:** Built a toolchain and verified the string was ingested all the way through. **Reviewer:** @grynspan @briancroom
1 parent 1268afa commit 9aa8076

File tree

5 files changed

+50
-12
lines changed

5 files changed

+50
-12
lines changed

Sources/Testing/Support/Versions.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ let simulatorVersion: String = {
125125
///
126126
/// This value is not part of the public interface of the testing library.
127127
var testingLibraryVersion: String {
128-
SWT_TESTING_LIBRARY_VERSION
128+
swt_getTestingLibraryVersion().flatMap(String.init(validatingCString:)) ?? "unknown"
129129
}
130130

131131
/// A human-readable string describing the Swift Standard Library's version.

Sources/_TestingInternals/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ set(CMAKE_CXX_SCAN_FOR_MODULES 0)
1111
include(LibraryVersion)
1212
add_library(_TestingInternals STATIC
1313
Discovery.cpp
14+
Versions.cpp
1415
WillThrow.cpp)
1516
target_include_directories(_TestingInternals PUBLIC
1617
${CMAKE_CURRENT_SOURCE_DIR}/include)
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//
2+
// This source file is part of the Swift.org open source project
3+
//
4+
// Copyright (c) 2024 Apple Inc. and the Swift project authors
5+
// Licensed under Apache License v2.0 with Runtime Library Exception
6+
//
7+
// See https://swift.org/LICENSE.txt for license information
8+
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
9+
//
10+
11+
#include "Versions.h"
12+
13+
const char *swt_getTestingLibraryVersion(void) {
14+
#if defined(_SWT_TESTING_LIBRARY_VERSION)
15+
return _SWT_TESTING_LIBRARY_VERSION;
16+
#else
17+
#warning _SWT_TESTING_LIBRARY_VERSION not defined: testing library version is unavailable
18+
return nullptr;
19+
#endif
20+
}

Sources/_TestingInternals/include/Defines.h

-11
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,4 @@
3232
/// An attribute that renames a C symbol in Swift.
3333
#define SWT_SWIFT_NAME(name) __attribute__((swift_name(#name)))
3434

35-
/// The testing library version from the package manifest.
36-
///
37-
/// - Bug: The value provided to the compiler (`_SWT_TESTING_LIBRARY_VERSION`)
38-
/// is not visible in Swift, so this second macro is needed.
39-
/// ((#43521)[https://github.com/swiftlang/swift/issues/43521])
40-
#if defined(_SWT_TESTING_LIBRARY_VERSION)
41-
#define SWT_TESTING_LIBRARY_VERSION _SWT_TESTING_LIBRARY_VERSION
42-
#else
43-
#define SWT_TESTING_LIBRARY_VERSION "unknown"
44-
#endif
45-
4635
#endif // SWT_DEFINES_H
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//
2+
// This source file is part of the Swift.org open source project
3+
//
4+
// Copyright (c) 2024 Apple Inc. and the Swift project authors
5+
// Licensed under Apache License v2.0 with Runtime Library Exception
6+
//
7+
// See https://swift.org/LICENSE.txt for license information
8+
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
9+
//
10+
11+
#if !defined(SWT_VERSIONS_H)
12+
#define SWT_VERSIONS_H
13+
14+
#include "Defines.h"
15+
16+
SWT_ASSUME_NONNULL_BEGIN
17+
18+
/// Get the human-readable version of the testing library.
19+
///
20+
/// - Returns: A human-readable string describing the version of the testing
21+
/// library, or `nullptr` if no version information is available. This
22+
/// string's value and format may vary between platforms, releases, or any
23+
/// other conditions. Do not attempt to parse it.
24+
SWT_EXTERN const char *_Nullable swt_getTestingLibraryVersion(void);
25+
26+
SWT_ASSUME_NONNULL_END
27+
28+
#endif

0 commit comments

Comments
 (0)