diff --git a/CMakeLists.txt b/CMakeLists.txt index 11ee875cffebc..e0b0ca0b83a7a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -336,6 +336,8 @@ set(SWIFT_COMPILER_VERSION "" CACHE STRING "The internal version of the Swift compiler") set(CLANG_COMPILER_VERSION "" CACHE STRING "The internal version of the Clang compiler") +set(SWIFT_TOOLCHAIN_VERSION "" CACHE STRING + "The Swift compiler tag") option(SWIFT_DISABLE_DEAD_STRIPPING "Turn off Darwin-specific dead stripping for Swift host tools." FALSE) diff --git a/include/swift/Basic/Version.h b/include/swift/Basic/Version.h index a97ef7eec93b2..e43ce5c7b01e5 100644 --- a/include/swift/Basic/Version.h +++ b/include/swift/Basic/Version.h @@ -171,11 +171,6 @@ std::string getSwiftFullVersion(Version effectiveLanguageVersion = /// this Swift was built. StringRef getSwiftRevision(); -/// Is the running compiler built with a version tag for distribution? -/// When true, \c version::getCurrentCompilerVersion returns a valid version -/// and \c getCurrentCompilerTag returns the version tuple in string format. -bool isCurrentCompilerTagged(); - /// Retrieves the distribution tag of the running compiler, if any. StringRef getCurrentCompilerTag(); diff --git a/lib/Basic/CMakeLists.txt b/lib/Basic/CMakeLists.txt index bf5520fe0e2b9..8dea0082b88fe 100644 --- a/lib/Basic/CMakeLists.txt +++ b/lib/Basic/CMakeLists.txt @@ -134,10 +134,8 @@ if(NOT "${SWIFT_VENDOR}" STREQUAL "") " -DSWIFT_VENDOR=\"\\\"${SWIFT_VENDOR}\\\"\"") endif() -set(SWIFT_COMPILER_VERSION "" CACHE STRING - "The string that identifies the SCM commit(s) for this build") - message(STATUS "Swift compiler version: ${SWIFT_COMPILER_VERSION}") +message(STATUS "Swift toolchain version: ${SWIFT_TOOLCHAIN_VERSION}") message(STATUS "Embedded clang compiler version: ${CLANG_COMPILER_VERSION}") if(SWIFT_COMPILER_VERSION) @@ -150,3 +148,7 @@ if(CLANG_COMPILER_VERSION) " -DCLANG_COMPILER_VERSION=\"\\\"${CLANG_COMPILER_VERSION}\\\"\"") endif() +if(SWIFT_TOOLCHAIN_VERSION) + set_property(SOURCE Version.cpp APPEND_STRING PROPERTY COMPILE_FLAGS + " -DSWIFT_TOOLCHAIN_VERSION=\"\\\"${SWIFT_TOOLCHAIN_VERSION}\\\"\"") +endif() diff --git a/lib/Basic/TargetInfo.cpp b/lib/Basic/TargetInfo.cpp index 53f3a219d7205..929b0266aa498 100644 --- a/lib/Basic/TargetInfo.cpp +++ b/lib/Basic/TargetInfo.cpp @@ -65,6 +65,14 @@ void printTargetInfo(const CompilerInvocation &invocation, writeEscaped(version::getSwiftFullVersion(version::Version::getCurrentLanguageVersion()), out); out << "\",\n"; + // Distribution tag, if any. + StringRef tag = version::getCurrentCompilerTag(); + if (!tag.empty()) { + out << " \"compilerTag\": \""; + writeEscaped(tag, out); + out << "\",\n"; + } + // Target triple and target variant triple. auto runtimeVersion = invocation.getIRGenOptions().AutolinkRuntimeCompatibilityLibraryVersion; diff --git a/lib/Basic/Version.cpp b/lib/Basic/Version.cpp index 13eb04be0db84..5dfdb030278c1 100644 --- a/lib/Basic/Version.cpp +++ b/lib/Basic/Version.cpp @@ -304,17 +304,9 @@ StringRef getSwiftRevision() { #endif } -bool isCurrentCompilerTagged() { -#ifdef SWIFT_COMPILER_VERSION - return true; -#else - return false; -#endif -} - StringRef getCurrentCompilerTag() { -#ifdef SWIFT_COMPILER_VERSION - return SWIFT_COMPILER_VERSION; +#ifdef SWIFT_TOOLCHAIN_VERSION + return SWIFT_TOOLCHAIN_VERSION; #else return StringRef(); #endif diff --git a/lib/Frontend/ModuleInterfaceLoader.cpp b/lib/Frontend/ModuleInterfaceLoader.cpp index 002918eb63c6d..1c28f550e68d6 100644 --- a/lib/Frontend/ModuleInterfaceLoader.cpp +++ b/lib/Frontend/ModuleInterfaceLoader.cpp @@ -932,7 +932,7 @@ class ModuleInterfaceLoaderImpl { return std::make_error_code(std::errc::not_supported); } else if (isInResourceDir(adjacentMod) && loadMode == ModuleLoadingMode::PreferSerialized && - !version::isCurrentCompilerTagged() && + version::getCurrentCompilerSerializationTag().empty() && rebuildInfo.getOrInsertCandidateModule(adjacentMod) .serializationStatus != serialization::Status::SDKMismatch && diff --git a/lib/Serialization/ModuleFileSharedCore.cpp b/lib/Serialization/ModuleFileSharedCore.cpp index 4d014d1990bde..f62a28871978f 100644 --- a/lib/Serialization/ModuleFileSharedCore.cpp +++ b/lib/Serialization/ModuleFileSharedCore.cpp @@ -392,7 +392,7 @@ static ValidationInfo validateControlBlock( // env var is set (for testing). static const char* forceDebugPreSDKRestriction = ::getenv("SWIFT_DEBUG_FORCE_SWIFTMODULE_PER_SDK"); - if (!version::isCurrentCompilerTagged() && + if (version::getCurrentCompilerSerializationTag().empty() && !forceDebugPreSDKRestriction) { break; } @@ -433,10 +433,12 @@ static ValidationInfo validateControlBlock( ::getenv("SWIFT_DEBUG_FORCE_SWIFTMODULE_REVISION"); StringRef moduleRevision = blobData; + StringRef serializationTag = + version::getCurrentCompilerSerializationTag(); if (forcedDebugRevision || - (requiresRevisionMatch && version::isCurrentCompilerTagged())) { - StringRef compilerRevision = forcedDebugRevision ? - forcedDebugRevision : version::getCurrentCompilerSerializationTag(); + (requiresRevisionMatch && !serializationTag.empty())) { + StringRef compilerRevision = + forcedDebugRevision ? forcedDebugRevision : serializationTag; if (moduleRevision != compilerRevision) { // The module versions are mismatching, record it and diagnose later. result.problematicRevision = moduleRevision;