[Scons-users] Controlling display of a builder

Carnë Draug carandraug+dev at gmail.com
Thu Nov 5 17:03:22 EST 2015

On 2 November 2015 at 21:45, Plunket, Tom
<tom.plunket at aristocrat-inc.com> wrote:
> My reading of the OP suggests an answer something like what I am doing for a
> couple of my site_tools pipelines in their generate() functions:
> def generate(env, **kw):
>     action = Action(audioBuild, 'Creating OGG audio ${TARGETS.file}')
>     builder = Builder(action = action)
>     env.Append(BUILDERS = { 'Audio': builder })
> This writes the text that I specify out for the user rather than the
> generated text.
> ‘audioBuild’ is a Python function that’s getting called; presumably the OP
> could just put his lambda object in place of that.

Thank you.  This is exactly what I was looking for.  I just could not
find the documentation for Action() because it is not in the user guide.
It keeps saying 'See the section "Action Objects"' which does not actually
exist in the document.  Now I found it deep in the man page).

For future reference, here's the code that I am using now:

    import subprocess
    env = Environment()

    def no_shell_command(target, source, env):
      ## To be used as action to Command().  This has the advantage that
      ## there's no shell involved, saving us from having to escape quotes,
      ## spaces, wildcards, and whatsnot.
      return subprocess.call(env['action'])
    def no_shell_command_strfunc(target, source, env):
      ## Even if possibly wrong, it's nice to display something
      args = env['action']
      return "$ " + args[0] + " ".join(["'%s'" % (arg) for arg in args[1:]])

    action = Action(no_shell_command, strfunction=no_shell_command_strfunc)
    env.Append(BUILDERS={'NoShellCommand' : Builder(action=action)})

      source = "...",
      target = "...",
      action = [list, of, args],

And also for future reference, changing SPAWN does not work for this.
The reasons are:

  1) SPAWN gets called once for each element in action but the whole point
    was to use a list to create a single command. Therefore one can't use
    action (one still needs to set it though, so it becomes a dummy unused
  2) since it's not possible to pass the options via action, one needs to
    pass via a random named attribute but they do not appear in the env
    passed to SPAWN as they do when action is a function.

See this example how ARGS is not accessible from spawn_func():

    env = Environment()

    def spawn_func(sh, escape, cmd, args, env):
      print sh
      print escape
      print cmd
      print args
      print env

    raw_data = env.Command(
      target = "pop",
      source = "foo.pl",
      action = "foobar", # we really need something, and it can't be empty
      ARGS = ["lol", "bar", "qux"],
      SPAWN = spawn_func,

Anyway, it is now solved by creating an Action() with a second argument.

Thannk you,

More information about the Scons-users mailing list