@@ -30,6 +30,7 @@ import PackagePlugin
30
30
}
31
31
32
32
let verbose = argumentExtractor. extractFlag ( named: " verbose " ) > 0
33
+ let isCombinedDocumentationEnabled = argumentExtractor. extractFlag ( named: PluginFlag . enableCombinedDocumentationSupportFlagName) > 0
33
34
34
35
// Parse the given command-line arguments
35
36
let parsedArguments = ParsedArguments ( argumentExtractor. remainingArguments)
@@ -100,14 +101,22 @@ import PackagePlugin
100
101
// arguments to pass to `docc`. ParsedArguments will merge the flags provided
101
102
// by the user with default fallback values for required flags that were not
102
103
// provided.
103
- let doccArguments = parsedArguments. doccArguments (
104
+ var doccArguments = parsedArguments. doccArguments (
104
105
action: . convert,
105
106
targetKind: target. kind == . executable ? . executable : . library,
106
107
doccCatalogPath: target. doccCatalogPath,
107
108
targetName: target. name,
108
109
symbolGraphDirectoryPath: symbolGraphs. unifiedSymbolGraphsDirectory. path,
109
110
outputPath: doccArchiveOutputPath
110
111
)
112
+ if isCombinedDocumentationEnabled {
113
+ doccArguments. append ( CommandLineOption . enableExternalLinkSupport. defaultName)
114
+
115
+ for taskDependency in task. dependencies {
116
+ let dependencyArchivePath = taskDependency. target. doccArchiveOutputPath ( in: context)
117
+ doccArguments. append ( contentsOf: [ CommandLineOption . externalLinkDependency. defaultName, dependencyArchivePath] )
118
+ }
119
+ }
111
120
112
121
if verbose {
113
122
let arguments = doccArguments. joined ( separator: " " )
@@ -171,9 +180,31 @@ import PackagePlugin
171
180
queue. addOperations ( operations, waitUntilFinished: true )
172
181
173
182
if documentationArchives. count > 1 {
183
+ documentationArchives = documentationArchives. sorted ( by: { $0. lastPathComponent < $1. lastPathComponent } )
184
+
185
+ if isCombinedDocumentationEnabled {
186
+ // Merge the archives into a combined archive
187
+ let combinedArchiveName = " Combined \( context. package . displayName) Documentation.doccarchive "
188
+ let combinedArchiveOutput = URL ( fileURLWithPath: context. pluginWorkDirectory. appending ( combinedArchiveName) . string)
189
+
190
+ var mergeCommandArguments = [ " merge " ]
191
+ mergeCommandArguments. append ( contentsOf: documentationArchives. map ( \. standardizedFileURL. path) )
192
+ mergeCommandArguments. append ( contentsOf: [ " --output-path " , combinedArchiveOutput. path] )
193
+
194
+ // Remove the combined archive if it already exists
195
+ try ? FileManager . default. removeItem ( at: combinedArchiveOutput)
196
+
197
+ // Create a new combined archive
198
+ let process = try Process . run ( doccExecutableURL, arguments: mergeCommandArguments)
199
+ process. waitUntilExit ( )
200
+
201
+ // Display the combined archive before the other generated archives
202
+ documentationArchives. insert ( combinedArchiveOutput, at: 0 )
203
+ }
204
+
174
205
print ( """
175
206
Generated \( documentationArchives. count) DocC archives in ' \( context. pluginWorkDirectory. string) ':
176
- \( documentationArchives. map ( \. lastPathComponent) . sorted ( ) . joined ( separator: " \n " ) )
207
+ \( documentationArchives. map ( \. lastPathComponent) . joined ( separator: " \n " ) )
177
208
""" )
178
209
}
179
210
}
0 commit comments