Skip to content

Commit 710799d

Browse files
authored
Merge pull request #30393 from bitjammer/acgarland/rdar-59262057-ssge-maccatalyst
[SymbolGraph] Add macCatalyst compatibility
2 parents fcf95ea + 8f96f67 commit 710799d

File tree

3 files changed

+31
-16
lines changed

3 files changed

+31
-16
lines changed

include/swift/Frontend/Frontend.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,12 @@ class CompilerInvocation {
203203

204204
void setRuntimeResourcePath(StringRef Path);
205205

206+
/// If we haven't explicitly passed -prebuilt-module-cache-path, set it to
207+
/// the default value of <resource-dir>/<platform>/prebuilt-modules.
208+
/// @note This should be called once, after search path options and frontend
209+
/// options have been parsed.
210+
void setDefaultPrebuiltCacheIfNecessary();
211+
206212
/// Computes the runtime resource path relative to the given Swift
207213
/// executable.
208214
static void computeRuntimeResourcePathFromExecutablePath(

lib/Frontend/CompilerInvocation.cpp

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -59,30 +59,24 @@ void CompilerInvocation::setMainExecutablePath(StringRef Path) {
5959
DiagnosticOpts.DiagnosticDocumentationPath = DiagnosticDocsPath.str();
6060
}
6161

62-
/// If we haven't explicitly passed -prebuilt-module-cache-path, set it to
63-
/// the default value of <resource-dir>/<platform>/prebuilt-modules.
64-
/// @note This should be called once, after search path options and frontend
65-
/// options have been parsed.
66-
static void setDefaultPrebuiltCacheIfNecessary(
67-
FrontendOptions &frontendOpts, const SearchPathOptions &searchPathOpts,
68-
const llvm::Triple &triple) {
69-
70-
if (!frontendOpts.PrebuiltModuleCachePath.empty())
62+
void CompilerInvocation::setDefaultPrebuiltCacheIfNecessary() {
63+
64+
if (!FrontendOpts.PrebuiltModuleCachePath.empty())
7165
return;
72-
if (searchPathOpts.RuntimeResourcePath.empty())
66+
if (SearchPathOpts.RuntimeResourcePath.empty())
7367
return;
7468

75-
SmallString<64> defaultPrebuiltPath{searchPathOpts.RuntimeResourcePath};
69+
SmallString<64> defaultPrebuiltPath{SearchPathOpts.RuntimeResourcePath};
7670
StringRef platform;
77-
if (tripleIsMacCatalystEnvironment(triple)) {
71+
if (tripleIsMacCatalystEnvironment(LangOpts.Target)) {
7872
// The prebuilt cache for macCatalyst is the same as the one for macOS, not iOS
7973
// or a separate location of its own.
8074
platform = "macosx";
8175
} else {
82-
platform = getPlatformNameForTriple(triple);
76+
platform = getPlatformNameForTriple(LangOpts.Target);
8377
}
8478
llvm::sys::path::append(defaultPrebuiltPath, platform, "prebuilt-modules");
85-
frontendOpts.PrebuiltModuleCachePath = defaultPrebuiltPath.str();
79+
FrontendOpts.PrebuiltModuleCachePath = defaultPrebuiltPath.str();
8680
}
8781

8882
static void updateRuntimeLibraryPaths(SearchPathOptions &SearchPathOpts,
@@ -1599,8 +1593,7 @@ bool CompilerInvocation::parseArgs(
15991593
}
16001594

16011595
updateRuntimeLibraryPaths(SearchPathOpts, LangOpts.Target);
1602-
setDefaultPrebuiltCacheIfNecessary(FrontendOpts, SearchPathOpts,
1603-
LangOpts.Target);
1596+
setDefaultPrebuiltCacheIfNecessary();
16041597

16051598
// Now that we've parsed everything, setup some inter-option-dependent state.
16061599
setIRGenOutputOptsFromFrontendOptions(IRGenOpts, FrontendOpts);

tools/driver/swift_symbolgraph_extract_main.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ static llvm::cl::list<std::string>
3838
FrameworkSearchPaths("F", llvm::cl::desc("Add a directory to the framework search paths"), llvm::cl::ZeroOrMore,
3939
llvm::cl::cat(Category));
4040

41+
static llvm::cl::list<std::string>
42+
SystemFrameworkSearchPaths("Fsystem", llvm::cl::desc("Add directory to system framework search path"), llvm::cl::ZeroOrMore,
43+
llvm::cl::cat(Category));
44+
4145
static llvm::cl::list<std::string>
4246
LibrarySearchPaths("L", llvm::cl::desc("Add a directory to the library search paths"), llvm::cl::ZeroOrMore,
4347
llvm::cl::cat(Category));
@@ -75,6 +79,11 @@ static llvm::cl::list<std::string>
7579
Xcc("Xcc", llvm::cl::desc("Pass the following command-line flag to Clang"),
7680
llvm::cl::cat(Category));
7781

82+
static llvm::cl::opt<std::string>
83+
ResourceDir("resource-dir",
84+
llvm::cl::desc("Override the directory that holds the compiler resource files"),
85+
llvm::cl::cat(Category));
86+
7887
static llvm::cl::opt<std::string>
7988
OutputDir("output-dir", llvm::cl::desc("Symbol Graph JSON Output Directory (Required)"), llvm::cl::cat(Category));
8089
} // end namespace options
@@ -132,6 +141,9 @@ int swift_symbolgraph_extract_main(ArrayRef<const char *> Args, const char *Argv
132141
Invocation.setMainExecutablePath(
133142
llvm::sys::fs::getMainExecutable(Argv0, MainAddr));
134143
Invocation.setModuleName("swift_symbolgraph_extract");
144+
if (!options::ResourceDir.empty()) {
145+
Invocation.setRuntimeResourcePath(options::ResourceDir);
146+
}
135147
Invocation.setSDKPath(options::SDK);
136148
Invocation.setTargetTriple(options::Target);
137149

@@ -143,6 +155,9 @@ int swift_symbolgraph_extract_main(ArrayRef<const char *> Args, const char *Argv
143155
for (const auto &Path : options::FrameworkSearchPaths) {
144156
FrameworkSearchPaths.push_back({ Path, /*isSystem*/ false});
145157
}
158+
for (const auto &Path : options::SystemFrameworkSearchPaths) {
159+
FrameworkSearchPaths.push_back({ Path, /*isSystem*/ true });
160+
}
146161
Invocation.setFrameworkSearchPaths(FrameworkSearchPaths);
147162
Invocation.getSearchPathOptions().LibrarySearchPaths = options::LibrarySearchPaths;
148163
Invocation.setImportSearchPaths(options::ImportSearchPaths);
@@ -154,6 +169,7 @@ int swift_symbolgraph_extract_main(ArrayRef<const char *> Args, const char *Argv
154169

155170
Invocation.setClangModuleCachePath(options::ModuleCachePath);
156171
Invocation.getClangImporterOptions().ModuleCachePath = options::ModuleCachePath;
172+
Invocation.setDefaultPrebuiltCacheIfNecessary();
157173

158174
if (!options::SwiftVersion.empty()) {
159175
using version::Version;

0 commit comments

Comments
 (0)