[Scons-users] env.MergeFlags does not accept dict CPPDEFINES

Olivier Renaud orenaud at coventor.com
Thu Jul 13 12:18:08 EDT 2017


Thanks for the quick reply.

I'm afraid I did not search the bugtracker before sending my mail, sorry 
about that.

Indeed, the issues you linked to are all various symptoms of the same 
underlying issue, and my report does not bring anything new. I'm working 
around the issue by merging the offending CPPDEFINES with custom code, 
and then merging the rest of the flags with MergeFlags.

Though, this unexpected behavior took me a few hours to track down (it 
did not result in an exception, but in a duplication of the /D flags in 
the compiler command), and it seems to be easy to run into. May I 
suggest the MergeFlags method perform a few basic type checks on its 
input, and at least report any unsupported operation as a warning?

Thanks for your time.

Olivier Renaud


Dirk Baechle (7/13/2017 2:32 PM)
> Hi Olivier,
>
> thanks a lot for reporting this. However, this looks like a known 
> problem to me. Please check the issues 2961, 2402, 2962 and 2599...as 
> well as the referenced mail thread. Is this a superset of your problems?
>
> Best regards,
>
> Dirk
>
>
> Am 13. Juli 2017 11:23:54 MESZ schrieb Olivier Renaud 
> <orenaud at coventor.com>:
>
>     Hi,
>
>     I would like to present to you an issue I have, and maybe submit it to
>     the bugtracker if appropriate.
>
>     I am trying to use the MergeFlags method of Environment. The docstring
>     of this method says:
>
>               Merge the dict in args into the construction variables of this
>               env, or the passed-in dict.  If args is not a dict, it is
>               converted into a dict using ParseFlags.  If unique is not set,
>               the flags are appended rather than merged.
>
>     It does not give details about what kind of flags are supported, though.
>     As a user, I would expect CPPDEFINES to be supported as a flag that can
>     be merged into the env.
>
>     The user manual for CPPDEFINES
>     (http://scons.org/doc/production/HTML/scons-user/apa.html#cv-CPPDEFINES)
>     says that it can be:
>     - a string (for a single define)
>     - a list of strings
>     - a list of tuples (each containing 2 strings)
>     - a list of lists (each containing 2 strings)
>     - a dictionary
>
>     The problem is that the implementation of MergeFlags seems to support
>     the merging of lists of strings only, and can behave poorly or raise an
>     exception when using other variants.
>
>     Some examples:
>     ___________________
>
>           # Example 1: list of tuples + list of tuples => OK
>           env_cppdefines = [('MY_DEF', 'hello')]
>           flags_cppdefines = [('OTHER_DEF', 'goodbye')]
>
>           env = Environment(CPPDEFINES = env_cppdefines)
>           env.MergeFlags({'CPPDEFINES': flags_cppdefines})
>
>           print env.Dump('CPPDEFINES')
>           print env.subst('$_CPPDEFFLAGS')
>     =>
>           [('MY_DEF', 'hello'), ('OTHER_DEF', 'goodbye')]
>           /DMY_DEF=hello /DOTHER_DEF=goodbye
>     ___________________
>
>           # Example 2: list + list => OK
>           env_cppdefines = ['MY_DEF']
>           flags_cppdefines = ['OTHER_DEF']
>     =>
>           ['MY_DEF', 'OTHER_DEF']
>           /DMY_DEF /DOTHER_DEF
>     ___________________
>
>           # Example 3: dict + dict => Exception
>           env_cppdefines = {'MY_DEF': 'hello'}
>           flags_cppdefines = {'OTHER_DEF': 'goodbye'}
>     =>
>           AttributeError: 'dict' object has no attribute 'insert':
>             File "C:\Users\me\tmp\bug_scons\SConstruct", line 5:
>               env.MergeFlags({'CPPDEFINES': flags_cppdefines})
>             File
>     "c:\python27\lib\site-packages\scons-2.5.1\SCons\Environment.py <http://Environment.py>", line 841:
>               value.insert(0, orig)
>     ___________________
>
>           # Example 4: list + identical list => OK
>           env_cppdefines = ['MY_DEF']
>           flags_cppdefines = ['MY_DEF']
>     =>
>           ['MY_DEF']
>           /DMY_DEF
>     ___________________
>
>           # Example 5: dict + identical list => duplication
>           env_cppdefines = {'MY_DEF': None}
>           flags_cppdefines = ['MY_DEF']
>     =>
>           [{ 'MY_DEF': None}, 'MY_DEF']
>           /DMY_DEF /DMY_DEF
>
>     Is it correct for me to expect MergeFlags to work with CPPDEFINES, and
>     in particular to work with the dictionary versions of it?
>
>     Best regards,
>     Olivier Renaud
>     ------------------------------------------------------------------------
>
>     Scons-users mailing list
>     Scons-users at scons.org
>     https://pairlist4.pair.net/mailman/listinfo/scons-users
>
>
> -- 
> Sent from my Android with K-9 Mail. 



More information about the Scons-users mailing list