Skip to content

Commit aa9aef4

Browse files
committed
[Target Info] Compute resource-directory relative to the SDK on non-Darwin targets
Since the new driver uses `-print-target-info` for the resource directory and the legacy C++ driver used the logic in `getResourceDirPath()`, mimic that logic now in the print-target-info job itself.
1 parent d8f381e commit aa9aef4

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

Diff for: include/swift/Frontend/Frontend.h

+4
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,10 @@ class CompilerInvocation {
262262
StringRef mainExecutablePath, bool shared,
263263
llvm::SmallVectorImpl<char> &runtimeResourcePath);
264264

265+
/// Computes the runtime resource path relative to the given Swift
266+
/// executable.
267+
std::string computeRuntimeResourcePathForTargetInfo();
268+
265269
/// Appends `lib/swift[_static]` to the given path
266270
static void appendSwiftLibDir(llvm::SmallVectorImpl<char> &path, bool shared);
267271

Diff for: lib/Frontend/CompilerInvocation.cpp

+28-1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,28 @@ getVersionTuple(const llvm::Triple &triple) {
6363
return triple.getOSVersion();
6464
}
6565

66+
std::string CompilerInvocation::computeRuntimeResourcePathForTargetInfo() {
67+
const auto &frontendOpts = getFrontendOptions();
68+
const auto &searchPathOpts = getSearchPathOptions();
69+
const auto &langOpts = getLangOptions();
70+
SmallString<128> resourceDirPath;
71+
if (!searchPathOpts.RuntimeResourcePath.empty()) {
72+
resourceDirPath = searchPathOpts.RuntimeResourcePath;
73+
} else if (!langOpts.Target.isOSDarwin() &&
74+
!searchPathOpts.getSDKPath().empty()) {
75+
StringRef value = searchPathOpts.getSDKPath();
76+
resourceDirPath.append(value.begin(), value.end());
77+
llvm::sys::path::append(resourceDirPath, "usr");
78+
CompilerInvocation::appendSwiftLibDir(resourceDirPath,
79+
frontendOpts.UseSharedResourceFolder);
80+
} else {
81+
CompilerInvocation::computeRuntimeResourcePathFromExecutablePath(frontendOpts.MainExecutablePath,
82+
frontendOpts.UseSharedResourceFolder,
83+
resourceDirPath);
84+
}
85+
return resourceDirPath.str().str();
86+
}
87+
6688
void CompilerInvocation::computeRuntimeResourcePathFromExecutablePath(
6789
StringRef mainExecutablePath, bool shared,
6890
llvm::SmallVectorImpl<char> &runtimeResourcePath) {
@@ -84,7 +106,9 @@ void CompilerInvocation::setMainExecutablePath(StringRef Path) {
84106
llvm::SmallString<128> LibPath;
85107
computeRuntimeResourcePathFromExecutablePath(
86108
Path, FrontendOpts.UseSharedResourceFolder, LibPath);
87-
setRuntimeResourcePath(LibPath.str());
109+
// Target info query computes the resource path wholesale
110+
if (!FrontendOpts.PrintTargetInfo)
111+
setRuntimeResourcePath(LibPath.str());
88112

89113
llvm::SmallString<128> clangPath(Path);
90114
llvm::sys::path::remove_filename(clangPath);
@@ -3552,6 +3576,9 @@ bool CompilerInvocation::parseArgs(
35523576
return true;
35533577
}
35543578

3579+
if (FrontendOpts.PrintTargetInfo)
3580+
setRuntimeResourcePath(computeRuntimeResourcePathForTargetInfo());
3581+
35553582
updateRuntimeLibraryPaths(SearchPathOpts, FrontendOpts, LangOpts);
35563583
setDefaultPrebuiltCacheIfNecessary();
35573584
setDefaultBlocklistsIfNecessary();

0 commit comments

Comments
 (0)