Is it possible to have Run/debug (build) injection from shell command?

Greetings

Sorry if the title is not understandable, I didn't know how to express it exactly.

I'd like to inject the compile date into the code, something like this:

 

Go tool argument: -ldflags "-X main.BUILD_DATE=`date -u '+%Y-%m-%d %H:%M:%S' ` "

 

Is it possible?

BTW are there built-in variable we can use in this configuration screen?

 

Thanks

0
4 comments

Hi Greg,

it is possible to specify flags for go tool, but they are static. So you can write put -ldflags "-X main.BUILD_DATE=dev" there, but run configuration won't expand the date pattern. The closest request similar to what you want is https://youtrack.jetbrains.com/issue/GO-7955. But unlike your scenario there the variable wasn't computed dynamically.

The workaround is to handle in your app the special static value you pass from IDE and build program in terminal when you need a real date.

0

Thanks for your answer.

I currently have a Makefile, but of course it's not as handy as having a "run configuration".

Maybe a possible improvement? :)

0

It is tempting to say: yes, but IMHO adding support for variables won't help. Your example shows that variables can be arbitrarily complex expressions and we would have to reimplement a whole shell. It is easier to install a Makefile support as a plugin - this will give you run configurations. As a benefit you would be able to run it not only in IDE, but also e.g. in CI environment or from command-line.

0

I agree with Greg's request... it would be nice to have a dynamic shell insertion into the build process. 

Custom macros seem to be an idea, but a shell like $(do-someting.sh) in the build process seems easier.

0

Please sign in to leave a comment.