Get git hash as go value at build time

Is there a straight forward way to amend the build process to execute code to set environment variable and incorporate them into the build? e.g. I’d like to have the code know it’s git hash.

On the command line I’d use:
"-X`git rev-parse HEAD` "
But GoLAND does not use a command processor (eg bash) to evaluate the command line. Looks like there is facility to run command before the go tool invocation but I can’t figure out how to make it do something that helps me accomplish this.

I personally user Makefile and set it there to be used with -ldflags parameter. GoLand has run configurations where you could even define custom commands to be run.

I guess that get to the heart of my question. How do I use the custom command to accomplish this. Make doesn’t help with the problem, unless I’m missing something, because it runs outside the IDE. Is there a way to get the debugger in the IDE to use the externally built executable?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.