Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plumb through the testing library version into a function instead of a C++ macro. #648

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/Testing/Support/Versions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ let simulatorVersion: String = {
///
/// This value is not part of the public interface of the testing library.
var testingLibraryVersion: String {
SWT_TESTING_LIBRARY_VERSION
swt_getTestingLibraryVersion().flatMap(String.init(validatingCString:)) ?? "unknown"
}

/// A human-readable string describing the Swift Standard Library's version.
Expand Down
1 change: 1 addition & 0 deletions Sources/_TestingInternals/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ set(CMAKE_CXX_SCAN_FOR_MODULES 0)
include(LibraryVersion)
add_library(_TestingInternals STATIC
Discovery.cpp
Versions.cpp
WillThrow.cpp)
target_include_directories(_TestingInternals PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include)
Expand Down
20 changes: 20 additions & 0 deletions Sources/_TestingInternals/Versions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2024 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
//

#include "Versions.h"

const char *swt_getTestingLibraryVersion(void) {
#if defined(_SWT_TESTING_LIBRARY_VERSION)
return _SWT_TESTING_LIBRARY_VERSION;
#else
#warning _SWT_TESTING_LIBRARY_VERSION not defined: testing library version is unavailable
return nullptr;
#endif
}
11 changes: 0 additions & 11 deletions Sources/_TestingInternals/include/Defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,4 @@
/// An attribute that renames a C symbol in Swift.
#define SWT_SWIFT_NAME(name) __attribute__((swift_name(#name)))

/// The testing library version from the package manifest.
///
/// - Bug: The value provided to the compiler (`_SWT_TESTING_LIBRARY_VERSION`)
/// is not visible in Swift, so this second macro is needed.
/// ((#43521)[https://github.com/swiftlang/swift/issues/43521])
#if defined(_SWT_TESTING_LIBRARY_VERSION)
#define SWT_TESTING_LIBRARY_VERSION _SWT_TESTING_LIBRARY_VERSION
#else
#define SWT_TESTING_LIBRARY_VERSION "unknown"
#endif

#endif // SWT_DEFINES_H
28 changes: 28 additions & 0 deletions Sources/_TestingInternals/include/Versions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2024 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
//

#if !defined(SWT_VERSIONS_H)
#define SWT_VERSIONS_H

#include "Defines.h"

SWT_ASSUME_NONNULL_BEGIN

/// Get the human-readable version of the testing library.
///
/// - Returns: A human-readable string describing the version of the testing
/// library, or `nullptr` if no version information is available. This
/// string's value and format may vary between platforms, releases, or any
/// other conditions. Do not attempt to parse it.
SWT_EXTERN const char *_Nullable swt_getTestingLibraryVersion(void);

SWT_ASSUME_NONNULL_END

#endif