Skip to content

Commit 5f2e247

Browse files
authored
Rename snippet-build to snippet-extract (#33)
In general, the "build" terminology isn't really correct for snippets, as no compilation is going on as far as the plugin is concerned. This tool is actually parsing and extracting text for creation of symbol graphs for a package's snippets. So we should call this process "extraction" rather than "building". rdar://101436368
1 parent 3e3305b commit 5f2e247

File tree

11 files changed

+96
-96
lines changed

11 files changed

+96
-96
lines changed

Package.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ let package = Package(
3030
intent: .documentationGeneration()
3131
),
3232
dependencies: [
33-
"snippet-build",
33+
"snippet-extract",
3434
],
3535
path: "Plugins/Swift-DocC Convert",
3636
exclude: ["Symbolic Links/README.md"]
@@ -45,7 +45,7 @@ let package = Package(
4545
)
4646
),
4747
dependencies: [
48-
"snippet-build",
48+
"snippet-extract",
4949
],
5050
exclude: ["Symbolic Links/README.md"]
5151
),
@@ -72,7 +72,7 @@ let package = Package(
7272
),
7373
.target(name: "Snippets"),
7474
.executableTarget(
75-
name: "snippet-build",
75+
name: "snippet-extract",
7676
dependencies: [
7777
"Snippets",
7878
.product(name: "SymbolKit", package: "swift-docc-symbolkit"),

Plugins/SharedPackagePluginExtensions/PackageManager+getSymbolGraphsForDocC.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ extension PackageManager {
3838
for target: SwiftSourceModuleTarget,
3939
context: PluginContext,
4040
verbose: Bool,
41-
snippetBuilder: SnippetBuilder?
41+
snippetExtractor: SnippetExtractor?
4242
) throws -> DocCSymbolGraphResult {
4343
// First generate the primary symbol graphs containing information about the
4444
// symbols defined in the target itself.
@@ -59,18 +59,18 @@ extension PackageManager {
5959
print("target symbol graph directory path: '\(targetSymbolGraphsDirectory.path)'")
6060
}
6161

62-
// Then, check to see if we were provided a snippet builder. If so,
62+
// Then, check to see if we were provided a snippet extractor. If so,
6363
// we should attempt to generate symbol graphs for any snippets included in the
6464
// target's containing package.
65-
guard let snippetBuilder = snippetBuilder else {
65+
guard let snippetExtractor = snippetExtractor else {
6666
return DocCSymbolGraphResult(targetSymbolGraphsDirectory: targetSymbolGraphsDirectory)
6767
}
6868

6969
if verbose {
70-
print("snippet builder provided, attempting to generate snippet symbol graph")
70+
print("snippet extractor provided, attempting to generate snippet symbol graph")
7171
}
7272

73-
guard let snippetSymbolGraphsDirectory = try snippetBuilder.generateSnippets(
73+
guard let snippetSymbolGraphsDirectory = try snippetExtractor.generateSnippets(
7474
for: target,
7575
context: context
7676
) else {

Plugins/SharedPackagePluginExtensions/SnippetBuilder+generateSnippetsForTarget.swift renamed to Plugins/SharedPackagePluginExtensions/SnippetExtractor+generateSnippetsForTarget.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import Foundation
1010
import PackagePlugin
1111

12-
extension SnippetBuilder {
12+
extension SnippetExtractor {
1313
func generateSnippets(
1414
for target: SwiftSourceModuleTarget,
1515
context: PluginContext

Plugins/Swift-DocC Convert/SwiftDocCConvert.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ import PackagePlugin
4747
}
4848

4949
#if swift(>=5.7)
50-
let snippetBuildTool = try context.tool(named: "snippet-build")
51-
let snippetBuilder = SnippetBuilder(
52-
snippetTool: URL(fileURLWithPath: snippetBuildTool.path.string, isDirectory: false),
50+
let snippetExtractTool = try context.tool(named: "snippet-extract")
51+
let snippetExtractor = SnippetExtractor(
52+
snippetTool: URL(fileURLWithPath: snippetExtractTool.path.string, isDirectory: false),
5353
workingDirectory: URL(fileURLWithPath: context.pluginWorkDirectory.string, isDirectory: true)
5454
)
5555
#else
56-
let snippetBuilder: SnippetBuilder? = nil
56+
let snippetExtractor: SnippetBuilder? = nil
5757
#endif
5858

5959

@@ -70,7 +70,7 @@ import PackagePlugin
7070
for: target,
7171
context: context,
7272
verbose: verbose,
73-
snippetBuilder: snippetBuilder
73+
snippetExtractor: snippetExtractor
7474
)
7575

7676
if try FileManager.default.contentsOfDirectory(atPath: symbolGraphs.targetSymbolGraphsDirectory.path).isEmpty {

Plugins/Swift-DocC Preview/SwiftDocCPreview.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,20 @@ import PackagePlugin
7070
}
7171

7272
#if swift(>=5.7)
73-
let snippetBuildTool = try context.tool(named: "snippet-build")
74-
let snippetBuilder = SnippetBuilder(
75-
snippetTool: URL(fileURLWithPath: snippetBuildTool.path.string, isDirectory: false),
73+
let snippetExtractTool = try context.tool(named: "snippet-extract")
74+
let snippetExtractor = SnippetExtractor(
75+
snippetTool: URL(fileURLWithPath: snippetExtractTool.path.string, isDirectory: false),
7676
workingDirectory: URL(fileURLWithPath: context.pluginWorkDirectory.string, isDirectory: true)
7777
)
7878
#else
79-
let snippetBuilder: SnippetBuilder? = nil
79+
let snippetExtractor: SnippetExtractor? = nil
8080
#endif
8181

8282
let symbolGraphs = try packageManager.doccSymbolGraphs(
8383
for: target,
8484
context: context,
8585
verbose: verbose,
86-
snippetBuilder: snippetBuilder
86+
snippetExtractor: snippetExtractor
8787
)
8888

8989
if try FileManager.default.contentsOfDirectory(atPath: symbolGraphs.targetSymbolGraphsDirectory.path).isEmpty {

Sources/SwiftDocCPluginUtilities/Snippets/SnippetBuilder.swift renamed to Sources/SwiftDocCPluginUtilities/Snippets/SnippetExtractor.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,22 @@
88

99
import Foundation
1010

11-
/// Manages snippet symbol graph building.
12-
public class SnippetBuilder {
11+
/// Manages snippet symbol graph extraction.
12+
public class SnippetExtractor {
1313
/// Uniquely identifies a Swift Package Manager package.
1414
public typealias PackageIdentifier = String
1515

16-
enum SymbolGraphBuildResult {
16+
enum SymbolGraphExtractionResult {
1717
case packageDoesNotProduceSnippets
1818
case packageContainsSnippets(symbolGraphDirectory: URL)
1919
}
2020

2121
private let snippetTool: URL
2222
private let workingDirectory: URL
2323

24-
private var snippetSymbolGraphBuildResults = [PackageIdentifier : SymbolGraphBuildResult]()
24+
private var snippetSymbolGraphExtractionResults = [PackageIdentifier : SymbolGraphExtractionResult]()
2525

26-
/// Create a new snippet builder with the given snippet building tool
26+
/// Create a new snippet extractor with the given tool
2727
/// and working directory.
2828
public init(snippetTool: URL, workingDirectory: URL) {
2929
self.snippetTool = snippetTool
@@ -68,15 +68,15 @@ public class SnippetBuilder {
6868

6969
/// Generate snippets for the given package.
7070
///
71-
/// The snippet builder has an internal cache so it's safe to call this
71+
/// The snippet extractor has an internal cache so it's safe to call this
7272
/// function multiple times with the same package identifier.
7373
///
7474
/// - Parameters:
7575
/// - packageIdentifier: A unique identifier for the packge.
7676
/// - packageDisplayName: A display name for the package.
7777
/// - packageDirectory: The root directory for this package.
7878
///
79-
/// The snippet builder will look for a `Snippets` subdirectory
79+
/// The snippet extractor will look for a `Snippets` subdirectory
8080
/// within this directory.
8181
///
8282
/// - Returns: A URL for the directory containing the generated snippets or nil if
@@ -86,7 +86,7 @@ public class SnippetBuilder {
8686
packageDisplayName: String,
8787
packageDirectory: URL
8888
) throws -> URL? {
89-
switch snippetSymbolGraphBuildResults[packageIdentifier] {
89+
switch snippetSymbolGraphExtractionResults[packageIdentifier] {
9090
case .packageContainsSnippets(symbolGraphDirectory: let symbolGraphDirectory):
9191
return symbolGraphDirectory
9292
case .packageDoesNotProduceSnippets:
@@ -97,7 +97,7 @@ public class SnippetBuilder {
9797
}
9898

9999
guard let snippetsDirectory = snippetsDirectory(in: packageDirectory) else {
100-
snippetSymbolGraphBuildResults[packageIdentifier] = .packageDoesNotProduceSnippets
100+
snippetSymbolGraphExtractionResults[packageIdentifier] = .packageDoesNotProduceSnippets
101101
return nil
102102
}
103103

@@ -118,10 +118,10 @@ public class SnippetBuilder {
118118
try _runProcess(process)
119119

120120
if _fileExists(outputDirectory.path) {
121-
snippetSymbolGraphBuildResults[packageIdentifier] = .packageContainsSnippets(symbolGraphDirectory: outputDirectory)
121+
snippetSymbolGraphExtractionResults[packageIdentifier] = .packageContainsSnippets(symbolGraphDirectory: outputDirectory)
122122
return outputDirectory
123123
} else {
124-
snippetSymbolGraphBuildResults[packageIdentifier] = .packageDoesNotProduceSnippets
124+
snippetSymbolGraphExtractionResults[packageIdentifier] = .packageDoesNotProduceSnippets
125125
return nil
126126
}
127127
}

Sources/snippet-build/SnippetBuildCommand.swift renamed to Sources/snippet-extract/SnippetBuildCommand.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ import Snippets
1111
import SymbolKit
1212

1313
@main
14-
struct SnippetBuildCommand {
14+
struct SnippetExtractCommand {
1515
var snippetsDir: String
1616
var outputDir: String
1717
var moduleName: String
1818

1919
static func printUsage() {
2020
let usage = """
21-
USAGE: snippet-build <snippet directory> <output directory> <module name>
21+
USAGE: snippet-extract <snippet directory> <output directory> <module name>
2222
2323
ARGUMENTS:
2424
<snippet directory> - The directory containing Swift snippets
@@ -38,7 +38,7 @@ struct SnippetBuildCommand {
3838

3939
func emitSymbolGraph(for snippets: [Snippet], to emitFilename: URL, moduleName: String) throws {
4040
let snippetSymbols = snippets.map { SymbolGraph.Symbol($0, moduleName: moduleName, inDirectory: URL(fileURLWithPath: snippetsDir).absoluteURL) }
41-
let metadata = SymbolGraph.Metadata(formatVersion: .init(major: 0, minor: 1, patch: 0), generator: "swift-docc-plugin/snippet-build")
41+
let metadata = SymbolGraph.Metadata(formatVersion: .init(major: 0, minor: 1, patch: 0), generator: "snippet-extract")
4242
let module = SymbolGraph.Module(name: moduleName, platform: .init(architecture: nil, vendor: nil, operatingSystem: nil, environment: nil), isVirtual: true)
4343
let symbolGraph = SymbolGraph(metadata: metadata, module: module, symbols: snippetSymbols, relationships: [])
4444
try FileManager.default.createDirectory(atPath: emitFilename.deletingLastPathComponent().path, withIntermediateDirectories: true, attributes: nil)
@@ -91,9 +91,9 @@ struct SnippetBuildCommand {
9191
printUsage()
9292
exit(0)
9393
}
94-
let snippetBuild = SnippetBuildCommand(snippetsDir: CommandLine.arguments[1],
95-
outputDir: CommandLine.arguments[2],
96-
moduleName: CommandLine.arguments[3])
97-
try snippetBuild.run()
94+
let snippetExtract = SnippetExtractCommand(snippetsDir: CommandLine.arguments[1],
95+
outputDir: CommandLine.arguments[2],
96+
moduleName: CommandLine.arguments[3])
97+
try snippetExtract.run()
9898
}
9999
}

0 commit comments

Comments
 (0)