如何编写使用存储库 ID 标记库或可执行文件的 makefile?
我有通过 makefile 生成可执行文件的代码。可执行文件本身生成一个包含数据的输出文件。将来,当我回头查看我保存的旧数据时,我希望能够以可靠且系统的方式重现这些数据。换句话说,我需要知道存储库 (GIT) 的 ID 号,以便可以恢复代码,而且我还需要知道如何编译代码以及使用的编译器和标志。解决这个问题的最佳方法是什么?
我如何完成与上面描述的相同的任务,但使用旧库而不是数据,以便我可以选择一个旧库,找出用于生成它的代码的存储库 ID 号,并找出Makefile信息是用来生成的吗?
I have code that generates an executable via a makefile. The executable itself generates an output file with data. In the future, when I go back and look at old data that I've kept, I would like to be able to reproduce the data in a reliable and systematic way. In other words, I would need to know an ID number form a repository (GIT) so that I can recover the code, and I would also need to know how I compiled the code and what compiler and flags I used. What is the best way to go about this?
How do I accomplish the same as I've described above but with an old library instead of data, so that I can pick an old library, find out the repository ID number for the code that was used to generate it, and find out the Makefile info used to generate it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有很多方法可以做到这一点;最好的选择取决于源代码控制系统的灵活性以及您想要防止多少用户恶作剧等因素。
一种可能性:我不熟悉 GIT,但我敢打赌,通过一些努力,您可以设置一个系统,这样当您检查代码和 makefile 的版本时,您还会生成一个包含版本号(或 ID 或任何)。稍加努力,您可以将版本号写入 makefile 以防止丢失/交换版本文件(尽管这在概念上是不卫生的,因为 makefile 将与源代码控制下的 makefile 不同)。可执行文件将读取文件并将版本号附加到数据中。 (同样,如果您愿意,可以将该数字合并到可执行文件中,这将使库成为一个独立的实体并防止交换 makefile/版本文件,但会引起 QA 人员的不满。)
另一种方法:使用校验和。 makefile 计算自己的校验和并将其记录在一个小文件中,可执行文件使用/合并并附加到数据中。可执行文件还计算自己的校验和(带有编译器不确定性的警告)并附加它。一个小型的校验和数据库,可以根据需要轻松构建,充当索引返回存储库的查找表。
There are many ways to do this; the choice of the best will depend on things like the flexibility of your source control system, and how much user mischief you want to guard against.
One possibility: I am not familiar with GIT, but I bet with some effort you could set up a system such that when you check out a version of the code and makefile, you also produce a small file containing the version number (or ID or whatever). With a little more effort you could write the version number into the makefile to guard against a lost/swapped version file (although this would be conceptually unhygienic, since the makefile would then not be identical to the one under source control). The executable would read the file and append the version number to the data. (Again, the number could be incorporated into the executable if you like, which would make the library a self-contained entity and guard against a swapped makefile/versionfile, but raise the hackles of your QA people.)
Another way: use checksums. The makefile calculates its own checksum and records it in a small file, which the executable uses/incorporates and appends to the data. The executable also calulates its own checksum (with caveats for compiler indeterminacies) and appends that too. A small database of checksums, easily constructed at need, acts as a lookup table for the index back into the repository.
这很简单。诀窍是,如果版本没有更改,则不要重新链接您的库。
将
version.c
包含在项目的源列表中,然后就完成了。这是什么
cmp -s $< $@ || cp$< $@?诀窍是仅更新
version.c
如果它与编译到项目中的最后版本不同。 OTOH 如果没有不同,则不得向 shell 返回任何错误。This is straight forward. The trick is to not relink your library if the version has not changed.
Include
version.c
in the source-list of your project, and you are done.What's all this
cmp -s $< $@ || cp $< $@
? The trick is to only updateversion.c
if it differs from the last version compiled into your project. OTOH if it does not differ, then no error must be returned to the shell.