-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Fix create symbol graph plugin entrypoint #7629
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
import Basics | ||
import CoreCommands | ||
import Foundation | ||
import PackageGraph | ||
import PackageModel | ||
import SPMBuildCore | ||
|
||
|
@@ -383,14 +384,38 @@ final class PluginDelegate: PluginInvocationDelegate { | |
// Create a build system for building the target., skipping the the cache because we need the build plan. | ||
let buildSystem = try swiftCommandState.createBuildSystem(explicitBuildSystem: .native, cacheBuildManifest: false) | ||
|
||
// Find the target in the build operation's package graph; it's an error if we don't find it. | ||
// Find the target in the build operation's package graph | ||
// 1. First look for a matching destination module | ||
// 2. If not found, search for a matching tools module, only allowing | ||
// modules that should be built for the host (macro, plugin, test). | ||
// 3. Error if no matching targets are found. | ||
// | ||
// FIXME: dynamic graph | ||
// This should work by requesting a build for a target w/ destination: | ||
// .destination and generating the graph needed on demand instead of | ||
// looking for a preexisting matching target. | ||
let target: ResolvedModule | ||
let destination: BuildParameters.Destination | ||
let packageGraph = try buildSystem.getPackageGraph() | ||
guard let target = packageGraph.target(for: targetName, destination: .destination) else { | ||
throw StringError("could not find a target named “\(targetName)”") | ||
if let _target = packageGraph.target(for: targetName, destination: .destination) { | ||
target = _target | ||
destination = .target | ||
} else if let _target = packageGraph.target(for: targetName, destination: .tools), | ||
(_target.type == .macro || _target.type == .plugin || _target.type == .test) { | ||
target = _target | ||
destination = .host | ||
} else { | ||
throw StringError("Could not find a target named “\(targetName)”") | ||
} | ||
|
||
// Build the target, if needed. | ||
try buildSystem.build(subset: .target(target.name)) | ||
try buildSystem.build(subset: .target(target.name, for: destination)) | ||
|
||
let buildParameters: BuildParameters = try if destination == .target { | ||
buildSystem.buildPlan.destinationBuildParameters | ||
} else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The indentation looks off here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is correct for let buildParameters: BuildParameters =
try if destination == .target {
buildSystem.buildPlan.destinationBuildParameters
} else {
buildSystem.buildPlan.toolsBuildParameters
} |
||
buildSystem.buildPlan.toolsBuildParameters | ||
} | ||
|
||
// Configure the symbol graph extractor. | ||
var symbolGraphExtractor = try SymbolGraphExtract( | ||
|
@@ -419,7 +444,7 @@ final class PluginDelegate: PluginInvocationDelegate { | |
guard let package = packageGraph.package(for: target) else { | ||
throw StringError("could not determine the package for target “\(target.name)”") | ||
} | ||
let outputDir = try buildSystem.buildPlan.toolsBuildParameters.dataPath.appending( | ||
let outputDir = buildParameters.dataPath.appending( | ||
components: "extracted-symbols", | ||
package.identity.description, | ||
target.name | ||
|
@@ -430,7 +455,7 @@ final class PluginDelegate: PluginInvocationDelegate { | |
let result = try symbolGraphExtractor.extractSymbolGraph( | ||
module: target, | ||
buildPlan: try buildSystem.buildPlan, | ||
buildParameters: buildSystem.buildPlan.destinationBuildParameters, | ||
buildParameters: buildParameters, | ||
outputRedirection: .collect, | ||
outputDirectory: outputDir, | ||
verboseOutput: self.swiftCommandState.logLevel <= .info | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should add a
func buildsetFor(target: String) throws -> Buildset
toBuildSystem
protocol which would encapsulate most of the logic here and allow you to select appropriate build parameters based on resulting buildset.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the client should be able to request any module built for the target/destination platform and we should create the graph that does that. Is that what you're suggesting here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, client would pass a name and we'd start with
.destination
and if that doesn't exist produce a.host
if it's appropriate.