File tree Expand file tree Collapse file tree 6 files changed +49
-39
lines changed Expand file tree Collapse file tree 6 files changed +49
-39
lines changed Original file line number Diff line number Diff line change @@ -468,16 +468,12 @@ extension Array where Element == PackageDescription.CXXSetting {
468
468
. define( " SWT_NO_LIBDISPATCH " , . whenEmbedded( ) ) ,
469
469
]
470
470
471
- // Capture the testing library's version as a C++ string constant .
471
+ // Capture the testing library's commit info as C++ constants .
472
472
if let git {
473
- let testingLibraryVersion = if let tag = git. currentTag {
474
- tag
475
- } else if git. hasUncommittedChanges {
476
- " \( git. currentCommit) (modified) "
477
- } else {
478
- git. currentCommit
473
+ result. append ( . define( " SWT_TESTING_LIBRARY_COMMIT_HASH " , to: #"" \#( git. currentCommit) ""# ) )
474
+ if git. hasUncommittedChanges {
475
+ result. append ( . define( " SWT_TESTING_LIBRARY_COMMIT_MODIFIED " , to: " 1 " ) )
479
476
}
480
- result. append ( . define( " SWT_TESTING_LIBRARY_VERSION " , to: #"" \#( testingLibraryVersion) ""# ) )
481
477
}
482
478
483
479
return result
Original file line number Diff line number Diff line change @@ -129,9 +129,28 @@ let simulatorVersion: String = {
129
129
/// an event writer.
130
130
///
131
131
/// This value is not part of the public interface of the testing library.
132
- var testingLibraryVersion: String {
133
- swt_getTestingLibraryVersion ( ) . flatMap ( String . init ( validatingCString: ) ) ?? " unknown "
134
- }
132
+ let testingLibraryVersion: String = {
133
+ guard var result = swt_getTestingLibraryVersion ( ) . flatMap ( String . init ( validatingCString: ) ) else {
134
+ return " unknown "
135
+ }
136
+
137
+ // Get details of the git commit used when compiling the testing library.
138
+ var commitHash : UnsafePointer < CChar > ?
139
+ var commitModified = CBool ( false )
140
+ swt_getTestingLibraryCommit ( & commitHash, & commitModified)
141
+
142
+ if let commitHash = commitHash. flatMap ( String . init ( validatingCString: ) ) {
143
+ // Truncate to 15 characters of the hash to match `swift --version`.
144
+ let commitHash = commitHash. prefix ( 15 )
145
+ if commitModified {
146
+ result = " \( result) ( \( commitHash) - modified) "
147
+ } else {
148
+ result = " \( result) ( \( commitHash) ) "
149
+ }
150
+ }
151
+
152
+ return result
153
+ } ( )
135
154
136
155
/// Get the LLVM target triple used to build the testing library, if available.
137
156
///
Original file line number Diff line number Diff line change 8
8
9
9
set (CMAKE_CXX_SCAN_FOR_MODULES 0)
10
10
11
+ include (GitCommit)
11
12
include (LibraryVersion)
12
13
include (TargetTriple)
13
14
add_library (_TestingInternals STATIC
Original file line number Diff line number Diff line change @@ -19,6 +19,19 @@ const char *swt_getTestingLibraryVersion(void) {
19
19
#endif
20
20
}
21
21
22
+ void swt_getTestingLibraryCommit (const char *_Nullable *_Nonnull outHash, bool *outModified) {
23
+ #if defined(SWT_TESTING_LIBRARY_COMMIT_HASH)
24
+ *outHash = SWT_TESTING_LIBRARY_COMMIT_HASH;
25
+ #else
26
+ *outHash = nullptr ;
27
+ #endif
28
+ #if defined(SWT_TESTING_LIBRARY_COMMIT_MODIFIED)
29
+ *outModified = (SWT_TESTING_LIBRARY_COMMIT_MODIFIED != 0 );
30
+ #else
31
+ *outModified = false ;
32
+ #endif
33
+ }
34
+
22
35
const char *swt_getTargetTriple (void ) {
23
36
#if defined(SWT_TARGET_TRIPLE)
24
37
return SWT_TARGET_TRIPLE;
Original file line number Diff line number Diff line change @@ -38,6 +38,15 @@ static inline uint64_t swt_getSwiftCompilerVersion(void) {
38
38
/// other conditions. Do not attempt to parse it.
39
39
SWT_EXTERN const char * _Nullable swt_getTestingLibraryVersion (void );
40
40
41
+ /// Get details of the source control (git) commit from which the testing
42
+ /// library was built.
43
+ ///
44
+ /// - Parameters:
45
+ /// - outHash: On return, set to a pointer to a string containing the commit
46
+ /// hash from which the testing library was built.
47
+ /// - outModified: On return, whether or not there were uncommitted changes.
48
+ SWT_EXTERN void swt_getTestingLibraryCommit (const char * _Nullable * _Nonnull outHash , bool * outModified );
49
+
41
50
/// Get the LLVM target triple used to build the testing library.
42
51
///
43
52
/// - Returns: A string containing the LLVM target triple used to build the
Original file line number Diff line number Diff line change 10
10
# remember to remove -dev.
11
11
set (SWT_TESTING_LIBRARY_VERSION "6.3-dev" )
12
12
13
- find_package (Git QUIET )
14
- if (Git_FOUND)
15
- # Get the commit hash corresponding to the current build. Limit length to 15
16
- # to match `swift --version` output format.
17
- execute_process (
18
- COMMAND ${GIT_EXECUTABLE} rev-parse --short=15 --verify HEAD
19
- WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
20
- OUTPUT_VARIABLE GIT_VERSION
21
- OUTPUT_STRIP_TRAILING_WHITESPACE
22
- ERROR_QUIET)
23
-
24
- # Check if there are local changes.
25
- execute_process (
26
- COMMAND ${GIT_EXECUTABLE} status -s
27
- WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
28
- OUTPUT_VARIABLE GIT_STATUS
29
- OUTPUT_STRIP_TRAILING_WHITESPACE)
30
- if (GIT_STATUS)
31
- set (GIT_VERSION "${GIT_VERSION} - modified" )
32
- endif ()
33
- endif ()
34
-
35
- # Combine the hard-coded Swift version with available Git information.
36
- if (GIT_VERSION)
37
- set (SWT_TESTING_LIBRARY_VERSION "${SWT_TESTING_LIBRARY_VERSION} (${GIT_VERSION} )" )
38
- endif ()
39
-
40
- # All done!
41
13
message (STATUS "Swift Testing version: ${SWT_TESTING_LIBRARY_VERSION} " )
42
14
add_compile_definitions (
43
15
"$<$<COMPILE_LANGUAGE:CXX>:SWT_TESTING_LIBRARY_VERSION=\" ${SWT_TESTING_LIBRARY_VERSION} \" >" )
You can’t perform that action at this time.
0 commit comments