获取图标以生成新的内部版本号 [英] Get scons to generate a new build number

查看:108
本文介绍了获取图标以生成新的内部版本号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让scons从文件中读取先前的版本号,使用新的版本号和当前日期更新源文件,然后将其写回到原始文件中,以备下一次构建.

I'd like to get scons to read a previous version number from a file, update a source file with a new version number and current date and then write the number back to the original file ready for the next build.

仅当目标已过期时才需要 发生. IOW如果不进行构建,则版本号不会更改.原始文件是受源代码控制的,不是 源文件,否则它可能会导致签入的另一个构建(由于CI). 澄清从scons的角度来看,由于自动生成的源文件,代码始终会过时,但仅当检测到SCM更改时,scons才会从持续集成作业(Jenkins)中运行

This needs to happen only when the target is out of date. IOW the version number doesn't change if no build takes place. The original file is source controlled and isn't a source file else it could trigger another build on check-in (due to CI). CLARIFICATION From scons' point of view the code will always be out of date due to the auto-generated source file but scons will only be run from a Continuous Integration job (Jenkins) when a SCM change is detected.

我研究了AddPostMethod,但这似乎对源文件列表中的所有文件都有效.
CommandBuilder方法使用VARIANT_DIR,因此我无法编辑这些文件,然后又将它们检入,因为它们不再映射到存储库.

I've looked into AddPostMethod, but this seems to fire for all files within the list of source files.
Command and Builder methods use the VARIANT_DIR so I can't edit these files and then check them back in as they no longer map to the repo.

我希望我只是误解了一些错误的细节,否则我的想法就用光了!

I'm hoping I'm just misunderstanding some of the finer details of scons else I'm running out of ideas!

更新 通过更多的思考,汤姆的评论是正确的.尽管我有两个文件,一个是版本控制的文本文件(非源代码),另一个是非源控制的源文件,但是无法检入一个文件并阻止连续的构建/检入周期. Jenkins将看到新的文本文件并生成一个版本,而scons将看到新生成的文件.因此,除非我在某个时候删除了生成的文件,尽管这似乎与这两种工具的工作流程背道而驰.

Update Thinking this through some more, Tom's comment is correct. Although I have two files, one version controlled text file (non-source code) and one non-source controlled source file there is no way to check one file in and prevent a continuous build/check-in cycle. Jenkins will see the new text file and spin off a build, and scons will see the new generated file. So unless I delete the generated file at some point, although this seems to go against the workflow of both tools.

有人能实现这一目标吗?看起来很简单.最终,我只想在每次开始构建时生成内部版本号.

Does anyone have any method for achieving this? It seems pretty straightforward. Ultimately I just want to generate build numbers each time a build is started.

推荐答案

来自 SCons用户指南的第8节,仅订购依赖项,您可以使用Requires方法:

From SCons User Guide section 8, Order-Only Dependencies, you can use the Requires method:

import time

# put whatever text you want in your version.c; this is just regular python
version_c_text = """
char *date = "%s";
""" % time.ctime(time.time())
open('version.c', 'w').write(version_c_text)

version_obj = Object('version.c')

hello = Program('hello.c',
                LINKFLAGS = str(version_obj[0]))

Requires(hello, version_obj)

需要注意的两件事:首先,您必须添加显式的Requires依赖项.其次,您不能使version_obj成为程序构建器的源代码,您必须作弊(此处将其作为linkflag传递),否则将自动获得对它的完全依赖.

Two things to note: first you have to add the explicit Requires dependency. Second, you can't make version_obj a source of the Program builder, you have to cheat (here we pass it as a linkflag), otherwise you'll get an automatic full dependency on it.

这将始终更新version.c,但不会仅因为version.c更改而重建.

This will update the version.c always, but won't rebuild just because version.c changed.

这篇关于获取图标以生成新的内部版本号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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