[Scons-users] Attaching an emitter to an existing builder

Bill Deegan bill at baddogconsulting.com
Fri Jan 29 13:57:49 EST 2021


Jeremy,

Glad that worked for you!
Please consider filing an enhancement request issue to support generating
map files?

Thanks,
Bill

On Thu, Jan 28, 2021 at 4:20 PM Jeremy Elson <jelson at gmail.com> wrote:

> Thanks, everyone for the help -- PROGEMITTER worked perfectly:
>
>         # Add map creation as a linker flag, and modify the standard
> Program
>         # emitter to know that map generation is a side-effect
>         map_filename = os.path.join(build_obj_dir, f"{target.name}.map")
>         env.Append(LINKFLAGS = f"-Wl,-Map={map_filename},--cref")
>         def map_emitter(target, source, env):
>             assert(str(target[0]) == os.path.abspath(program_name))
>             target.append(map_filename)
>             return target, source
>         env.Append(PROGEMITTER = [map_emitter])
>
> My only concern with PROGEMITTER was that it was not a general solution to
> this problem -- i.e., what if I want to override something other than
> Program()? But from looking at MSlink.py as Mats suggested, it seems that
> nearly all the standard builders have similar overrides (SHLIBEMITTER,
> LDMODULEEMITTER, etc). I guess it's similar to the *COMSTR series of
> constants for modifying the message printed at each build step.
>
> Thanks again for a great build system. SCons is a pleasure to use.
>
> -Jeremy
>
>
>
> On Thu, Jan 28, 2021 at 7:19 AM Mats Wichmann <mats at wichmann.us> wrote:
>
>> On 1/27/21 3:11 PM, Bill Deegan wrote:
>> > Jeremy,
>> >
>> > Greetings!
>> > You're not the first to mention adding the map file as a side effect.
>> > (or target)
>> > Please go ahead and file and Issue on github for this.
>> > Ideally with a simple example, what the gcc flag is, and what the file
>> > naming/location would be?
>> >
>> > So likely the easiest way to add an emitter to Program() would be the
>> > following (not tested)
>> >
>> > env.Append(PROGEMITTER = [my_map_emitter])
>> >
>> > Give that a try and let us know if it works for you?
>> >
>> > Also there's a discord server for scons help if you'd like to ask
>> > questions/get help there.
>> > https://discord.gg/bXVpWAy <https://discord.gg/bXVpWAy>
>> >
>> > Hope that helps!
>> > -Bill
>>
>> For inspiration, the mslink tool does this (as does the qt tool) - see
>> the somewhat messy SCons/Tool/mslink.py.
>>
>> Meanwhile, while many tools use add_emitter, the code for add_emitter
>> itself includes this comment:
>>
>>          This assumes that emitter has been initialized with an
>>          appropriate dictionary type, and will throw a TypeError if
>>          not, so the caller is responsible for knowing that this is an
>>          appropriate method to call for the Builder in question.
>>
>> >              env["BUILDERS"]["Program"].add_emitter(
>> >                  suffix = ".map",
>> >                  emitter = map_emitter)
>> >
>> >     But it throws an exception:
>> >
>> >     TypeError: 'EmitterProxy' object does not support item assignment
>>
>> So I guess "expected"? although pretty awkward....
>>
>> _______________________________________________
>> Scons-users mailing list
>> Scons-users at scons.org
>> https://pairlist4.pair.net/mailman/listinfo/scons-users
>>
> _______________________________________________
> Scons-users mailing list
> Scons-users at scons.org
> https://pairlist4.pair.net/mailman/listinfo/scons-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist4.pair.net/pipermail/scons-users/attachments/20210129/fdae8593/attachment.html>


More information about the Scons-users mailing list