0

我有一个项目,其中包含几个具有相同名称但位于不同文件夹中的文件。

前任 :

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

在我的 gprfile 中,我包含了源代码

for Source_Dirs use ( "sources/**" )

现在,我想通过使用原语“Excluded_Source_File”来忽略 src 中的文件。

不幸的是,这个原语需要一个文件名,而不是完整路径,所以当我想忽略 ac 时,它会忽略 src 和 stub 中的两个文件。

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

有谁知道我怎么能做到这一点,而不改变当前的文件夹架构并且不重命名文件?

4

2 回答 2

6

听起来你想要的是一个项目扩展,即。创建第二个项目文件,扩展第一个。在此秒项目文件中,您可以覆盖a.c

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

您可以在GPRBuild 用户指南中阅读有关项目扩展的更多信息

于 2018-11-19T15:28:48.130 回答
6

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
于 2018-11-19T16:32:27.443 回答