FelixHerrmann / swift-package-list

A command-line tool to get all used SPM-dependencies of an Xcode project or workspace.
MIT License
132 stars 15 forks source link

Option for getting dependencies of a specific target? #119

Open jverkoey opened 1 month ago

jverkoey commented 1 month ago

I have multiple Xcode projects in a single workspace. Each project has one or more targets, and each target has a unique set of Swift package dependencies.

The docs for this tool indicate that it might only get you the dependencies for a project, swift-package-list <project-path>; is there a possibility of getting dependencies for a specific target as well?

Possibly related, I get the following error when trying to run the command:

> swift-package-list MyApp.xcodeproj
Error: The file “Package.resolved” couldn’t be opened because there is no such file.

Notably, I am using Xcode's UI to manage all of my Swift package dependencies.

FelixHerrmann commented 3 weeks ago

Hey @jverkoey, thanks for reaching out!

Let me clarify things a bit: this tool relies on the contents of Package.resolved; depending on which kind of project you have (Xcode project/workspace, Swift package, Tuist project) this file is located in various places. Once you add a Xcode project to a workspace the workspace manages SPM so you have to run the tool with the workspace path, e.g. swift-package-list Test.xcworkspace.

Now to your actual question if you can configure it to filter by target: This information is not part of the Package.resolved, the only reliable method would be to parse project.pbxproj AFIAK. In the case of a workspace it is not even project specific, the Package.resolved will contain the packages from all the workspace's projects. So to answer it, no it is not possible and it would also not be a simple addition (not sure how easy it is to parse the project file, but if you think about sub-dependencies which are not declared at all and SPM plugins things get quiet complex).