A comprehensive guide to ‘go generate’
eli.thegreenplace.net
eli.thegreenplace.net
We have the unix -r custom already. Now we have another, that makes no sense, that you just have to learn.
For example, GNU cp uses -r or -R for recursive copy, but OpenBSD cp only uses -R. ls uses -R only (-r is listing in reverse order). scp uses -r only (-R is remote copy). rm allows both -r and -R.
But then, commands like mv or find don't support anything like -r or -R, they implicitly affect the whole directory structure. Bash has * (with shopt -s globstar) for globbing with subdirectories. Make doesn't support any concept of recursive subdirectory traversal.
Other software that supports -r: rsync, fdupes, zfs destroy, et c.
I'm not saying they're breaking spec, I'm saying they're being weird and divergent for no particular benefit (and at a quite obvious cost in terms of Google-specific learning curve, as Go is used widely outside of Google).
I often think that a substantial portion of my job is software archaeology...
There. I did just learn it without following a tutorial or somethin. It's so simple, easy to remember. It's even faster to write that -R or -r.
This is a huge attack vector. Enabling arbitrary execution at compile time creates two problems which the Go authors have done well to avoid:
- all Go code builds without external tool dependencies (with a single exception).
- no execution of untrusted software in the build environment.
It would be comically easy to inject malware into a popular Go package otherwise.
Erm, I must say I disagree with the decision if it's true. Do you have a link supporting it? I don't recall seeing anything like that when the feature was released.
Also I wasn't referring to "external tools" but a way to pipeline the embed.FS tree through a filepath.WalkFn function that the developer adds.
> //go:embed assets/* minifyFn > var minifiedAssets embed.FS > var minifyFn filepath.WalkFn
Making paternalistic decisions for your users from the presumption that they're idiots is never a good idea in my opinion.
And I'm sure people can already use the aforementioned go generate to execute untrusted software.
From the `go generate` design doc:
> Second, go build should never cause generation to happen automatically by the client of the package. Generators should run only when explicitly requested.
https://docs.google.com/document/d/1V03LUfjSADDooDMhe-_K59Eg...
I think both me and xyzzy_plugh were referring to go:embed. But I take your meaning that using go generate as a build step is not meant to be idiomatic. I guess I've been using it wrong all this time. :)
https://go.googlesource.com/proposal/+/master/design/draft-e...
`go build` & co are designed to easily integrate into complex or overarching build systems (which are inevitable for any large project, as you mentioned), and the lack of expectation of being able to shell out arbitrarily during a 'normal' build of some leaf library is what contributes to this ease of integration. Contrast that to how difficult it is to integrate with Rust/Cargo's build system where every second package has a `build.rs` which expects some undefined ambient environment to be present and makes any attempt to make the builds hermetic extremely painful.