简体   繁体   English

如何有效地使用git存储库/子模块用于具有多个依赖项的C ++产品?

[英]How to effectively use git repositories / submodules for a C++ product that has many dependencies?

I'm very new to Git and still figuring things out... I think I'm finally understanding the whole branching/merging aspects. 我对Git很新,还在搞清楚......我想我终于理解了整个分支/合并方面。 But I'm still not sure what the best solution for handling project dependencies are. 但我仍然不确定处理项目依赖性的最佳解决方案是什么。 What is best practice? 什么是最佳做法? This has got to be a common problem and yet I can't find a good tutorial or best practice on doing this. 这必须是一个常见问题,但我找不到一个好的教程或最佳实践。

Suppose I have a C++ product that depends on several other C++ libraries, ultimately making up a complicated dependency graph. 假设我有一个依赖于其他几个C ++库的C ++产品,最终构成了一个复杂的依赖图。 Libraries like: other internally developed C++ libraries, public open source libraries, off-the-shelf closed source libraries 图书馆如:其他内部开发的C ++库,公共开源库,现成的闭源库

The final C++ product's source code relies on the output of its dependencies in order to compile. 最终的C ++产品的源代码依赖于其依赖项的输出以进行编译。 These outputs are composed of: 这些产出包括:

  • A series of C++ header files (notice that the C++ implementation files are absent) 一系列C ++头文件(注意C ++实现文件不存在)
  • A set of compiled binaries (LIB files, DLL files, EXE files, etc) 一组已编译的二进制文件(LIB文件,DLL文件,EXE文件等)

My understanding is I should put each library its own repository. 我的理解是我应该将每个库都放在自己的存储库中。 Then it sounds like Git's submodules are mostly what we are looking for. 然后听起来像Git的子模块主要是我们正在寻找的。 The write-up at http://chrisjean.com/2009/04/20/git-submodules-adding-using-removing-and-updating/ in particular seems like a good introduction and I can almost understand. http://chrisjean.com/2009/04/20/git-submodules-adding-using-removing-and-updating/上的文章似乎是一个很好的介绍,我几乎可以理解。 For example, I could have my master project repository refer to a specific external Git repository as a submodule / dependency. 例如,我可以将我的主项目存储库引用到特定的外部Git存储库作为子模块/依赖项。 C++ code can "#include" header files in the appropriate submodule directories. C ++代码可以在相应的子模块目录中“#include”头文件。 A build script included with the master product / repository could conceivably proceed to recursively compile all submodules. 主产品/存储库中包含的构建脚本可以设想继续递归编译所有子模块。

OK now the question: 好了,现在问题是:

How do you typically cache binaries for each repository? 您通常如何缓存每个存储库的二进制文件? Some of our dependencies take hours to compile and aren't updated on a very frequent basis. 我们的一些依赖项需要数小时才能编译,并且不会经常更新。 With the above scheme, I might clone / check out a high-level project from the server to fix a small bug. 通过上面的方案,我可以从服务器克隆/检查一个高级项目来修复一个小bug。 Now as I understand it, I'm also forced to clone all the thousands of files that make up each of these open source dependencies - I'm worried that could take some time (especially on Windows). 据我了解,我也被迫克隆构成这些开源依赖项的所有数千个文件 - 我担心这可能需要一些时间(特别是在Windows上)。 Even worse, wouldn't I then be forced recompile each and every submodule, even if nobody has changed that submodule for months? 更糟糕的是,我不会被强制重新编译每个子模块,即使几个月没有人改变过这个子模块吗? (It seems like some kind of local "hash table" scheme on each developer computer that links a changeset ID to a set of compiled binaries would be handy...) (似乎每个开发人员计算机上的某种本地“哈希表”方案将变更集ID链接到一组已编译的二进制文件将会很方便...)

(A previous shop I worked at a few years ago used Mercurial - the extent of , but all code - internal projects, etc. was rolled into one single big giant repository, and you had to build everything in a big fat monolithic build script when cloning a newly-created branch from the server. When we were done with the fix / new feature and had merged back with upstream, we deleted the local repository for that particular branch.) (我之前在几年前工作过的一家商店使用的是Mercurial - 但是所有代码 - 内部项目等等都被整合到一个巨大的巨型存储库中,你必须在一个巨大的单片构建脚本中构建所有东西 。从服务器克隆新创建的分支。当我们完成修复/新功能并与上游合并时,我们删除了该特定分支的本地存储库。)

We're doing development on Windows, but will eventually branch out to other non-Microsoft platforms - so portability is important. 我们正在Windows上进行开发,但最终将分支到其他非Microsoft平台 - 因此可移植性非常重要。

Normally this is a bad idea, but why don't you check the binaries into the submodules as well as the compiled code for submodules that don't change often? 通常这是一个坏主意,但为什么不检查子模块中的二进制文件以及不经常更改的子模块的编译代码? That way, the fetch will pull down the bins, and when you compile a new version of a dependency with changed binaries, you will see the binaries show up in the git status output. 这样,获取将拉下垃圾箱,当您使用更改的二进制文件编译新版本的依赖项时,您将看到二进制文件显示在git status输出中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM