Skip to content

Commit e90ea40

Browse files
committed
Add the distribution tag to -print-target-info
Ideally this would also update the `--version` output to be overridden by `SWIFT_TOOLCHAIN_VERSION`, but unfortunately various tools rely on the current format (eg. swift-build).
1 parent f7529ea commit e90ea40

File tree

7 files changed

+23
-22
lines changed

7 files changed

+23
-22
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,8 @@ set(SWIFT_COMPILER_VERSION "" CACHE STRING
336336
"The internal version of the Swift compiler")
337337
set(CLANG_COMPILER_VERSION "" CACHE STRING
338338
"The internal version of the Clang compiler")
339+
set(SWIFT_TOOLCHAIN_VERSION "" CACHE STRING
340+
"The Swift compiler tag")
339341

340342
option(SWIFT_DISABLE_DEAD_STRIPPING
341343
"Turn off Darwin-specific dead stripping for Swift host tools." FALSE)

include/swift/Basic/Version.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,6 @@ std::string getSwiftFullVersion(Version effectiveLanguageVersion =
171171
/// this Swift was built.
172172
StringRef getSwiftRevision();
173173

174-
/// Is the running compiler built with a version tag for distribution?
175-
/// When true, \c version::getCurrentCompilerVersion returns a valid version
176-
/// and \c getCurrentCompilerTag returns the version tuple in string format.
177-
bool isCurrentCompilerTagged();
178-
179174
/// Retrieves the distribution tag of the running compiler, if any.
180175
StringRef getCurrentCompilerTag();
181176

lib/Basic/CMakeLists.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,8 @@ if(NOT "${SWIFT_VENDOR}" STREQUAL "")
134134
" -DSWIFT_VENDOR=\"\\\"${SWIFT_VENDOR}\\\"\"")
135135
endif()
136136

137-
set(SWIFT_COMPILER_VERSION "" CACHE STRING
138-
"The string that identifies the SCM commit(s) for this build")
139-
140137
message(STATUS "Swift compiler version: ${SWIFT_COMPILER_VERSION}")
138+
message(STATUS "Swift toolchain version: ${SWIFT_TOOLCHAIN_VERSION}")
141139
message(STATUS "Embedded clang compiler version: ${CLANG_COMPILER_VERSION}")
142140

143141
if(SWIFT_COMPILER_VERSION)
@@ -150,3 +148,7 @@ if(CLANG_COMPILER_VERSION)
150148
" -DCLANG_COMPILER_VERSION=\"\\\"${CLANG_COMPILER_VERSION}\\\"\"")
151149
endif()
152150

151+
if(SWIFT_TOOLCHAIN_VERSION)
152+
set_property(SOURCE Version.cpp APPEND_STRING PROPERTY COMPILE_FLAGS
153+
" -DSWIFT_TOOLCHAIN_VERSION=\"\\\"${SWIFT_TOOLCHAIN_VERSION}\\\"\"")
154+
endif()

lib/Basic/TargetInfo.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ void printTargetInfo(const CompilerInvocation &invocation,
6565
writeEscaped(version::getSwiftFullVersion(version::Version::getCurrentLanguageVersion()), out);
6666
out << "\",\n";
6767

68+
// Distribution tag, if any.
69+
StringRef tag = version::getCurrentCompilerTag();
70+
if (!tag.empty()) {
71+
out << " \"compilerTag\": \"";
72+
writeEscaped(tag, out);
73+
out << "\",\n";
74+
}
75+
6876
// Target triple and target variant triple.
6977
auto runtimeVersion =
7078
invocation.getIRGenOptions().AutolinkRuntimeCompatibilityLibraryVersion;

lib/Basic/Version.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -304,17 +304,9 @@ StringRef getSwiftRevision() {
304304
#endif
305305
}
306306

307-
bool isCurrentCompilerTagged() {
308-
#ifdef SWIFT_COMPILER_VERSION
309-
return true;
310-
#else
311-
return false;
312-
#endif
313-
}
314-
315307
StringRef getCurrentCompilerTag() {
316-
#ifdef SWIFT_COMPILER_VERSION
317-
return SWIFT_COMPILER_VERSION;
308+
#ifdef SWIFT_TOOLCHAIN_VERSION
309+
return SWIFT_TOOLCHAIN_VERSION;
318310
#else
319311
return StringRef();
320312
#endif

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,7 @@ class ModuleInterfaceLoaderImpl {
932932
return std::make_error_code(std::errc::not_supported);
933933
} else if (isInResourceDir(adjacentMod) &&
934934
loadMode == ModuleLoadingMode::PreferSerialized &&
935-
!version::isCurrentCompilerTagged() &&
935+
version::getCurrentCompilerSerializationTag().empty() &&
936936
rebuildInfo.getOrInsertCandidateModule(adjacentMod)
937937
.serializationStatus !=
938938
serialization::Status::SDKMismatch &&

lib/Serialization/ModuleFileSharedCore.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -433,10 +433,12 @@ static ValidationInfo validateControlBlock(
433433
::getenv("SWIFT_DEBUG_FORCE_SWIFTMODULE_REVISION");
434434

435435
StringRef moduleRevision = blobData;
436+
StringRef serializationTag =
437+
version::getCurrentCompilerSerializationTag();
436438
if (forcedDebugRevision ||
437-
(requiresRevisionMatch && version::isCurrentCompilerTagged())) {
438-
StringRef compilerRevision = forcedDebugRevision ?
439-
forcedDebugRevision : version::getCurrentCompilerSerializationTag();
439+
(requiresRevisionMatch && !serializationTag.empty())) {
440+
StringRef compilerRevision =
441+
forcedDebugRevision ? forcedDebugRevision : serializationTag;
440442
if (moduleRevision != compilerRevision) {
441443
// The module versions are mismatching, record it and diagnose later.
442444
result.problematicRevision = moduleRevision;

0 commit comments

Comments
 (0)