Hook up generate_telemetry_build.py to PRESUBMIT.py

Bug: chromium:872521
Change-Id: I5f4952bfca5fca6dd3c93a00845e7c5fe15234be
R=kbr@chromium.org,nednguyen@google.com
Reviewed-on: https://chromium-review.googlesource.com/1188391
Reviewed-by: Ned Nguyen <nednguyen@google.com>
Reviewed-by: Kenneth Russell <kbr@chromium.org>
Commit-Queue: Zhenyao Mo <zmo@chromium.org>
diff --git a/generate_telemetry_build.py b/generate_telemetry_build.py
index 97b63db..05307cd 100644
--- a/generate_telemetry_build.py
+++ b/generate_telemetry_build.py
@@ -178,7 +178,8 @@
   for entry in entry_list:
     full_path = os.path.join(path, entry)
     rel_path = os.path.relpath(full_path, root_path)
-    if entry.startswith('.') or entry.endswith('~') or entry.endswith('.pyc'):
+    if (entry.startswith('.') or entry.endswith('~') or
+        entry.endswith('.pyc') or entry.endswith('#')):
       logging.debug('ignored ' + rel_path)
       continue
     if os.path.isfile(full_path):
@@ -269,6 +270,7 @@
     build_file.close()
 
 def CheckForChanges():
+  # Return 0 if no changes are detected; return 1 otherwise.
   root_path = os.path.dirname(os.path.realpath(__file__))
   temp_path = os.path.join(root_path, "TEMP.gn")
   GenerateBuildFile(root_path, temp_path, chromium=False)
@@ -276,7 +278,7 @@
   ref_path = os.path.join(root_path, "BUILD.gn")
   if not os.path.exists(ref_path):
     logging.error("Can't localte BUILD.gn!")
-    return False
+    return 1
 
   temp_file = open(temp_path, 'r')
   temp_content = temp_file.readlines()
@@ -294,9 +296,9 @@
   if len(diff_data) > 0:
     logging.error('Diff found. Please rerun generate_telemetry_build.py.')
     logging.debug('\n' + ''.join(diff_data))
-    return False
+    return 1
   logging.debug('No diff found. Everything is good.')
-  return True
+  return 0
 
 
 def main(argv):
@@ -314,8 +316,8 @@
     logging.basicConfig(level=logging.DEBUG)
 
   if options.check:
-    CheckForChanges()
-  elif options.chromium:
+    return CheckForChanges()
+  if options.chromium:
     root_path = os.path.dirname(os.path.realpath(__file__))
     output_path = os.path.join(
         root_path, "../../tools/perf/chrome_telemetry_build/BUILD.gn")
@@ -324,6 +326,7 @@
     root_path = os.path.dirname(os.path.realpath(__file__))
     output_path = os.path.join(root_path, "BUILD.gn")
     GenerateBuildFile(root_path, output_path, chromium=False)
+  return 0
 
 if __name__ == '__main__':
   sys.exit(main(sys.argv[1:]))