[Pitch] SwiftPM support for Swift scripts (revision)

For scripts, I propose to use a unified directory for caching. A cache location for my-script.swift, for example, may be ~/.swiftpm/scripts/my-script-abc123, which will contain the .build and Package.resolved cache. abc123 is a hash value computed against the real path of the script.

Such design can prevent scripts from producing scattered wastes, and enable centralized control over build caches. This will allow scripts to be moved easily throughout the system. swift script cleanup can remove the cache for scripts that no longer exist.

1 Like

Not going to be done in this pitch in order to keep it simple and focused on scripting support. With this pitch you may use a library package with absolute path to eliminate the effort.

A more elegant way to interact with external programs and scripts will be mentioned in future directions. I believe that’s another important improvement worthy of further discussions.

1 Like

swift-sh does this I believe. One of the problems with this is that you potentially run into problems when you have the script named the same across different folders. Maybe a hash of the folder name and the script name for managing things centrally, or simply apply the folder name then the script as part of the path so it's recognizable.

I think the answer has already been there👀

You’re right that projects like swift-sh already does the same thing, but I believe the community would prefer # or @ annotations with familiar SwiftPM-styled declaration, instead of other workarounds like comments.

In other words, we’re now going to make scripting officially supported by SwiftPM itself.

1 Like

Yep. I missed it. :raised_hands:t5:

Terms of Service

Privacy Policy

Cookie Policy