Re: [Scons-dev] env.subst and variable substitution including whitespace in parameters

Bill Deegan <[email protected]>
Newsgroups gmane.comp.programming.tools.scons.user
Message-ID <CAEyG4CFz6K==nHDG8XybJ_87DYs1t_Ch8zzzS_m5vPHox+DBDw@mail.gmail.com>
Really shouldn't need to run paths through subst to get the strings
properly escaped (or quoted depending on the platform)..

Can you create a small testcase demonstrating the problem, and I'll take a
look at it in a few days when I'm back from vacation..

On Mon, Sep 17, 2018 at 8:03 PM RW via Scons-users <[email protected]>
wrote:

> Sorry I'll keep any replies to the user list,
> I'm basically piping in a string from python then capturing the output and
> using the results in python
> so I'm capturing stdin and stdout. PSPAWN might work thanks for the info
>
> I did also find another example where env.subst_list is useful
> if you have a list of paths stored in an env variable, and those paths
> contain spaces
>
> ```
> env.Replace(Example1=['D:\\Temp\Test Folder 1\\src1.c'])
> env.Append(Example1=['D:\\Temp\Test Folder 1\\src2.c'])
> env.Append(Example1=['D:\\Temp\Test Folder 1\\src3.c'])
>
> env.Replace(Example2=['D:\\Temp\Test Folder 1\\src4.c'])
> env.Append(Example2=['D:\\Temp\Test Folder 1\\src5.c'])
> env.Append(Example2=['D:\\Temp\Test Folder 1\\src6.c'])
>
> env.Replace(SRCS='$Example1 $Example2')
>
> # This doesn't work due to spaces in path
> #items = env.Split('$SRCS')
>
> # This results in a single string with unescaped paths
> # making it difficult to split them apart or escape them
> #items = env.subst('$SRCS')
>
> items = env.subst_list('$SRCS')[0]
> for item in items:
>     print(item)
> ```
>
> this is why I was wondering if having env.subst_list as some form of
> public api should be on the github issues / todo list
> to give some context, this is what the Preprocess tool I've written looks
> like so far
>
> ```
> def generate(env):
>     env.AddMethod(PreProcessStream, 'PreProcessStream')
>
>
> def PreProcessStream(env, stdin_str):
>     # Handle escaping / quoting variable expansion
>     escape = env.get('ESCAPE', lambda x: x)
>     escape_list = SCons.Subst.escape_list
>
>     cmdstr = '${CPP} -E ${CFLAGS} ${CCFLAGS} ${_CCCOMCOM} -'
>     cmd_list = env.subst_list(cmdstr, SCons.Subst.SUBST_CMD)
>
>     cmd_list = escape_list(cmd_list[0], escape)
>     cmd = ' '.join(cmd_list)
>
>     p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
> stdin=subprocess.PIPE, stderr=subprocess.PIPE)
>     out, err = p.communicate(input=stdin_str.encode())
>     return out, err
> ```
>
> Many Thanks
> Richard
>
>
> On Mon, 17 Sep 2018 at 19:47, Mats Wichmann <[email protected]> wrote:
>
>> On 09/17/2018 12:07 PM, Bill Deegan wrote:
>> > Did you try having pipes in your action command string?
>> > I'm thinking it should work..
>> >
>> > I wrote the wiki page you mentioned and it's a WIP.
>>
>> >> I'm wondering if this should be filed as a github issue
>> >>
>> >> Recently I ran into a problem, I needed to write a method to pipe some
>> >> input into and out of gcc via the preprocessor
>> >> this meant using subprocess instead of calling an scons Action since I
>> >> wanted to do piping, but to do that I needed to expand outwards the
>> gcc /
>> >> cpppath etc into a string.
>>
>> there is some mechanism for piping in a command, see the PSPAWN
>> construction environment variable.
>> _______________________________________________
>> 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
>

_______________________________________________
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.