@@ -60,6 +60,28 @@ getVersionTuple(const llvm::Triple &triple) {
60
60
return triple.getOSVersion ();
61
61
}
62
62
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
+
63
85
void CompilerInvocation::computeRuntimeResourcePathFromExecutablePath (
64
86
StringRef mainExecutablePath, bool shared,
65
87
llvm::SmallVectorImpl<char > &runtimeResourcePath) {
@@ -81,7 +103,9 @@ void CompilerInvocation::setMainExecutablePath(StringRef Path) {
81
103
llvm::SmallString<128 > LibPath;
82
104
computeRuntimeResourcePathFromExecutablePath (
83
105
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 ());
85
109
86
110
llvm::SmallString<128 > clangPath (Path);
87
111
llvm::sys::path::remove_filename (clangPath);
@@ -3359,6 +3383,9 @@ bool CompilerInvocation::parseArgs(
3359
3383
return true ;
3360
3384
}
3361
3385
3386
+ if (FrontendOpts.PrintTargetInfo )
3387
+ computeRuntimeResourcePathForTargetInfo ();
3388
+
3362
3389
updateRuntimeLibraryPaths (SearchPathOpts, FrontendOpts, LangOpts);
3363
3390
setDefaultPrebuiltCacheIfNecessary ();
3364
3391
setDefaultBlocklistsIfNecessary ();
0 commit comments