Skip to content

Commit 12492c1

Browse files
committed
Call colorized notify when --color for build.py, make.py, test.py
1 parent 6b8bde9 commit 12492c1

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

tools/build.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929

3030
from tools.toolchains import TOOLCHAINS
31+
from tools.toolchains import mbedToolchain
3132
from tools.targets import TARGET_NAMES, TARGET_MAP
3233
from tools.options import get_default_options_parser
3334
from tools.build_api import build_library, build_mbed_libs, build_lib
@@ -36,6 +37,7 @@
3637
from tools.build_api import print_build_results
3738
from tools.settings import CPPCHECK_CMD, CPPCHECK_MSG_FORMAT
3839
from utils import argparse_filestring_type
40+
from tools.settings import CPPCHECK_CMD, CPPCHECK_MSG_FORMAT, CLI_COLOR_MAP
3941

4042
if __name__ == '__main__':
4143
start = time()
@@ -164,6 +166,17 @@
164166
# Get toolchains list
165167
toolchains = options.tool if options.tool else TOOLCHAINS
166168

169+
if options.color:
170+
# This import happens late to prevent initializing colorization when we don't need it
171+
import colorize
172+
if options.verbose:
173+
notify = mbedToolchain.print_notify_verbose
174+
else:
175+
notify = mbedToolchain.print_notify
176+
notify = colorize.print_in_color_notifier(CLI_COLOR_MAP, notify)
177+
else:
178+
notify = None
179+
167180
# Get libraries list
168181
libraries = []
169182

@@ -224,6 +237,7 @@
224237
lib_build_res = build_library(options.source_dir, options.build_dir, mcu, toolchain,
225238
options=options.options,
226239
extra_verbose=options.extra_verbose_notify,
240+
notify=notify,
227241
verbose=options.verbose,
228242
silent=options.silent,
229243
jobs=options.jobs,
@@ -235,6 +249,7 @@
235249
lib_build_res = build_mbed_libs(mcu, toolchain,
236250
options=options.options,
237251
extra_verbose=options.extra_verbose_notify,
252+
notify=notify,
238253
verbose=options.verbose,
239254
silent=options.silent,
240255
jobs=options.jobs,
@@ -245,6 +260,7 @@
245260
build_lib(lib_id, mcu, toolchain,
246261
options=options.options,
247262
extra_verbose=options.extra_verbose_notify,
263+
notify=notify,
248264
verbose=options.verbose,
249265
silent=options.silent,
250266
clean=options.clean,

tools/make.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
from utils import argparse_filestring_type
4747
from utils import argparse_many
4848
from argparse import ArgumentTypeError
49+
from tools.toolchains import mbedToolchain
50+
from tools.settings import CLI_COLOR_MAP
4951

5052
if __name__ == '__main__':
5153
# Parse Options
@@ -212,6 +214,17 @@
212214
args_error(parser, "[ERROR] You should specify a TOOLCHAIN")
213215
toolchain = options.tool[0]
214216

217+
if options.color:
218+
# This import happens late to prevent initializing colorization when we don't need it
219+
import colorize
220+
if options.verbose:
221+
notify = mbedToolchain.print_notify_verbose
222+
else:
223+
notify = mbedToolchain.print_notify
224+
notify = colorize.print_in_color_notifier(CLI_COLOR_MAP, notify)
225+
else:
226+
notify = None
227+
215228
# Test
216229
for test_no in p:
217230
test = Test(test_no)
@@ -250,6 +263,7 @@
250263
linker_script=options.linker_script,
251264
clean=options.clean,
252265
verbose=options.verbose,
266+
notify=notify,
253267
silent=options.silent,
254268
macros=options.macros,
255269
jobs=options.jobs,

tools/test.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
from tools.utils import mkdir, ToolException, NotSupportedException
3535
from tools.test_exporters import ReportExporter, ResultExporterType
3636
from utils import argparse_filestring_type, argparse_lowercase_type, argparse_many
37+
from tools.toolchains import mbedToolchain
38+
from tools.settings import CLI_COLOR_MAP
3739

3840
if __name__ == '__main__':
3941
try:
@@ -121,6 +123,17 @@
121123
else:
122124
tests = all_tests
123125

126+
if options.color:
127+
# This import happens late to prevent initializing colorization when we don't need it
128+
import colorize
129+
if options.verbose:
130+
notify = mbedToolchain.print_notify_verbose
131+
else:
132+
notify = mbedToolchain.print_notify
133+
notify = colorize.print_in_color_notifier(CLI_COLOR_MAP, notify)
134+
else:
135+
notify = None
136+
124137
if options.list:
125138
# Print available tests in order and exit
126139
print_tests(tests, options.format)
@@ -155,6 +168,7 @@
155168
name="mbed-build",
156169
macros=options.macros,
157170
verbose=options.verbose,
171+
notify=notify,
158172
archive=False)
159173

160174
library_build_success = True
@@ -179,6 +193,7 @@
179193
properties=build_properties,
180194
macros=options.macros,
181195
verbose=options.verbose,
196+
notify=notify,
182197
jobs=options.jobs,
183198
continue_on_build_fail=options.continue_on_build_fail)
184199

0 commit comments

Comments
 (0)