Skip to content

Commit adc8503

Browse files
Remove confusing error when no docs are produced (#149)
Removes a confusing error that started being emitted when `docc convert` failed to actually produce documentation for an otherwise valid DocC catalog. This regression was introduced by the enablement of transform for static hosting by default since that command relies on a `data` subdirectory existing in the produced documentation archive. Resolves rdar://91790147.
1 parent 201f01f commit adc8503

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

Sources/SwiftDocCUtilities/Action/Actions/Convert/ConvertAction.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,12 +377,19 @@ public struct ConvertAction: Action, RecreatingContext {
377377
}
378378

379379
// Process Static Hosting as needed.
380-
if transformForStaticHosting, let templateDirectory = htmlTemplateDirectory {
380+
if transformForStaticHosting,
381+
let templateDirectory = htmlTemplateDirectory,
382+
// If this conversion didn't actually produce documentation, then we expect
383+
// the creation of this data provider to fail because there will be no 'data' subdirectory
384+
// in the documentation output. (r91790147)
385+
let dataProvider = try? LocalFileSystemDataProvider(
386+
rootURL: temporaryFolder.appendingPathComponent(NodeURLGenerator.Path.dataFolderName)
387+
)
388+
{
381389
if indexHTMLData == nil {
382390
indexHTMLData = try StaticHostableTransformer.transformHTMLTemplate(htmlTemplate: templateDirectory, hostingBasePath: hostingBasePath)
383391
}
384392

385-
let dataProvider = try LocalFileSystemDataProvider(rootURL: temporaryFolder.appendingPathComponent(NodeURLGenerator.Path.dataFolderName))
386393
let transformer = StaticHostableTransformer(dataProvider: dataProvider, fileManager: fileManager, outputURL: temporaryFolder, indexHTMLData: indexHTMLData!)
387394
try transformer.transform()
388395
}

Tests/SwiftDocCUtilitiesTests/ConvertActionTests.swift

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2300,6 +2300,35 @@ class ConvertActionTests: XCTestCase {
23002300

23012301
expectedOutput.assertExist(at: result.outputs[0], fileManager: testDataProvider)
23022302
}
2303+
2304+
// Tests that the default behavior of `docc convert` on the command-line does not throw an error
2305+
// when processing a DocC catalog that does not actually produce documentation. (r91790147)
2306+
func testConvertDocCCatalogThatProducesNoDocumentationDoesNotThrowError() throws {
2307+
let emptyCatalog = Folder(
2308+
name: "unit-test.docc",
2309+
content: [InfoPlist(displayName: "TestBundle", identifier: "com.test.example")]
2310+
)
2311+
2312+
let temporaryDirectory = try createTemporaryDirectory()
2313+
let outputDirectory = temporaryDirectory.appendingPathComponent("output", isDirectory: true)
2314+
let doccCatalogDirectory = try emptyCatalog.write(inside: temporaryDirectory)
2315+
let htmlTemplateDirectory = try Folder.emptyHTMLTemplateDirectory.write(inside: temporaryDirectory)
2316+
2317+
setenv(TemplateOption.environmentVariableKey, htmlTemplateDirectory.path, 1)
2318+
defer {
2319+
unsetenv(TemplateOption.environmentVariableKey)
2320+
}
2321+
2322+
let convertCommand = try Docc.Convert.parse(
2323+
[
2324+
doccCatalogDirectory.path,
2325+
"--output-path", outputDirectory.path,
2326+
]
2327+
)
2328+
2329+
var action = try ConvertAction(fromConvertCommand: convertCommand)
2330+
_ = try action.perform(logHandle: .none)
2331+
}
23032332

23042333
func testConvertWithCustomTemplates() throws {
23052334
let info = InfoPlist(displayName: "TestConvertWithCustomTemplates", identifier: "com.test.example")

0 commit comments

Comments
 (0)