1

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.

5
  • 1
    I'm pretty sure Delphi does not compile unchanged units unless you build. Jun 23, 2010 at 10:24
  • But it generates a different hash. It can be a timestamp or something else...But the binary is always different. Jun 23, 2010 at 10:45
  • Looking at Version Information, Delphi 2010 seems to put the CompileDate into the exe (it includes the time of day). But why would you want to make the same exe twice? And I can tell you for sure Jens Björnhager is right, Delphi doesn't compile unchanged units (got bitten by this when using different conditional defines for different projects). Jun 23, 2010 at 10:53
  • The usage is this: I have a very very large project group and all the binaries are web updated based on a hash. If I make some changes and then execute the compile all command, all the files will change its hash, but really only some files need to be updated. Jun 23, 2010 at 11:17
  • Use version number for that: for every new release, increase the version number. Than you only have to compare versionnumbers to see if there is a new version.
    – The_Fox
    Jun 23, 2010 at 13:58

3 Answers 3

2

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.

4
  • Your aproach is right, but I'm trying with something more generic. Jun 23, 2010 at 15:14
  • 1
    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.
    – user160694
    Jun 23, 2010 at 21:11
  • @Idsandon: If the files are the same - who cares which is newer and which is older? Not to mention that the external file attributes can tell you that. The problem with version info is that it needs to be changed (manually or automatically) to be effective. There would be nothing safer than hash/file comparisons if not for that fact that there's no override to the automatic timestamp change. May 3, 2011 at 12:49
  • @Craig: the OP asked about a web update functionality. I wouldn't risk to update a file with an older version by mistake. Ok, with an hash you would not replace an identical file, but what about different files? Which is newer? Any good Windows setup utility (and Windows SetupAPI itself) relies on version informations to update executables correctly. External file attributes can be changed. Version informations, especially in a signed file, are much more difficult to manipulate. Of course, you need a good build process to generate files with the correct version numbers.
    – user160694
    May 3, 2011 at 16:40
0

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.

10
  • You have a timestamp and cheksum in the PE header that would be different each compilation. Jun 23, 2010 at 10:58
  • Yes, but the differences are more widespread than that. In fact very widespread... Jun 23, 2010 at 11:01
  • 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 bjmsoftware.com/delphistuff/exe_comparison.jpg Jun 23, 2010 at 11:10
  • The first is a timestamp, 34 seconds off. Jun 23, 2010 at 11:17
  • Is the change only in the PE header? Is the PE header fully manipulable with DCC32.exe? Jun 23, 2010 at 11:22
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.