@@ -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+ 
6688void  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