[Scons-users] escaping brackets () in file path

Bill Deegan bill at baddogconsulting.com
Sat Feb 27 22:24:48 EST 2016


Also I see you filed a bug.
We ask that users bring bugs to the users mailing list and only file bugs
if we've determined that it is a bug, and also that it's not a duplicate.
(this is to a) make that problems get more eyes (here on the users mailing
list), and b) try to minimize the noise in the bug tracking system and keep
the signal high.. )

I don't believe any of the developers have yet requested that you file a
bug.

If you take a look at the manpage there are several items which will
probably help you resolve your issue:
( http://scons.org/doc/production/HTML/scons-man.html )
SPAWN

A command interpreter function that will be called to execute command line
strings. The function must expect the following arguments:

def spawn(shell, escape, cmd, args, env):

sh is a string naming the shell program to use. escape is a function that
can be called to escape shell special characters in the command line. cmd
is the path to the command to be executed. args is the arguments to the
command. env is a dictionary of the environment variables in which the
command should be executed.
ESCAPE

A function that will be called to escape shell special characters in
command lines. The function should take one argument: the command line
string to escape; and should return the escaped command line.


SHELL

A string naming the shell program that will be passed to the $SPAWN
function. See the $SPAWN construction variable for more information.

I"m guessing changing env['ESCAPE'] to point to a function which properly
handles escaping your parens in the path (that's a new one for me) and/or
changing SHELL or SPAWN should be the simplest way to resolve this.


Any reason in particular you want to have parens in your file names/paths?


-Bill


On Sat, Feb 27, 2016 at 10:15 PM, Bill Deegan <bill at baddogconsulting.com>
wrote:

> Likely you could just swap out SPAWN to not use a shell?
>
> On Sat, Feb 27, 2016 at 7:41 AM, Carnë Draug <carandraug+dev at gmail.com>
> wrote:
>
>> On 27 February 2016 at 00:19, Plunket, Tom
>> <tom.plunket at aristocrat-inc.com> wrote:
>> > It's not a direct answer to your query, but can you just quote your file
>> > arguments? I have to do that anyway because my users love to put spaces
>> > in their filenames but it also covers other shell characters pretty
>> well.
>> > The only character I need to handle manually (presumably because I can't
>> > figure out how to get env.Literal to work) is the dollar symbol $ but
>> that's
>> > because SCons tries to process it before it gets to the shell.
>> >
>>
>> I tried it but it does not work.  The quotes become part of the argument.
>>
>>     $ cat SConstruct
>>     #!/usr/bin/env python
>>     # -*- coding: utf-8 -*-
>>
>>     Command(target='foo (bar) qux', source=None, action="touch '$TARGET'")
>>
>>     $ scons
>>     scons: Reading SConscript files ...
>>     scons: done reading SConscript files.
>>     scons: Building targets ...
>>     touch "'foo (bar) qux'"
>>     scons: done building targets.
>>
>>     $ ls
>>     'foo (bar) qux'  SConstruct
>>
>> Changing to quotes does not fix it either:
>>
>>     $ cat SConstruct
>>     #!/usr/bin/env python
>>     # -*- coding: utf-8 -*-
>>
>>     Command(target='foo (bar) qux', source=None, action='touch "$TARGET"')
>>
>>     $ scons
>>     scons: Reading SConscript files ...
>>     scons: done reading SConscript files.
>>     scons: Building targets ...
>>     touch ""foo (bar) qux""
>>     sh: 1: Syntax error: "(" unexpected
>>     scons: *** [foo (bar) qux] Error 2
>>     scons: building terminated because of errors.
>>
>> I have previously bumped into similar issues where my arguments were
>> regular expressions and I couldn't trust SCons to quote things correctly.
>> This may be of help to you.  My solution at the time was the following:
>>
>>     ## Add a NoShellCommand builder to be used like Command()
>>     ##
>>     ## This has the advantage that there's no shell involved, saving us
>>     ## from having to escape quotes, spaces, wildcards, and whatsnot.
>>
>>     import subprocess
>>     def no_shell_command(target, source, env):
>>       return subprocess.call(env['action'])
>>     def no_shell_command_strfunc(target, source, env):
>>       args = env['action']
>>       return "$ %s " % (args[0]) + " ".join(["'%s'" % (arg) for arg in
>> args[1:]])
>>     no_shell_command_action = Action(no_shell_command,
>> strfunction=no_shell_command_strfunc)
>>     env.Append(BUILDERS={'NoShellCommand' :
>> Builder(action=no_shell_command_action)})
>>
>> Which you can then use like this:
>>
>>     NoShellCommand(source = foo, target = bar, action = [prog, foo,
>> bar, arg1, arg2])
>>
>> Carnë
>> _______________________________________________
>> Scons-users mailing list
>> Scons-users at scons.org
>> https://pairlist4.pair.net/mailman/listinfo/scons-users
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist4.pair.net/pipermail/scons-users/attachments/20160227/d6c7648b/attachment.html>


More information about the Scons-users mailing list