Skip to content

[5.2] [Driver] Add unversioned triple to the output of -print-target-info. #28875

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

Merged
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
4 changes: 3 additions & 1 deletion include/swift/Basic/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ namespace swift {
/// llvm::Triple::normalize() would not affect it.
llvm::Triple getTargetSpecificModuleTriple(const llvm::Triple &triple);


/// Computes the target triple without version information.
llvm::Triple getUnversionedTriple(const llvm::Triple &triple);

/// Get the Swift runtime version to deploy back to, given a deployment target expressed as an
/// LLVM target triple.
Optional<llvm::VersionTuple>
Expand Down
14 changes: 14 additions & 0 deletions lib/Basic/Platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,20 @@ llvm::Triple swift::getTargetSpecificModuleTriple(const llvm::Triple &triple) {
return triple;
}

llvm::Triple swift::getUnversionedTriple(const llvm::Triple &triple) {
StringRef unversionedOSName = triple.getOSName().take_until(llvm::isDigit);
if (triple.getEnvironment()) {
StringRef environment =
llvm::Triple::getEnvironmentTypeName(triple.getEnvironment());

return llvm::Triple(triple.getArchName(), triple.getVendorName(),
unversionedOSName, environment);
}

return llvm::Triple(triple.getArchName(), triple.getVendorName(),
unversionedOSName);
}

Optional<llvm::VersionTuple>
swift::getSwiftRuntimeCompatibilityVersionForTarget(
const llvm::Triple &Triple) {
Expand Down
4 changes: 4 additions & 0 deletions lib/FrontendTool/FrontendTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1880,6 +1880,10 @@ static void printTargetInfo(CompilerInvocation &invocation,
out.write_escaped(langOpts.Target.getTriple());
out << "\",\n";

out << " \"unversionedTriple\": \"";
out.write_escaped(getUnversionedTriple(langOpts.Target).getTriple());
out << "\",\n";

out << " \"moduleTriple\": \"";
out.write_escaped(getTargetSpecificModuleTriple(langOpts.Target).getTriple());
out << "\",\n";
Expand Down
1 change: 1 addition & 0 deletions test/Driver/print_target_info.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

// CHECK-IOS: "target": {
// CHECK-IOS: "triple": "arm64-apple-ios12.0",
// CHECK-IOS: "unversionedTriple": "arm64-apple-ios",
// CHECK-IOS: "moduleTriple": "arm64-apple-ios",
// CHECK-IOS: "swiftRuntimeCompatibilityVersion": "5.0",
// CHECK-IOS: "librariesRequireRPath": true
Expand Down
3 changes: 2 additions & 1 deletion test/Driver/print_target_info_macos.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@

// REQUIRES: OS=macosx

// CHECK: "triple": "x86_64-apple-macosx
// CHECK: "triple": "x86_64-apple-macosx10
// CHECK: "unversionedTriple": "x86_64-apple-macosx"