Skip to content
Open
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
3 changes: 2 additions & 1 deletion Sources/SWBCSupport/CLibclang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2213,11 +2213,12 @@ extern "C" {
bool libclang_scanner_generate_reproducer(libclang_scanner_t scanner,
int argc, char *const *argv,
const char *workingDirectory,
const char *reproducerLocation,
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=*/nullptr, /*UseUniqueReproducerName=*/true);
argc, argv, /*ModuleName=*/nullptr, workingDirectory, reproducerLocation, /*UseUniqueReproducerName=*/true);
auto result = lib->fns.clang_experimental_DependencyScanner_generateReproducer(
reproducerOpts, &messageString);
lib->fns.clang_experimental_DependencyScannerReproducerOptions_dispose(reproducerOpts);
Expand Down
2 changes: 1 addition & 1 deletion Sources/SWBCSupport/CLibclang.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ 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 **message);
const char *reproducerLocation, 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 @@ -291,13 +291,14 @@ public final class DependencyScanner {

public func generateReproducer(
commandLine: [String],
workingDirectory: String
workingDirectory: String,
location: String?
) 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, &messageUnsafe);
let success = libclang_scanner_generate_reproducer(scanner, CInt(args.cArray.count - 1), args.cArray, workingDirectory, location, &messageUnsafe);
let message = String(cString: messageUnsafe)
guard success else {
throw message.isEmpty ? Error.dependencyScanUnknownError : Error.dependencyScanErrorString(message)
Expand Down
2 changes: 2 additions & 0 deletions Sources/SWBCore/Settings/BuiltinMacros.swift
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,7 @@ public final class BuiltinMacros {
public static let CLANG_EXPLICIT_MODULES_OUTPUT_PATH = BuiltinMacros.declarePathMacro("CLANG_EXPLICIT_MODULES_OUTPUT_PATH")
public static let SWIFT_EXPLICIT_MODULES_OUTPUT_PATH = BuiltinMacros.declarePathMacro("SWIFT_EXPLICIT_MODULES_OUTPUT_PATH")
public static let CLANG_EXPLICIT_MODULES_ENABLE_REPRODUCER_FOR_ERRORS = BuiltinMacros.declareBooleanMacro("_EXPERIMENTAL_CLANG_EXPLICIT_MODULES_ENABLE_REPRODUCER_FOR_ERRORS")
public static let CLANG_EXPLICIT_MODULES_REPRODUCER_OUTPUT_PATH = BuiltinMacros.declarePathMacro("CLANG_CRASH_DIAGNOSTICS_DIR")
public static let CLANG_ENABLE_COMPILE_CACHE = BuiltinMacros.declareBooleanMacro("CLANG_ENABLE_COMPILE_CACHE")
public static let CLANG_CACHE_FINE_GRAINED_OUTPUTS = BuiltinMacros.declareEnumMacro("CLANG_CACHE_FINE_GRAINED_OUTPUTS") as EnumMacroDeclaration<FineGrainedCachingSetting>
public static let CLANG_CACHE_FINE_GRAINED_OUTPUTS_VERIFICATION = BuiltinMacros.declareEnumMacro("CLANG_CACHE_FINE_GRAINED_OUTPUTS_VERIFICATION") as EnumMacroDeclaration<FineGrainedCachingVerificationSetting>
Expand Down Expand Up @@ -1515,6 +1516,7 @@ public final class BuiltinMacros {
CLANG_EXPLICIT_MODULES_OUTPUT_PATH,
SWIFT_EXPLICIT_MODULES_OUTPUT_PATH,
CLANG_EXPLICIT_MODULES_ENABLE_REPRODUCER_FOR_ERRORS,
CLANG_EXPLICIT_MODULES_REPRODUCER_OUTPUT_PATH,
CLANG_EXTRACT_API_EXEC,
CLANG_GENERATE_OPTIMIZATION_REMARKS,
CLANG_GENERATE_OPTIMIZATION_REMARKS_FILTER,
Expand Down
13 changes: 9 additions & 4 deletions Sources/SWBCore/SpecImplementations/Tools/CCompiler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,9 @@ public struct ClangExplicitModulesPayload: Serializable, Encodable, Sendable {
public let reportRequiredTargetDependencies: BooleanWarningLevel
public let verifyingModule: String?
public let shouldGenerateReproducerForErrors: Bool
public let reproducerOutputPath: Path?

fileprivate init(uniqueID: String, sourcePath: Path, libclangPath: Path, usesCompilerLauncher: Bool, outputPath: Path, scanningOutputPath: Path, casOptions: CASOptions?, cacheFallbackIfNotAvailable: Bool, dependencyFilteringRootPath: Path?, reportRequiredTargetDependencies: BooleanWarningLevel, verifyingModule: String?, shouldGenerateReproducerForErrors: Bool) {
fileprivate init(uniqueID: String, sourcePath: Path, libclangPath: Path, usesCompilerLauncher: Bool, outputPath: Path, scanningOutputPath: Path, casOptions: CASOptions?, cacheFallbackIfNotAvailable: Bool, dependencyFilteringRootPath: Path?, reportRequiredTargetDependencies: BooleanWarningLevel, verifyingModule: String?, shouldGenerateReproducerForErrors: Bool, reproducerOutputPath: Path?) {
self.uniqueID = uniqueID
self.sourcePath = sourcePath
self.libclangPath = libclangPath
Expand All @@ -382,10 +383,11 @@ public struct ClangExplicitModulesPayload: Serializable, Encodable, Sendable {
self.reportRequiredTargetDependencies = reportRequiredTargetDependencies
self.verifyingModule = verifyingModule
self.shouldGenerateReproducerForErrors = shouldGenerateReproducerForErrors
self.reproducerOutputPath = reproducerOutputPath
}

public func serialize<T: Serializer>(to serializer: T) {
serializer.serializeAggregate(12) {
serializer.serializeAggregate(13) {
serializer.serialize(uniqueID)
serializer.serialize(sourcePath)
serializer.serialize(libclangPath)
Expand All @@ -398,11 +400,12 @@ public struct ClangExplicitModulesPayload: Serializable, Encodable, Sendable {
serializer.serialize(reportRequiredTargetDependencies)
serializer.serialize(verifyingModule)
serializer.serialize(shouldGenerateReproducerForErrors)
serializer.serialize(reproducerOutputPath)
}
}

public init(from deserializer: any Deserializer) throws {
try deserializer.beginAggregate(12)
try deserializer.beginAggregate(13)
self.uniqueID = try deserializer.deserialize()
self.sourcePath = try deserializer.deserialize()
self.libclangPath = try deserializer.deserialize()
Expand All @@ -415,6 +418,7 @@ public struct ClangExplicitModulesPayload: Serializable, Encodable, Sendable {
self.reportRequiredTargetDependencies = try deserializer.deserialize()
self.verifyingModule = try deserializer.deserialize()
self.shouldGenerateReproducerForErrors = try deserializer.deserialize()
self.reproducerOutputPath = try deserializer.deserialize()
}

}
Expand Down Expand Up @@ -1028,7 +1032,8 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
dependencyFilteringRootPath: isForPCHTask ? nil : cbc.producer.sdk?.path,
reportRequiredTargetDependencies: cbc.scope.evaluate(BuiltinMacros.DIAGNOSE_MISSING_TARGET_DEPENDENCIES),
verifyingModule: verifyingModule(cbc),
shouldGenerateReproducerForErrors: cbc.scope.evaluate(BuiltinMacros.CLANG_EXPLICIT_MODULES_ENABLE_REPRODUCER_FOR_ERRORS)
shouldGenerateReproducerForErrors: cbc.scope.evaluate(BuiltinMacros.CLANG_EXPLICIT_MODULES_ENABLE_REPRODUCER_FOR_ERRORS),
reproducerOutputPath: cbc.scope.evaluate(BuiltinMacros.CLANG_EXPLICIT_MODULES_REPRODUCER_OUTPUT_PATH).nilIfEmpty
)
let explicitModulesSignatureData = cachedBuild ? "cached" : nil

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ package final class ClangModuleDependencyGraph {
}

package func generateReproducer(forFailedDependency dependency: DependencyInfo,
libclangPath: Path, casOptions: CASOptions?) throws -> String? {
libclangPath: Path, casOptions: CASOptions?, location: String?) throws -> String? {
let clangWithScanner = try libclangWithScanner(
forPath: libclangPath,
casOptions: casOptions,
Expand All @@ -583,7 +583,7 @@ package final class ClangModuleDependencyGraph {
return nil
}
return try clangWithScanner.scanner.generateReproducer(
commandLine: dependency.scanningCommandLine, workingDirectory: dependency.workingDirectory.str)
commandLine: dependency.scanningCommandLine, workingDirectory: dependency.workingDirectory.str, location: location)
}

package var isEmpty: Bool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,42 +22,47 @@ public struct PrecompileClangModuleTaskKey: Serializable, CustomDebugStringConve
let casOptions: CASOptions?
let verifyingModule: String?
let fileNameMapPath: Path?
let reproducerOutputPath: Path?

init(
dependencyInfoPath: Path,
usesSerializedDiagnostics: Bool,
libclangPath: Path,
casOptions: CASOptions?,
verifyingModule: String?,
fileNameMapPath: Path?
fileNameMapPath: Path?,
reproducerOutputPath: Path?
) {
self.dependencyInfoPath = dependencyInfoPath
self.usesSerializedDiagnostics = usesSerializedDiagnostics
self.libclangPath = libclangPath
self.casOptions = casOptions
self.verifyingModule = verifyingModule
self.fileNameMapPath = fileNameMapPath
self.reproducerOutputPath = reproducerOutputPath
}

public func serialize<T: Serializer>(to serializer: T) {
serializer.serializeAggregate(6) {
serializer.serializeAggregate(7) {
serializer.serialize(dependencyInfoPath)
serializer.serialize(usesSerializedDiagnostics)
serializer.serialize(libclangPath)
serializer.serialize(casOptions)
serializer.serialize(verifyingModule)
serializer.serialize(fileNameMapPath)
serializer.serialize(reproducerOutputPath)
}
}

public init(from deserializer: any Deserializer) throws {
try deserializer.beginAggregate(6)
try deserializer.beginAggregate(7)
self.dependencyInfoPath = try deserializer.deserialize()
self.usesSerializedDiagnostics = try deserializer.deserialize()
self.libclangPath = try deserializer.deserialize()
self.casOptions = try deserializer.deserialize()
self.verifyingModule = try deserializer.deserialize()
self.fileNameMapPath = try deserializer.deserialize()
self.reproducerOutputPath = try deserializer.deserialize()
}

public var debugDescription: String {
Expand All @@ -68,6 +73,9 @@ public struct PrecompileClangModuleTaskKey: Serializable, CustomDebugStringConve
if let fileNameMapPath {
result += " fileNameMap=\(fileNameMapPath)"
}
if let reproducerOutputPath {
result += " reproducerOutputPath=\(reproducerOutputPath)"
}
result += ">"
return result
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ public final class ClangCompileTaskAction: TaskAction, BuildValueValidatingTaskA
libclangPath: explicitModulesPayload.libclangPath,
casOptions: explicitModulesPayload.casOptions,
verifyingModule: explicitModulesPayload.verifyingModule,
fileNameMapPath: payload.fileNameMapPath
fileNameMapPath: payload.fileNameMapPath,
reproducerOutputPath: explicitModulesPayload.reproducerOutputPath
)

dynamicExecutionDelegate.requestDynamicTask(
Expand Down Expand Up @@ -327,7 +328,8 @@ public final class ClangCompileTaskAction: TaskAction, BuildValueValidatingTaskA
if let reproducerMessage = try clangModuleDependencyGraph.generateReproducer(
forFailedDependency: dependencyInfo,
libclangPath: explicitModulesPayload.libclangPath,
casOptions: explicitModulesPayload.casOptions) {
casOptions: explicitModulesPayload.casOptions,
location: explicitModulesPayload.reproducerOutputPath?.str) {
outputDelegate.emitOutput(ByteString(encodingAsUTF8: reproducerMessage) + "\n")
}
} catch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ final public class PrecompileClangModuleTaskAction: TaskAction, BuildValueValida
libclangPath: key.libclangPath,
casOptions: key.casOptions,
verifyingModule: key.verifyingModule,
fileNameMapPath: key.fileNameMapPath
fileNameMapPath: key.fileNameMapPath,
reproducerOutputPath: key.reproducerOutputPath
)

dynamicExecutionDelegate.requestDynamicTask(
Expand Down Expand Up @@ -232,7 +233,8 @@ final public class PrecompileClangModuleTaskAction: TaskAction, BuildValueValida
if let reproducerMessage = try clangModuleDependencyGraph.generateReproducer(
forFailedDependency: dependencyInfo,
libclangPath: key.libclangPath,
casOptions: key.casOptions) {
casOptions: key.casOptions,
location: key.reproducerOutputPath?.str) {
outputDelegate.emitOutput(ByteString(encodingAsUTF8: reproducerMessage) + "\n")
}
} catch {
Expand Down
Loading