summaryrefslogtreecommitdiff
path: root/SConstruct
diff options
context:
space:
mode:
authorSteve Reinhardt <steve.reinhardt@amd.com>2011-01-07 21:50:13 -0800
committerSteve Reinhardt <steve.reinhardt@amd.com>2011-01-07 21:50:13 -0800
commitd650f4138eaa68c856d0879e39a78f66d205b017 (patch)
tree257321d1adfe8559eca2f36c6f8c0a1319e2e7af /SConstruct
parentd36cc62c117c2ec37dd99b1e55f3663f4af65b8d (diff)
downloadgem5-d650f4138eaa68c856d0879e39a78f66d205b017.tar.xz
scons: show sources and targets when building, and colorize output.
I like the brevity of Ali's recent change, but the ambiguity of sometimes showing the source and sometimes the target is a little confusing. This patch makes scons typically list all sources and all targets for each action, with the common path prefix factored out for brevity. It's a little more verbose now but also more informative. Somehow Ali talked me into adding colors too, which is a whole 'nother story.
Diffstat (limited to 'SConstruct')
-rwxr-xr-x[-rw-r--r--]SConstruct114
1 files changed, 96 insertions, 18 deletions
diff --git a/SConstruct b/SConstruct
index 07ddfd540..a3af75ffb 100644..100755
--- a/SConstruct
+++ b/SConstruct
@@ -1,5 +1,6 @@
# -*- mode:python -*-
+# Copyright (c) 2011 Advanced Micro Devices, Inc.
# Copyright (c) 2009 The Hewlett-Packard Development Company
# Copyright (c) 2004-2005 The Regents of The University of Michigan
# All rights reserved.
@@ -120,6 +121,18 @@ sys.path[1:1] = extra_python_paths
from m5.util import compareVersions, readCommand
+AddOption('--colors', dest='use_colors', action='store_true')
+AddOption('--no-colors', dest='use_colors', action='store_false')
+use_colors = GetOption('use_colors')
+
+if use_colors:
+ from m5.util.terminal import termcap
+elif use_colors is None:
+ # option unspecified; default behavior is to use colors iff isatty
+ from m5.util.terminal import tty_termcap as termcap
+else:
+ from m5.util.terminal import no_termcap as termcap
+
########################################################################
#
# Set up the main build environment.
@@ -357,7 +370,7 @@ Export('extras_dir_list')
# the ext directory should be on the #includes path
main.Append(CPPPATH=[Dir('ext')])
-def _STRIP(path, env):
+def strip_build_path(path, env):
path = str(path)
variant_base = env['BUILDROOT'] + os.path.sep
if path.startswith(variant_base):
@@ -366,29 +379,94 @@ def _STRIP(path, env):
path = path[6:]
return path
-def _STRIP_SOURCE(target, source, env, for_signature):
- return _STRIP(source[0], env)
-main['STRIP_SOURCE'] = _STRIP_SOURCE
+# Generate a string of the form:
+# common/path/prefix/src1, src2 -> tgt1, tgt2
+# to print while building.
+class Transform(object):
+ # all specific color settings should be here and nowhere else
+ tool_color = termcap.Normal
+ pfx_color = termcap.Yellow
+ srcs_color = termcap.Yellow + termcap.Bold
+ arrow_color = termcap.Blue + termcap.Bold
+ tgts_color = termcap.Yellow + termcap.Bold
+
+ def __init__(self, tool, max_sources=99):
+ self.format = self.tool_color + (" [%8s] " % tool) \
+ + self.pfx_color + "%s" \
+ + self.srcs_color + "%s" \
+ + self.arrow_color + " -> " \
+ + self.tgts_color + "%s" \
+ + termcap.Normal
+ self.max_sources = max_sources
+
+ def __call__(self, target, source, env, for_signature=None):
+ # truncate source list according to max_sources param
+ source = source[0:self.max_sources]
+ def strip(f):
+ return strip_build_path(str(f), env)
+ if len(source) > 0:
+ srcs = map(strip, source)
+ else:
+ srcs = ['']
+ tgts = map(strip, target)
+ # surprisingly, os.path.commonprefix is a dumb char-by-char string
+ # operation that has nothing to do with paths.
+ com_pfx = os.path.commonprefix(srcs + tgts)
+ com_pfx_len = len(com_pfx)
+ if com_pfx:
+ # do some cleanup and sanity checking on common prefix
+ if com_pfx[-1] == ".":
+ # prefix matches all but file extension: ok
+ # back up one to change 'foo.cc -> o' to 'foo.cc -> .o'
+ com_pfx = com_pfx[0:-1]
+ elif com_pfx[-1] == "/":
+ # common prefix is directory path: OK
+ pass
+ else:
+ src0_len = len(srcs[0])
+ tgt0_len = len(tgts[0])
+ if src0_len == com_pfx_len:
+ # source is a substring of target, OK
+ pass
+ elif tgt0_len == com_pfx_len:
+ # target is a substring of source, need to back up to
+ # avoid empty string on RHS of arrow
+ sep_idx = com_pfx.rfind(".")
+ if sep_idx != -1:
+ com_pfx = com_pfx[0:sep_idx]
+ else:
+ com_pfx = ''
+ elif src0_len > com_pfx_len and srcs[0][com_pfx_len] == ".":
+ # still splitting at file extension: ok
+ pass
+ else:
+ # probably a fluke; ignore it
+ com_pfx = ''
+ # recalculate length in case com_pfx was modified
+ com_pfx_len = len(com_pfx)
+ def fmt(files):
+ f = map(lambda s: s[com_pfx_len:], files)
+ return ', '.join(f)
+ return self.format % (com_pfx, fmt(srcs), fmt(tgts))
+
+Export('Transform')
-def _STRIP_TARGET(target, source, env, for_signature):
- return _STRIP(target[0], env)
-main['STRIP_TARGET'] = _STRIP_TARGET
if main['VERBOSE']:
def MakeAction(action, string, *args, **kwargs):
return Action(action, *args, **kwargs)
else:
MakeAction = Action
- main['CCCOMSTR'] = ' [ CC] $STRIP_SOURCE'
- main['CXXCOMSTR'] = ' [ CXX] $STRIP_SOURCE'
- main['ASCOMSTR'] = ' [ AS] $STRIP_SOURCE'
- main['SWIGCOMSTR'] = ' [ SWIG] $STRIP_SOURCE'
- main['ARCOMSTR'] = ' [ AR] $STRIP_TARGET'
- main['LINKCOMSTR'] = ' [ LINK] $STRIP_TARGET'
- main['RANLIBCOMSTR'] = ' [ RANLIB] $STRIP_TARGET'
- main['M4COMSTR'] = ' [ M4] $STRIP_TARGET'
- main['SHCCCOMSTR'] = ' [ SHCC] $STRIP_TARGET'
- main['SHCXXCOMSTR'] = ' [ SHCXX] $STRIP_TARGET'
+ main['CCCOMSTR'] = Transform("CC")
+ main['CXXCOMSTR'] = Transform("CXX")
+ main['ASCOMSTR'] = Transform("AS")
+ main['SWIGCOMSTR'] = Transform("SWIG")
+ main['ARCOMSTR'] = Transform("AR", 0)
+ main['LINKCOMSTR'] = Transform("LINK", 0)
+ main['RANLIBCOMSTR'] = Transform("RANLIB", 0)
+ main['M4COMSTR'] = Transform("M4")
+ main['SHCCCOMSTR'] = Transform("SHCC")
+ main['SHCXXCOMSTR'] = Transform("SHCXX")
Export('MakeAction')
CXX_version = readCommand([main['CXX'],'--version'], exception=False)
@@ -828,7 +906,7 @@ def make_switching_dir(dname, switch_headers, env):
# action depends on; when env['ALL_ISA_LIST'] changes these actions
# should get re-executed.
switch_hdr_action = MakeAction(gen_switch_hdr,
- " [GENERATE] $STRIP_TARGET", varlist=['ALL_ISA_LIST'])
+ Transform("GENERATE"), varlist=['ALL_ISA_LIST'])
# Instantiate actions for each header
for hdr in switch_headers: