Temporarily override Package.swift

Is there a way to specify a different file to take the place of Package.swift as an option to swift build?

I’m trying to set up a build system that parses the actual Package.swift using swift package dump-package, generates a bunch of new package configurations based off of the original Package.swift, and then builds the package using the transformed configurations.

Aside from moving it out and replacing it, I don’t think so.

I think my recommendation for accomplishing that sort of thing would be to have the build system write the modifications into the tail end of Package.swift guarded by if ProcessInfo.processInfo.environment["whatever"]. Then you can load the base package without the environment variable, or build the modified version with the environment variable. You may still want to clean up afterward, but even if that is prevented by some interruption, nothing from the base package will be lost. (That’s compared to the changes the user would lose if you moved it to some temporary location the user doesn’t know about and then ran out of batteries.)

1 Like

I took a stab at implementing this as a --manifest-prefix flag in the SPM, and got it working for the most basic build configurations (no dependencies). Pull request is here:

The SPM seems to be really dependent on the assumption that Package.swift is always at the package root though, so I couldn’t get it working for more realistic build configurations. If anyone more familiar with the codebase would like to give some pointers though, that’d be really appreciated…

1 Like
Terms of Service

Privacy Policy

Cookie Policy