如何使用 Git 在开发和生产环境中分发 Thrift 生成的代码?
如何使用 Git(PHP、Python 等)管理存储库和部署例程中生成的源代码文件?
例如,我有一个名为“interfaces”的存储库,其中包含 Thrift 定义。它们可以转换为 Python、PHP、JS 等骨架/存根。其他不同语言的项目(每个项目都在自己的存储库中)想要使用这些存根。如何将存根交付给项目?
我只看到两种方法:
生成存根文件并将它们存储在“接口”存储库中,并且该存储库应附加到项目的存储库中(作为只读子模块或任何其他方式)。但是,由于“git子模块”概念过于复杂,这种方式在检查接口和存根的更新时会带来很多麻烦。
将纯“接口”存储库附加到每个项目,并生成存根文件作为临时 git-ignorable(!) 文件(使用“make 存根”或类似文件)。这样,每个项目都可以有自己的生成设置,并应用自己的补丁(如果需要的话)。但是您需要向 PHP/Python 开发和生产环境引入一些编译命令(不仅仅是“git pull”)。
这些方法的优点和缺点是什么?
How do you manage generated source code files in you repositories and deployment routines with Git (PHP, Python, etc)?
For example, I have a repository named "interfaces" with Thrift definitions in it. They can be converted to Python, PHP, JS, etc skeletons/stubs. Other projects in different languages, each in its own repository, want to use those stubs. How to deliver the stubs to the projects?
I see only two ways:
Generate the stub files and store them in the "interfaces" repository, and this repository should be attached to the projects' ones (as readonly submodule or any other way). But this way introduces a lot of headaches when checking out the updates to the interfaces and the stubs due to overcomplicated "git submodules" concepts.
Attach pure "interfaces" repository to each project, and generate stub files as temporary git-ignorable(!) files (with "make stubs" or alike). This way, each project can have their own generation settings with their own patches applied (if needed at all). But you need to introduce some compilation commands to PHP/Python development and production environments (not just "git pull").
What are the pros and cons of these approaches?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通常最好选择“生成”路线而不是“存储生成的内容”路线,主要是因为您并不总是 100% 确定所述生成内容的当前状态:它是否与源同步?
接收后挂钩可以在
推送
时负责生成相关内容。请参阅 Git Hooks 或 Pro-Git 挂钩。
不过,在您自己的本地实例上(即在
git pull
上),别名可能会将拉取和生成所述内容结合起来。It is generally best to favour the "generation" route over the "storing generated content" route, mainly because you are not always 100% sure of the current status of said generated content: is it in sync with the sources?
A post-receive hook can take care, upon a
push
, of generating the relevant content.See Git Hooks or Pro-Git hooks.
On your own local instance though, (i.e. on a
git pull
), an alias might combine both pulling and generating said content.我认为 #2 是可行的方法,如果没有别的办法的话,因为你不希望 git 自动合并生成的文件。
在 php 或 python 应用程序初始化代码中,您可以检查 idl 文件和生成的存根上的时间戳,并发出警告和/或中止,或者启动 thrift 编译器(如果可用)。
I think the #2 is way to go, if nothing else because you do not want git to auto merge generated files.
In your php or python app initialization code, you could check timestamp on idl files and generated stubs, and issue warning and/or abort, or start thrift compiler if available.