Skip to content

Commit 20a1088

Browse files
committed
Add minimum access level as a setting for the symbol graph extraction
1 parent de0261d commit 20a1088

File tree

3 files changed

+56
-11
lines changed

3 files changed

+56
-11
lines changed

Sources/SWBCore/Settings/BuiltinMacros.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,6 +1099,7 @@ public final class BuiltinMacros {
10991099
public static let DOCC_ARCHIVE_PATH = BuiltinMacros.declareStringMacro("DOCC_ARCHIVE_PATH")
11001100
public static let DOCC_PRETTY_PRINT = BuiltinMacros.declareBooleanMacro("DOCC_PRETTY_PRINT")
11011101
public static let DOCC_EXTRACT_SPI_DOCUMENTATION = BuiltinMacros.declareBooleanMacro("DOCC_EXTRACT_SPI_DOCUMENTATION")
1102+
public static let DOCC_MINIMUM_ACCESS_LEVEL = BuiltinMacros.declareEnumMacro("DOCC_MINIMUM_ACCESS_LEVEL") as EnumMacroDeclaration<DoccMinimumAccessLevel>
11021103
public static let DOCC_SKIP_SYNTHESIZED_MEMBERS = BuiltinMacros.declareBooleanMacro("DOCC_SKIP_SYNTHESIZED_MEMBERS")
11031104
public static let DOCC_EXTRACT_EXTENSION_SYMBOLS = BuiltinMacros.declareBooleanMacro("DOCC_EXTRACT_EXTENSION_SYMBOLS")
11041105
public static let DOCC_EXTRACT_SWIFT_INFO_FOR_OBJC_SYMBOLS = BuiltinMacros.declareBooleanMacro("DOCC_EXTRACT_SWIFT_INFO_FOR_OBJC_SYMBOLS")
@@ -1650,6 +1651,7 @@ public final class BuiltinMacros {
16501651
DOCC_ARCHIVE_PATH,
16511652
DOCC_PRETTY_PRINT,
16521653
DOCC_SKIP_SYNTHESIZED_MEMBERS,
1654+
DOCC_MINIMUM_ACCESS_LEVEL,
16531655
DOCC_EXTRACT_SPI_DOCUMENTATION,
16541656
DOCC_EXTRACT_EXTENSION_SYMBOLS,
16551657
DOCC_EXTRACT_SWIFT_INFO_FOR_OBJC_SYMBOLS,
@@ -2757,6 +2759,18 @@ public enum LinkerDriverChoice: String, Equatable, Hashable, EnumerationMacroTyp
27572759
case auto
27582760
}
27592761

2762+
public enum DoccMinimumAccessLevel: String, Equatable, Hashable, EnumerationMacroType {
2763+
public static let defaultValue = DoccMinimumAccessLevel.none
2764+
2765+
case none = ""
2766+
case `private` = "private"
2767+
case `fileprivate` = "fileprivate"
2768+
case `internal` = "internal"
2769+
case `package` = "package"
2770+
case `public` = "public"
2771+
case `open` = "open"
2772+
}
2773+
27602774
/// Enumeration macro type for the value of the `INFOPLIST_KEY_LSApplicationCategoryType` build setting.
27612775
public enum ApplicationCategory: String, Equatable, Hashable, EnumerationMacroType {
27622776
public static let defaultValue = ApplicationCategory.none

Sources/SWBCore/SpecImplementations/Tools/DocumentationCompiler.swift

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ final public class DocumentationCompilerSpec: GenericCompilerSpec, SpecIdentifie
7878
var additionalFlags = [String]()
7979

8080
// Check if pretty print is requested
81-
if cbc.scope.evaluate(BuiltinMacros.DOCC_PRETTY_PRINT) && swiftCompilerInfo.toolFeatures.has(.emitExtensionBlockSymbols) {
81+
if cbc.scope.evaluate(BuiltinMacros.DOCC_PRETTY_PRINT) {
8282
additionalFlags.append("-symbol-graph-pretty-print")
8383
}
8484

@@ -88,19 +88,34 @@ final public class DocumentationCompilerSpec: GenericCompilerSpec, SpecIdentifie
8888
}
8989

9090
// Check if synthesized members should be skipped
91-
if cbc.scope.evaluate(BuiltinMacros.DOCC_SKIP_SYNTHESIZED_MEMBERS) && swiftCompilerInfo.toolFeatures.has(.emitExtensionBlockSymbols) {
91+
if cbc.scope.evaluate(BuiltinMacros.DOCC_SKIP_SYNTHESIZED_MEMBERS) {
9292
additionalFlags.append("-symbol-graph-skip-synthesized-members")
9393
}
9494

95-
switch DocumentationType(from: cbc) {
96-
case .executable:
97-
// When building executable types (like applications and command-line tools), include
98-
// internal symbols in the generated symbol graph.
99-
return additionalFlags.appending(contentsOf: ["-symbol-graph-minimum-access-level", "internal"])
100-
case .framework, .none:
101-
// For frameworks (and non-documentable types), just use the default behavior
102-
// of the symbol graph tool.
103-
return additionalFlags
95+
switch cbc.scope.evaluate(BuiltinMacros.DOCC_MINIMUM_ACCESS_LEVEL) {
96+
case .none:
97+
switch DocumentationType(from: cbc) {
98+
case .executable:
99+
// When building executable types (like applications and command-line tools), include
100+
// internal symbols in the generated symbol graph.
101+
return additionalFlags.appending(contentsOf: ["-symbol-graph-minimum-access-level", "internal"])
102+
case .framework, .none:
103+
// For frameworks (and non-documentable types), just use the default behavior
104+
// of the symbol graph tool.
105+
return additionalFlags
106+
}
107+
case .private:
108+
return additionalFlags.appending(contentsOf: ["symbol-graph-minimum-access-level", "private"])
109+
case .fileprivate:
110+
return additionalFlags.appending(contentsOf: ["symbol-graph-minimum-access-level", "fileprivate"])
111+
case .internal:
112+
return additionalFlags.appending(contentsOf: ["symbol-graph-minimum-access-level", "internal"])
113+
case .package:
114+
return additionalFlags.appending(contentsOf: ["symbol-graph-minimum-access-level", "package"])
115+
case .public:
116+
return additionalFlags.appending(contentsOf: ["symbol-graph-minimum-access-level", "public"])
117+
case .open:
118+
return additionalFlags.appending(contentsOf: ["symbol-graph-minimum-access-level", "open"])
104119
}
105120
}
106121

Sources/SWBUniversalPlatform/Specs/Documentation.xcspec

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,22 @@
175175
DefaultValue = NO;
176176
},
177177

178+
// The minimum access level for API for the symbol graph extractor to generate
179+
{
180+
Name = DOCC_MINIMUM_ACCESS_LEVEL;
181+
Type = Enumeration;
182+
Values = (
183+
none,
184+
private,
185+
fileprivate,
186+
internal,
187+
package,
188+
public,
189+
open,
190+
);
191+
DefaultValue = none;
192+
},
193+
178194
{
179195
Name = DOCC_EXTRACT_SWIFT_INFO_FOR_OBJC_SYMBOLS;
180196
Type = bool;

0 commit comments

Comments
 (0)