Skip to content

Commit 211b6a4

Browse files
authored
Merge pull request #2814 from akyrtzi/1300-libclang-scan-deps-driver-args
[libclang] Support passing driver arguments for the dependency scanner
2 parents 7d4c2a1 + b5bf28c commit 211b6a4

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

clang/test/Index/Core/scan-deps.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55
// RUN: -o FoE.o -x objective-c %s >> %t.result
66
// RUN: cat %t.result | sed 's/\\/\//g' | FileCheck %s
77

8+
// Use driver arguments.
9+
// RUN: rm -rf %t.mcp
10+
// RUN: echo %S > %t.result
11+
// RUN: c-index-test core --scan-deps %S -- %clang -c -I %S/Inputs/module \
12+
// RUN: -fmodules -fmodules-cache-path=%t.mcp \
13+
// RUN: -o FoE.o -x objective-c %s >> %t.result
14+
// RUN: cat %t.result | sed 's/\\/\//g' | FileCheck %s
15+
816
@import ModA;
917

1018
// CHECK: [[PREFIX:.*]]

clang/tools/libclang/CDependencies.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include "clang-c/Dependencies.h"
1717

18+
#include "clang/Frontend/CompilerInstance.h"
1819
#include "clang/Tooling/DependencyScanning/DependencyScanningService.h"
1920
#include "clang/Tooling/DependencyScanning/DependencyScanningTool.h"
2021
#include "clang/Tooling/DependencyScanning/DependencyScanningWorker.h"
@@ -218,7 +219,17 @@ clang_experimental_DependencyScannerWorker_getFileDependencies_v0(
218219
for (int i = 2; i < argc; ++i)
219220
Compilation.push_back(argv[i]);
220221
else {
221-
return nullptr; // TODO: Run the driver to get -cc1 args.
222+
// Run the driver to get -cc1 args.
223+
ArrayRef<const char *> CArgs = llvm::makeArrayRef(argv, argv+argc);
224+
IntrusiveRefCntPtr<DiagnosticsEngine>
225+
Diags(CompilerInstance::createDiagnostics(new DiagnosticOptions));
226+
auto CI = createInvocationFromCommandLine(CArgs, Diags, /*VFS=*/nullptr,
227+
/*ShouldRecoverOnErrors=*/false, &Compilation);
228+
if (!CI) {
229+
if (error)
230+
*error = cxstring::createRef("failed creating 'cc1' arguments");
231+
return nullptr;
232+
}
222233
}
223234

224235
if (Worker->getFormat() == ScanningOutputFormat::Full)

0 commit comments

Comments
 (0)