Skip to content

Commit 082ec5d

Browse files
committed
force recovery from failure in swift-symbolgraph-extract
1 parent 8026f6c commit 082ec5d

File tree

3 files changed

+52
-17
lines changed

3 files changed

+52
-17
lines changed

Sources/SymbolGraphBuilder/SSGC.Compile.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,18 @@ extension SSGC
117117
""")
118118
var removeClone:Bool = false
119119

120+
// The great irony of this flag is that adding the flag itself causes
121+
// swift-argument-parser to crash with a bad pointer dereference. XD
122+
/*
123+
@Flag(
124+
name: [.customLong("recover-from-apple-bugs")],
125+
help: """
126+
Recover from known bugs in the Apple Swift compiler - this may result in \
127+
incomplete or broken documentation!
128+
""")
129+
var recoverFromAppleBugs:Bool = false
130+
*/
131+
120132
@Flag(
121133
name: [.customLong("pretty"), .customShort("p")],
122134
help: """
@@ -223,6 +235,7 @@ extension SSGC.Compile
223235
{
224236
let toolchain:SSGC.Toolchain = try .detect(appleSDK: self.appleSDK,
225237
paths: .init(swiftPM: self.swiftCache, usr: self.swiftTools),
238+
recoverFromAppleBugs: true, // self.recoverFromAppleBugs,
226239
pretty: self.pretty)
227240

228241
let object:SymbolGraphObject<Void>

Sources/SymbolGraphBuilder/Toolchains/SSGC.Toolchain.swift

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,22 @@ extension SSGC
2323
private
2424
let paths:Paths
2525

26+
private
27+
let recoverFromAppleBugs:Bool
2628
private
2729
let pretty:Bool
2830

2931
public
3032
init(appleSDK:AppleSDK?,
3133
splash:Splash,
3234
paths:Paths,
35+
recoverFromAppleBugs:Bool,
3336
pretty:Bool)
3437
{
3538
self.appleSDK = appleSDK
3639
self.splash = splash
3740
self.paths = paths
41+
self.recoverFromAppleBugs = recoverFromAppleBugs
3842
self.pretty = pretty
3943
}
4044
}
@@ -44,6 +48,7 @@ extension SSGC.Toolchain
4448
public static
4549
func detect(appleSDK:SSGC.AppleSDK? = nil,
4650
paths:Paths = .init(swiftPM: nil, usr: nil),
51+
recoverFromAppleBugs:Bool = true,
4752
pretty:Bool = false) throws -> Self
4853
{
4954
let (readable, writable):(FileDescriptor, FileDescriptor) = try FileDescriptor.pipe()
@@ -58,6 +63,7 @@ extension SSGC.Toolchain
5863
return .init(appleSDK: appleSDK,
5964
splash: try .init(parsing: try readable.read(buffering: 1024)),
6065
paths: paths,
66+
recoverFromAppleBugs: recoverFromAppleBugs,
6167
pretty: pretty)
6268
}
6369
}
@@ -303,25 +309,40 @@ extension SSGC.Toolchain
303309
{
304310
try extractor()
305311
}
306-
catch SystemProcessError.exit(139, _)
307-
{
308-
print("""
309-
Failed to dump symbols for module '\(id)' due to SIGSEGV \
310-
from 'swift symbolgraph-extract'. This is a known bug in the Apple Swift \
311-
compiler; see https://github.com/apple/swift/issues/68767.
312-
""")
313-
}
314-
catch SystemProcessError.exit(134, _)
315-
{
316-
print("""
317-
Failed to dump symbols for module '\(id)' due to SIGABRT \
318-
from 'swift symbolgraph-extract'. This is a known bug in the Apple Swift \
319-
compiler; see https://github.com/swiftlang/swift/issues/75318.
320-
""")
321-
}
322312
catch SystemProcessError.exit(let code, let invocation)
323313
{
324-
throw SSGC.PackageBuildError.swift_symbolgraph_extract(code, invocation)
314+
guard self.recoverFromAppleBugs
315+
else
316+
{
317+
throw SSGC.PackageBuildError.swift_symbolgraph_extract(code, invocation)
318+
}
319+
320+
switch code
321+
{
322+
case 139:
323+
print("""
324+
Failed to dump symbols for module '\(id)' due to SIGSEGV \
325+
from 'swift symbolgraph-extract'. \
326+
This is a known bug in the Apple Swift compiler; see \
327+
https://github.com/apple/swift/issues/68767.
328+
""")
329+
case 134:
330+
print("""
331+
Failed to dump symbols for module '\(id)' due to SIGABRT \
332+
from 'swift symbolgraph-extract'. \
333+
This is a known bug in the Apple Swift compiler; see \
334+
https://github.com/swiftlang/swift/issues/75318.
335+
""")
336+
337+
case let code:
338+
print("""
339+
Failed to dump symbols for module '\(id)' due to exit code \(code) \
340+
from 'swift symbolgraph-extract'. \
341+
If the output above indicates 'swift symbolgraph-extract' exited \
342+
gracefully, this is most likely because the module.modulemap file declares \
343+
a different module name than we detected from the package manifest.
344+
""")
345+
}
325346
}
326347
}
327348
}

Sources/UnidocClient/Unidoc.Client.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ extension Unidoc.Client
338338
"--project-type", "\(type)",
339339
"--workspace", "\(workspace.location)",
340340
"--output", "\(docs)",
341+
"--recover-from-apple-bugs",
341342
]
342343
if self.pretty
343344
{

0 commit comments

Comments
 (0)