Re: Attaching an emitter to an existing builder

Jeremy Elson <[email protected]>
Newsgroups gmane.comp.programming.tools.scons.user
Message-ID <CAKufN8U6F16vtxOpyPX2rQDugQ8SWUcGqNs=Y9BR+753feXrpw@mail.gmail.com>
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 <[email protected]> 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
> [email protected]
> https://pairlist4.pair.net/mailman/listinfo/scons-users
>

_______________________________________________
Scons-users mailing list
[email protected]
https://pairlist4.pair.net/mailman/listinfo/scons-users
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.