Skip to content

[SymbolGraph] Add macCatalyst compatibility #30393

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/swift/Frontend/Frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@ class CompilerInvocation {

void setRuntimeResourcePath(StringRef Path);

/// If we haven't explicitly passed -prebuilt-module-cache-path, set it to
/// the default value of <resource-dir>/<platform>/prebuilt-modules.
/// @note This should be called once, after search path options and frontend
/// options have been parsed.
void setDefaultPrebuiltCacheIfNecessary();

/// Computes the runtime resource path relative to the given Swift
/// executable.
static void computeRuntimeResourcePathFromExecutablePath(
Expand Down
25 changes: 9 additions & 16 deletions lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,30 +59,24 @@ void CompilerInvocation::setMainExecutablePath(StringRef Path) {
DiagnosticOpts.DiagnosticDocumentationPath = DiagnosticDocsPath.str();
}

/// If we haven't explicitly passed -prebuilt-module-cache-path, set it to
/// the default value of <resource-dir>/<platform>/prebuilt-modules.
/// @note This should be called once, after search path options and frontend
/// options have been parsed.
static void setDefaultPrebuiltCacheIfNecessary(
FrontendOptions &frontendOpts, const SearchPathOptions &searchPathOpts,
const llvm::Triple &triple) {

if (!frontendOpts.PrebuiltModuleCachePath.empty())
void CompilerInvocation::setDefaultPrebuiltCacheIfNecessary() {

if (!FrontendOpts.PrebuiltModuleCachePath.empty())
return;
if (searchPathOpts.RuntimeResourcePath.empty())
if (SearchPathOpts.RuntimeResourcePath.empty())
return;

SmallString<64> defaultPrebuiltPath{searchPathOpts.RuntimeResourcePath};
SmallString<64> defaultPrebuiltPath{SearchPathOpts.RuntimeResourcePath};
StringRef platform;
if (tripleIsMacCatalystEnvironment(triple)) {
if (tripleIsMacCatalystEnvironment(LangOpts.Target)) {
// The prebuilt cache for macCatalyst is the same as the one for macOS, not iOS
// or a separate location of its own.
platform = "macosx";
} else {
platform = getPlatformNameForTriple(triple);
platform = getPlatformNameForTriple(LangOpts.Target);
}
llvm::sys::path::append(defaultPrebuiltPath, platform, "prebuilt-modules");
frontendOpts.PrebuiltModuleCachePath = defaultPrebuiltPath.str();
FrontendOpts.PrebuiltModuleCachePath = defaultPrebuiltPath.str();
}

static void updateRuntimeLibraryPaths(SearchPathOptions &SearchPathOpts,
Expand Down Expand Up @@ -1597,8 +1591,7 @@ bool CompilerInvocation::parseArgs(
}

updateRuntimeLibraryPaths(SearchPathOpts, LangOpts.Target);
setDefaultPrebuiltCacheIfNecessary(FrontendOpts, SearchPathOpts,
LangOpts.Target);
setDefaultPrebuiltCacheIfNecessary();

// Now that we've parsed everything, setup some inter-option-dependent state.
setIRGenOutputOptsFromFrontendOptions(IRGenOpts, FrontendOpts);
Expand Down
16 changes: 16 additions & 0 deletions tools/driver/swift_symbolgraph_extract_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ static llvm::cl::list<std::string>
FrameworkSearchPaths("F", llvm::cl::desc("Add a directory to the framework search paths"), llvm::cl::ZeroOrMore,
llvm::cl::cat(Category));

static llvm::cl::list<std::string>
SystemFrameworkSearchPaths("Fsystem", llvm::cl::desc("Add directory to system framework search path"), llvm::cl::ZeroOrMore,
llvm::cl::cat(Category));

static llvm::cl::list<std::string>
LibrarySearchPaths("L", llvm::cl::desc("Add a directory to the library search paths"), llvm::cl::ZeroOrMore,
llvm::cl::cat(Category));
Expand Down Expand Up @@ -75,6 +79,11 @@ static llvm::cl::list<std::string>
Xcc("Xcc", llvm::cl::desc("Pass the following command-line flag to Clang"),
llvm::cl::cat(Category));

static llvm::cl::opt<std::string>
ResourceDir("resource-dir",
llvm::cl::desc("Override the directory that holds the compiler resource files"),
llvm::cl::cat(Category));

static llvm::cl::opt<std::string>
OutputDir("output-dir", llvm::cl::desc("Symbol Graph JSON Output Directory (Required)"), llvm::cl::cat(Category));
} // end namespace options
Expand Down Expand Up @@ -132,6 +141,9 @@ int swift_symbolgraph_extract_main(ArrayRef<const char *> Args, const char *Argv
Invocation.setMainExecutablePath(
llvm::sys::fs::getMainExecutable(Argv0, MainAddr));
Invocation.setModuleName("swift_symbolgraph_extract");
if (!options::ResourceDir.empty()) {
Invocation.setRuntimeResourcePath(options::ResourceDir);
}
Invocation.setSDKPath(options::SDK);
Invocation.setTargetTriple(options::Target);

Expand All @@ -143,6 +155,9 @@ int swift_symbolgraph_extract_main(ArrayRef<const char *> Args, const char *Argv
for (const auto &Path : options::FrameworkSearchPaths) {
FrameworkSearchPaths.push_back({ Path, /*isSystem*/ false});
}
for (const auto &Path : options::SystemFrameworkSearchPaths) {
FrameworkSearchPaths.push_back({ Path, /*isSystem*/ true });
}
Invocation.setFrameworkSearchPaths(FrameworkSearchPaths);
Invocation.getSearchPathOptions().LibrarySearchPaths = options::LibrarySearchPaths;
Invocation.setImportSearchPaths(options::ImportSearchPaths);
Expand All @@ -154,6 +169,7 @@ int swift_symbolgraph_extract_main(ArrayRef<const char *> Args, const char *Argv

Invocation.setClangModuleCachePath(options::ModuleCachePath);
Invocation.getClangImporterOptions().ModuleCachePath = options::ModuleCachePath;
Invocation.setDefaultPrebuiltCacheIfNecessary();

if (!options::SwiftVersion.empty()) {
using version::Version;
Expand Down