ADA GNAT项目,其中包括不同命名的文件,用于不同的构建配置
我有一个具有多种构建配置的GNAT/GPRBUILD项目。我有一个主源文件和一个辅助广告文件,主要源文件包含:
with Secondary_File; use Secondary_File;
问题是,在每种配置中,辅助文件具有不同的名称。例如,它可以称为一个config和secondary_file_2.ads的secontary_file_1.ads。这使得无法将上述与
语句一起使用。
在C中,我会做这样的事情:
#ifdef BUILD_CFG_1
#include "secondary_file_1.h"
#else
#include "secondary_file_2.h"
#endif
使用GPRBuild系统,是否有一种聪明的方式在ADA中做这样的事情?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
许多纯粹主义者拒绝预处理的想法,但是可以使用gnat 。
您可以通过编写源来将其包括在基于GPR的构建环境中,例如
main.adb
,例如:(观察
$ numbern :
编译给予
(汇编查找
secondary_file_1.ads
)(汇编寻找
second> secondary_file_2.ads
)Many purists reject the idea of preprocessing, but it’s possible using GNAT.
You can include this in a GPR-based build environment by writing your source, e.g.
main.adb
, like so:(observe the
$NUMBER
) and the project file like so:Compiling gives
(the compilation looked for
secondary_file_1.ads
)(the compilation looked for
secondary_file_2.ads
)Simon Wright 的答案的一个小变化是使用
naming
naming package> package 和spec> spec
spec 。当文件名不同时,此变化很有用,但是软件包名称是相同的:secondary_file
。因此,不确定这在您的情况下是否有效。main.adb
secondary_file_1.ads
secondary_file_2.ads
prj.gpr
uptump (编译器) )
A small variation on the answer of Simon Wright is one that uses a
Naming
package andSpec
attributes in the GPRbuild file. This variation is useful when file names are different, but package names are the same:Secondary_File
. So, not sure if this works in your case.main.adb
secondary_file_1.ads
secondary_file_2.ads
prj.gpr
output (compiler)
在 simon's
和纯粹主义者的回答的想法是:使用GPR项目文件,他们提供“ 方案变量 ”功能,这些功能应该完全可以完成您想要的事情,而无需重命名或依赖文件一些预处理步骤。
我猜
secondary_file.ads
是唯一的(接口/合同),因此您将每个Secondary_file.adb
放在其自己的文件夹中(不同的实现)。然后,它易于根据方案变量调整GPR source_dir/source_files列表。该变量可以在GNATSTUDIO IDE,ENV VAR和命令行标志中设置。
因此,您可以拥有此文件夹树:
然后使用此GPR文件
my_project.gpr
:然后,您要做的就是使用GPR构建构建:
或偶数:
根据您的特定软件,您也可以考虑对象在某些情况下可以帮助获得类似结果的定向设计模式。
Bouncing on Simon's answer
And a purist's answer would be: use GPR project files, they offer the "scenario variables" feature that should do exactly what you want, without having to rename files or rely on some preprocessing step.
I guess
Secondary_File.ads
is unique (interface/contract), so you put eachSecondary_File.adb
in its own folder (distinct implementations).Then its easy to adapt the GPR source_dir/source_files list according to a scenario variable. The variable can be set in the GnatStudio IDE, in an env var, and in a command line flag.
So you could have this folder tree:
Then use this GPR file
my_project.gpr
:All you have to do is then build using gpr build:
or even :
Depending on your specific software, you may also consider object oriented design patterns that can help achieve a similar result in some cases.
如果某些文件不同,那么为什么没有两个不同的.gpr配置文件?您可以将不同的代码分为不同的目录,并具有第三个目录的通用代码,然后在.gpr中在类似的块中指定。
现在
,您在同一项目中具有不同的配置,并且可以构建一个。您甚至可以走得更远,创建包含两个配置之间共享功能的常见ADA规格文件(.1.ADA),但具有不同的行为不同的ADA Body Files(.2.ADA)。
If some of the files are different then why not have two different .gpr configuration files? You can separate the different code into different directories and have a third directory for common code and then specify in the .gpr in a block like this
and this
Now you have different configurations in the same project and can build either one. You can even go further and create common ada spec files (.1.ada) that contain shared functions between the two configuration but have two different ada body files (.2.ada) that behave differently.