我正在尝试生成一个每个源文件的宏,它将保存源文件的基本文件名。这是为 make here描述的。
我试图覆盖对象生成器,但它没有工作......我试图做这里描述的事情。
def my_object_builder(env, target, source, **kwargs):
"""A builder that calls the Object builder, with the addition of defining
a macro that holds the source file's basename
"""
if SCons.Util.is_List(source):
if len(source) > 1:
raise ValueError('cannot pass a list of sources to Object builder: %s',
[str(x) for x in source])
else:
source, = source
if 'CPPDEFINES' not in kwargs:
kwargs['CPPDEFINES'] = []
kwargs['CPPDEFINES'].append(('__MY_FILENAME',
os.path.basename(str(source))))
ret = env._Object(target=target,
source=source,
**kwargs)
return ret
然后,更换建设者:
env['BUILDERS']['_Object'] = env['BUILDERS']['Object']
env['BUILDERS']['Object'] = my_object_builder
这没有用。我收到以下错误:
AttributeError: 'function' object has no attribute 'src_suffixes'
我认为这与 Environment 的 MethodWrapper 有关,但我无法验证。
也许我从错误的角度去做这个。也许我应该更改每个源文件的环境(似乎需要做很多工作......)
主要要求是无缝使用。我不希望用户必须调用 MyObjectBuilder 类。此外,StaticLibrary 构建器应该调用新的对象构建器。
任何帮助将非常感激。谢谢!
BUGOK。