From f8ebc98483d97170983f5b1fcb37294894214be6 Mon Sep 17 00:00:00 2001 From: Ben Langmuir Date: Fri, 24 Jan 2020 11:39:51 -0800 Subject: [PATCH] [sourcekitd-test] When setting -fmodules-cache-path also set -fmodules When doing header interface generation, we interpret clang command-line arguments in `initInvocationByClangArguments` and attempt to setup a matching Swift compiler invocation. One important argument is the module cache, but clang will only interpret `-fmodules-cache-path` if modules are enabled (typically with `-fmodules`). While the header itself might not need modules, Swift will import its own shims module and during testing this needs to honour lit's provided cache. So we add -fmodules in sourcekitd-test anytime we add -fmodules-cache-path. rdar://58836540 --- tools/SourceKit/tools/sourcekitd-test/sourcekitd-test.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tools/SourceKit/tools/sourcekitd-test/sourcekitd-test.cpp b/tools/SourceKit/tools/sourcekitd-test/sourcekitd-test.cpp index 074b8bae5a568..2188f711a48dc 100644 --- a/tools/SourceKit/tools/sourcekitd-test/sourcekitd-test.cpp +++ b/tools/SourceKit/tools/sourcekitd-test/sourcekitd-test.cpp @@ -987,6 +987,13 @@ static int handleTestInvocation(TestOptions Opts, TestOptions &InitOpts) { sourcekitd_object_t Args = sourcekitd_request_array_create(nullptr, 0); if (!Opts.ModuleCachePath.empty()) { if (compilerArgsAreClang) { + // We need -fmodules or else the clang argument parsing does not honour + // -fmodules-cache-path. In reality, the swift ClangImporter will always + // enable modules when importing, so this should only impact the + // clang argument parsing. This is needed even if the header doesn't + // use modules, since Swift itself will import its shims module, and + // that needs to honour the -module-cache-path option when testing. + sourcekitd_request_array_set_string(Args, SOURCEKITD_ARRAY_APPEND, "-fmodules"); std::string opt = "-fmodules-cache-path=" + Opts.ModuleCachePath; sourcekitd_request_array_set_string(Args, SOURCEKITD_ARRAY_APPEND, opt.c_str()); } else {