Skip to content

Commit c92600b

Browse files
committed
[Frontend] Add some paths to the output of -print-target-info.
Add various target-specific and compiler-determined paths to the output of `-print-target-info`, such as the runtime resource path, SDK path, and runtime library paths.
1 parent 61c83d2 commit c92600b

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

lib/Driver/Driver.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2126,9 +2126,18 @@ bool Driver::handleImmediateArgs(const ArgList &Args, const ToolChain &TC) {
21262126
SmallVector<const char *, 5> commandLine;
21272127
commandLine.push_back("-frontend");
21282128
commandLine.push_back("-print-target-info");
2129-
if (const Arg *TargetArg = Args.getLastArg(options::OPT_target)) {
2129+
if (const Arg *targetArg = Args.getLastArg(options::OPT_target)) {
21302130
commandLine.push_back("-target");
2131-
commandLine.push_back(TargetArg->getValue());
2131+
commandLine.push_back(targetArg->getValue());
2132+
}
2133+
if (const Arg *sdkArg = Args.getLastArg(options::OPT_sdk)) {
2134+
commandLine.push_back("-sdk");
2135+
commandLine.push_back(sdkArg->getValue());
2136+
}
2137+
2138+
if (const Arg *resourceDirArg = Args.getLastArg(options::OPT_resource_dir)) {
2139+
commandLine.push_back("-resource-dir");
2140+
commandLine.push_back(resourceDirArg->getValue());
21322141
}
21332142

21342143
std::string executable = getSwiftProgramPath();

lib/FrontendTool/FrontendTool.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1892,6 +1892,38 @@ static void printTargetInfo(CompilerInvocation &invocation,
18921892
<< (tripleRequiresRPathForSwiftInOS(langOpts.Target) ? "true" : "false")
18931893
<< "\n";
18941894

1895+
out << " },\n";
1896+
1897+
// Various paths.
1898+
auto &searchOpts = invocation.getSearchPathOptions();
1899+
out << " \"paths\": {\n";
1900+
1901+
if (!searchOpts.SDKPath.empty()) {
1902+
out << " \"sdkPath\": \"";
1903+
out.write_escaped(searchOpts.SDKPath);
1904+
out << "\",\n";
1905+
}
1906+
1907+
auto outputPaths = [&](StringRef name, const std::vector<std::string> &paths){
1908+
out << " \"" << name << "\": [\n";
1909+
interleave(paths, [&out](const std::string &path) {
1910+
out << " \"";
1911+
out.write_escaped(path);
1912+
out << "\"";
1913+
}, [&out] {
1914+
out << ",\n";
1915+
});
1916+
out << "\n ],\n";
1917+
};
1918+
1919+
outputPaths("runtimeLibraryPaths", searchOpts.RuntimeLibraryPaths);
1920+
outputPaths("runtimeLibraryImportPaths",
1921+
searchOpts.RuntimeLibraryImportPaths);
1922+
1923+
out << " \"runtimeResourcePath\": \"";
1924+
out.write_escaped(searchOpts.RuntimeResourcePath);
1925+
out << "\"\n";
1926+
18951927
out << " }\n";
18961928

18971929
out << "}\n";

test/Driver/print_target_info.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
// CHECK-IOS: "librariesRequireRPath": true
1212
// CHECK-IOS: }
1313

14+
// CHECK-IOS: "paths": {
15+
// CHECK-IOS: "runtimeLibraryPaths": [
16+
// CHECK-IOS: "runtimeResourcePath":{{.*}}lib{{(/|\\)}}swift"
17+
// CHECK-IOS: }
18+
19+
1420
// CHECK-LINUX: "target": {
1521
// CHECK-LINUX: "triple": "x86_64-unknown-linux",
1622
// CHECK-LINUX: "moduleTriple": "x86_64-unknown-linux",

0 commit comments

Comments
 (0)