I'm trying to generate a per-sourcefile macro that will hold the base file name of the source file. This is described for make here.
I tried to override the Object builder, but it didn't work... I tried to do what is described 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
Then, replacing the builders:
env['BUILDERS']['_Object'] = env['BUILDERS']['Object']
env['BUILDERS']['Object'] = my_object_builder
This didn't work. I got the following error:
AttributeError: 'function' object has no attribute 'src_suffixes'
I think it has to do with something with Environment's MethodWrapper, but I couldn't verify.
Maybe I'm going for this from the wrong angle. Maybe I should change the environment for each source file (seems like a lot of work...)
The main requirement is that the usage will be seamless. I don't want users to have to call a MyObjectBuilder class. Also, the StaticLibrary Builder should call the new Object builder.
Any help would be much appreciated. Thanks!
BugoK.