[CAS] Improve swift cas options

Using the same CASOption from clang to communicate CAS configurations so
it is easier to exchange CAS configuration between them.
This commit is contained in:
Steven Wu
2023-06-12 15:33:35 -07:00
parent b1b16981fe
commit 2b7d38dc16
15 changed files with 289 additions and 39 deletions

View File

@@ -352,8 +352,16 @@ bool ArgsToFrontendOptionsConverter::convert(
}
Opts.EnableCAS = Args.hasArg(OPT_enable_cas);
Opts.CASPath =
Opts.CASOpts.CASPath =
Args.getLastArgValue(OPT_cas_path, llvm::cas::getDefaultOnDiskCASPath());
Opts.CASOpts.PluginPath = Args.getLastArgValue(OPT_cas_plugin_path);
for (StringRef Opt : Args.getAllArgValues(OPT_cas_plugin_option)) {
StringRef Name, Value;
std::tie(Name, Value) = Opt.split('=');
Opts.CASOpts.PluginOptions.emplace_back(std::string(Name),
std::string(Value));
}
Opts.CASFSRootIDs = Args.getAllArgValues(OPT_cas_fs);
Opts.ClangIncludeTrees = Args.getAllArgValues(OPT_clang_include_tree_root);

View File

@@ -1506,7 +1506,7 @@ static bool ParseClangImporterArgs(ClangImporterOptions &Opts,
// Forward the FrontendOptions to clang importer option so it can be
// accessed when creating clang module compilation invocation.
if (FrontendOpts.EnableCAS)
Opts.CASPath = FrontendOpts.CASPath;
Opts.CASOpts = FrontendOpts.CASOpts;
return false;
}

View File

@@ -406,14 +406,13 @@ bool CompilerInstance::setupCASIfNeeded(ArrayRef<const char *> Args) {
if (!Opts.EnableCAS)
return false;
auto MaybeCache = llvm::cas::createOnDiskUnifiedCASDatabases(Opts.CASPath);
if (!MaybeCache) {
Diagnostics.diagnose(SourceLoc(), diag::error_create_cas, Opts.CASPath,
toString(MaybeCache.takeError()));
auto MaybeDB= Opts.CASOpts.getOrCreateDatabases();
if (!MaybeDB) {
Diagnostics.diagnose(SourceLoc(), diag::error_cas,
toString(MaybeDB.takeError()));
return true;
}
CAS = std::move(MaybeCache->first);
ResultCache = std::move(MaybeCache->second);
std::tie(CAS, ResultCache) = *MaybeDB;
// create baseline key.
auto BaseKey = createCompileJobBaseCacheKey(*CAS, Args);

View File

@@ -39,6 +39,7 @@
#include "llvm/ADT/Hashing.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/Twine.h"
#include "llvm/CAS/ActionCache.h"
#include "llvm/CAS/ObjectStore.h"
#include "llvm/Support/CommandLine.h"
@@ -1600,12 +1601,23 @@ void InterfaceSubContextDelegateImpl::inheritOptionsForBuildingInterface(
GenericArgs.push_back(clangImporterOpts.BuildSessionFilePath);
}
if (!clangImporterOpts.CASPath.empty()) {
genericSubInvocation.getClangImporterOptions().CASPath =
clangImporterOpts.CASPath;
if (clangImporterOpts.CASOpts) {
genericSubInvocation.getClangImporterOptions().CASOpts =
clangImporterOpts.CASOpts;
GenericArgs.push_back("-enable-cas");
GenericArgs.push_back("-cas-path");
GenericArgs.push_back(clangImporterOpts.CASPath);
if (!clangImporterOpts.CASOpts->CASPath.empty()) {
GenericArgs.push_back("-cas-path");
GenericArgs.push_back(clangImporterOpts.CASOpts->CASPath);
}
if (!clangImporterOpts.CASOpts->PluginPath.empty()) {
GenericArgs.push_back("-cas-plugin-path");
GenericArgs.push_back(clangImporterOpts.CASOpts->PluginPath);
for (auto Opt : clangImporterOpts.CASOpts->PluginOptions) {
GenericArgs.push_back("-cas-plugin-option");
std::string pair = (llvm::Twine(Opt.first) + "=" + Opt.second).str();
GenericArgs.push_back(ArgSaver.save(pair));
}
}
}
if (clangImporterOpts.UseClangIncludeTree) {
@@ -1702,7 +1714,7 @@ InterfaceSubContextDelegateImpl::InterfaceSubContextDelegateImpl(
// required by sourcekitd.
subClangImporterOpts.DetailedPreprocessingRecord =
clangImporterOpts.DetailedPreprocessingRecord;
subClangImporterOpts.CASPath = clangImporterOpts.CASPath;
subClangImporterOpts.CASOpts = clangImporterOpts.CASOpts;
// If the compiler has been asked to be strict with ensuring downstream dependencies
// get the parent invocation's context, or this is an Explicit build, inherit the