Upstream version 11.40.277.0
[platform/framework/web/crosswalk.git] / src / chrome / test / chromedriver / embed_version_in_cpp.py
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.
5
6 """Embeds Chrome user data files in C++ code."""
7
8 import optparse
9 import os
10 import re
11 import sys
12
13 import chrome_paths
14 import cpp_source
15
16 sys.path.insert(0, os.path.join(chrome_paths.GetSrc(), 'build', 'util'))
17 import lastchange
18
19
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()
27
28   version = open(options.version_file, 'r').read().strip()
29   revision = lastchange.FetchVersionInfo(None).revision
30
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
41
42   global_string_map = {
43       'kChromeDriverVersion': version
44   }
45   cpp_source.WriteSource('version',
46                          'chrome/test/chromedriver',
47                          options.directory, global_string_map)
48
49
50 if __name__ == '__main__':
51   sys.exit(main())
52