build_abi.sh: omit impacted interfaces for the printed report

Using build_abi.sh with --print-report is a means to print a useful
message for commits. The list of impacted interfaces can become quite
lengthy and can be omitted in most cases as the impact can be seen from
the sheer number alone.

Hence, adjust diff_abi to also generate a short report and use this
report instead for printing the report.

Change-Id: Ib400c0d41a511dbf8be7dd9bbf94ff2bd23ba7a3
Signed-off-by: Matthias Maennich <maennich@google.com>
diff --git a/abi/abitool.py b/abi/abitool.py
index a54d5e5..0ba9486 100644
--- a/abi/abitool.py
+++ b/abi/abitool.py
@@ -15,6 +15,7 @@
 # limitations under the License.
 #
 
+import re
 import subprocess
 import logging
 
@@ -25,7 +26,7 @@
     def dump_kernel_abi(self, linux_tree, dump_path, whitelist):
         raise NotImplementedError()
 
-    def diff_abi(self, old_dump, new_dump, diff_report, whitelist):
+    def diff_abi(self, old_dump, new_dump, diff_report, short_report, whitelist):
         raise NotImplementedError()
 
     def name(self):
@@ -49,7 +50,7 @@
 
         subprocess.check_call(dump_abi_cmd)
 
-    def diff_abi(self, old_dump, new_dump, diff_report, whitelist):
+    def diff_abi(self, old_dump, new_dump, diff_report, short_report, whitelist):
         log.info('libabigail diffing: {} and {} at {}'.format(old_dump,
                                                                 new_dump,
                                                                 diff_report))
@@ -71,6 +72,13 @@
                     raise
                 return True  # actual abi change
 
+        if short_report is not None:
+            with open(diff_report) as full_report:
+                with open(short_report, 'w') as out:
+                    out.write(re.sub(r'impacted interfaces:\n([ ]+.+\n)+',
+                           'impacted interfaces\n',
+                           full_report.read()))
+
         return False  # no abi change
 
 def get_abi_tool(abi_tool):
diff --git a/abi/diff_abi b/abi/diff_abi
index 738466b..196916d 100755
--- a/abi/diff_abi
+++ b/abi/diff_abi
@@ -21,9 +21,9 @@
 
 from abitool import get_abi_tool
 
-def diff_abi(abitool, baseline, new, out_file, whitelist):
+def diff_abi(abitool, baseline, new, report, short_report, whitelist):
     tool = get_abi_tool(abitool)
-    return tool.diff_abi(baseline, new, out_file, whitelist)
+    return tool.diff_abi(baseline, new, report, short_report, whitelist)
 
 def main():
     """ Build the linux kernel, freshly cloning if needed"""
@@ -36,6 +36,8 @@
                         help='abi tool to be used to monitor abi')
     parser.add_argument('--report', help='where to write the report to',
                         required=True)
+    parser.add_argument('--short-report', help='where to write a short report to',
+                        default=None)
     parser.add_argument('--kmi-whitelist', default=None,
                         help='KMI whitelist to filter for')
 
@@ -45,6 +47,7 @@
                            args.baseline,
                            args.new,
                            args.report,
+                           args.short_report,
                            args.kmi_whitelist)
     if abi_changed:
         return 8
diff --git a/build_abi.sh b/build_abi.sh
index 073dfd9..aa50196 100755
--- a/build_abi.sh
+++ b/build_abi.sh
@@ -160,6 +160,7 @@
         ${ROOT_DIR}/build/abi/diff_abi --baseline $KERNEL_DIR/$ABI_DEFINITION \
                                        --new      ${DIST_DIR}/${abi_out_file} \
                                        --report   ${abi_report}               \
+                                       --short-report ${abi_report}.short
                                        $KMI_WHITELIST_FLAG
         rc=$?
         set -e
@@ -172,7 +173,7 @@
 
         if [ $PRINT_REPORT -eq 1 ] && [ $rc -ne 0 ] ; then
             echo "========================================================"
-            cat ${abi_report}
+            cat ${abi_report}.short
         fi
     fi
     if [ $UPDATE -eq 1 ] ; then