Search code examples
pythonscons

How to specify a COMSTR for the Command Builder in 'scons'


Many of the builtin builders in scons have $*COMSTR variables which are used to change the default output of their associated Builder. We can use $*COMSTR variables to optionally make our build processes more legible.

I would like to set a $*COMSTR variable for a Command builder.

target = 'mydb.db3'

populatesql = 'populate.sql'
sources = [populatesql]

command = '@sqlite3 $TARGET < ' + populatesql

built_database = env.Command(target, sources, command)

I've found that I can prefix my command with the '@' character to suppress output, but I've been unable to discover how to utilize a $*COMSTR with the Command builder. Am I missing a trick here?

Thanks.


Solution

  • You don't associate a command string with a builder. Command strings are associate with an Action object.

    If you want a command string, just write something like this:

    built_database = env.Command(target, sources, 
                                 Action('mySqlite3', 'Generating $TARGET with sqlite3'))
    

    or if you want that more fine tuned

    env['SQLITE3COMSTR'] = 'Generating $TARGET from $SOURCES with sqlite3'
    ...
    built_database = env.Command(target, sources, Action('mySqlite3', '$SQLITE3COMSTR'))