Skip to content

Commit 9c0ffb3

Browse files
committed
implement a way to pass custom defines from SSGC.CompileCommand down to SSGC.Linker.Tables
1 parent 9765cfd commit 9c0ffb3

File tree

6 files changed

+40
-12
lines changed

6 files changed

+40
-12
lines changed

Sources/SymbolGraphBuilder/Builds/SSGC.Workspace.swift

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ extension SSGC.Workspace
5757
validation:SSGC.ValidationBehavior = .ignoreErrors,
5858
clean:Bool = true) throws -> SymbolGraphObject<Void>
5959
{
60-
try self.build(some: build, toolchain: swift,
61-
status: nil,
60+
try self.build(some: build,
61+
toolchain: swift,
6262
logger: .init(validation: validation, file: nil),
6363
clean: clean)
6464
}
@@ -69,8 +69,8 @@ extension SSGC.Workspace
6969
validation:SSGC.ValidationBehavior = .ignoreErrors,
7070
clean:Bool = true) throws -> SymbolGraphObject<Void>
7171
{
72-
try self.build(some: build, toolchain: swift,
73-
status: nil,
72+
try self.build(some: build,
73+
toolchain: swift,
7474
logger: .init(validation: validation, file: nil),
7575
clean: clean)
7676
}
@@ -79,11 +79,15 @@ extension SSGC.Workspace
7979
{
8080
func build<Build>(some build:consuming Build,
8181
toolchain swift:SSGC.Toolchain,
82-
status:SSGC.StatusStream?,
82+
define defines:[String] = [],
83+
status:SSGC.StatusStream? = nil,
8384
logger:SSGC.Logger = .default(),
8485
clean:Bool) throws -> SymbolGraphObject<Void>
8586
where Build:SSGC.DocumentationBuild
8687
{
88+
/// TODO: support values?
89+
let definitions:[String: Void] = defines.reduce(into: [:]) { $0[$1] = () }
90+
8791
let metadata:SymbolGraphMetadata
8892
let package:any SSGC.DocumentationSources
8993

@@ -96,6 +100,7 @@ extension SSGC.Workspace
96100
clean: clean)
97101

98102
let documentation:SymbolGraph = try package.link(
103+
definitions: definitions,
99104
logger: logger,
100105
with: swift)
101106

Sources/SymbolGraphBuilder/SSGC.CompileCommand.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ extension SSGC
6565
var appleSDK:AppleSDK? = nil
6666

6767

68+
@Option(
69+
name: [.customLong("define"), .customShort("D")],
70+
parsing: .unconditionalSingleValue,
71+
help: "Define a trait for the Documentation compiler")
72+
var defines:[String] = []
73+
6874
@Option(
6975
name: [.customLong("Xswiftc")],
7076
parsing: .unconditionalSingleValue,
@@ -304,6 +310,7 @@ extension SSGC.CompileCommand
304310

305311
object = try workspace.build(some: build,
306312
toolchain: toolchain,
313+
define: self.defines,
307314
status: status,
308315
logger: logger,
309316
clean: self.cleanArtifacts)
@@ -312,6 +319,7 @@ extension SSGC.CompileCommand
312319
{
313320
object = try workspace.build(some: SSGC.StandardLibraryBuild.swift,
314321
toolchain: toolchain,
322+
define: self.defines,
315323
status: status,
316324
logger: logger,
317325
clean: self.cleanArtifacts)
@@ -355,6 +363,7 @@ extension SSGC.CompileCommand
355363

356364
object = try workspace.build(some: build,
357365
toolchain: toolchain,
366+
define: self.defines,
358367
status: status,
359368
logger: logger,
360369
clean: self.cleanArtifacts)

Sources/SymbolGraphBuilder/Sources/SSGC.DocumentationSources.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ extension SSGC
3131
}
3232
extension SSGC.DocumentationSources
3333
{
34-
func link(logger:SSGC.Logger, with swift:SSGC.Toolchain) throws -> SymbolGraph
34+
func link(definitions:[String: Void],
35+
logger:SSGC.Logger,
36+
with swift:SSGC.Toolchain) throws -> SymbolGraph
3537
{
3638
let moduleLayouts:[SSGC.ModuleLayout] = self.cultures
3739
let snippets:[SSGC.LazyFile] = self.snippets
@@ -143,6 +145,7 @@ extension SSGC.DocumentationSources
143145
let graph:SymbolGraph = try profiler.measure(\.linking)
144146
{
145147
try .link(projectRoot: prefix,
148+
definitions: definitions,
146149
plugins: [.swift(index: index)],
147150
modules: moduleLayouts.map(\.module),
148151
indexes: moduleIndexes,

Sources/SymbolGraphLinker/SSGC.Linker.Tables.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ extension SSGC.Linker
1111
@_spi(testable) public
1212
struct Tables//:~Copyable
1313
{
14+
let definitions:[String: Void]
1415
var diagnostics:Diagnostics<SSGC.Symbolicator>
1516

1617
@_spi(testable) public
@@ -34,12 +35,15 @@ extension SSGC.Linker
3435
var graph:SymbolGraph
3536

3637
@_spi(testable) public
37-
init(diagnostics:Diagnostics<SSGC.Symbolicator> = .init(),
38+
init(
39+
definitions:[String: Void] = [:],
40+
diagnostics:Diagnostics<SSGC.Symbolicator> = .init(),
3841
packageLinks:UCF.ResolutionTable<UCF.PackageOverload> = .init(),
3942
articleLinks:UCF.ArticleTable = .init(),
4043
anchors:SSGC.AnchorResolver = .init(),
4144
modules:[SymbolGraph.Module] = [])
4245
{
46+
self.definitions = definitions
4347
self.diagnostics = diagnostics
4448
self.packageLinks = packageLinks
4549
self.articleLinks = articleLinks
@@ -57,7 +61,6 @@ extension SSGC.Linker
5761
self.files = [:]
5862

5963
self.graph = .init(modules: modules)
60-
6164
}
6265
}
6366
}
@@ -400,6 +403,7 @@ extension SSGC.Linker.Tables
400403
{
401404
var outliner:SSGC.Outliner = .init(
402405
resolver: .init(scopes: environment, tables: consume self))
406+
403407
do
404408
{
405409
let success:Success = try body(&outliner)

Sources/SymbolGraphLinker/SSGC.Linker.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,14 @@ extension SSGC
6565
}
6666
extension SSGC.Linker
6767
{
68-
init(plugins:[any Markdown.CodeLanguageType] = [], modules:[SymbolGraph.Module])
68+
init(definitions:[String: Void],
69+
plugins:[any Markdown.CodeLanguageType],
70+
modules:[SymbolGraph.Module])
6971
{
7072
// If we were given a plugin that says it can highlight swift,
7173
// make it the default plugin for the doccomment parser.
7274
let swift:(any Markdown.CodeLanguageType)? = plugins.first { $0.name == "swift" }
73-
let tables:Tables = .init(modules: modules)
75+
let tables:Tables = .init(definitions: definitions, modules: modules)
7476

7577
self = .init(
7678
doccommentParser: .init(plugins: plugins, default: swift),

Sources/SymbolGraphLinker/SymbolGraph (ext).swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,19 @@ import Symbols
99
extension SymbolGraph
1010
{
1111
public
12-
static func link(projectRoot:Symbol.FileBase? = nil,
12+
static func link(
13+
projectRoot:Symbol.FileBase? = nil,
14+
definitions:[String: Void],
1315
plugins:consuming [any Markdown.CodeLanguageType] = [],
1416
modules:consuming [SymbolGraph.Module],
1517
indexes:consuming [SSGC.ModuleIndex],
1618
snippets:[any SSGC.ResourceFile],
1719
logger:any DiagnosticLogger) throws -> Self
1820
{
19-
var linker:SSGC.Linker = .init(plugins: plugins, modules: modules)
21+
var linker:SSGC.Linker = .init(definitions: definitions,
22+
plugins: plugins,
23+
modules: modules)
24+
2025
try linker.attach(snippets: snippets, indexes: indexes, projectRoot: projectRoot)
2126
try linker.collate()
2227

0 commit comments

Comments
 (0)