Can we make `compute-checksum` work from anywhere?

I'm opening this topic trying to understand the limitations we have in place for computing the checksum of an arbitrary package and if it would be justified to support this operation without requiring the caller to be in any package root.

The problem

Calling swift package compute-checksum /absolute/path/to/some/ fails with error: Could not find Package.swift in this directory or any of its parent directories. if called from outside a package.

The motivation

When writing scripts and generally automating releases you want to output the correct checksum without being forced to be inside a package directory or artificially create one just for this purpose.

The questions

  1. Is there a reason I'm missing for which we enforce this behaviour on the user?
  2. What's the limitation here?
  3. Would the effort put in changing this justify the relatively small gain? (I really dislike having to create fake Package.swifts, but I can understand it's niche use case)
1 Like

The checksum is SHA256, so you can do shasum -a 256 | cut -b 1-64 rather than use compute-checksum.

I know, but that kinda beats the purpose of compute-checksum (you're assuming you know the hashing algo now and forever). Won't argue, might work now and forever just as well, but I'd rather use compute-checksum as intended.

swift package and all its subcommands require a package currently.

I don't think it is trivial to do something specific for compute-checksum but we have previously talked about reorganizing SwiftPM's command structure so that swift package itself doesn't carry semantics like that which would allow us to reparent things like package-collection as well. When that happens, I would imagine that compute-checksum would no longer require a package.

cc @bitjammer


Alright @NeoNacho, so it's safe to assume this is on the radar and it would be non-trivial trying to push it as a small improvement before the more general command structure reshaping. Do you know if there's a plan for this restructuring, or just general talks? Slightly unrelated, but I'm curious to follow.

There's no concrete plan so far, but it has come up multiple times.