问题
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
回答1:
The help for gnatelim
is rather limited, but I have experimented a bit, and the trick seems to be to pass gnatelim
the file name of your main unit:
gnatelim main.adb
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:
gnatelim -P black_examples.gpr client.adb
回答2:
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 which with
ed units aren't really needed.
回答3:
As a follow-up to Jacob's answer, it seems necessary to pass to gnatelim
- exactly one main unit, taken from those named in the project file
- the project file
For example, in a project file I have several main units listed as
for Main use ("pack-prog.ada", "driver.ada", ...);
(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
$ gnatelim -Pasnip pack-prog.ada driver.ada
gnatelim: No main unit specified
try "gnatelim --help" for more information.
Specifying exactly one unit, I get
$ gnatelim -Pasnip pack-prog.ada
---------------------------------------------------------
-- List of unused entities to be placed in gnat.adc. --
---------------------------------------------------------
pragma Eliminate (...
The diagnostic message of gnatelim
, or via gnatelim
, seems not entirely adequate.
来源:https://stackoverflow.com/questions/40909885/list-unused-files-in-gnat