Skip to content

Commit 492f5ab

Browse files
[Caching] Do not infer default on disk cas path when parsing options
Currently, swift-frontend will always try to infer a default CASPath if no `-cas-path` is passed. The function `getDefaultOnDiskCASPath` called to infer the default path can fatal error in some environment where no caching directory and home directory, no matter if caching is used or not. Remove the inferred path during parsing since that is not strictly necessary. If caching is enabled and no CASPath is passed, error can be issued during CAS construction time. rdar://158899187
1 parent b444a0b commit 492f5ab

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

lib/Frontend/CompilerInvocation.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -778,8 +778,6 @@ static bool ParseCASArgs(CASOptions &Opts, ArgList &Args,
778778
Opts.CacheSkipReplay |= Args.hasArg(OPT_cache_disable_replay);
779779
if (const Arg *A = Args.getLastArg(OPT_cas_path))
780780
Opts.CASOpts.CASPath = A->getValue();
781-
else if (Opts.CASOpts.CASPath.empty())
782-
Opts.CASOpts.CASPath = llvm::cas::getDefaultOnDiskCASPath();
783781

784782
if (const Arg *A = Args.getLastArg(OPT_cas_plugin_path))
785783
Opts.CASOpts.PluginPath = A->getValue();

lib/Frontend/Frontend.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,11 @@ bool CompilerInstance::setupCASIfNeeded(ArrayRef<const char *> Args) {
466466
return false;
467467

468468
const auto &Opts = getInvocation().getCASOptions();
469+
if (Opts.CASOpts.CASPath.empty() && Opts.CASOpts.PluginPath.empty()) {
470+
Diagnostics.diagnose(SourceLoc(), diag::error_cas_initialization,
471+
"no CAS options provided");
472+
return true;
473+
}
469474
auto MaybeDB = Opts.CASOpts.getOrCreateDatabases();
470475
if (!MaybeDB) {
471476
Diagnostics.diagnose(SourceLoc(), diag::error_cas_initialization,

test/CAS/cas_output_backend.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
// RUN: echo "\"-disable-implicit-concurrency-module-import\"" >> %t/MyApp.cmd
1414
// RUN: echo "\"-parse-stdlib\"" >> %t/MyApp.cmd
1515

16+
// RUN: not %target-swift-frontend -c -cache-compile-job %s -o %t/test.o @%t/MyApp.cmd 2>&1 | %FileCheck %s --check-prefix=NOT-CONFIG
17+
// NOT-CONFIG: error: CAS cannot be initialized from the specified '-cas-*' options: no CAS options provided
18+
1619
// RUN: %target-swift-frontend -c -cache-compile-job -cas-path %t/cas %s -o %t/test.o @%t/MyApp.cmd
1720
// RUN: %cache-tool -cas-path %t/cas -cache-tool-action print-output-keys -- \
1821
// RUN: %target-swift-frontend -c -cache-compile-job -cas-path %t/cas %s -o %t/test.o @%t/MyApp.cmd > %t/cache_key.json

0 commit comments

Comments
 (0)