Skip to content

Commit 427b250

Browse files
committed
Copy snippet symbol graphs to the correct final destination
The snippet symbol graph is currently being generated with the changes in e013865, however they are not being copied to the correct final destination. The `snippet-extract` tool now takes input and output *files* instead of directories, however there is still one place in the plugin where we are still treating the output like a directory, so the snippet symbol graph basename path component looks like a directory, and needs additional basenames to put it in the right place with the correct file extension. rdar://104045850
1 parent 252c51b commit 427b250

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

IntegrationTests/Tests/SnippetDocumentationGenerationTests.swift

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ import XCTest
1010

1111
final class SnippetDocumentationGenerationTests: ConcurrencyRequiringTestCase {
1212
func testGenerateDocumentationForPackageWithSnippets() throws {
13+
let packageName = "PackageWithSnippets"
1314
let result = try swiftPackage(
1415
"generate-documentation",
1516
"--target", "Library",
16-
workingDirectory: try setupTemporaryDirectoryForFixture(named: "PackageWithSnippets")
17+
workingDirectory: try setupTemporaryDirectoryForFixture(named: packageName)
1718
)
1819

1920
result.assertExitStatusEquals(0)
@@ -45,6 +46,19 @@ final class SnippetDocumentationGenerationTests: ConcurrencyRequiringTestCase {
4546
"symbol-graphs/unified-symbol-graphs",
4647
]
4748
)
49+
50+
let unifiedSymbolGraphDirectory = subDirectoriesOfSymbolGraphDirectory.first {
51+
$0.pathComponents.last == "unified-symbol-graphs"
52+
}!
53+
54+
let symbolGraphEnumerator = FileManager.default.enumerator(at: unifiedSymbolGraphDirectory,
55+
includingPropertiesForKeys: [.isRegularFileKey])!
56+
let symbolGraphPaths = try (symbolGraphEnumerator.allObjects as! [URL]).filter {
57+
try $0.resourceValues(forKeys: [.isRegularFileKey]).isRegularFile!
58+
}
59+
XCTAssertNotNil(symbolGraphPaths.first {
60+
$0.pathComponents.last == "\(packageName)-snippets.symbols.json"
61+
})
4862
}
4963

5064
func testPreviewDocumentationWithSnippets() throws {

Plugins/SharedPackagePluginExtensions/PackageManager+getSymbolGraphsForDocC.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,22 @@ extension PackageManager {
1313
struct DocCSymbolGraphResult {
1414
let unifiedSymbolGraphsDirectory: URL
1515
let targetSymbolGraphsDirectory: URL
16-
let snippetSymbolGraphsDirectory: URL?
16+
let snippetSymbolGraphFile: URL?
1717

1818
init(
1919
unifiedSymbolGraphsDirectory: URL,
2020
targetSymbolGraphsDirectory: URL,
21-
snippetSymbolGraphsDirectory: URL?
21+
snippetSymbolGraphFile: URL?
2222
) {
2323
self.unifiedSymbolGraphsDirectory = unifiedSymbolGraphsDirectory
2424
self.targetSymbolGraphsDirectory = targetSymbolGraphsDirectory
25-
self.snippetSymbolGraphsDirectory = snippetSymbolGraphsDirectory
25+
self.snippetSymbolGraphFile = snippetSymbolGraphFile
2626
}
2727

2828
init(targetSymbolGraphsDirectory: URL) {
2929
self.unifiedSymbolGraphsDirectory = targetSymbolGraphsDirectory
3030
self.targetSymbolGraphsDirectory = targetSymbolGraphsDirectory
31-
self.snippetSymbolGraphsDirectory = nil
31+
self.snippetSymbolGraphFile = nil
3232
}
3333
}
3434

@@ -70,7 +70,7 @@ extension PackageManager {
7070
print("snippet extractor provided, attempting to generate snippet symbol graph")
7171
}
7272

73-
guard let snippetSymbolGraphsDirectory = try snippetExtractor.generateSnippets(
73+
guard let snippetSymbolGraphFile = try snippetExtractor.generateSnippets(
7474
for: target,
7575
context: context
7676
) else {
@@ -82,7 +82,7 @@ extension PackageManager {
8282
}
8383

8484
if verbose {
85-
print("snippet symbol graph directory path: '\(snippetSymbolGraphsDirectory.path)'")
85+
print("snippet symbol graph file: '\(snippetSymbolGraphFile.path)'")
8686
}
8787

8888
// Since we successfully produced symbol graphs for snippets contained in the
@@ -125,20 +125,20 @@ extension PackageManager {
125125
toPath: targetSymbolGraphsUnifiedDirectory.path
126126
)
127127

128-
let snippetSymbolGraphsUnifiedDirectory = unifiedSymbolGraphsDirectory.appendingPathComponent(
129-
"snippet-symbol-graphs", isDirectory: true
128+
let snippetSymbolGraphFileInUnifiedDirectory = unifiedSymbolGraphsDirectory.appendingPathComponent(
129+
snippetSymbolGraphFile.lastPathComponent, isDirectory: false
130130
)
131131

132132
// Copy the snippet symbol graphs into the unified directory
133133
try FileManager.default.copyItem(
134-
atPath: snippetSymbolGraphsDirectory.path,
135-
toPath: snippetSymbolGraphsUnifiedDirectory.path
134+
atPath: snippetSymbolGraphFile.path,
135+
toPath: snippetSymbolGraphFileInUnifiedDirectory.path
136136
)
137137

138138
return DocCSymbolGraphResult(
139139
unifiedSymbolGraphsDirectory: unifiedSymbolGraphsDirectory,
140140
targetSymbolGraphsDirectory: targetSymbolGraphsUnifiedDirectory,
141-
snippetSymbolGraphsDirectory: snippetSymbolGraphsUnifiedDirectory
141+
snippetSymbolGraphFile: snippetSymbolGraphFileInUnifiedDirectory
142142
)
143143
}
144144
}

0 commit comments

Comments
 (0)