2

I use Delphi XE2 and I have a project called PGetBase. In this project, there is a module with a constant declaration. For example:

const
   FragH = 5;
   FragW = 4;
...

After compiling, the file is called PGetBase.exe. Is it possible to make the name of the build file dependent on the constants declared in the module, e.g. PGetBase_5_4.exe, by making use of a Post-Build event?

NGLN
  • 43,011
  • 8
  • 105
  • 200
user2996299
  • 123
  • 3
  • 1
    In what cases do the constants change? How often do they change? Have you considered Build Configurations and Compiler Directives? – Marcus Adams Nov 20 '13 at 18:06
  • 1
    Write a post build event. – David Heffernan Nov 20 '13 at 18:11
  • 1
    Certainly. Write a small console utility that will read your constants from the unit and then rename `PGetBase.exe` accordingly, and then run that small console utility in your Post-Build event. – Ken White Nov 20 '13 at 18:12
  • @KenWhite This is where a good general purpose scripting la gauge comes in handy. No need to compile scripts. Simplifies maintenance hugely. My entire build process is orchestrated through Python. – David Heffernan Nov 20 '13 at 18:17

2 Answers2

3

Add a project to the projectgroup which creates an executable that uses the same unit and changes the filename. Build and run that executable in the Post-Build event.

NGLN
  • 43,011
  • 8
  • 105
  • 200
  • Wow! an elegant and hermeutic idea! Like it! ...but you may just forgot to re-compile the renamer. So it seems like "make renamer" should be not in the project group, but in the pre-build event for the project – Arioch 'The Nov 21 '13 at 07:56
  • @Arioch'The Better still is to remove the need to make the renamer – David Heffernan Nov 21 '13 at 09:40
  • @Arioch I chose to build the renamer in the Post-Build event of the main project, because there is no need to recompile the renamer when a build of the main project fails. – NGLN Nov 21 '13 at 11:52
2

Microsoft Build knows nothing about the Pascal language and cannot parse the sources.

However you may extract "5" and "4" into some external text files.

const
   FragH = 
   {$I Frag_h.txt}
   ;
   FragW = 
   {$I Frag_W.txt}
   ;

Then make a simple program (or script: WSH, PowerShell, etc), that would be launched from post-build events. You program would read those file and rename the Delphi-made PGetBase.exe to anything you wish.

PS. Of course one can parse the source unit to regain those constants, rather than offloading them into external storage. Comments hold the discussion pro et con.

PPS. NGLN came wit ha neat idea. Rather than parsing the file, you can just include that unit as part of your renamer project. Then you can add a pre-build event, that would compile(make) renamer and in post-buid the renamer would have those constants within itself. While calling make/dcc32 would probably be slower than just parsing the sources from inside the version-neutral pre-compiled renamer.exe, that NGLN's approach is elegant and self-contained in its own way.

Arioch 'The
  • 15,799
  • 35
  • 62