return -1 iff any file is updated

Test: ./script/update_makefiles.py
Bug: 117826861
Change-Id: I06d622fcff84bc8c4101171d98f7a3008b944dbb
diff --git a/script/build/build_rule_gen.py b/script/build/build_rule_gen.py
index 695f994..da80504 100755
--- a/script/build/build_rule_gen.py
+++ b/script/build/build_rule_gen.py
@@ -52,12 +52,17 @@
 
         Args:
             test_config_dir: string, directory storing the configurations.
+
+        Returns:
+            True if any file is updated, False otherwise
         """
         hal_list = self._vts_spec_parser.HalNamesAndVersions()
-        gen_file_paths = self.UpdateHalDirBuildRule(hal_list, test_config_dir)
-        utils.RemoveFilesInDirIf(
+        gen_file_paths, updated = self.UpdateHalDirBuildRule(
+            hal_list, test_config_dir)
+        updated |= utils.RemoveFilesInDirIf(
             os.path.join(self._ANDROID_BUILD_TOP, test_config_dir),
             lambda x: self._IsAutoGenerated(x) and (x not in gen_file_paths))
+        return updated
 
     def UpdateHalDirBuildRule(self, hal_list, test_config_dir):
         """Updates build rules for vts drivers/profilers.
@@ -73,8 +78,10 @@
         Returns:
             a list of strings where each string contains the path of a checked
             or updated build file.
+            boolean, True if any file is updated, False otherwise.
         """
         file_paths = []
+        updated = False
         for target in hal_list:
             hal_name = target[0]
             hal_version = target[1]
@@ -84,10 +91,10 @@
                 utils.HalNameDir(hal_name), utils.HalVerDir(hal_version))
 
             file_path = os.path.join(hal_dir, 'build', 'Android.bp')
-            utils.WriteBuildRule(file_path, self._VtsBuildRuleFromTemplate(
+            updated |= utils.WriteBuildRule(file_path, self._VtsBuildRuleFromTemplate(
                 self._VTS_BUILD_TEMPLATE, hal_name, hal_version))
             file_paths.append(file_path)
-        return file_paths
+        return file_paths, updated
 
     def _VtsBuildRuleFromTemplate(self, template_path, hal_name, hal_version):
         """Returns build rules in string form by filling out a template.
diff --git a/script/build/build_rule_gen_utils.py b/script/build/build_rule_gen_utils.py
index 1565eec..94bbb9f 100644
--- a/script/build/build_rule_gen_utils.py
+++ b/script/build/build_rule_gen_utils.py
@@ -50,10 +50,9 @@
 
     if exist:
         with open(file_path, 'r') as existing_file:
-            existing_content = "".join(existing_file.readlines())
-        if build_rule == existing_content:
-            print 'Skipping %s' % file_path
-            return False
+            if build_rule == existing_file.read():
+                print 'Skipping %s' % file_path
+                return False
 
     print 'Updating %s' % file_path
     with open(file_path, 'w') as bp_file:
@@ -86,10 +85,16 @@
         dir_path: string, path to directory
         condition: boolean function takes absolute file path,
             returns True iff file needs to be removed.
+
+    Returns:
+        True if removed, False otherwise
     """
+    removed = False
     for base, _, files in os.walk(dir_path):
         for f in files:
             abs_path = os.path.join(base, f)
             if condition(abs_path):
                 print "Removing", abs_path
                 os.remove(abs_path)
+                removed = True
+    return removed
diff --git a/script/update_makefiles.py b/script/update_makefiles.py
index a84b666..b3e7fac 100755
--- a/script/update_makefiles.py
+++ b/script/update_makefiles.py
@@ -28,6 +28,7 @@
 """
 import argparse
 import re
+import sys
 
 from build.build_rule_gen import BuildRuleGen
 from utils.const import Constant
@@ -55,7 +56,10 @@
             sys.exit(1)
         package_name, version = args.hal_package_name.split('@')
         hal_list = [(package_name, version)]
-        build_rule_gen.UpdateHalDirBuildRule(hal_list,
-                                             Constant.VTS_HAL_TEST_CASE_PATH)
+        _, updated = build_rule_gen.UpdateHalDirBuildRule(
+            hal_list, Constant.VTS_HAL_TEST_CASE_PATH)
     else:
-        build_rule_gen.UpdateBuildRule(Constant.VTS_HAL_TEST_CASE_PATH)
+        updated = build_rule_gen.UpdateBuildRule(Constant.VTS_HAL_TEST_CASE_PATH)
+    if updated:
+        sys.exit(-1)
+