Please note:The SCons wiki is now restored from the attack in March 2013. All old passwords have been invalidated. Please reset your password if you have an account. If you note missing pages, please report them to Also, new account creation is currently disabled due to an ongoing spam flood (2013/08/27).
Differences between revisions 1 and 2
Revision 1 as of 2006-07-28 21:25:05
Size: 1957
Revision 2 as of 2008-03-12 02:47:06
Size: 1957
Editor: localhost
Comment: converted to 1.6 markup
No differences found!

Hiding Command Lines in SCons Output

Q: I want scons to only show a summary of the build commands rather than the full things with all the millions of options I pass.

A: No problem. First, make sure you have 0.96.92 or later. Then there are two ways to do it.


Define env['CCCOMSTR'] to whatever you want (like "Compiling $SOURCE ..."); that just overrides the C compiler message. All standard commands have a ...STR variable that is used instead of the actual command line if it's defined.


The other takes a little more work but is more flexible; define a PRINT_CMD_LINE_FUNC that takes over the printing of the command lines. You can do basically any transformation of the command line output this way.


def print_cmd_line(s, target, src, env):
    """s is the original command line, target and src are lists of target
    and source nodes respectively, and env is the environment."""
    sys.stdout.write(" Making %s...\n"%\
         (' and '.join([str(x) for x in target])))
env['PRINT_CMD_LINE_FUNC'] = print_cmd_line

I like to use this to print a short version to stdout, while logging the full command to a log file. That looks like this:

def print_cmd_line(s, target, src, env):
    if config.quiet:
        sys.stdout.write(" %s...\n"%(' and '.join([str(x) for x in target])))
        # Save real cmd to log file
        open(env['CMD_LOGFILE'], 'a').write("%s\n"%s);
env['PRINT_CMD_LINE_FUNC'] = print_cmd_line
env['CMD_LOGFILE'] = 'build-log.txt'

You can set config.quiet to 1 however you like; parse from cmdline option, use env['CMDLINE_QUIET'] instead, whatever. Notice it's not a full build-logging solution because the output from the commands doesn't go into the build-log file. But it's still better than clogging up your shell.

HidingCommandLinesInOutput (last edited 2008-03-12 02:47:06 by localhost)