Spec not allow body (remove in gpr file) without touching source files

476 views Asked by At

I got the following error which is common with generated sources:

spec of this package does not allow a body

I would like to know if it exist a rule to put in the gpr file to ignore this error. Like a ignore flag.

As I mentioned this files are generated so I have no right on them (not allowed to suppress them neither rewrite them). More over it would be nice to have a rule that work for every generation.

2

There are 2 answers

2
egilhh On

You can exclude the body from the list of source files:

for Excluded_Source_Files use ("my_body.adb");
7
Simon Wright On

If you were to compile

package Guillaume is
end Guillaume;

package body Guillaume is
end Guillaume;

in Ada 1983 mode, you would get e.g.

gnatmake -gnat83 guillaume.ads
gcc -c -gnat83 guillaume.ads
guillaume.ada:1:09: warning: package "Guillaume" does not require a body
guillaume.ada:1:09: warning: body in file "guillaume.adb" will be ignored

Having a body that isn’t required by the spec was made illegal with Ada 95 (it would be possible to change a body and for the compilation process not to notice that it needed to be recompiled, leading to confusion). If your code generator was designed to produce Ada 83, then I guess you may have to face compiling in Ada 83 mode - but GNAT doesn’t, as far as I know, guarantee to be 100% compatible, particularly as far as the run time system is concerned.

Are the offending package bodies all actually empty? If so, you might be able to list them and use the Excluded_Source_List_File attribute in your project. If not, you are in trouble, because there’s no way (without changing package sources) to get the code in them to execute.

(Later): actually, Excluded_Source_List_File doesn’t help; it stops gprbuild looking at the file, but not the compiler; and it’s the compiler that rejects the body. Sorry. But if you could make such a list you could use it to delete the bad bodies.