Skip to content

Commit f451dc4

Browse files
authored
Merge pull request #28646 from DougGregor/print-target-info-paths
[Frontend] Add some paths to the output of -print-target-info.
2 parents 01f46b3 + c92600b commit f451dc4

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
@@ -2128,9 +2128,18 @@ bool Driver::handleImmediateArgs(const ArgList &Args, const ToolChain &TC) {
21282128
SmallVector<const char *, 5> commandLine;
21292129
commandLine.push_back("-frontend");
21302130
commandLine.push_back("-print-target-info");
2131-
if (const Arg *TargetArg = Args.getLastArg(options::OPT_target)) {
2131+
if (const Arg *targetArg = Args.getLastArg(options::OPT_target)) {
21322132
commandLine.push_back("-target");
2133-
commandLine.push_back(TargetArg->getValue());
2133+
commandLine.push_back(targetArg->getValue());
2134+
}
2135+
if (const Arg *sdkArg = Args.getLastArg(options::OPT_sdk)) {
2136+
commandLine.push_back("-sdk");
2137+
commandLine.push_back(sdkArg->getValue());
2138+
}
2139+
2140+
if (const Arg *resourceDirArg = Args.getLastArg(options::OPT_resource_dir)) {
2141+
commandLine.push_back("-resource-dir");
2142+
commandLine.push_back(resourceDirArg->getValue());
21342143
}
21352144

21362145
std::string executable = getSwiftProgramPath();

lib/FrontendTool/FrontendTool.cpp

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

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

19001932
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)