In Adacore's GPR file, how can I set the compiler to exclude file with full path

838 Views Asked by At

I have a project which contains several files which have the same name but in differents folders.

Ex :

 ->sources
    ->src 
      - a.c
      - b.c
    ->stub
      - a.c
      - z.c

In my gprfile I included the source with

for Source_Dirs use ( "sources/**" )

Now, I want to ignore the files in src by using the primitive "Excluded_Source_File".

Unfortunatly, this primitive needs a file name, and not a full path, so when I want to ignore a.c, it ignore the both files in src and stub.

for Excluded_Source_Files use ( "sources/src/a.c" ); -- KO by gprbuild
for Excluded_Source_Files use ( "a.c" ); -- OK but ignore both

Does anyone know how can I do this, without alterate the current folder architecture and without rename files ?

2

There are 2 best solutions below

0
On BEST ANSWER

Sounds like what you want is a project extension, ie. create a second project file, which extends the first. In this seconds project file, you can override a.c

project Stubbed extends "my_project.gpr" is
   for Source_Dirs use ("stub");
end Stubbed;

You can read more about project extentions in the GPRBuild User Guide

0
On

I would use scenario variables; also, it sounds as though Excluded_Source_Dirs would be useful.

type Source_T is ("normal", "stubbed");
Sources : Source_T := external ("SOURCES", "normal");

then either

for Source_Dirs use ("sources/**");
case Sources is
   when "normal" =>
      for Excluded_Source_Dirs use ("sources/stub");
   when "stubbed" =>
      for Excluded_Source_Dirs use ("sources/src");
end case;

or

for Source_Dirs use ("sources");
case Sources is
   when "normal" =>
      for Source_Dirs use project'Source_Dirs & "sources/src";
   when "stubbed" =>
      for Source_Dirs use project'Source_Dirs & "sources/stub";
end case;

In either case,

gprbuild -P prj

(you could add the defaulted -XSOURCES=normal) or

gprbuild -P prj -XSOURCES=stubbed