'swift package dump-package' command does not work on build pre-action and build phase

Viewed 140

I want to list in a view of my app all open source dependencies I use. As dependencies manager, I am using Swift Package Manager. By doing some searches, I discovered that there is a SPM command to list dependencies in JSON format, which is perfect for my feature.

swift package dump-package

Moreover, I do not want execute this command manually each time a new dependency is added in my Package.swift file. So, my idea was to add a script in the "Target Build Phases" to write the result of the command in a JSON file. Then I could use the JSON file directly in my app to display dependencies informations.

The problem is that the command work well when I execute it from the Terminal but not from a script executed from "Target Build Phases". I also tried to execute the command from "Build Pre-Action" but it do not work too.

Here the full command I use to generate the JSON with the errors I get:

swift package --package-path ${PROJECT_DIR}/SwiftPackageManager/AppDependencies dump-package > ${PROJECT_DIR}/dependencies.json

enter image description here

Can someone explain me why I get this errors ? What's the right solution to do my feature ?

My configuration:

  • Xcode 12.4
  • swift-tools-version:5.2

Thanks in advance for your answers and reactions

0 Answers
Related