Cleaned up a number of small tweaks in the scripts

- Added the littlefs license note to the scripts.

- Adopted parse_intermixed_args everywhere for more consistent arg
  handling.

- Removed argparse's implicit help text formatting as it does not
  work with perse_intermixed_args and breaks sometimes.

- Used string concatenation for argparse everywhere, uses backslashed
  line continuations only works with argparse because it strips
  redundant whitespace.

- Consistent argparse formatting.

- Consistent openio mode handling.

- Consistent color argument handling.

- Adopted functools.lru_cache in tracebd.py.

- Moved unicode printing behind --subscripts in traceby.py, making all
  scripts ascii by default.

- Renamed pretty_asserts.py -> prettyasserts.py.

- Renamed struct.py -> struct_.py, the original name conflicts with
  Python's built in struct module in horrible ways.
This commit is contained in:
Christopher Haster
2022-09-19 14:29:41 -05:00
parent 11d6d1251e
commit 20ec0be875
11 changed files with 307 additions and 162 deletions

View File

@@ -4,6 +4,13 @@
# around nm with some extra conveniences for comparing builds. Heavily inspired
# by Linux's Bloat-O-Meter.
#
# Example:
# ./scripts/data.py lfs.o lfs_util.o -S
#
# Copyright (c) 2022, The littlefs authors.
# Copyright (c) 2020, Arm Limited. All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
#
import collections as co
import csv
@@ -126,7 +133,7 @@ class DataResult(co.namedtuple('DataResult', 'file,function,data_size')):
def openio(path, mode='r'):
if path == '-':
if 'r' in mode:
if mode == 'r':
return os.fdopen(os.dup(sys.stdin.fileno()), 'r')
else:
return os.fdopen(os.dup(sys.stdout.fileno()), 'w')
@@ -417,7 +424,7 @@ if __name__ == "__main__":
nargs='*',
default=OBJ_PATHS,
help="Description of where to find *.o files. May be a directory "
"or a list of paths. Defaults to %(default)r.")
"or a list of paths. Defaults to %r." % OBJ_PATHS)
parser.add_argument(
'-v', '--verbose',
action='store_true',
@@ -468,16 +475,16 @@ if __name__ == "__main__":
'--type',
default=TYPE,
help="Type of symbols to report, this uses the same single-character "
"type-names emitted by nm. Defaults to %(default)r.")
"type-names emitted by nm. Defaults to %r." % TYPE)
parser.add_argument(
'--nm-tool',
type=lambda x: x.split(),
default=NM_TOOL,
help="Path to the nm tool to use. Defaults to %(default)r")
help="Path to the nm tool to use. Defaults to %r." % NM_TOOL)
parser.add_argument(
'--build-dir',
help="Specify the relative build directory. Used to map object files "
"to the correct source files.")
sys.exit(main(**{k: v
for k, v in vars(parser.parse_args()).items()
for k, v in vars(parser.parse_intermixed_args()).items()
if v is not None}))