PreBuild steps

When I build outside of the ide I use :

 go install -ldflags "-X github.com/FactomProject/factomd/engine.Build=`git rev-parse HEAD` -X github.com/FactomProject/factomd/engine.=`cat VERSION`"

But the ``git rev-parse HEAD` don't evaluate when I use taht as the go tool args in GoLAND. Is there a way to accomplish the same thing using the prebuild executions?

1
7 comments

Unfortunately running shell commands like that inside the command runner is not currently supported for run configurations.

 

However, in your run configurations you can still use ` -ldflags "-X github.com/FactomProject/factomd/engine.Build=dev -X github.com/FactomProject/factomd/engine=dev" ` by setting that as a value for the ` Go tool arguments field ` either in the current run configuration, or as default, for all run configurations, under Defaults | Go Build.

 

Hope this helps.

0

IntelliJ runs pure processes, not bash. If you need to use shell commands, you can create a shell script and invoke it via bash like `/usr/bin/bash prebuild.sh` as a Before task.

 

prebuild.sh

#!/usr/bin/bash 
go install -ldflags "-X github.com/FactomProject/factomd/engine.Build=`git rev-parse HEAD` -X github.com/FactomProject/factomd/engine.=`cat VERSION`"
0

Can I use environment variables to communicate the values from the prebuild.sh to the tool command line? Does GoLAND replace environment variable reference in tool command line before calling exec or would my script have to change source code files to get my values into my build? Can you elaborate on how I get the prebuild.sh to automatically run before my build?

0

> Can I use environment variables to communicate the values from the prebuild.sh to the tool command line?

I'm afraid this is not how the environment works. The environment is inherited by children processes, you cannot change the environment of the parent or sibling process.

> Does GoLAND replace environment variable reference in tool command line before calling exec or would my script have to change source code files to get my values into my build?

For some processes (like running `go build`) GoLand sets GOROOT and GOPATH environment variables inferring them from project's settings.

> Can you elaborate on how I get the prebuild.sh to automatically run before my build?

You can try to use Before launch tasks in Run configurations for this and configure `Go Command` to run `install -ldflags...` (see screenshot).

If you need more complicated building and running scenarios, I'd recommend using terminal or appropriate building tools like make, gradle, etc. 

 

0

Neither of these options worked well with me. I would like to cat a file and embed the contents inside a dedicated variable. Yet, this is not possible.

0

Lyubomir Gardev Please, fill out a new issue on our bug-tracker. Also, describe your current workflow and problems that you encounter. It'll help us to understand what we can do from our side.

1

Thank you, Daniil! I have filled a new issue in the tracker - https://youtrack.jetbrains.com/issue/IDEA-256050.

0

Please sign in to leave a comment.