Skip to content

Commit 6c02203

Browse files
committed
[Explicit Module Builds] Add a setting to specify a reproducer location.
The idea is the same as Clang flag `-fcrash-diagnostics-dir` but for explicit module builds. Making it a build setting instead of an environment variable on purpose. The plan is to have this setting more visible and not hidden. rdar://164202916
1 parent 469349f commit 6c02203

File tree

9 files changed

+38
-17
lines changed

9 files changed

+38
-17
lines changed

Sources/SWBCSupport/CLibclang.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2213,11 +2213,12 @@ extern "C" {
22132213
bool libclang_scanner_generate_reproducer(libclang_scanner_t scanner,
22142214
int argc, char *const *argv,
22152215
const char *workingDirectory,
2216+
const char *reproducerLocation,
22162217
const char **message) {
22172218
auto lib = scanner->scanner->lib;
22182219
LibclangFunctions::CXString messageString;
22192220
auto reproducerOpts = lib->fns.clang_experimental_DependencyScannerReproducerOptions_create(
2220-
argc, argv, /*ModuleName=*/nullptr, workingDirectory, /*ReproducerLocation=*/nullptr, /*UseUniqueReproducerName=*/true);
2221+
argc, argv, /*ModuleName=*/nullptr, workingDirectory, reproducerLocation, /*UseUniqueReproducerName=*/true);
22212222
auto result = lib->fns.clang_experimental_DependencyScanner_generateReproducer(
22222223
reproducerOpts, &messageString);
22232224
lib->fns.clang_experimental_DependencyScannerReproducerOptions_dispose(reproducerOpts);

Sources/SWBCSupport/CLibclang.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ CSUPPORT_EXPORT bool libclang_scanner_scan_dependencies(
222222
/// \returns True on success, false if something failed (see \p message for more details).
223223
CSUPPORT_EXPORT bool libclang_scanner_generate_reproducer(
224224
libclang_scanner_t scanner, int argc, char *const *argv, const char *workingDirectory,
225-
const char **message);
225+
const char *reproducerLocation, const char **message);
226226

227227
/// Get the list of commands invoked by the given Clang driver command line.
228228
///

Sources/SWBCore/LibclangVendored/Libclang.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,13 +291,14 @@ public final class DependencyScanner {
291291

292292
public func generateReproducer(
293293
commandLine: [String],
294-
workingDirectory: String
294+
workingDirectory: String,
295+
location: String?
295296
) throws -> String {
296297
let args = CStringArray(commandLine)
297298
var messageUnsafe: UnsafePointer<Int8>!
298299
defer { messageUnsafe?.deallocate() }
299300
// The count is `- 1` here, because CStringArray appends a trailing nullptr.
300-
let success = libclang_scanner_generate_reproducer(scanner, CInt(args.cArray.count - 1), args.cArray, workingDirectory, &messageUnsafe);
301+
let success = libclang_scanner_generate_reproducer(scanner, CInt(args.cArray.count - 1), args.cArray, workingDirectory, location, &messageUnsafe);
301302
let message = String(cString: messageUnsafe)
302303
guard success else {
303304
throw message.isEmpty ? Error.dependencyScanUnknownError : Error.dependencyScanErrorString(message)

Sources/SWBCore/Settings/BuiltinMacros.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,7 @@ public final class BuiltinMacros {
510510
public static let CLANG_EXPLICIT_MODULES_OUTPUT_PATH = BuiltinMacros.declarePathMacro("CLANG_EXPLICIT_MODULES_OUTPUT_PATH")
511511
public static let SWIFT_EXPLICIT_MODULES_OUTPUT_PATH = BuiltinMacros.declarePathMacro("SWIFT_EXPLICIT_MODULES_OUTPUT_PATH")
512512
public static let CLANG_EXPLICIT_MODULES_ENABLE_REPRODUCER_FOR_ERRORS = BuiltinMacros.declareBooleanMacro("_EXPERIMENTAL_CLANG_EXPLICIT_MODULES_ENABLE_REPRODUCER_FOR_ERRORS")
513+
public static let CLANG_EXPLICIT_MODULES_REPRODUCER_OUTPUT_PATH = BuiltinMacros.declarePathMacro("CLANG_CRASH_DIAGNOSTICS_DIR")
513514
public static let CLANG_ENABLE_COMPILE_CACHE = BuiltinMacros.declareBooleanMacro("CLANG_ENABLE_COMPILE_CACHE")
514515
public static let CLANG_CACHE_FINE_GRAINED_OUTPUTS = BuiltinMacros.declareEnumMacro("CLANG_CACHE_FINE_GRAINED_OUTPUTS") as EnumMacroDeclaration<FineGrainedCachingSetting>
515516
public static let CLANG_CACHE_FINE_GRAINED_OUTPUTS_VERIFICATION = BuiltinMacros.declareEnumMacro("CLANG_CACHE_FINE_GRAINED_OUTPUTS_VERIFICATION") as EnumMacroDeclaration<FineGrainedCachingVerificationSetting>
@@ -1515,6 +1516,7 @@ public final class BuiltinMacros {
15151516
CLANG_EXPLICIT_MODULES_OUTPUT_PATH,
15161517
SWIFT_EXPLICIT_MODULES_OUTPUT_PATH,
15171518
CLANG_EXPLICIT_MODULES_ENABLE_REPRODUCER_FOR_ERRORS,
1519+
CLANG_EXPLICIT_MODULES_REPRODUCER_OUTPUT_PATH,
15181520
CLANG_EXTRACT_API_EXEC,
15191521
CLANG_GENERATE_OPTIMIZATION_REMARKS,
15201522
CLANG_GENERATE_OPTIMIZATION_REMARKS_FILTER,

Sources/SWBCore/SpecImplementations/Tools/CCompiler.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,9 @@ public struct ClangExplicitModulesPayload: Serializable, Encodable, Sendable {
368368
public let reportRequiredTargetDependencies: BooleanWarningLevel
369369
public let verifyingModule: String?
370370
public let shouldGenerateReproducerForErrors: Bool
371+
public let reproducerOutputPath: Path?
371372

372-
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) {
373+
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?) {
373374
self.uniqueID = uniqueID
374375
self.sourcePath = sourcePath
375376
self.libclangPath = libclangPath
@@ -382,10 +383,11 @@ public struct ClangExplicitModulesPayload: Serializable, Encodable, Sendable {
382383
self.reportRequiredTargetDependencies = reportRequiredTargetDependencies
383384
self.verifyingModule = verifyingModule
384385
self.shouldGenerateReproducerForErrors = shouldGenerateReproducerForErrors
386+
self.reproducerOutputPath = reproducerOutputPath
385387
}
386388

387389
public func serialize<T: Serializer>(to serializer: T) {
388-
serializer.serializeAggregate(12) {
390+
serializer.serializeAggregate(13) {
389391
serializer.serialize(uniqueID)
390392
serializer.serialize(sourcePath)
391393
serializer.serialize(libclangPath)
@@ -398,11 +400,12 @@ public struct ClangExplicitModulesPayload: Serializable, Encodable, Sendable {
398400
serializer.serialize(reportRequiredTargetDependencies)
399401
serializer.serialize(verifyingModule)
400402
serializer.serialize(shouldGenerateReproducerForErrors)
403+
serializer.serialize(reproducerOutputPath)
401404
}
402405
}
403406

404407
public init(from deserializer: any Deserializer) throws {
405-
try deserializer.beginAggregate(12)
408+
try deserializer.beginAggregate(13)
406409
self.uniqueID = try deserializer.deserialize()
407410
self.sourcePath = try deserializer.deserialize()
408411
self.libclangPath = try deserializer.deserialize()
@@ -415,6 +418,7 @@ public struct ClangExplicitModulesPayload: Serializable, Encodable, Sendable {
415418
self.reportRequiredTargetDependencies = try deserializer.deserialize()
416419
self.verifyingModule = try deserializer.deserialize()
417420
self.shouldGenerateReproducerForErrors = try deserializer.deserialize()
421+
self.reproducerOutputPath = try deserializer.deserialize()
418422
}
419423

420424
}
@@ -1028,7 +1032,8 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
10281032
dependencyFilteringRootPath: isForPCHTask ? nil : cbc.producer.sdk?.path,
10291033
reportRequiredTargetDependencies: cbc.scope.evaluate(BuiltinMacros.DIAGNOSE_MISSING_TARGET_DEPENDENCIES),
10301034
verifyingModule: verifyingModule(cbc),
1031-
shouldGenerateReproducerForErrors: cbc.scope.evaluate(BuiltinMacros.CLANG_EXPLICIT_MODULES_ENABLE_REPRODUCER_FOR_ERRORS)
1035+
shouldGenerateReproducerForErrors: cbc.scope.evaluate(BuiltinMacros.CLANG_EXPLICIT_MODULES_ENABLE_REPRODUCER_FOR_ERRORS),
1036+
reproducerOutputPath: cbc.scope.evaluate(BuiltinMacros.CLANG_EXPLICIT_MODULES_REPRODUCER_OUTPUT_PATH).nilIfEmpty
10321037
)
10331038
let explicitModulesSignatureData = cachedBuild ? "cached" : nil
10341039

Sources/SWBTaskExecution/DynamicTaskSpecs/ClangModuleDependencyGraph.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ package final class ClangModuleDependencyGraph {
572572
}
573573

574574
package func generateReproducer(forFailedDependency dependency: DependencyInfo,
575-
libclangPath: Path, casOptions: CASOptions?) throws -> String? {
575+
libclangPath: Path, casOptions: CASOptions?, location: String?) throws -> String? {
576576
let clangWithScanner = try libclangWithScanner(
577577
forPath: libclangPath,
578578
casOptions: casOptions,
@@ -583,7 +583,7 @@ package final class ClangModuleDependencyGraph {
583583
return nil
584584
}
585585
return try clangWithScanner.scanner.generateReproducer(
586-
commandLine: dependency.scanningCommandLine, workingDirectory: dependency.workingDirectory.str)
586+
commandLine: dependency.scanningCommandLine, workingDirectory: dependency.workingDirectory.str, location: location)
587587
}
588588

589589
package var isEmpty: Bool {

Sources/SWBTaskExecution/DynamicTaskSpecs/PrecompileClangModuleDynamicTaskSpec.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,42 +22,47 @@ public struct PrecompileClangModuleTaskKey: Serializable, CustomDebugStringConve
2222
let casOptions: CASOptions?
2323
let verifyingModule: String?
2424
let fileNameMapPath: Path?
25+
let reproducerOutputPath: Path?
2526

2627
init(
2728
dependencyInfoPath: Path,
2829
usesSerializedDiagnostics: Bool,
2930
libclangPath: Path,
3031
casOptions: CASOptions?,
3132
verifyingModule: String?,
32-
fileNameMapPath: Path?
33+
fileNameMapPath: Path?,
34+
reproducerOutputPath: Path?
3335
) {
3436
self.dependencyInfoPath = dependencyInfoPath
3537
self.usesSerializedDiagnostics = usesSerializedDiagnostics
3638
self.libclangPath = libclangPath
3739
self.casOptions = casOptions
3840
self.verifyingModule = verifyingModule
3941
self.fileNameMapPath = fileNameMapPath
42+
self.reproducerOutputPath = reproducerOutputPath
4043
}
4144

4245
public func serialize<T: Serializer>(to serializer: T) {
43-
serializer.serializeAggregate(6) {
46+
serializer.serializeAggregate(7) {
4447
serializer.serialize(dependencyInfoPath)
4548
serializer.serialize(usesSerializedDiagnostics)
4649
serializer.serialize(libclangPath)
4750
serializer.serialize(casOptions)
4851
serializer.serialize(verifyingModule)
4952
serializer.serialize(fileNameMapPath)
53+
serializer.serialize(reproducerOutputPath)
5054
}
5155
}
5256

5357
public init(from deserializer: any Deserializer) throws {
54-
try deserializer.beginAggregate(6)
58+
try deserializer.beginAggregate(7)
5559
self.dependencyInfoPath = try deserializer.deserialize()
5660
self.usesSerializedDiagnostics = try deserializer.deserialize()
5761
self.libclangPath = try deserializer.deserialize()
5862
self.casOptions = try deserializer.deserialize()
5963
self.verifyingModule = try deserializer.deserialize()
6064
self.fileNameMapPath = try deserializer.deserialize()
65+
self.reproducerOutputPath = try deserializer.deserialize()
6166
}
6267

6368
public var debugDescription: String {
@@ -68,6 +73,9 @@ public struct PrecompileClangModuleTaskKey: Serializable, CustomDebugStringConve
6873
if let fileNameMapPath {
6974
result += " fileNameMap=\(fileNameMapPath)"
7075
}
76+
if let reproducerOutputPath {
77+
result += " reproducerOutputPath=\(reproducerOutputPath)"
78+
}
7179
result += ">"
7280
return result
7381
}

Sources/SWBTaskExecution/TaskActions/ClangCompileTaskAction.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ public final class ClangCompileTaskAction: TaskAction, BuildValueValidatingTaskA
138138
libclangPath: explicitModulesPayload.libclangPath,
139139
casOptions: explicitModulesPayload.casOptions,
140140
verifyingModule: explicitModulesPayload.verifyingModule,
141-
fileNameMapPath: payload.fileNameMapPath
141+
fileNameMapPath: payload.fileNameMapPath,
142+
reproducerOutputPath: explicitModulesPayload.reproducerOutputPath
142143
)
143144

144145
dynamicExecutionDelegate.requestDynamicTask(
@@ -327,7 +328,8 @@ public final class ClangCompileTaskAction: TaskAction, BuildValueValidatingTaskA
327328
if let reproducerMessage = try clangModuleDependencyGraph.generateReproducer(
328329
forFailedDependency: dependencyInfo,
329330
libclangPath: explicitModulesPayload.libclangPath,
330-
casOptions: explicitModulesPayload.casOptions) {
331+
casOptions: explicitModulesPayload.casOptions,
332+
location: explicitModulesPayload.reproducerOutputPath?.str) {
331333
outputDelegate.emitOutput(ByteString(encodingAsUTF8: reproducerMessage) + "\n")
332334
}
333335
} catch {

Sources/SWBTaskExecution/TaskActions/PrecompileClangModuleTaskAction.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ final public class PrecompileClangModuleTaskAction: TaskAction, BuildValueValida
9393
libclangPath: key.libclangPath,
9494
casOptions: key.casOptions,
9595
verifyingModule: key.verifyingModule,
96-
fileNameMapPath: key.fileNameMapPath
96+
fileNameMapPath: key.fileNameMapPath,
97+
reproducerOutputPath: key.reproducerOutputPath
9798
)
9899

99100
dynamicExecutionDelegate.requestDynamicTask(
@@ -232,7 +233,8 @@ final public class PrecompileClangModuleTaskAction: TaskAction, BuildValueValida
232233
if let reproducerMessage = try clangModuleDependencyGraph.generateReproducer(
233234
forFailedDependency: dependencyInfo,
234235
libclangPath: key.libclangPath,
235-
casOptions: key.casOptions) {
236+
casOptions: key.casOptions,
237+
location: key.reproducerOutputPath?.str) {
236238
outputDelegate.emitOutput(ByteString(encodingAsUTF8: reproducerMessage) + "\n")
237239
}
238240
} catch {

0 commit comments

Comments
 (0)