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."""
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
30 'boringssl_tests.gypi',
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
:
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
:
60 sys
.stderr
.write('Usage: %s [COMMIT]' % sys
.argv
[0])
63 if not IsPristine(SRC_PATH
):
64 print >>sys
.stderr
, 'Chromium checkout not pristine.'
66 if not IsPristine(BORINGSSL_SRC_PATH
):
67 print >>sys
.stderr
, 'BoringSSL checkout not pristine.'
71 commit
= RevParse(BORINGSSL_SRC_PATH
, sys
.argv
[1])
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')
78 print 'BoringSSL already up-to-date.'
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
)
92 for file in GENERATED_FILES
:
93 path
= os
.path
.join(BORINGSSL_PATH
, file)
97 subprocess
.check_call(['python',
98 os
.path
.join(BORINGSSL_SRC_PATH
, 'util',
99 'generate_build_files.py'),
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
117 """ % (head
[:9], commit
[:9], head
, commit
)
118 subprocess
.check_call(['git', 'commit', '-m', message
], cwd
=SRC_PATH
)
123 if __name__
== '__main__':