2 # Copyright (c) 2016 Stefan Seefeld
5 # Distributed under the Boost Software License, Version 1.0.
6 # (See accompanying file LICENSE_1_0.txt or copy at
7 # http://www.boost.org/LICENSE_1_0.txt)
9 from SCons
.Script
import AddOption
12 variables
=[] # remember 'public' variables
15 def add_option(*args
, **kwds
):
16 """Capture the help messages so we can produce a helpful usage text."""
17 options
.append('{:25} {}'.format(', '.join(args
), kwds
.get('help', '')))
18 AddOption(*args
, **kwds
)
20 def add_variable(vars, var
):
21 variables
.append(var
[0])
25 def options_help(env
):
27 return '\n '.join(options
)
30 def variables_help(vars, env
):
31 """This is cloned from SCons' Variables.GenerateHelpText, to only report 'public' variables."""
33 opts
= [o
for o
in vars.options
if o
.key
in variables
]
37 actual
= env
.subst('${%s}' % opt
.key
)
40 return vars.FormatVariableHelpText(env
, opt
.key
, opt
.help, opt
.default
, actual
, opt
.aliases
)
41 text
= ''.join([f
for f
in map(format
, opts
) if f
])
42 lines
= [' %s'%l
for l
in text
.split('\n')] # Add some indentation
43 return '\n'.join(lines
)
49 return """Usage: scons [--option...] [variable=value...] [target...]
57 """.format(options_help(env
), variables_help(vars, env
))
59 def pretty_output(env
):
62 colors
['red'] = '\033[31m'
63 colors
['green'] = '\033[32m'
64 colors
['blue'] = '\033[34m'
65 colors
['yellow'] = '\033[93m'
66 colors
['Red'] = '\033[91m'
67 colors
['Green'] = '\033[92m'
68 colors
['Blue'] = '\033[94m'
69 colors
['Purple'] = '\033[95m'
70 colors
['Cyan'] = '\033[96m'
71 colors
['end'] = '\033[0m'
73 #If the output is not a terminal, remove the colors
74 if not sys
.stdout
.isatty():
75 for key
, value
in colors
.iteritems():
78 compile_source_message
= '{green}Compiling $TARGET{end}'.format(**colors
)
79 compile_shared_source_message
= '{green}Compiling $TARGET{end}'.format(**colors
)
80 link_program_message
= '{blue}Linking $TARGET{end}'.format(**colors
)
81 link_library_message
= '{blue}Linking $TARGET{end}'.format(**colors
)
82 ranlib_library_message
= '{blue}Ranlib $TARGET{end}'.format(**colors
)
83 link_shared_library_message
= '{blue}Linking $TARGET{end}'.format(**colors
)
84 test_message
= '{blue}Testing $SOURCE{end}'.format(**colors
)
85 testsum_message
= '{Blue}Test Summary{end}'.format(**colors
)
87 env
.Replace(CXXCOMSTR
= compile_source_message
,
88 CCCOMSTR
= compile_source_message
,
89 SHCCCOMSTR
= compile_shared_source_message
,
90 SHCXXCOMSTR
= compile_shared_source_message
,
91 ARCOMSTR
= link_library_message
,
92 RANLIBCOMSTR
= ranlib_library_message
,
93 SHLINKCOMSTR
= link_shared_library_message
,
94 LINKCOMSTR
= link_program_message
,
95 TESTCOMSTR
= test_message
,
96 TESTSUMCOMSTR
= testsum_message
)