cancel
Showing results for 
Search instead for 
Did you mean: 

How to run a bash script from the build command of eclipse IDE on windows

ali rostami
Associate III

I have a C/C++ project which has its own make files and is imported to a STM32CubeIDE on Win 11.

In order to compile the project, I have to enter some commands in git-bash. so for simplicity, I wrote them into a .sh file which is named build.sh, and put it in the project folder, since then I just need to run this in bash like this: 

source build.sh

And here is its content:

#!/bin/sh
 
source Q:/stm32.sh
cd Q:/dev/my_project
make build_all

Right now, I want this script to be called, whenever I press the Build button of the IDE. I found out that for this I have to change the build command from Propertise->C/C++ Build, uncheck the use default build command and then enter the proper command for running the script. But I could have not done this by now. I've tried to solve this problem by entering this 

bash source Q:\dev\my_project\build.sh

 into the build command, which didn't work.

So my question is that what should I enter here to run the build.sh? Do you know a better solution to my problem?

5 REPLIES 5
Bob S
Principal

try "sh -c Q:/dev/my_project/build.sh" (without the quotes), or perhaps "sh -c ${ProjDirPath}/build.sh" (again, without quotes). I haven't tried this as the build command line, but I DO use that form to run bash-style scripts as the "pre-build" and "post-build" steps on a Windows machine.

CubeIDE for Windows comes with busybox which contains sh, bash and many usual commands (type 'busybox' to see them all). All this can be used in pre/post build commands and makefiles.

Installed in ...\plugins\com.st.stm32cube.ide.mcu.externaltools.make.win32_xxxxx\tools\bin.

Other bash'es (git, WSL) are obscured by this because CubeIDE prepends it to PATH.

ali rostami
Associate III

Oh, Finally it worked like this for me:

It's important to put this address "C:\Program Files\Git\bin;" in the PATH of IDE, at the beginning and before other things, like this:

0693W00000Y8OYYQA3.pngthen in the build command part I just wrote "bash":

0693W00000Y8OZbQAN.pngand in the next tab -Behavior- I entered the address of bash like this:

0693W00000Y8OaKQAV.pngIt seems to me that I can only enter the address of the script as an input for bash command here. right?

what do you guys think?

Semer CHERNI
ST Employee

Hello @ali rostami​ 

I want to highlight an other feature of the CubeIDE that could came in help for your need.

I suggest if you try the headless build option (for more details check the STM32CubeIDE user guide 2.4.3 Headless build). This option would be valid if the make file is generated automatically.

If you are writing the make file your self; you can proceed as you have already done.

Kind regards,

Semer.

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

ali rostami
Associate III

Hi @Semer CHERNI​ 

Thanks, I will check that too.

But according to my attempts, why I couldn't enter the arguments of bash in front of it​? like this:

bash Q:\dev\my_project\build.sh

While in this article, the writer shows us -in the "Setup Build Variables" section- it is possible to do such a thing in Eclipse IDE.

Any idea?