views:

186

answers:

3

Hello there,

I need to know if is there any option to compile a delphi project only if the source or any used unit, package etc has been changed.

If this is not possible, second alternative : Is there any option to generate exactly the same binary compiling two times the same project.

Thanks.

Edit: The usage is for a hash based WebUpdate.

A: 

Delphi compiles only changed units on a compile, and compiles all units regardless of change-status on a build.

Exe's are never the same, on a binary level. Just built a project twice, renamed the exe's to have a txt extension and compared them with Beyond Compare: it shows differences.

Marjan Venema
You have a timestamp and cheksum in the PE header that would be different each compilation.
Jens Björnhager
Yes, but the differences are more widespread than that. In fact very widespread...
Marjan Venema
Just checked the comparison I did again. There are many differences, though most are exactly the same type of difference between the two exe's. See http://www.bjmsoftware.com/delphistuff/exe_comparison.jpg
Marjan Venema
The first is a timestamp, 34 seconds off.
Jens Björnhager
Is the change only in the PE header? Is the PE header fully manipulable with DCC32.exe?
Francis Lee
No, only the first is in the header. I don't know if you can make Delphi spit out a predefined timestamp.
Jens Björnhager
Anyway if the sources are the same, the binary need to be the same always except if it has any timestamp inserted or a version number. The code generated cannot change from one compiling to another.
Francis Lee
If that's your requirement, Francis, then Delphi is not the tool for you.
Rob Kennedy
@Rob, I think it can be done with the Set Extra PE Header flags because if I build an application two times and I set the same machine time in the prebuild events both compilations produces exactly the same binary. I'm looking for documentation over it.
Francis Lee
Strictly speaking it only recompiles if the part of the unit that is in the .pas is recompiled. Parts in .incs don't count.
Marco van de Voort
+2  A: 

A Delphi "compile" will compile only changed units. But as said, unit have data so the compiler can check which needs updating and which not. And the executable can change because the build process can rearrange the exe. Your web updates should not use a file hash, it should use version information to decide what to update and what not. That's the way installers check which files should be replaced.

ldsandon
Your aproach is right, but I'm trying with something more generic.
Francis Lee
An hash can tell you only if the file is different or not, not if it is older or newer. That's one of the reason version informations were added.
ldsandon
A: 

One (hard) solution: Make your exes using a Makefile! A makefile allows you to say "this exe is made from those files, using those commands". Make will only run "those commands" if at least one of the files you list as making up your exe is newer then your exe.

The hard part in this is setting up the list of files that make up your exe: You can easily get the list of files listed in the DPR/DPROJ, but you'll also need to identify all the linked resources ($R), all the included files ($INCLUDE), all the files that are implictelly compiled by Delphi because they're used in the "uses" clauses and are found on the Library Path.

Generating a Makefile for the general case is very difficult, but for one particular project it might work. For example you might consider your file dependent on only the files listed in the DPR files and then make sure you add all the relevant files to the DPR.

Cosmin Prund