I have a project in GNAT and I would like to list all the files that are never used. I am thinking about doing it with a python script, but, is it possible to do so easily with GNAT?
Update:
I found about gnatelim, but although in the help it says to have the -P option
usage: gnatelim [options] -main=main_unit_name {filename} [-cargs gcc_switches]
options:
--version - Display version and exit
--help - Display usage and exit
-Pproject - Use project file project. Only one such switch can be used.
It seems that it does not work as it asks for a main unit (having the whole project!):
>gnatelim -Prelease.gpr
gnatelim: No main unit specified
try "gnatelim.exe --help" for more information.
I am using GNAT 2015
As a follow-up to Jacob's answer, it seems necessary to pass to
gnatelim
For example, in a project file I have several main units listed as
(and also
for Executable ("pack-prog.ada") use ("prog");
etc.)Specifying either zero units, as you did, or more than one main unit, I get
Specifying exactly one unit, I get
The diagnostic message of
gnatelim
, or viagnatelim
, seems not entirely adequate.The help for
gnatelim
is rather limited, but I have experimented a bit, and the trick seems to be to passgnatelim
the file name of your main unit:If your project is more complicated than a single directory containing all needed source files, you pass
gnatelim
both a project file and the file name of your main unit:If your project doesn't have any main units, the answer is very simple; nothing is used.
You need to have at least one main unit, to have a reference from which to look at which units aren't used.
In practice there is a much simpler possibility than using
gnatelim
. Combine the-gnatwe
(treat warnings as errors) with-gnatwa
(turn on most warnings), and GNAT will tell you whichwith
ed units aren't really needed.