Skip to content

Add the distribution tag to -print-target-info #81697

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 0 additions & 5 deletions include/swift/Basic/Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
8 changes: 5 additions & 3 deletions lib/Basic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
8 changes: 8 additions & 0 deletions lib/Basic/TargetInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 2 additions & 10 deletions lib/Basic/Version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/Frontend/ModuleInterfaceLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
10 changes: 6 additions & 4 deletions lib/Serialization/ModuleFileSharedCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down