build.sh: Treat missing symbols from depmod as an error

Currently depmod isn't treating missing symbols as an error. This causes
the modules with missing symbols to fail to load. A missing symbols
warning will occur when an out-of-tree driver is compiled and missing
a symbol either from the kernel or some other kernel module.

This patch parses the output of depmod to detect any missing symbols. If
any missing symbols are found, then build.sh will return an error.

Signed-off-by: Will McVicker <willmcvicker@google.com>
Test: Remove symbol that an out-of-tree driver depends on
Change-Id: Ia74c11ea843cba6057c7be85889d6808446e5881
diff --git a/build.sh b/build.sh
index 3e4a53f..66b5bbf 100755
--- a/build.sh
+++ b/build.sh
@@ -397,7 +397,23 @@
 
     # Re-run depmod to detect any dependencies between in-kernel and external
     # modules. Then, create modules.load based on all the modules compiled.
-    (cd ${INITRAMFS_STAGING_DIR} && depmod -b . 0.0)
+    (
+      set +x
+      set +e # disable exiting of error so we can add extra comments
+      cd ${INITRAMFS_STAGING_DIR}
+      DEPMOD_OUTPUT=$(depmod -e -F ${DIST_DIR}/System.map -b . 0.0 2>&1)
+      if [[ "$?" -ne 0 ]]; then
+        echo "$DEPMOD_OUTPUT"
+        exit 1;
+      fi
+      echo "$DEPMOD_OUTPUT"
+      if [[ -n $(echo $DEPMOD_OUTPUT | grep "needs unknown symbol") ]]; then
+        echo "ERROR: out-of-tree kernel module(s) need unknown symbol(s)"
+        exit 1
+      fi
+      set -e
+      set -x
+    )
     (cd ${INITRAMFS_STAGING_DIR}/lib/modules/0.0 && \
         find . -type f -name *.ko | cut -c3- > modules.load)
     echo "${MODULES_OPTIONS}" > ${INITRAMFS_STAGING_DIR}/lib/modules/0.0/modules.options