Skip to content
Draft
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
9 changes: 9 additions & 0 deletions Sources/SWBCSupport/CLibclang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,9 @@ extern "C" {
int argc, const char *const *argv, const char *ModuleName, const char *WorkingDirectory,
const char *ReproducerLocation, bool UseUniqueReproducerName);

void (*clang_experimental_DependencyScannerReproducerOptions_setCASOptions)(
CXDependencyScannerReproducerOptions, CXCASDatabases, CXCASOptions);

void (*clang_experimental_DependencyScannerReproducerOptions_dispose)(CXDependencyScannerReproducerOptions);

/**
Expand Down Expand Up @@ -1449,6 +1452,7 @@ struct LibclangWrapper {
LOOKUP_OPTIONAL(clang_experimental_cas_ReplayResult_getStderr);
LOOKUP_OPTIONAL(clang_experimental_DependencyScanner_generateReproducer);
LOOKUP_OPTIONAL(clang_experimental_DependencyScannerReproducerOptions_create);
LOOKUP_OPTIONAL(clang_experimental_DependencyScannerReproducerOptions_setCASOptions);
LOOKUP_OPTIONAL(clang_experimental_DependencyScannerReproducerOptions_dispose);
LOOKUP_OPTIONAL(clang_experimental_DependencyScannerServiceOptions_create);
LOOKUP_OPTIONAL(clang_experimental_DependencyScannerServiceOptions_dispose);
Expand Down Expand Up @@ -2214,11 +2218,16 @@ extern "C" {
int argc, char *const *argv,
const char *workingDirectory,
const char *reproducerLocation,
libclang_casdatabases_t casDBs,
libclang_casoptions_t casOpts,
const char **message) {
auto lib = scanner->scanner->lib;
LibclangFunctions::CXString messageString;
auto reproducerOpts = lib->fns.clang_experimental_DependencyScannerReproducerOptions_create(
argc, argv, /*ModuleName=*/nullptr, workingDirectory, reproducerLocation, /*UseUniqueReproducerName=*/true);
if (lib->fns.clang_experimental_DependencyScannerReproducerOptions_setCASOptions)
lib->fns.clang_experimental_DependencyScannerReproducerOptions_setCASOptions(
reproducerOpts, casDBs ? casDBs->dbs.casDBs : nullptr, casOpts ? casOpts->opts.casOpts : nullptr);
auto result = lib->fns.clang_experimental_DependencyScanner_generateReproducer(
reproducerOpts, &messageString);
lib->fns.clang_experimental_DependencyScannerReproducerOptions_dispose(reproducerOpts);
Expand Down
3 changes: 2 additions & 1 deletion Sources/SWBCSupport/CLibclang.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ CSUPPORT_EXPORT bool libclang_scanner_scan_dependencies(
/// \returns True on success, false if something failed (see \p message for more details).
CSUPPORT_EXPORT bool libclang_scanner_generate_reproducer(
libclang_scanner_t scanner, int argc, char *const *argv, const char *workingDirectory,
const char *reproducerLocation, const char **message);
const char *reproducerLocation,
libclang_casdatabases_t, libclang_casoptions_t, const char **message);

/// Get the list of commands invoked by the given Clang driver command line.
///
Expand Down
5 changes: 3 additions & 2 deletions Sources/SWBCore/LibclangVendored/Libclang.swift
Original file line number Diff line number Diff line change
Expand Up @@ -292,13 +292,14 @@ public final class DependencyScanner {
public func generateReproducer(
commandLine: [String],
workingDirectory: String,
location: String?
location: String?,
casDBs: ClangCASDatabases?, casOpts: ClangCASOptions?
) throws -> String {
let args = CStringArray(commandLine)
var messageUnsafe: UnsafePointer<Int8>!
defer { messageUnsafe?.deallocate() }
// The count is `- 1` here, because CStringArray appends a trailing nullptr.
let success = libclang_scanner_generate_reproducer(scanner, CInt(args.cArray.count - 1), args.cArray, workingDirectory, location, &messageUnsafe);
let success = libclang_scanner_generate_reproducer(scanner, CInt(args.cArray.count - 1), args.cArray, workingDirectory, location, casDBs?.dbs, casOpts?.options, &messageUnsafe);
let message = String(cString: messageUnsafe)
guard success else {
throw message.isEmpty ? Error.dependencyScanUnknownError : Error.dependencyScanErrorString(message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,13 @@ package final class ClangModuleDependencyGraph {
let libclang: Libclang
let scanner: DependencyScanner
let casDBs: ClangCASDatabases?
let casOptsForInvocations: ClangCASOptions?

init(libclang: Libclang, casDBs: ClangCASDatabases?, casOptsForInvocations: ClangCASOptions?) throws {
self.libclang = libclang
self.scanner = try libclang.createScanner(casDBs: casDBs, casOpts: casOptsForInvocations)
self.casDBs = casDBs
self.casOptsForInvocations = casOptsForInvocations
}
}

Expand Down Expand Up @@ -583,7 +585,8 @@ package final class ClangModuleDependencyGraph {
return nil
}
return try clangWithScanner.scanner.generateReproducer(
commandLine: dependency.scanningCommandLine, workingDirectory: dependency.workingDirectory.str, location: location)
commandLine: dependency.scanningCommandLine, workingDirectory: dependency.workingDirectory.str, location: location,
casDBs: clangWithScanner.casDBs, casOpts: clangWithScanner.casOptsForInvocations)
}

package var isEmpty: Bool {
Expand Down
Loading