1

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

gccinac
  • 103
  • 2
  • 11
  • Are you looking at [*§8.3 Improving Performance*](https://gcc.gnu.org/onlinedocs/gcc-6.2.0/gnat_ugn/Improving-Performance.html#Improving-Performance) with respect to size? – trashgod Dec 02 '16 at 03:46
  • What I wnat todo is get the files that are never withed or to get large chunks of dead code and remove it. The link you posted is a possibility, but I don't see how to get it working with a gpr project. – gccinac Dec 02 '16 at 07:46

3 Answers3

2

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
Jacob Sparre Andersen
  • 6,733
  • 17
  • 22
  • It seems that, as my project is a library, It is not possible to pass a main unit. However, I tested it with a small stub project and it did work. Thanks a lot! PD: sorry for taking so long in accepting the answer, I was out of town. – gccinac Dec 13 '16 at 09:12
1

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 withed units aren't really needed.

Jacob Sparre Andersen
  • 6,733
  • 17
  • 22
  • I do have a main unit in my project, that's why I don't get why it does not work. On the other hand, thanks a lot for the other alternative that you give. I'll try it and let you know :) – gccinac Dec 04 '16 at 21:07
  • Is the main unit listed properly in the project file? `for Main use ("main_unit");` – Jacob Sparre Andersen Dec 05 '16 at 05:44
  • Yes, the main unit is listed. I can compile the gpr and it executes fine, that's why I don't get why the gnatelim does not work. On the other hand, I still have not been able to try your idea. – gccinac Dec 06 '16 at 08:58
1

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.

Community
  • 1
  • 1
B98
  • 1,229
  • 12
  • 20