Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: chrome/tools/build/version.py

Issue 118192: Fetch last change (revision) info in a separate action that can run... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/chrome.gyp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2009 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2009 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """ 6 """
7 version.py -- Chromium version string substitution utility. 7 version.py -- Chromium version string substitution utility.
8 """ 8 """
9 9
10 import getopt 10 import getopt
11 import os 11 import os
12 import re 12 import re
13 import subprocess 13 import subprocess
14 import sys 14 import sys
15 15
16 16
17 class Usage(Exception): 17 class Usage(Exception):
18 def __init__(self, msg): 18 def __init__(self, msg):
19 self.msg = msg 19 self.msg = msg
20 20
21 21
22 def svn_fetch_revision():
23 """
24 Fetch the Subversion revision for the local tree.
25
26 Errors are swallowed.
27 """
28 try:
29 p = subprocess.Popen(['svn', 'info'],
30 stdout=subprocess.PIPE,
31 stderr=subprocess.PIPE)
32 except OSError:
33 # 'svn' is apparently either not installed or not executable.
34 return None
35 revision = None
36 if p:
37 svn_re = re.compile('^Revision:\s+(\S+)$', re.M)
38 m = svn_re.search(p.stdout.read())
39 if m:
40 revision = m.group(1)
41 return revision
42
43
44 def git_fetch_id():
45 """
46 Fetch the GIT identifier for the local tree.
47
48 Errors are swallowed.
49 """
50 try:
51 p = subprocess.Popen(['git', 'log', '-1'],
52 stdout=subprocess.PIPE,
53 stderr=subprocess.PIPE)
54 except OSError:
55 # 'git' is apparently either not installed or not executable.
56 return None
57 id = None
58 if p:
59 git_re = re.compile('^\s*git-svn-id:\s+(\S+)@(\d+)', re.M)
60 m = git_re.search(p.stdout.read())
61 if m:
62 id = m.group(1)
63 return id
64
65
66 def fetch_values_from_file(values_dict, file_name): 22 def fetch_values_from_file(values_dict, file_name):
67 """ 23 """
68 Fetches KEYWORD=VALUE settings from the specified file. 24 Fetches KEYWORD=VALUE settings from the specified file.
69 25
70 Everything to the left of the first '=' is the keyword, 26 Everything to the left of the first '=' is the keyword,
71 everything to the right is the value. No stripping of 27 everything to the right is the value. No stripping of
72 white space, so beware. 28 white space, so beware.
73 29
74 The file must exist, otherwise you get the Python exception from open(). 30 The file must exist, otherwise you get the Python exception from open().
75 """ 31 """
76 for line in open(file_name, 'r').readlines(): 32 for line in open(file_name, 'r').readlines():
77 key, val = line.rstrip('\r\n').split('=', 1) 33 key, val = line.rstrip('\r\n').split('=', 1)
78 values_dict[key] = val 34 values_dict[key] = val
79 35
80 36
81 def fetch_values(file_list): 37 def fetch_values(file_list):
82 """ 38 """
83 Returns a dictionary of values to be used for substitution, populating 39 Returns a dictionary of values to be used for substitution, populating
84 the dictionary with KEYWORD=VALUE settings from the files in 'file_list'. 40 the dictionary with KEYWORD=VALUE settings from the files in 'file_list'.
85 41
86 Explicitly adds the following values from internal calculations: 42 Explicitly adds the following value from internal calculations:
87 43
88 LASTCHANGE (the SVN revision, or GIT id of the local tree)
89 OFFICIAL_BUILD 44 OFFICIAL_BUILD
90 """ 45 """
91 change = svn_fetch_revision()
92 if not change and sys.platform in ('linux2',):
93 change = git_fetch_id()
94 if not change:
95 change = '0'
96
97 CHROME_BUILD_TYPE = os.environ.get('CHROME_BUILD_TYPE') 46 CHROME_BUILD_TYPE = os.environ.get('CHROME_BUILD_TYPE')
98 if CHROME_BUILD_TYPE == '_official': 47 if CHROME_BUILD_TYPE == '_official':
99 official_build = '1' 48 official_build = '1'
100 else: 49 else:
101 official_build = '0' 50 official_build = '0'
102 51
103 values = dict( 52 values = dict(
104 LASTCHANGE = change,
105 OFFICIAL_BUILD = official_build, 53 OFFICIAL_BUILD = official_build,
106 ) 54 )
107 55
108 for file_name in file_list: 56 for file_name in file_list:
109 fetch_values_from_file(values, file_name) 57 fetch_values_from_file(values, file_name)
110 58
111 return values 59 return values
112 60
113 61
114 def subst_contents(file_name, values): 62 def subst_contents(file_name, values):
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 if out_file: 164 if out_file:
217 write_if_changed(out_file, contents) 165 write_if_changed(out_file, contents)
218 else: 166 else:
219 print contents 167 print contents
220 168
221 return 0 169 return 0
222 170
223 171
224 if __name__ == '__main__': 172 if __name__ == '__main__':
225 sys.exit(main()) 173 sys.exit(main())
OLDNEW
« no previous file with comments | « chrome/chrome.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698