Roll src/third_party/WebKit bf18a82:a9cee16 (svn 185297:185304)
[chromium-blink-merge.git] / chrome / test / chromedriver / embed_version_in_cpp.py
blobb7f953b9564a2a7e33e301ff14905b3a7ea37d6d
1 #!/usr/bin/env python
2 # Copyright 2013 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 """Embeds Chrome user data files in C++ code."""
8 import optparse
9 import os
10 import re
11 import sys
13 import chrome_paths
14 import cpp_source
16 sys.path.insert(0, os.path.join(chrome_paths.GetSrc(), 'build', 'util'))
17 import lastchange
20 def main():
21 parser = optparse.OptionParser()
22 parser.add_option('', '--version-file')
23 parser.add_option(
24 '', '--directory', type='string', default='.',
25 help='Path to directory where the cc/h file should be created')
26 options, args = parser.parse_args()
28 version = open(options.version_file, 'r').read().strip()
29 revision = lastchange.FetchVersionInfo(None).revision
31 if revision:
32 match = re.match('([0-9a-fA-F]+)(-refs/heads/master@{#(\d+)})?', revision)
33 if match:
34 git_hash = match.group(1)
35 commit_position = match.group(3)
36 if commit_position:
37 version += '.' + commit_position
38 version += ' (%s)' % git_hash
39 else:
40 version += ' (%s)' % revision
42 global_string_map = {
43 'kChromeDriverVersion': version
45 cpp_source.WriteSource('version',
46 'chrome/test/chromedriver',
47 options.directory, global_string_map)
50 if __name__ == '__main__':
51 sys.exit(main())