在 gprbuild 文件中设置 --create-missing-dirs 选项

Setting the --create-missing-dirs option in a gprbuild file

有一个单独的目录来存储目标文件很有用。但是,如果该目录不存在,gprbuild 会报错。我使用 hg 进行版本控制,它不允许您跟踪空目录(AFAIK 这对 git 也是如此),但即使它这样做了,不幸的是不得不弄乱具有空目录的存储库。 gprbuild 有一个选项,--create-missing-dirs(缩写形式 -p),它完全按照锡罐上的说明进行操作。这非常有用。但是,我想知道是否有某种方法可以在 .gpr 文件中进行设置。不得不提醒我的用户使用 -p 选项进行编译,而不是只能 运行 gprbuild project,这是令人讨厌的。不幸的是,gprguild 的文档是这样说的:

By default, GPRbuild checks that the object, library and exec directories specified in project files exist. Switch -p instructs GPRbuild to attempt to create missing directories. Note that these switches may be specified in package Builder of the main project, but they are useless there as either the directories already exist or the processing of the project files has failed before the evaluation of the Builder switches, because there is at least one missing directory.

肯定有办法完成我所描述的事情吗?

如果您要提交一个空目录,您可能也不希望 git/hg 跟踪该目录中的文件。一种解决方案是在目录中放置一个隐藏*跟踪文件,并添加一条规则以忽略所有其他文件。

对于 hg.hgignore 必须位于顶层(据我所知),因此您需要添加一个 .keep 文件(或其他一些描述名称)在您要保留的目录中,并向 .hgignore 添加规则以忽略其他所有内容。

对于 git,您可以将 .gitignore 文件放在目录本身中,并使用忽略所有文件的规则。在这种情况下,.gitignore 本身就是隐藏的跟踪文件。 (奖励:规则更容易编写)

  • 在以 . 开头的文件被隐藏的系统上

gprbuild 的最新版本(自 2016 年 8 月 19 日起,参见 Git)支持 Create_Missing_Dirs 属性。

project Foo is
   for Create_Missing_Dirs use "True";
   ...

GNAT GPL 2017 有这个。