Support option to show file sizes in Runtime APEX test scripts' list output.
Support option `--size` in `build/apex/art_apex_test.py` for list
output (`--list`).
Adjust `build/apex/runtests.sh` to honor option `-s`/`--print-sizes`
when using `--list-files`.
Test: art/build/apex/runtests.sh --list-files --print-sizes
Change-Id: Icbe102f1ff1469f1d988c46ac1839ff62478c6f2
diff --git a/build/apex/art_apex_test.py b/build/apex/art_apex_test.py
index 1d85ef5..3bcf7c6 100755
--- a/build/apex/art_apex_test.py
+++ b/build/apex/art_apex_test.py
@@ -643,8 +643,9 @@
class List:
- def __init__(self, provider):
+ def __init__(self, provider, print_size):
self._provider = provider
+ self._print_size = print_size
def print_list(self):
@@ -659,7 +660,13 @@
del apex_map['..']
for (_, val) in sorted(apex_map.items()):
val_path = os.path.join(path, val.name)
- print(val_path)
+ if self._print_size:
+ if val.size < 0:
+ print('[ n/a ] %s' % val_path)
+ else:
+ print('[%11d] %s' % (val.size, val_path))
+ else:
+ print(val_path)
if val.is_dir:
print_list_rec(val_path)
@@ -730,8 +737,8 @@
if test_args.list and test_args.tree:
logging.error("Both of --list and --tree set")
return 1
- if test_args.size and not test_args.tree:
- logging.error("--size set but --tree not set")
+ if test_args.size and not (test_args.list or test_args.tree):
+ logging.error("--size set but neither --list nor --tree set")
return 1
if not test_args.tmpdir:
logging.error("Need a tmpdir.")
@@ -758,7 +765,7 @@
Tree(apex_provider, test_args.apex, test_args.size).print_tree()
return 0
if test_args.list:
- List(apex_provider).print_list()
+ List(apex_provider, test_args.size).print_list()
return 0
checkers = []
@@ -877,7 +884,7 @@
parser.add_argument('--list', help='List all files', action='store_true')
parser.add_argument('--tree', help='Print directory tree', action='store_true')
- parser.add_argument('--size', help='Print file sizes in tree output', action='store_true')
+ parser.add_argument('--size', help='Print file sizes', action='store_true')
parser.add_argument('--tmpdir', help='Directory for temp files')
parser.add_argument('--debugfs', help='Path to debugfs')
diff --git a/build/apex/runtests.sh b/build/apex/runtests.sh
index 58bd28a..c5a3e46 100755
--- a/build/apex/runtests.sh
+++ b/build/apex/runtests.sh
@@ -65,7 +65,7 @@
-B, --skip-build skip the build step
-l, --list-files list the contents of the ext4 image (\`find\`-like style)
-t, --print-tree list the contents of the ext4 image (\`tree\`-like style)
- -s, --print-sizes print the size in bytes of each file in tree output
+ -s, --print-sizes print the size in bytes of each file when listing contents
-h, --help display this help and exit
EOF
@@ -96,20 +96,21 @@
# maybe_list_apex_contents_apex APEX TMPDIR [other]
function maybe_list_apex_contents_apex {
+ local print_options=()
+ if $print_file_sizes_p; then
+ print_options+=(--size)
+ fi
+
# List the contents of the apex in list form.
if $list_image_files_p; then
say "Listing image files"
- $SCRIPT_DIR/art_apex_test.py --list $@
+ $SCRIPT_DIR/art_apex_test.py --list ${print_options[@]} $@
fi
# List the contents of the apex in tree form.
if $print_image_tree_p; then
say "Printing image tree"
- tree_options=()
- if $print_file_sizes_p; then
- tree_options+=(--size)
- fi
- $SCRIPT_DIR/art_apex_test.py --tree ${tree_options[@]} $@
+ $SCRIPT_DIR/art_apex_test.py --tree ${print_options[@]} $@
fi
}