获取cmake运行之前,建设从git拉 [英] Getting cmake to run before building after pulling from git

查看:242
本文介绍了获取cmake运行之前,建设从git拉的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个项目保存在git存储库中,我们使用cmake和ninja构建它。
我们使用globbing表达式/函数来收集所有要编译的源文件。这意味着每次添加/删除文件时,都必须调用cmake来重新解析目录。

There is this project kept in a git repository, which we build with cmake and ninja. We are using globbing expressions/functions to collect all the source files to be compiled. That means that every time a file is added/removed, cmake has to be called to re-parse the directories.

我们已经看到,当某人在某人推送了一些新文件后,无需修改任何cmake文件。我说这最后一件事,因为任何cmake文件的修改将触发对cmake(由忍者)的调用,一切都会很好。

We have seen this is bringing some time loss when somebody pulls after somebody has pushed some new file, without modifications to any of the cmake files. I say this last thing because a modification to any of the cmake files would trigger a call to cmake (by ninja), and everything would be fine.

如何我可以获得,cmake是之前/当我开始构建我的项目后,再次建立?
(注意:没有关系,如果cmake运行有点多了必要,只要它是不一定)

How can I obtain that cmake is called before/when I start building again my project after pulling? (Note: it does not matter if cmake is run a little bit more than necessary, as long as it is not always)

我正在构建源代码,此外使用几个构建目录,例如我测试不同的编译器。

I am building out of source, furthermore using several build directory where for example I test different compilers.

我正在探索一些解决方案。一个使用git钩子脚本,即后合并(但我如何可以保证我将检索源/ CMakeLists.txt到触摸它的路径?我可以提交脚本,以便它为每个人运行?它不是一个公共项目)。我不知道是否相关,我们主要通过图形界面(TortoiseGit)使用git。

I am exploring some solutions. One using git hooks script, namely post-merge (but how can I guarantee I will retrieve the path to source/CMakeLists.txt to touch it? Can I commit the script so that it runs for everybody? It is not a public project). I don't know if it is relevant, we mainly use git through graphic interface (TortoiseGit).

另一个可能的解决方案是在cmake中使用自定义目标.git \refs \heads目录的内容,但我不能想到一个可以真正工作的组合...

The other possible solution would be using in cmake a custom target dependent on the content of .git\refs\heads directory, but I cannot think of a combination that could really work...

一些链接:


  1. http://git-scm.com/book/en/Customizing-Git-Git-Hooks

  2. https://www.kernel.org/pub/software/scm/git/docs/githooks.html li>
  1. http://git-scm.com/book/en/Customizing-Git-Git-Hooks
  2. https://www.kernel.org/pub/software/scm/git/docs/githooks.html

CMake命令: http://www.cmake.org/cmake/help/v2.8.11/cmake.html

推荐答案

.git / hooks 中放置后合并脚本文件:

#!/bin/sh
#

touch source/CMakeLists.txt

执行路径显然是项目的根目录,这是这种操作的理想选择。我通过在TartoiseGit上下文菜单中从项目的一个随机子文件夹调用pull来测试这个。 以下是有关如何测试脚本的一些说明

The execution path is apparently the root directory of the project, which is ideal for this kind of operation. I tested this by calling "pull" in the TartoiseGit context menu from one "random" subfolder of the project. Here are some instructions on how one could test the script.

缺点:如果有人在他的编辑器中修改CMakeLists.txt,有一些未保存的修改,如果回答提示文件已在磁盘上更改...太快,他可能会丢失一些工作

Drawback: if somebody is modifying the CMakeLists.txt in his editor, with some unsaved modifications, he might lose some work if too quick in answering to the prompt "the file has changed on the disk..."

然后,为了使这个脚本成为版本库的一部分,我发现了下面的解决方案,似乎对我们的。

Then, to make this script part of the repository, I found the following solution that seems to be good for our (non-public) project.

1)为git钩子脚本创建一个文件夹(例如zz_gitHookScripts),并放入所有人都应该使用的文件。将它添加到存储库。

2)将这样的东西添加到CMakeLists.txt,这样文件将被放在第一次运行cmake的有效目录中(并且,这将发生我们第一次建立之后拉,也是第一次,因为CMakeLists.txt通过此编辑修改):

1) Create a folder (e.g. zz_gitHookScripts) for git hook scripts and put the files everybody should be using. Add it to the repository.
2) Add something like this to the CMakeLists.txt, so that the files will be put in the effective directory first time cmake will be run (and, given the above, this will happen the first time we build after pulling, also the first time because CMakeLists.txt gets modified through this edit):

file(GLOB HOOK_SCRIPTS zz_gitHookScripts/*)
if (HOOK_SCRIPTS)
    file(COPY ${HOOK_SCRIPTS} DESTINATION ${CMAKE_SOURCE_DIR}/../.git/hooks) 
endif (HOOK_SCRIPTS)






如果是补丁,可能会使用$ c> post-applypatch 钩子。

缺点:


  • 在用户隐藏的情况下(用户保存添加/删除文件的更改,必须记住手动运行cmake)或修补程序


  • 删除一些我们不想再使用的hook脚本可能很复杂

  • 一般来说,所有分支机构都必须共享相同的挂钩

  • it is not triggered in case of stash (a user stashing a change which adds/removes files, must still remember to manually run cmake), or in case of a patch
  • users cannot personalize the hook scripts
  • removing some hook script we don't want to use anymore might be complicated
  • in general all branches will have to share the same hooks

无论如何,这对我们的需求很有用。

Anyway, like this it's good for our needs.

这篇关于获取cmake运行之前,建设从git拉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆