Hi,
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.
one approach to this might be

```
cmdstr = '${CPP} -E ${CFLAGS} ${CCFLAGS} ${_CCCOMCOM} -'
cmd = env.subst(cmdstr)
```

However if any of the include directories include spaces then this doesn't
work
we end up with:
``
arm-none-eabi-gcc -E -I. -ID:\Some Folder with whitespace\src -Ibuild -
```
instead of:
``
arm-none-eabi-gcc -E -I. "-ID:\Some Folder with whitespace\src" -Ibuild -
```

It turns out the Action / CommandAction class has a way of dealing with
this.
the use of env.subst_list and the escape method burried in the
SCons/Subst.py code
Typically the function that puts quotes around strings contaning whitespace
is quote_spaces within SCons/Subst.py
If I follow the code back, this is called by CmdStringHolder which is only
referenced within the ListSubber class
which appears to be used by env.subst_list but not env.subst

The end result after a bit of copying / pasting is the below
I'm fairly sure this isn't using what's supposed to be public API's

```
def generate(env):
    env.AddMethod(PreProcessStream, 'PreProcessStream')


def PreProcessStream(env, stdin_str):
    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
```

After a bit googling for "env.subst_list" it looks like a few others have
also used this method
I also came across this

  * https://github.com/SCons/scons/wiki/ProposalForImprovedSubstEngine

So what I'm proposing here is that perhaps we need some public api way of
handling this problem without diving into the scons internals

Many Thanks
Richard
_______________________________________________
Scons-dev mailing list
Scons-dev@scons.org
https://pairlist2.pair.net/mailman/listinfo/scons-dev

Reply via email to