如何增加 scons 的 $*COMSTR [英] How to augment scons' $*COMSTR

查看:59
本文介绍了如何增加 scons 的 $*COMSTR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以通过定义$*来定义自定义构建命令输出COMSTR 在我的环境中:

env['CXXCOMSTR'] = compile_source_message

但是,这会覆盖为构建命令显示的消息.我想增加消息,例如通过在目标前面加上前缀.我的目标是有这样的消息:

% scons编译 foo.occ -o foo.o -c foo.c

我尝试了以下方法:

env['CXXCOMSTR'] = compile_source_message + '\n' + env['CXXCOMSTR']

但是,这不起作用,因为 CXXCOMSTR 不在 env 中,我收到 KeyError: 'CXXCOMSTR'.>

如何增加/添加默认的 $*COMSTR 前缀?

解决方案

您遇到的问题是由于以下行为:

如果 *COMSTR 评估为空字符串,则取消操作的 CommandAction 对象将默认使用 *COM 字符串生成输出.

尝试:打印 env.Dump('CXXCOMSTR')除了 KeyError 为 e:打印 env.Dump('CXXCOM')

将输出您要查找的值.并针对您的特定用途:

尝试:env['CXXCOMSTR'] = compile_source_message + '\n' + env['CXXCOMSTR']除了:KeyError 为 e:env['CXXCOMSTR'] = compile_source_message + '\n' + env['CXXCOM']

当然,如果您构建中的某些逻辑稍后会更改 CXXCOM 的值,那么该更改不会影响您的新设置.

如果您想确保对 CXXCOM 的更改会传播到您的 CXXCOMSTR 的新值,则应执行以下操作:

if env.get('CXXCOMSTR',False):env['CXXCOMSTR'] = compile_source_message + '\n' + env['CXXCOMSTR']别的:env['CXXCOMSTR'] = "%s \n $CXXCOM"%compile_source_message

请注意,在新的 CXXCOMSTR 中使用 $CXXCOM(*) 允许 SCons 替换并完全扩展每个目标的输出.

I can define a custom build command output by defining $*COMSTR in my environment:

env['CXXCOMSTR'] = compile_source_message 

However, this overrides the message shown for the build command. I want to augment the message instead, e.g. by prefixing it with the target. My goal is to have a message like this:

% scons
Compiling foo.o
cc -o foo.o -c foo.c

I tried the following:

env['CXXCOMSTR'] = compile_source_message + '\n' + env['CXXCOMSTR']

However, this doesn't work because CXXCOMSTR is not in env yet, I get a KeyError: 'CXXCOMSTR'.

How can I augment/prefix the default $*COMSTR?

解决方案

The problem you're having is due to the following behavior:

If the *COMSTR evaulates to a null string, then the CommandAction object which undelies the Action for this will default to using the *COM string to generate the output.

try:
    print env.Dump('CXXCOMSTR')
except KeyError as e:
    print env.Dump('CXXCOM')

Would output the value you're looking for. And for your specific usage:

try:
    env['CXXCOMSTR'] = compile_source_message + '\n' + env['CXXCOMSTR']
except: KeyError as e:
    env['CXXCOMSTR'] = compile_source_message + '\n' + env['CXXCOM']

Of course if some logic in your build were to later on alter the value of CXXCOM then that change would not affect your new setting.

If you wanted to ensure that changes to CXXCOM would propogate to your new value of CXXCOMSTR then the following should work:

if env.get('CXXCOMSTR',False):
    env['CXXCOMSTR'] = compile_source_message + '\n' + env['CXXCOMSTR']
else:
    env['CXXCOMSTR'] = "%s \n $CXXCOM"%compile_source_message

Note that having the $CXXCOM(*) in your new CXXCOMSTR allows SCons to substitute and fully expand the output for each target.

这篇关于如何增加 scons 的 $*COMSTR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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