Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: rioki on August 29, 2009, 08:21:22 pm

Title: Help? My pre build script fails; but only under CB.
Post by: rioki on August 29, 2009, 08:21:22 pm
Hi,

I am trying to get my post pre script to run, it works in cmd but not under CB.

I am running:
  - Window XP SP3
  - CB 8.02 (Build: Feb 27 2008 20:59:09)

Basically everything works as expected except if I am trying to run

Code
rd /Q /S $(TARGET_OBJECT_DIR)\*

The entire script is:

Code
xcopy /Y $(TARGET_OUTPUT_BASENAME).nsi $(TARGET_OBJECT_DIR)
mkdir $(TARGET_OBJECT_DIR)include
mkdir $(TARGET_OBJECT_DIR)lib
mkdir $(TARGET_OBJECT_DIR)bin
xcopy /Y ..\..\Tools\IcedResource\bin\$(TARGET_NAME)\IcedResource.exe $(TARGET_OBJECT_DIR)\bin
$(#nsis)\makensis $(TARGET_OBJECT_DIR)\$(TARGET_OUTPUT_BASENAME).nsi
xcopy /Y $(TARGET_OBJECT_DIR)$(TARGET_OUTPUT_BASENAME).exe $(TARGET_OUTPUT_DIR)
rd /S /Q $(TARGET_OBJECT_DIR)\*

When I execute the code under windows command line all works as expected...

I kinda hit a wall here, any help or ideas are very very welcome. I am thinking of writing a shell script and pass that by MSys (bash)...
Title: Re: Help? My pre build script fails; but only under CB.
Post by: MortenMacFly on August 29, 2009, 08:27:07 pm
Code
rd /Q /S $(TARGET_OBJECT_DIR)\*
What do you see at the command line if you put an echo before that?
Title: Re: Help? My pre build script fails; but only under CB.
Post by: rioki on August 29, 2009, 08:35:01 pm
Code
rd /Q /S $(TARGET_OBJECT_DIR)\*
What do you see at the command line if you put an echo before that?

Code
echo rd /S /Q $(TARGET_OBJECT_DIR)\*

gives:

Code
echo rd /S /Q obj\Debug\*
Execution of 'echo rd /S /Q obj\Debug\*' in 'D:\Development\IcedLiquid\Trunk\IcedBlue\Installers\IcedBlue-SDK' failed.

Could that be that something is not properly escaped?
Title: Re: Help? My pre build script fails; but only under CB.
Post by: rioki on August 29, 2009, 08:38:27 pm
It is even worse:

Code
echo "Hello World"
Execution of 'echo "Hello World"' in 'D:\Development\IcedLiquid\Trunk\IcedBlue\Installers\IcedBlue-SDK' failed.

Something is definitely broken (on my end?)...
Title: Re: Help? My pre build script fails; but only under CB.
Post by: rioki on August 29, 2009, 08:41:04 pm
Oddly enough:

Code
mkdir $(TDAY)

Works like a charm...
Title: Re: Help? My pre build script fails; but only under CB.
Post by: MortenMacFly on August 29, 2009, 08:44:38 pm
Code
echo "Hello World"
Ah - sorry, that cannot work, indeed. You can try to put everything in a batch file and run it providing the batch file with the required macro as command line params.
Execution of 'echo "Hello World"' in 'D:\Development\IcedLiquid\Trunk\IcedBlue\Installers\IcedBlue-SDK' failed.
Would that be the right base folder so that the command (especially "(TARGET_OBJECT_DIR)\*") makes sense in that folder?

Edit: Another Idea: Do you have a conflicting RD executable in the path (for example in the compiler directory) that would not have the same command line params (e.g. a unix derivate)?
Title: Re: Help? My pre build script fails; but only under CB.
Post by: rioki on August 29, 2009, 08:59:34 pm
Ok:

Code
set TARGET_OUTPUT_BASENAME=IcedBlue-SDK
set TARGET_OUTPUT_DIR=bin\Debug\
set TARGET_OBJECT_DIR=obj\Debug\
set TARGET_NAME=Debug
set nsis=C:\Program Files\NSIS

xcopy /Y %TARGET_OUTPUT_BASENAME%.nsi %TARGET_OBJECT_DIR%
mkdir %TARGET_OBJECT_DIR%include
mkdir %TARGET_OBJECT_DIR%lib
mkdir %TARGET_OBJECT_DIR%bin
xcopy /Y ..\..\Tools\IcedResource\bin\%TARGET_NAME%\IcedResource.exe %TARGET_OBJECT_DIR%\bin
"%nsis%\makensis" %TARGET_OBJECT_DIR%\%TARGET_OUTPUT_BASENAME%.nsi
xcopy /Y %TARGET_OBJECT_DIR%%TARGET_OUTPUT_BASENAME%.exe %TARGET_OUTPUT_DIR%
rd /S /Q %TARGET_OBJECT_DIR%

Works like a charm...
Title: Re: Help? My pre build script fails; but only under CB.
Post by: rioki on August 29, 2009, 09:15:09 pm
FIXED:

Using the following command works:

Code
cmd /C "rd /Q /S $(TARGET_OBJECT_DIR"

Why? Well in cmd rd or rmdir is not a program like on *nix. It is a built in command that is translated to API call.

Actually I would like "Shell to run command in:" option for win two... Would either add bash from MSys or cmd...
Title: Re: Help? My pre build script fails; but only under CB.
Post by: oBFusCATed on August 29, 2009, 10:33:11 pm
If you want to have unix tools on windows you can install UnixTools or GnuWin32.
I'm using the former and I'm happy wiNIX user :) :)
Title: Re: Help? My pre build script fails; but only under CB.
Post by: rioki on August 31, 2009, 09:55:59 am
I have MSys (MinGW) installed. Yes I ended up writing a shell script... Much more sane...

But I thing the way the pre and post-build scripts are executed is broken. In Code::Blocks (it seems) that every line is taken on its own and it is fed to something like exec(). Instead of passing the entire chunk to cmd or <insert configurable tool here>. You end up with the situation that you can't cd into a different directory and execute some command there.

I (was forced to) use Visual Studio (at my paying job) and coming from there I assumed that the post and pre build scripts run in cmd and you can basically copy and past cmd scripts there. Me bad for assuming that.
Title: Re: Help? My pre build script fails; but only under CB.
Post by: Pecan on August 31, 2009, 01:20:30 pm
I have MSys (MinGW) installed. Yes I ended up writing a shell script... Much more sane...

But I thing the way the pre and post-build scripts are executed is broken. In Code::Blocks (it seems) that every line is taken on its own and it is fed to something like exec(). Instead of passing the entire chunk to cmd or <insert configurable tool here>. You end up with the situation that you can't cd into a different directory and execute some command there.

I (was forced to) use Visual Studio (at my paying job) and coming from there I assumed that the post and pre build scripts run in cmd and you can basically copy and past cmd scripts there. Me bad for assuming that.

For me, grouping all the one-liners into a single .cmd file that accepts the CB macros works ok.

For example:
Code
cmd /c showargs.cmd $(TARGET_OBJECT_DIR)

with contexts:
echo %0 %1
echo finished

would produce
Code
Target is up to date.
Running target post-build steps
cmd /c showargs.cmd gcc_mswu\toolbar
C:\Usr\Proj\test\toolbar>echo showargs.cmd gcc_mswu\toolbar
showargs.cmd gcc_mswu\toolbar
C:\Usr\Proj\test\toolbar>echo finished
finished
Process terminated with status 0 (0 minutes, 0 seconds)
0 errors, 0 warnings