Delphi compiler: the –depends switch / DCC_OutputDependencies property outputs a .d file listing all .dcu and .dcp files – via Stack Overflow/G+
Posted by jpluimers on 2017/02/01
Every now and then you want to know what units your project is made of. Not just the units require to build your project, but actually the ones ending up in the executable (i.e. not removed by the compiler or linker).
I had long forgotten that Chris Hesik [WayBack] wrote in debugging – How can I find all the units in my Delphi app? – Stack Overflow [WayBack]:
you can have the Delphi compiler show you a list of used .dcus by passing –depends when you compile a project. It will output a .d file with a list of the .dcus (and .dcps) that were required.
This reminded me of that: The –depends option is supposed to work with the Delphi compiler, and it outputs a .d file. Does it still work in Berlin, and where is the file supposed to be output to? – David Nottage – Google+ [WayBack]
In the mean time, I wrote a batch file that parses the .MAP file to see which units actually made it into your .EXE [WayBack] which works only for Widows executables (as I hardly do cross-platform Delphi development).
Uwe Schuster [WayBack] reported the IDE won’t pass on the –depends switch in Delphi XE and up (version 15.0.3953.35171) [WayBack] which means you need to pass this from the command-line.
Ondrej Kelle (G+/SO) pointed out that:
- the list of units can be obtained from the PACKAGEINFO resource at run-time as well [WayBack] by using the GetPackageInfo RTL routine [WayBack].
- you can have msbuild pass this parameter by using the below
DCC_OutputDependenciestrick
msbuild hello.dproj /property:DCC_OutputDependencies=true
- It does work from the IDE if you check “use MSBuild externally”
The msbuild property setting is available in at least Delphi/C++Builder versions 2007 and 2010..Berlin as it is in CodeGear.Cpp.Targets and CodeGear.Delphi.Targets/RTL.Build.targets for BDS versions 5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 and 18. It might be available in versions 2005/2006/2009 as well but I don’t have these lying around any more.
–jeroen
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @echo off | |
| if ["%*"]==[] goto :help | |
| :logic | |
| if not exist %1 goto :notExist | |
| setlocal | |
| :: do not use periods (.) in delims as unit names may contain them! | |
| :: it might be that the segment (%%a) for C=CODE/S=.text/G=(none)/M=*/ACBP=A9 is always 0001 | |
| :: it might be that the segment (%%a) for C=ICODE/S=.itext/G=(none)/M=*/ACBP=A9 is always 0002 | |
| :: it might be that the segment (%%a) for C=DATA/S=.data/G=DGROUP/M=*/ACBP=A9 is always 0003 | |
| :: it might be that the segment (%%a) for C=BSS/S=.bss/G=DGROUP/M=*/ACBP=A9 is always 0004 | |
| :: it might be that the segment (%%a) for C=TLS/S=.tls/G=(none)/M=*/ACBP=A9 is always 0005 | |
| :: the `if ["%%h"]==["(none)"] ` trick is to prevent this error: | |
| :: ) was unexpected at this time. | |
| for /f "tokens=1,2,3,4,5,6,7,8,9,10,11,12,13,14,* delims=()= " %%a IN (%1) do ( | |
| if [%%c]==[C] if [%%e]==[S] if [%%g]==[G] if [%%i]==[M] if [%%k]==[ACBP] if [%%l]==[A9] if [%%m]==[] ( | |
| if [%%d]==[CODE] if [%%f]==[.text] if ["%%h"]==["(none)"] echo %%j | |
| if [%%d]==[ICODE] if [%%f]==[.itext] if ["%%h"]==["(none)"] echo %%j | |
| if [%%d]==[DATA] if [%%f]==[.data] if ["%%h"]==["DGROUP"] echo %%j | |
| if [%%d]==[BSS] if [%%f]==[.bss] if ["%%h"]==["DGROUP"] echo %%j | |
| if [%%d]==[TLS] if [%%f]==[.tls] if ["%%h"]==["(none)"] echo %%j | |
| ) | |
| if [%%a]==[line] if [%%b]==[numbers] if [%%c]==[for] if [%%f]==[segment] if [%%g]==[.text] if [%%h]==[] ( | |
| echo %%d | |
| ) | |
| ) | |
| endlocal | |
| goto :eof | |
| echo a=%%a;b=%%b;b=%%b;c=%%c;d=%%d;e=%%e;f=%%f;g=%%g;h=%%h;i=%%i;j=%%j;k=%%k;l=%%l;m=%%m;n=%%n | |
| if [%%c]==[C] if [%%d]==[CODE] if [%%e]==[S] if [%%f]==[.text] if [%%g]==[G] if ["%%h"]==["(none)"] if [%%i]==[M] if [%%k]==[ACBP] if [%%l]==[A9] if [%%m]==[] echo %%j | |
| :notExist | |
| echo %* does not exist. | |
| :help | |
| echo syntax: %0 MAP-file | |
| echo will list all the Delphi units that got compiled into your EXE in a non-sorted non-unique way | |
| goto :eof |






Leave a comment