Add a Notification Settings Button to all web notifications behind the web platform...
[chromium-blink-merge.git] / third_party / boringssl / roll_boringssl.py
blob884df5ba029d34b3ec47565b61938657c0b481dd
1 #!/usr/bin/env python
2 # Copyright 2015 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 """Rolls third_party/boringssl/src in DEPS and updates generated build files."""
8 import os
9 import os.path
10 import shutil
11 import subprocess
12 import sys
15 SCRIPT_PATH = os.path.abspath(__file__)
16 SRC_PATH = os.path.dirname(os.path.dirname(os.path.dirname(SCRIPT_PATH)))
17 DEPS_PATH = os.path.join(SRC_PATH, 'DEPS')
18 BORINGSSL_PATH = os.path.join(SRC_PATH, 'third_party', 'boringssl')
19 BORINGSSL_SRC_PATH = os.path.join(BORINGSSL_PATH, 'src')
21 if not os.path.isfile(DEPS_PATH) or not os.path.isdir(BORINGSSL_SRC_PATH):
22 raise Exception('Could not find Chromium checkout')
24 # Pull OS_ARCH_COMBOS out of the BoringSSL script.
25 sys.path.append(os.path.join(BORINGSSL_SRC_PATH, 'util'))
26 import generate_build_files
28 GENERATED_FILES = [
29 'boringssl.gypi',
30 'boringssl_tests.gypi',
31 'err_data.c',
35 def IsPristine(repo):
36 """Returns True if a git checkout is pristine."""
37 cmd = ['git', 'diff', '--ignore-submodules']
38 return not (subprocess.check_output(cmd, cwd=repo).strip() or
39 subprocess.check_output(cmd + ['--cached'], cwd=repo).strip())
42 def RevParse(repo, rev):
43 """Resolves a string to a git commit."""
44 return subprocess.check_output(['git', 'rev-parse', rev], cwd=repo).strip()
47 def UpdateDEPS(deps, from_hash, to_hash):
48 """Updates all references of |from_hash| to |to_hash| in |deps|."""
49 with open(deps, 'rb') as f:
50 contents = f.read()
51 if from_hash not in contents:
52 raise Exception('%s not in DEPS' % from_hash)
53 contents = contents.replace(from_hash, to_hash)
54 with open(deps, 'wb') as f:
55 f.write(contents)
58 def main():
59 if len(sys.argv) > 2:
60 sys.stderr.write('Usage: %s [COMMIT]' % sys.argv[0])
61 return 1
63 if not IsPristine(SRC_PATH):
64 print >>sys.stderr, 'Chromium checkout not pristine.'
65 return 0
66 if not IsPristine(BORINGSSL_SRC_PATH):
67 print >>sys.stderr, 'BoringSSL checkout not pristine.'
68 return 0
70 if len(sys.argv) > 1:
71 commit = RevParse(BORINGSSL_SRC_PATH, sys.argv[1])
72 else:
73 subprocess.check_call(['git', 'fetch', 'origin'], cwd=BORINGSSL_SRC_PATH)
74 commit = RevParse(BORINGSSL_SRC_PATH, 'origin/master')
76 head = RevParse(BORINGSSL_SRC_PATH, 'HEAD')
77 if head == commit:
78 print 'BoringSSL already up-to-date.'
79 return 0
81 print 'Rolling BoringSSL from %s to %s...' % (head, commit)
83 UpdateDEPS(DEPS_PATH, head, commit)
85 # Checkout third_party/boringssl/src to generate new files.
86 subprocess.check_call(['git', 'checkout', commit], cwd=BORINGSSL_SRC_PATH)
88 # Clear the old generated files.
89 for (osname, arch, _, _, _) in generate_build_files.OS_ARCH_COMBOS:
90 path = os.path.join(BORINGSSL_PATH, osname + '-' + arch)
91 shutil.rmtree(path)
92 for file in GENERATED_FILES:
93 path = os.path.join(BORINGSSL_PATH, file)
94 os.unlink(path)
96 # Generate new ones.
97 subprocess.check_call(['python',
98 os.path.join(BORINGSSL_SRC_PATH, 'util',
99 'generate_build_files.py'),
100 'gyp'],
101 cwd=BORINGSSL_PATH)
103 # Commit everything.
104 subprocess.check_call(['git', 'add', DEPS_PATH], cwd=SRC_PATH)
105 for (osname, arch, _, _, _) in generate_build_files.OS_ARCH_COMBOS:
106 path = os.path.join(BORINGSSL_PATH, osname + '-' + arch)
107 subprocess.check_call(['git', 'add', path], cwd=SRC_PATH)
108 for file in GENERATED_FILES:
109 path = os.path.join(BORINGSSL_PATH, file)
110 subprocess.check_call(['git', 'add', path], cwd=SRC_PATH)
112 message = """Roll src/third_party/boringssl/src %s..%s
114 https://boringssl.googlesource.com/boringssl/+log/%s..%s
116 BUG=none
117 """ % (head[:9], commit[:9], head, commit)
118 subprocess.check_call(['git', 'commit', '-m', message], cwd=SRC_PATH)
120 return 0
123 if __name__ == '__main__':
124 sys.exit(main())