在与NetBeans建立远程Git的嵌入在修改可执行 [英] Embed Git revision in executable during remote build with NetBeans

查看:231
本文介绍了在与NetBeans建立远程Git的嵌入在修改可执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在编译时嵌入到我的可执行文件的Git版本(SHA1)。我能做到在本地是这样的:

I'd like to embed the Git revision (SHA1) in my executables at build time. I can do it locally like this:

 git log -1 --format='%h' >version
 objcopy --input binary --output elf64-x86-64 version version.o
 # link version.o into the executable

问题是,我使用的的NetBeans (在Windows上)来远程建(在Linux上)。这是一个有点悖论:Git的命令似乎需要在本地计算机(其中源)上运行,但objcopy把命令需要在远程服务器上运行(其中构建发生)。这是一个问题,因为在NetBeans的确实让我编辑项目的Makefile中插入pre-生成步骤,我无法弄清楚如何或在哪里把git的命令,以便它运行在本地计算机上远程前打造步骤。

The problem is, I'm using NetBeans (on Windows) to build remotely (on Linux). It's a bit of a paradox: the git command seems to need to run on the local machine (where the source is), but the objcopy command needs to run on the remote server (where the build happens). This is a problem because while NetBeans does let me edit the project's Makefile to insert a pre-build step, I can't figure out how or where to put the git command so that it runs on the local machine before the remote build steps.

我试图使一个单独的NetBeans项目运行localhost上的git的命令,以为我会再做出真正的项目依赖于这一点,但NetBeans的似乎并没有让我创建一​​个项目,不无(即它没有源文件,并且不产生一个库,也不可执行 - 这将仅生成版本文本文件)。

I tried making a separate NetBeans project to run the git command on localhost, thinking that I'd then make the "real" project depend on that, but NetBeans doesn't seem to allow me to create a project that "does nothing" (i.e. it has no source files, and does not produce a library nor an executable--it would only generate the version text file).

我使用NetBeans 7.3 C ++与自动复制选项进行远程构建。一个可能的解决方案可能是使用NFS / Samba的模式与存储在服务器上的Git仓库,但由于该项目使用自动复制很长一段时间已经多开发商会相当的破坏性。因此,这将是巨大的,有一个解决方案,启动远程构建之前产生在NetBeans在本地的一些文件。

I'm using NetBeans 7.3 for C++ with the "Automatic Copying" option for remote builds. A possible solution might be to use the NFS/Samba mode with the Git repository stored on the server, but that would be fairly disruptive because the project has multiple developers using Automatic Copying for a long time already. So it would be great to have a solution to generate some files locally in NetBeans before starting the remote build.

推荐答案

一个解决办法是有一个版本的文件已经达到最新的,当你启动你的Netbeans的工作。

One solution would be to have that version file already up-to-date when you launch your Netbeans job.

一个 post-commit钩子可以在合适的地方生成文件,您N​​etbean工作阅读。

A post-commit hook could generate that file at the right place, for your Netbean job to read.

这篇关于在与NetBeans建立远程Git的嵌入在修改可执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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