Skip to content

Commit 6612e9c

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 0f5dc13 commit 6612e9c

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
@@ -254,6 +254,10 @@ class CompilerInvocation {
254254
StringRef mainExecutablePath, bool shared,
255255
llvm::SmallVectorImpl<char> &runtimeResourcePath);
256256

257+
/// Computes the runtime resource path relative to the given Swift
258+
/// executable.
259+
void computeRuntimeResourcePathForTargetInfo();
260+
257261
/// Appends `lib/swift[_static]` to the given path
258262
static void appendSwiftLibDir(llvm::SmallVectorImpl<char> &path, bool shared);
259263

Diff for: lib/Frontend/CompilerInvocation.cpp

+28-1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,28 @@ getVersionTuple(const llvm::Triple &triple) {
6060
return triple.getOSVersion();
6161
}
6262

63+
void CompilerInvocation::computeRuntimeResourcePathForTargetInfo() {
64+
const auto &frontendOpts = getFrontendOptions();
65+
const auto &searchPathOpts = getSearchPathOptions();
66+
const auto &langOpts = getLangOptions();
67+
SmallString<128> resourceDirPath;
68+
if (!searchPathOpts.RuntimeResourcePath.empty()) {
69+
resourceDirPath = searchPathOpts.RuntimeResourcePath;
70+
} else if (!langOpts.Target.isOSDarwin() &&
71+
!searchPathOpts.getSDKPath().empty()) {
72+
StringRef value = searchPathOpts.getSDKPath();
73+
resourceDirPath.append(value.begin(), value.end());
74+
llvm::sys::path::append(resourceDirPath, "usr");
75+
CompilerInvocation::appendSwiftLibDir(resourceDirPath,
76+
frontendOpts.UseSharedResourceFolder);
77+
} else {
78+
CompilerInvocation::computeRuntimeResourcePathFromExecutablePath(frontendOpts.MainExecutablePath,
79+
frontendOpts.UseSharedResourceFolder,
80+
resourceDirPath);
81+
}
82+
setRuntimeResourcePath(resourceDirPath.str().str());
83+
}
84+
6385
void CompilerInvocation::computeRuntimeResourcePathFromExecutablePath(
6486
StringRef mainExecutablePath, bool shared,
6587
llvm::SmallVectorImpl<char> &runtimeResourcePath) {
@@ -81,7 +103,9 @@ void CompilerInvocation::setMainExecutablePath(StringRef Path) {
81103
llvm::SmallString<128> LibPath;
82104
computeRuntimeResourcePathFromExecutablePath(
83105
Path, FrontendOpts.UseSharedResourceFolder, LibPath);
84-
setRuntimeResourcePath(LibPath.str());
106+
// Target info query computes the resource path wholesale
107+
if (!FrontendOpts.PrintTargetInfo)
108+
setRuntimeResourcePath(LibPath.str());
85109

86110
llvm::SmallString<128> clangPath(Path);
87111
llvm::sys::path::remove_filename(clangPath);
@@ -3359,6 +3383,9 @@ bool CompilerInvocation::parseArgs(
33593383
return true;
33603384
}
33613385

3386+
if (FrontendOpts.PrintTargetInfo)
3387+
computeRuntimeResourcePathForTargetInfo();
3388+
33623389
updateRuntimeLibraryPaths(SearchPathOpts, FrontendOpts, LangOpts);
33633390
setDefaultPrebuiltCacheIfNecessary();
33643391
setDefaultBlocklistsIfNecessary();

0 commit comments

Comments
 (0)