Author Topic: Help? My pre build script fails; but only under CB.  (Read 9153 times)

Offline rioki

  • Multiple posting newcomer
  • *
  • Posts: 13
Help? My pre build script fails; but only under CB.
« 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)...
« Last Edit: August 29, 2009, 08:24:34 pm by rioki »

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9723
Re: Help? My pre build script fails; but only under CB.
« Reply #1 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?
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline rioki

  • Multiple posting newcomer
  • *
  • Posts: 13
Re: Help? My pre build script fails; but only under CB.
« Reply #2 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?

Offline rioki

  • Multiple posting newcomer
  • *
  • Posts: 13
Re: Help? My pre build script fails; but only under CB.
« Reply #3 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?)...

Offline rioki

  • Multiple posting newcomer
  • *
  • Posts: 13
Re: Help? My pre build script fails; but only under CB.
« Reply #4 on: August 29, 2009, 08:41:04 pm »
Oddly enough:

Code
mkdir $(TDAY)

Works like a charm...

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9723
Re: Help? My pre build script fails; but only under CB.
« Reply #5 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)?
« Last Edit: August 29, 2009, 08:47:12 pm by MortenMacFly »
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline rioki

  • Multiple posting newcomer
  • *
  • Posts: 13
Re: Help? My pre build script fails; but only under CB.
« Reply #6 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...

Offline rioki

  • Multiple posting newcomer
  • *
  • Posts: 13
Re: Help? My pre build script fails; but only under CB.
« Reply #7 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...

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: Help? My pre build script fails; but only under CB.
« Reply #8 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 :) :)
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline rioki

  • Multiple posting newcomer
  • *
  • Posts: 13
Re: Help? My pre build script fails; but only under CB.
« Reply #9 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.

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2876
Re: Help? My pre build script fails; but only under CB.
« Reply #10 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
 

« Last Edit: August 31, 2009, 01:24:06 pm by Pecan »