Tuesday, December 23, 2014

Generating Go Code

Rob Pike (via David Nolen):

Programs that write programs are therefore important elements in software engineering, but programs like Yacc that produce source code need to be integrated into the build process so their output can be compiled. When an external build tool like Make is being used, this is usually easy to do. But in Go, whose go tool gets all necessary build information from the Go source, there is a problem. There is simply no mechanism to run Yacc from the go tool alone.

Until now, that is.

The latest Go release, 1.4, includes a new command that makes it easier to run such tools. It’s called gogenerate, and it works by scanning for special comments in Go source code that identify general commands to run. It’s important to understand that gogenerate is not part of gobuild. It contains no dependency analysis and must be run explicitly before running gobuild. It is intended to be used by the author of the Go package, not its clients.

Comments RSS · Twitter

Leave a Comment