tools/gen_binary_descriptor: Simplify --check-only

Checking SHAs is not enough because the generated descriptor doesn't
depend only on one file, but more than one.

With this commit, `--check-only` just regenerates the descriptor and
compares the result

Change-Id: Iebc61bda20b6239448a335cbd51b01a052884974
diff --git a/python/perfetto/trace_processor/metrics.descriptor.sha1 b/python/perfetto/trace_processor/metrics.descriptor.sha1
deleted file mode 100644
index 0a69bdf..0000000
--- a/python/perfetto/trace_processor/metrics.descriptor.sha1
+++ /dev/null
@@ -1,6 +0,0 @@
-
-// SHA1(tools/gen_binary_descriptors)
-// 6886b319e65925c037179e71a803b8473d06dc7d
-// SHA1(protos/perfetto/metrics/metrics.proto)
-// b07fa0b4ad2deed79d2d8cc320f70502e19eee0c
-  
\ No newline at end of file
diff --git a/python/perfetto/trace_processor/trace_processor.descriptor.sha1 b/python/perfetto/trace_processor/trace_processor.descriptor.sha1
deleted file mode 100644
index 7f7827f..0000000
--- a/python/perfetto/trace_processor/trace_processor.descriptor.sha1
+++ /dev/null
@@ -1,6 +0,0 @@
-
-// SHA1(tools/gen_binary_descriptors)
-// 6886b319e65925c037179e71a803b8473d06dc7d
-// SHA1(protos/perfetto/trace_processor/trace_processor.proto)
-// 59f86a32aa28f29e290d8ce3f97461725aa8b9f8
-  
\ No newline at end of file
diff --git a/tools/gen_binary_descriptors b/tools/gen_binary_descriptors
index 952e809..e09a5c4 100755
--- a/tools/gen_binary_descriptors
+++ b/tools/gen_binary_descriptors
@@ -21,7 +21,6 @@
 import argparse
 import tempfile
 import subprocess
-import hashlib
 from compat import iteritems
 
 SOURCE_TARGET = [
@@ -36,13 +35,6 @@
 SCRIPT_PATH = 'tools/gen_binary_descriptors'
 
 
-def hash_path(path):
-  hash = hashlib.sha1()
-  with open(os.path.join(ROOT_DIR, path), 'rb') as f:
-    hash.update(f.read())
-  return hash.hexdigest()
-
-
 def find_protoc():
   for root, _, files in os.walk(os.path.join(ROOT_DIR, 'out')):
     if 'protoc' in files:
@@ -50,26 +42,7 @@
   return None
 
 
-def check(source, target):
-  assert os.path.exists(os.path.join(ROOT_DIR, target)), \
-      'Output file {} does not exist and so cannot be checked'.format(target)
-
-  sha1_file = target + '.sha1'
-  assert os.path.exists(sha1_file), \
-      'SHA1 file {} does not exist and so cannot be checked'.format(sha1_file)
-
-  with open(sha1_file, 'rb') as f:
-    s = f.read()
-
-  hashes = re.findall(r'// SHA1\((.*)\)\n// (.*)\n', s.decode())
-  assert sorted([SCRIPT_PATH, source]) == sorted([key for key, _ in hashes])
-  for path, expected_sha1 in hashes:
-    actual_sha1 = hash_path(os.path.join(ROOT_DIR, path))
-    assert actual_sha1 == expected_sha1, \
-        'In {} hash given for {} did not match'.format(target, path)
-
-
-def generate(source, target, protoc_path):
+def generate(source, target, protoc_path, check_only):
   # delete=False + manual unlink is required for Windows. Otherwise the temp
   # file is kept locked exclusively and unaccassible until it's destroyed.
   with tempfile.NamedTemporaryFile(delete=False) as fdescriptor:
@@ -86,23 +59,17 @@
     s = fdescriptor.read()
     fdescriptor.close()
     os.remove(fdescriptor.name)
+
+    if check_only:
+      with open(target, 'rb') as old:
+        old_content = old.read()
+        if (s != old_content):
+          raise AssertionError('Target {} does not match', target)
+      return
+
     with open(target, 'wb') as out:
       out.write(s)
 
-    sha1_path = target + '.sha1'
-    with open(sha1_path, 'wb') as c:
-      c.write("""
-// SHA1({script_path})
-// {script_hash}
-// SHA1({source_path})
-// {source_hash}
-  """.format(
-          script_path=SCRIPT_PATH,
-          script_hash=hash_path(__file__),
-          source_path=source,
-          source_hash=hash_path(os.path.join(source)),
-      ).encode())
-
 
 def main():
   parser = argparse.ArgumentParser()
@@ -112,15 +79,12 @@
 
   try:
     for source, target in SOURCE_TARGET:
-      if args.check_only:
-        check(source, target)
-      else:
-        protoc = args.protoc or find_protoc()
-        assert protoc, 'protoc not found specific (--protoc PROTOC_PATH)'
-        assert os.path.exists(protoc), '{} does not exist'.format(protoc)
-        if protoc is not args.protoc:
-          print('Using protoc: {}'.format(protoc))
-        generate(source, target, protoc)
+      protoc = args.protoc or find_protoc()
+      assert protoc, 'protoc not found specific (--protoc PROTOC_PATH)'
+      assert os.path.exists(protoc), '{} does not exist'.format(protoc)
+      if protoc is not args.protoc:
+        print('Using protoc: {}'.format(protoc))
+      generate(source, target, protoc, args.check_only)
   except AssertionError as e:
     if not str(e):
       raise