[Scons-users] generating cpp defines with a function

Kenny, Jason L jason.l.kenny at intel.com
Wed Jun 3 10:26:45 EDT 2015


Given defines you should get something like:

-DABC=123 –DDEF=456 –Dxyzzy

Which is probably what you want. That is why SCons has something like when it make defines internally:
[('ABC', '123'), ('DEF', '456'), 'XYZZY'], it does not make lists within lists

However for this is using tuples.. not lists.

It is not uncommon for a person to want to say

env.Append(CPPDEFINES=[“$COMPONENTA_DEFINES”, “$COMPONENTB_DEFINES”])
where
COMPONENTA_DEFINES=[‘DEFA1’,(‘DEFA2’,’aval’)]
COMPONENTB_DEFINES=[‘DEFB1’,(‘DEFB2’,’bval’)]

And expect to see on the command line:
-DDEFA1 -DDEFA2=aval –DDEFB1 –DDEFB2=bval

But because of the subst() problem we get something like:
“-DDDEFA1 DEFA2 aval”  “-DDDEFB1 DEFB2 bval”

This breaks need abstraction to allow data to be expanded correctly. This is a major I deal with at work and my customers using Parts. I have address some of this. However the better fix in my mind would be to have a _func to flatten [] not () that can be used to items like CPPPATH and CPPDEFINES to help resolve this issue. ( I am also for fixing subst().. but I agree that it might have a negative side effect for some people that worked around this issue). I think every case I have seen of a build actions that uses _concat and like functions to add –I or –D, etc.. to a value on the command line wants it flatten with some possible support for stuff like –D in which we want k=v addition, which SCons has custom logic for CPPDEFINES for with () and {}. Maybe this should be more general case, and instead of a flatten we have the ability to provide a separator for k and value and possible separator if we have more than one value.. ie difference with:

[(k,v1),bfoo] vs [(k,v1,v2),bfoo]

Jason


From: Scons-users [mailto:scons-users-bounces at scons.org] On Behalf Of Tom Tanner (BLOOMBERG/ LONDON)
Sent: Wednesday, June 3, 2015 8:00 AM
To: scons-users at scons.org
Subject: Re: [Scons-users] generating cpp defines with a function


That doesn't seem like the problem to me. It seems almost the opposite.

If I have CCPDEFINES = '${myfunc()}', and myfunc returns [['ABC', '123'], ['DEF', '456'], 'XYZZY'], then I'd like CPPDEFINES to contain [['ABC', '123'], ['DEF', '456'], 'XYZZY']

it doesn't though, it gets set to ['ABC', '123', 'DEF', '456', 'XYZZY'] which gives a totally wrong result when evaluated, i get '-DABC 123 DEF 456 XYZZY']

Mind you I have a feeling that fixing this so that subst maintained lists and dicts might be liable to break existing builds.


From: jason.l.kenny at intel.com<mailto:jason.l.kenny at intel.com> At: Jun 2 2015 16:11:28
To: Tom Tanner (BLOOMBERG/ LONDON)<mailto:ttanner2 at bloomberg.net>, scons-users at scons.org<mailto:scons-users at scons.org>
Subject: RE: [Scons-users] generating cpp defines with a function
The issue is in subst().

The code that subst a list assumes a 1:1 mapping of a given item in the list so it assumes that given:

[‘$sayit’,’$foo’]

The current code assume that “$sayit” return a value like “hello” it does not assume that [‘hello’,’world’] would be returned.

So it replaces [‘$sayit’]  with [[‘hello’,’world’],’fooval’] instead of what the desired [‘hello’,’world’,’fooval’].

Jason

From: Scons-users [mailto:scons-users-bounces at scons.org] On Behalf Of Tom Tanner (BLOOMBERG/ LONDON)
Sent: Tuesday, June 2, 2015 10:01 AM
To: scons-users at scons.org<mailto:scons-users at scons.org>
Subject: Re: [Scons-users] generating cpp defines with a function


The code in _defines doesn't like that at all.

return [ [ 'ABC', 'ABC' ] ]

Is fine (but wrong)

return [ { 'ABC' : 'ABC' } ] # or variants thereon

Gets this:

scons: *** [test.o] TypeError `get expected at least 1 arguments, got 0' trying to evaluate `${_defines(CPPDEFPREFIX, CPPDEFINES, CPPDEFSUFFIX, __env__)}'



From: garyo at oberbrunner.com<mailto:garyo at oberbrunner.com> At: Jun 2 2015 15:48:07
To: Tom Tanner (BLOOMBERG/ LONDON)<mailto:ttanner2 at bloomberg.net>, scons-users at scons.org<mailto:scons-users at scons.org>
Subject: Re: [Scons-users] generating cpp defines with a function
Does it help if you return a dict (or convert your nested list to a dict)?
It may help if you look at the tests in test/CPPDEFINES (and if you see missing cases there, feel free to add them.)

On Tue, Jun 2, 2015 at 10:21 AM, Tom Tanner (BLOOMBERG/ LONDON) <ttanner2 at bloomberg.net<mailto:ttanner2 at bloomberg.net>> wrote:
I have a requirement to do something like this:

env.Append(CPPDEFINES = '${some_func(arg1, arg2)}')

My trouble comes when some_func returns something relatively complicated, like

[['FGH', 'string'], ['ABC', 'another string'], 'IJK' ]

This appears to get flattened and you get

gcc ... "-DFGH FGH ABC ABC IJK"

Which is very definitely not very helpful.

Is there anything I can do to get the return from some_func not to be flattened?



_______________________________________________
Scons-users mailing list
Scons-users at scons.org<mailto:Scons-users at scons.org>
https://pairlist4.pair.net/mailman/listinfo/scons-users


--
Gary


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist4.pair.net/pipermail/scons-users/attachments/20150603/0baa7a82/attachment-0001.html>


More information about the Scons-users mailing list