Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to force Delphi to leave unused code in the executable?

Tags:

delphi

The Delphi Linker strips out any functions that aren't actually used, thus reducing the executable size.

Is there any way to stop the Delphi Linker doing this? e.g. a compiler switch?

To those wondering "why?"...

I am trying to use the delphi-code-coverage tool, but it only reports on code that is actually compiled into the executable. Which makes it not very useful. If I could get Delphi to include all code, I'm hoping I could then get some useful code coverage statistics.

I should mention that I have DUnit tests in a separate project to my application. So even though the code is "unused" in the DUnit project, it is used in the actual application.

See here for more details.

like image 847
awmross Avatar asked Oct 20 '11 01:10

awmross


1 Answers

Your code-coverage tool is measuring the wrong thing. It works off the map file instead of the source code, so it will only report on live code instead of on all code in a project. The linker already filters out the dead code, and in a blank unit-test project, all code is dead code. There is no way to tell Delphi to include dead code in an EXE.

Run the code-coverage tool on your application to get a list of functions that needs testing. Then, write code in your unit-test project that mentions all those functions. (It doesn't have to call everything yet, and it certainly doesn't have to test it all. We're just making sure it's linked to the unit-test project.) Now the coverage tool can get an accurate measurement of what's been executed and what hasn't.

like image 196
Rob Kennedy Avatar answered Sep 27 '22 22:09

Rob Kennedy