test_image_content: support large arg lists better

For some builds, we're hitting the arg list limit.
Use xargs to split it up into smaller chunks.

BUG=chromium:369314
TEST=build_image for link still works

Change-Id: I6c7e1dc8200450063de82d39d2200afa5e9e7bf7
Reviewed-on: https://chromium-review.googlesource.com/198120
Reviewed-by: Nam Nguyen <namnguyen@chromium.org>
Tested-by: Nam Nguyen <namnguyen@chromium.org>
Commit-Queue: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
diff --git a/build_library/test_image_content.sh b/build_library/test_image_content.sh
index 5d27f24..5d78743 100644
--- a/build_library/test_image_content.sh
+++ b/build_library/test_image_content.sh
@@ -9,7 +9,22 @@
   local root="$1"
   shift
 
-  sudo "${lddtree}" -R "${root}" --no-auto-root --skip-non-elfs "$@"
+  # Since we'll feed files via xargs, we need to extract the options
+  # so we can pass it to the lddtree tool.
+  local flags=()
+  while [[ $# -gt 0 ]]; do
+    case $1 in
+    --) break ;;
+    -*) flags+=( "$1" ) ;;
+    *) break ;;
+    esac
+    shift
+  done
+
+  # In case the file list is too big, send it through xargs.
+  # http://crbug.com/369314
+  printf '%s\0' "$@" | xargs -0 \
+    sudo "${lddtree}" -R "${root}" --no-auto-root --skip-non-elfs "${flags[@]}"
 }
 
 # Usage: test_elf_deps <root> <files to check>