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

Side by Side Diff: native_client_sdk/src/build_tools/build_version.py

Issue 507883003: [NaCl SDK] Fix the SDK builders to use Cr-Commit-Position. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 6 years, 3 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
« no previous file with comments | « no previous file | 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 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Small utility library of python functions used during SDK building. 5 """Small utility library of python functions used during SDK building.
6 """ 6 """
7 7
8 import os 8 import os
9 import re
9 import sys 10 import sys
10 11
11 # pylint: disable=E0602 12 # pylint: disable=E0602
12 13
13 # Reuse last change utility code. 14 # Reuse last change utility code.
14 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) 15 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
15 SRC_DIR = os.path.dirname(os.path.dirname(os.path.dirname(SCRIPT_DIR))) 16 SRC_DIR = os.path.dirname(os.path.dirname(os.path.dirname(SCRIPT_DIR)))
16 sys.path.append(os.path.join(SRC_DIR, 'build/util')) 17 sys.path.append(os.path.join(SRC_DIR, 'build/util'))
17 import lastchange 18 import lastchange
18 19
19 20
20 # Location of chrome's version file. 21 # Location of chrome's version file.
21 VERSION_PATH = os.path.join(SRC_DIR, 'chrome', 'VERSION') 22 VERSION_PATH = os.path.join(SRC_DIR, 'chrome', 'VERSION')
22 23
23 24
24 def ChromeVersion(): 25 def ChromeVersion():
25 '''Extract chrome version from src/chrome/VERSION + svn. 26 '''Extract chrome version from src/chrome/VERSION + svn.
26 27
27 Returns: 28 Returns:
28 Chrome version string or trunk + svn rev. 29 Chrome version string or trunk + svn rev.
29 ''' 30 '''
30 info = lastchange.FetchVersionInfo(None) 31 info = FetchVersionInfo()
31 if info.url.startswith('/trunk/'): 32 if info.url.startswith('/trunk/'):
32 return 'trunk.%s' % info.revision 33 return 'trunk.%s' % info.revision
33 else: 34 else:
34 return ChromeVersionNoTrunk() 35 return ChromeVersionNoTrunk()
35 36
36 37
37 def ChromeVersionNoTrunk(): 38 def ChromeVersionNoTrunk():
38 '''Extract the chrome version from src/chrome/VERSION. 39 '''Extract the chrome version from src/chrome/VERSION.
39 Ignore whether this is a trunk build. 40 Ignore whether this is a trunk build.
40 41
(...skipping 10 matching lines...) Expand all
51 Returns: 52 Returns:
52 Chrome major version. 53 Chrome major version.
53 ''' 54 '''
54 exec(open(VERSION_PATH, 'r').read()) 55 exec(open(VERSION_PATH, 'r').read())
55 return str(MAJOR) 56 return str(MAJOR)
56 57
57 58
58 def ChromeRevision(): 59 def ChromeRevision():
59 '''Extract chrome revision from svn. 60 '''Extract chrome revision from svn.
60 61
62 Now that the Chrome source-of-truth is git, this will return the
63 Cr-Commit-Position instead. fortunately, this value is equal to the SVN
64 revision if one exists.
65
61 Returns: 66 Returns:
62 The Chrome revision as a string. e.g. "12345" 67 The Chrome revision as a string. e.g. "12345"
63 ''' 68 '''
64 return lastchange.FetchVersionInfo(None).revision 69 return FetchVersionInfo().revision
70
65 71
66 def NaClRevision(): 72 def NaClRevision():
67 '''Extract NaCl revision from svn. 73 '''Extract NaCl revision from svn.
68 74
69 Returns: 75 Returns:
70 The NaCl revision as a string. e.g. "12345" 76 The NaCl revision as a string. e.g. "12345"
71 ''' 77 '''
72 nacl_dir = os.path.join(SRC_DIR, 'native_client') 78 nacl_dir = os.path.join(SRC_DIR, 'native_client')
73 return lastchange.FetchVersionInfo(None, nacl_dir).revision 79 return FetchVersionInfo(nacl_dir, 'native_client').revision
80
81
82 def FetchVersionInfo(directory=None,
83 directory_regex_prior_to_src_url='chrome|blink|svn'):
84 """
85 Returns the last change (in the form of a branch, revision tuple),
86 from some appropriate revision control system.
87
88 TODO(binji): This is copied from lastchange.py. Remove this function and use
89 lastchange.py directly when the dust settles. (see crbug.com/406783)
90 """
91 svn_url_regex = re.compile(
92 r'.*/(' + directory_regex_prior_to_src_url + r')(/.*)')
93
94 version_info = (lastchange.FetchSVNRevision(directory, svn_url_regex) or
95 lastchange.FetchGitSVNRevision(directory, svn_url_regex) or
96 FetchGitCommitPosition(directory))
97 if not version_info:
98 version_info = lastchange.VersionInfo(None, None)
99 return version_info
100
101
102 def FetchGitCommitPosition(directory=None):
103 """
104 Return the "commit-position" of the Chromium git repo. This should be
105 equivalent to the SVN revision if one eixsts.
106
107 This is a copy of the (recently reverted) change in lastchange.py.
108 TODO(binji): Move this logic to lastchange.py when the dust settles.
109 (see crbug.com/406783)
110 """
111 proc = lastchange.RunGitCommand(directory,
112 ['show', '-s', '--format=%B', 'HEAD'])
113 pos = ''
114 if proc:
115 output = proc.communicate()[0]
116 if proc.returncode == 0 and output:
117 for line in reversed(output.splitlines()):
118 match = re.search('Cr-Commit-Position: .*@{#(\d+)}', line)
119 if match:
120 pos = match.group(1)
121 if not pos:
122 return lastchange.VersionInfo(None, None)
123 return lastchange.VersionInfo('git', pos)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698