Skip to content

Copy snippet symbol graphs to the correct final destination #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion IntegrationTests/Tests/SnippetDocumentationGenerationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import XCTest

final class SnippetDocumentationGenerationTests: ConcurrencyRequiringTestCase {
func testGenerateDocumentationForPackageWithSnippets() throws {
let packageName = "PackageWithSnippets"
let result = try swiftPackage(
"generate-documentation",
"--target", "Library",
workingDirectory: try setupTemporaryDirectoryForFixture(named: "PackageWithSnippets")
workingDirectory: try setupTemporaryDirectoryForFixture(named: packageName)
)

result.assertExitStatusEquals(0)
Expand Down Expand Up @@ -45,6 +46,19 @@ final class SnippetDocumentationGenerationTests: ConcurrencyRequiringTestCase {
"symbol-graphs/unified-symbol-graphs",
]
)

let unifiedSymbolGraphDirectory = subDirectoriesOfSymbolGraphDirectory.first {
$0.pathComponents.last == "unified-symbol-graphs"
}!

let symbolGraphEnumerator = FileManager.default.enumerator(at: unifiedSymbolGraphDirectory,
includingPropertiesForKeys: [.isRegularFileKey])!
let symbolGraphPaths = try (symbolGraphEnumerator.allObjects as! [URL]).filter {
try $0.resourceValues(forKeys: [.isRegularFileKey]).isRegularFile!
}
XCTAssertNotNil(symbolGraphPaths.first {
$0.pathComponents.last == "\(packageName)-snippets.symbols.json"
})
}

func testPreviewDocumentationWithSnippets() throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@ extension PackageManager {
struct DocCSymbolGraphResult {
let unifiedSymbolGraphsDirectory: URL
let targetSymbolGraphsDirectory: URL
let snippetSymbolGraphsDirectory: URL?
let snippetSymbolGraphFile: URL?

init(
unifiedSymbolGraphsDirectory: URL,
targetSymbolGraphsDirectory: URL,
snippetSymbolGraphsDirectory: URL?
snippetSymbolGraphFile: URL?
) {
self.unifiedSymbolGraphsDirectory = unifiedSymbolGraphsDirectory
self.targetSymbolGraphsDirectory = targetSymbolGraphsDirectory
self.snippetSymbolGraphsDirectory = snippetSymbolGraphsDirectory
self.snippetSymbolGraphFile = snippetSymbolGraphFile
}

init(targetSymbolGraphsDirectory: URL) {
self.unifiedSymbolGraphsDirectory = targetSymbolGraphsDirectory
self.targetSymbolGraphsDirectory = targetSymbolGraphsDirectory
self.snippetSymbolGraphsDirectory = nil
self.snippetSymbolGraphFile = nil
}
}

Expand Down Expand Up @@ -70,7 +70,7 @@ extension PackageManager {
print("snippet extractor provided, attempting to generate snippet symbol graph")
}

guard let snippetSymbolGraphsDirectory = try snippetExtractor.generateSnippets(
guard let snippetSymbolGraphFile = try snippetExtractor.generateSnippets(
for: target,
context: context
) else {
Expand All @@ -82,7 +82,7 @@ extension PackageManager {
}

if verbose {
print("snippet symbol graph directory path: '\(snippetSymbolGraphsDirectory.path)'")
print("snippet symbol graph file: '\(snippetSymbolGraphFile.path)'")
}

// Since we successfully produced symbol graphs for snippets contained in the
Expand Down Expand Up @@ -125,20 +125,20 @@ extension PackageManager {
toPath: targetSymbolGraphsUnifiedDirectory.path
)

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

// Copy the snippet symbol graphs into the unified directory
try FileManager.default.copyItem(
atPath: snippetSymbolGraphsDirectory.path,
toPath: snippetSymbolGraphsUnifiedDirectory.path
atPath: snippetSymbolGraphFile.path,
toPath: snippetSymbolGraphFileInUnifiedDirectory.path
)

return DocCSymbolGraphResult(
unifiedSymbolGraphsDirectory: unifiedSymbolGraphsDirectory,
targetSymbolGraphsDirectory: targetSymbolGraphsUnifiedDirectory,
snippetSymbolGraphsDirectory: snippetSymbolGraphsUnifiedDirectory
snippetSymbolGraphFile: snippetSymbolGraphFileInUnifiedDirectory
)
}
}