wire icon indicating copy to clipboard operation
wire copied to clipboard

Add an option to include a hash/checksum of the source files

Open firelizzard18 opened this issue 5 years ago • 3 comments

Describe the solution you'd like

I would like an option that adds a field to the generated go code, the value of which is a hash of the source files consumed by wire to generate the go code. Something like:

const __WireGenSourceHash = `
    SHA256(wire.go)= d9e5810b60740bf4cc0f1f7494cff955b3c67f5eb4a32cc8f4e23c93b91ac670
`

What I would like to achieve is a git pre-commit hook that would prevent committing when wire.go and wire_gen.go no longer match.

Describe alternatives you've considered

I've considered something like //go:generate sha256sum wire.go > wire_gen.sha, but nothing I've thought of is as foolproof as having Wire generate the hash itself.

Additional context

I imagine there are other scenarios that would benefit from a verifiable signature of the files that were used to generate wire_gen.go.

I generated this SHA via openssl dgst -sha256 wire.go on macOS.

firelizzard18 avatar Mar 09 '19 05:03 firelizzard18

What I would like to achieve is a git pre-commit hook that would prevent committing when wire.go and wire_gen.go no longer match

Can you use wire diff for this instead? Here's an example in the shell script that our Travis job over on the go-cloud repo runs, for a similar purpose (except it causes the checks to fail instead of being a git pre-commit hook).

https://github.com/google/go-cloud/blob/master/internal/testing/runchecks.sh#L57

vangent avatar Mar 09 '19 06:03 vangent

I want the pre-commit hook to be runnable without Wire installed. Linux, macOS, and Windows all come OOTB with a hash tool or two, so a pre-commit hook based on this could work without requiring the dev to do anything but clone my project and install the hook.

firelizzard18 avatar Mar 09 '19 07:03 firelizzard18

What is the dev expected to do if the pre-commit hook fails? It seems like they'd need to install Wire to fix the problem anyway, no?

Also, note that the "expected" contents of wire_gen.go could change when wire.go changes, but also when you get a new version of wire itself.

vangent avatar Mar 11 '19 17:03 vangent