-1

In some build systems like gradle or blaze I can generate code (ent or proto) on a build stage and don't add in to a repository.

Is it possible to do the same for the go build command?

rdo
  • 3,872
  • 6
  • 34
  • 51
  • 2
    No, the `go build` command is only for compiling Go code, and not intended to be a general purpose build tool. Generated code is typically generated once and checked into version control so that you can be certain the builds are reproducible. If you want to generate source on demand, then you will need to script that outside of `go build`. – JimB Feb 07 '22 at 20:48

1 Answers1

2

Yes, if you add "go generate" as your pre-build step in CI script.

$ go generate
$ go build
$ go test

But I would recommend more practical approach: to store your generated code in your repo and check it on CI - run go generate and assert that there is no changes.

Links

Alexus1024
  • 447
  • 5
  • 7
  • 1. What are the reasons to store >30 generated files for ent? 2. I don't want to mix "manual" and genereted code – rdo Feb 07 '22 at 20:40
  • 1
    The (1) reason is simple - less context needed to run and debug the code. It can be handy in some cases. And (2) you not have to mix it -place it into separate directory. But ok, you really should't do it if you do not like this approach. Storing generated code is not the main point of my answer and of your question too ). – Alexus1024 Feb 07 '22 at 20:49