@@ -1229,37 +1229,55 @@ final class PluginDelegate: PluginInvocationDelegate {
1229
1229
}
1230
1230
1231
1231
private func createSymbolGraph( forTarget targetName: String , options: PluginInvocationSymbolGraphOptions ) throws -> PluginInvocationSymbolGraphResult {
1232
- // Current implementation uses `SymbolGraphExtract()` but we can probably do better in the future.
1233
- let buildParameters = try swiftTool. buildParameters ( )
1234
- let buildOperation = try swiftTool. createBuildOperation ( cacheBuildManifest: false ) // We only get a build plan if we don't cache
1235
- try buildOperation. build ( subset: . target( targetName) )
1236
- let symbolGraphExtract = try SymbolGraphExtract ( tool: swiftTool. getToolchain ( ) . getSymbolGraphExtract ( ) )
1237
- let minimumAccessLevel : AccessLevel
1232
+ // Current implementation uses `SymbolGraphExtract()` but in the future we should emit the symbol graph while building.
1233
+
1234
+ // Create a build operation for building the target., skipping the the cache because we need the build plan.
1235
+ let buildOperation = try swiftTool. createBuildOperation ( cacheBuildManifest: false )
1236
+
1237
+ // Find the target in the build operation's package graph; it's an error if we don't find it.
1238
+ let packageGraph = try buildOperation. getPackageGraph ( )
1239
+ guard let target = packageGraph. allTargets. first ( where: { $0. name == targetName } ) else {
1240
+ throw StringError ( " could not find a target named “ \( targetName) ” " )
1241
+ }
1242
+
1243
+ // Build the target, if needed.
1244
+ try buildOperation. build ( subset: . target( target. name) )
1245
+
1246
+ // Configure the symbol graph extractor.
1247
+ var symbolGraphExtractor = try SymbolGraphExtract ( tool: swiftTool. getToolchain ( ) . getSymbolGraphExtract ( ) )
1248
+ symbolGraphExtractor. skipSynthesizedMembers = !options. includeSynthesized
1238
1249
switch options. minimumAccessLevel {
1239
1250
case . private:
1240
- minimumAccessLevel = . private
1251
+ symbolGraphExtractor . minimumAccessLevel = . private
1241
1252
case . fileprivate:
1242
- minimumAccessLevel = . fileprivate
1253
+ symbolGraphExtractor . minimumAccessLevel = . fileprivate
1243
1254
case . internal:
1244
- minimumAccessLevel = . internal
1255
+ symbolGraphExtractor . minimumAccessLevel = . internal
1245
1256
case . public:
1246
- minimumAccessLevel = . public
1257
+ symbolGraphExtractor . minimumAccessLevel = . public
1247
1258
case . open:
1248
- minimumAccessLevel = . open
1259
+ symbolGraphExtractor . minimumAccessLevel = . open
1249
1260
}
1250
-
1251
- // Extract the symbol graph.
1252
- try symbolGraphExtract. dumpSymbolGraph (
1253
- buildPlan: buildOperation. buildPlan!,
1254
- prettyPrint: false ,
1255
- skipSynthesisedMembers: !options. includeSynthesized,
1256
- minimumAccessLevel: minimumAccessLevel,
1257
- skipInheritedDocs: true ,
1258
- includeSPISymbols: options. includeSPI)
1259
-
1261
+ symbolGraphExtractor. skipInheritedDocs = true
1262
+ symbolGraphExtractor. includeSPISymbols = options. includeSPI
1263
+
1264
+ // Run the symbol graph extractor on the target.
1265
+ guard let buildPlan = buildOperation. buildPlan else {
1266
+ throw StringError ( " could not get the build plan from the build operation " )
1267
+ }
1268
+ guard let package = packageGraph. package ( for: target) else {
1269
+ throw StringError ( " could not determine the package for target “ \( target. name) ” " )
1270
+ }
1271
+ let outputDir = buildPlan. buildParameters. dataPath. appending ( components: " extracted-symbols " , package . identity. description, target. name)
1272
+ try symbolGraphExtractor. extractSymbolGraph (
1273
+ target: target,
1274
+ buildPlan: buildPlan,
1275
+ outputRedirection: . collect,
1276
+ verbose: false ,
1277
+ outputDirectory: outputDir)
1278
+
1260
1279
// Return the results to the plugin.
1261
- return PluginInvocationSymbolGraphResult (
1262
- directoryPath: buildParameters. symbolGraph. pathString)
1280
+ return PluginInvocationSymbolGraphResult ( directoryPath: outputDir. pathString)
1263
1281
}
1264
1282
}
1265
1283
0 commit comments