Author Topic: Conditional Pre-build step?  (Read 6160 times)

Offline ironhead

  • Almost regular
  • **
  • Posts: 210
Conditional Pre-build step?
« on: April 09, 2008, 04:02:27 am »
Is it possible to create a conditional pre-build step (based on a custom variable)?  Basically I need to be able to dynamically generate a file that contains the svn version of HEAD and write it to a file.  I currently have:

Code
cmd /c if $(SVN_BUILD) == yes svn info --revision HEAD | grep Revision | sed -e "s/Revision:/#define SVN_VERSION/" > svnversion.h

But this is to me is really cludgy because it's dependant on the 'if' functionality built in to cmd.  Is there a 'native' if / then / else, etc. that can be used in the pre-build steps?

mariocup

  • Guest
Re: Conditional Pre-build step?
« Reply #1 on: April 09, 2008, 07:49:32 am »
Hi ironhead,

yes it is possible to make a conditional pre/post-build step. In the user manual chapter "variable expansion" in the section "conditional evaluation" you will find an example.

Code
 [[ if (PLATFORM ==  PLATFORM_MSW) { print (_T("cmd /c")); } else { print (_T("sh ")); } ]] <command>

Bye,

Mario

Offline ironhead

  • Almost regular
  • **
  • Posts: 210
Re: Conditional Pre-build step?
« Reply #2 on: April 10, 2008, 08:05:32 pm »
How do I check a project specific Custom Variable?

I have SVN_BUILD = 0 in the projects Custom Variable tab, in the pre-build, for testing I have:

Code
[[ if ($SVN_BUILD ==  0) { print (_T("cmd /c")); } ]] echo hello

But I get an expression expected error.  Am I accessing the Custom Variable in the wrong way?

thomas_on_vacation

  • Guest
Re: Conditional Pre-build step?
« Reply #3 on: April 10, 2008, 09:23:20 pm »
Fighting with a French keyboard on a public PC in the lounge (as usual, the airport nazis broke my laptop, like every time)... how the hell do they type in France...

Mario mixed up $if()  and [[ ]], you want to simply use $if().
I forgot whether or not the "else" branch is obligatory... so if it fails, you may have to add an  else{}.

[[ ]] does not know custom vars, it is for scripts.

So long and thanks for the fish, going back to holidays.

Offline ironhead

  • Almost regular
  • **
  • Posts: 210
Re: Conditional Pre-build step?
« Reply #4 on: April 11, 2008, 03:12:19 am »
I'm getting there, I know have:

Code
$if(SVN_BUILD){cmd /c echo true}

which works if I have:

Code
$if(0){cmd /c echo true}

In that the 'true' clause isn't executed.  The problem is that when using SVN_BUILD (or $SVN_BUILD or $(SVN_BUILD)) the 'true' clause is always being execute, despite the fact that I've defined SVN_BUILD as '0' (or if I leave it undefined) in the Custom Variables tab.  I take it I'm missing something?

thomas_on_vacation

  • Guest
Re: Conditional Pre-build step?
« Reply #5 on: April 11, 2008, 07:53:50 pm »
The problem is that when using SVN_BUILD (or $SVN_BUILD or $(SVN_BUILD)) the 'true' clause is always being execute, despite the fact that I've defined SVN_BUILD as '0' (or if I leave it undefined) in the Custom Variables tab.  I take it I'm missing something?
Hmm, darn... if that's the case, there's a bug :(

The true clause should be exectuted whenever the expression is not false, and "not false" is assumed if none of the following is the case:
1. whatever is inside () has the int value 0 or the ASCII code of '0'
2. whatever is inside () evaluates to an empty string, or
3. is not defined

Apparently, something is going wrong there, if "0" evaluates to true...
Unluckily, I won't be on a computer with Code::Blocks for the next 10 days still, so no bug hunting from my side... Martin, pretty please?


p.s.: Did you know that Windows XP lets you change a French keyboard to a German one with one mouse click, if you only care to look? I just found out... :)

Offline ironhead

  • Almost regular
  • **
  • Posts: 210
Re: Conditional Pre-build step?
« Reply #6 on: April 13, 2008, 02:44:11 am »
Apparently, something is going wrong there, if "0" evaluates to true...
Unluckily, I won't be on a computer with Code::Blocks for the next 10 days still, so no bug hunting from my side... Martin, pretty please?

I'm not sure if it's executing the 'true' clause because of '0' (since I tested $if (0) and it behaved as expected).  I think it's more that SVN_BUILD isn't being evaluated.

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Conditional Pre-build step?
« Reply #7 on: April 16, 2008, 01:11:40 pm »
Yes, you're right, it errornously uses the non-expanded string, thank you for pointing it out. There seems to be another problem related to the regex... at least it doesn't seem to grasp everything under all conditions.
A fix will be in svn shortly, probably this afternoon.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Conditional Pre-build step?
« Reply #8 on: April 16, 2008, 01:45:25 pm »
r5006 should do... it still can't evaluate complicated stuff, but it should work for most reasonable stuff (including what you wanted). I've added a test project, too.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline ironhead

  • Almost regular
  • **
  • Posts: 210
Re: Conditional Pre-build step?
« Reply #9 on: April 16, 2008, 06:46:01 pm »
Perfect, thanx!  I'll grab the C::B source from SVN and compile it (unless there is a new nightly on the way :) ).