1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
|
//===--- TargetInfo.cpp - Target information printing --------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
#include "swift/Basic/TargetInfo.h"
#include "swift/Basic/Version.h"
#include "swift/Basic/Platform.h"
#include "swift/Basic/StringExtras.h"
#include "swift/Frontend/Frontend.h"
#include "llvm/Support/raw_ostream.h"
using namespace swift;
/// Print information about a
static void printCompatibilityLibrary(
llvm::VersionTuple runtimeVersion, llvm::VersionTuple maxVersion,
StringRef filter, StringRef libraryName, bool forceLoad,
bool &printedAny, llvm::raw_ostream &out) {
if (runtimeVersion > maxVersion)
return;
if (printedAny) {
out << ",";
}
out << "\n";
out << " {";
out << "\n \"libraryName\": \"";
swift::writeEscaped(libraryName, out);
out << "\",";
out << "\n \"filter\": \"";
swift::writeEscaped(filter, out);
out << "\"";
if (!forceLoad) {
out << ",\n \"forceLoad\": false";
}
out << "\n }";
printedAny = true;
}
/// Print information about the selected target in JSON.
void targetinfo::printTargetInfo(const CompilerInvocation &invocation,
llvm::raw_ostream &out) {
out << "{\n";
// Compiler version, as produced by --version.
out << " \"compilerVersion\": \"";
writeEscaped(version::getSwiftFullVersion(version::Version::getCurrentLanguageVersion()), out);
out << "\",\n";
// Target triple and target variant triple.
auto runtimeVersion =
invocation.getIRGenOptions().AutolinkRuntimeCompatibilityLibraryVersion;
auto &langOpts = invocation.getLangOptions();
out << " \"target\": ";
printTripleInfo(langOpts.Target, runtimeVersion, out);
out << ",\n";
if (auto &variant = langOpts.TargetVariant) {
out << " \"targetVariant\": ";
printTripleInfo(*variant, runtimeVersion, out);
out << ",\n";
}
// Various paths.
auto &searchOpts = invocation.getSearchPathOptions();
out << " \"paths\": {\n";
if (!searchOpts.getSDKPath().empty()) {
out << " \"sdkPath\": \"";
writeEscaped(searchOpts.getSDKPath(), out);
out << "\",\n";
}
auto outputPaths = [&](StringRef name, const std::vector<std::string> &paths){
out << " \"" << name << "\": [\n";
llvm::interleave(paths, [&out](const std::string &path) {
out << " \"";
writeEscaped(path, out);
out << "\"";
}, [&out] {
out << ",\n";
});
out << "\n ],\n";
};
outputPaths("runtimeLibraryPaths", searchOpts.RuntimeLibraryPaths);
outputPaths("runtimeLibraryImportPaths",
searchOpts.getRuntimeLibraryImportPaths());
out << " \"runtimeResourcePath\": \"";
writeEscaped(searchOpts.RuntimeResourcePath, out);
out << "\"\n";
out << " }\n";
out << "}\n";
}
// Print information about the target triple in JSON.
void targetinfo::printTripleInfo(
const llvm::Triple &triple,
std::optional<llvm::VersionTuple> runtimeVersion, llvm::raw_ostream &out) {
out << "{\n";
out << " \"triple\": \"";
writeEscaped(triple.getTriple(), out);
out << "\",\n";
out << " \"unversionedTriple\": \"";
writeEscaped(getUnversionedTriple(triple).getTriple(), out);
out << "\",\n";
out << " \"moduleTriple\": \"";
writeEscaped(getTargetSpecificModuleTriple(triple).getTriple(), out);
out << "\",\n";
if (runtimeVersion) {
out << " \"swiftRuntimeCompatibilityVersion\": \"";
writeEscaped(runtimeVersion->getAsString(), out);
out << "\",\n";
// Compatibility libraries that need to be linked.
out << " \"compatibilityLibraries\": [";
bool printedAnyCompatibilityLibrary = false;
#define BACK_DEPLOYMENT_LIB(Version, Filter, LibraryName, ForceLoad) \
printCompatibilityLibrary( \
*runtimeVersion, llvm::VersionTuple Version, #Filter, LibraryName, \
ForceLoad, printedAnyCompatibilityLibrary, out);
#include "swift/Frontend/BackDeploymentLibs.def"
if (printedAnyCompatibilityLibrary) {
out << "\n ";
}
out << " ],\n";
} else {
out << " \"compatibilityLibraries\": [ ],\n";
}
out << " \"librariesRequireRPath\": "
<< (tripleRequiresRPathForSwiftLibrariesInOS(triple) ? "true" : "false")
<< "\n";
out << " }";
}
|