OLD | NEW |
---|---|
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 Loading... | |
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 |
65 | 70 |
66 def NaClRevision(): | 71 def NaClRevision(): |
67 '''Extract NaCl revision from svn. | 72 '''Extract NaCl revision from svn. |
68 | 73 |
69 Returns: | 74 Returns: |
70 The NaCl revision as a string. e.g. "12345" | 75 The NaCl revision as a string. e.g. "12345" |
71 ''' | 76 ''' |
72 nacl_dir = os.path.join(SRC_DIR, 'native_client') | 77 nacl_dir = os.path.join(SRC_DIR, 'native_client') |
73 return lastchange.FetchVersionInfo(None, nacl_dir).revision | 78 return FetchVersionInfo(nacl_dir, 'native_client').revision |
79 | |
80 def FetchVersionInfo(directory=None, | |
81 directory_regex_prior_to_src_url='chrome|blink|svn'): | |
82 """ | |
83 Returns the last change (in the form of a branch, revision tuple), | |
84 from some appropriate revision control system. | |
85 | |
86 TODO(binji): This is copied from lastchange.py. Remove this function and use | |
87 lastchange.py directly when the dust settles. (see crbug.com/406783) | |
88 """ | |
89 svn_url_regex = re.compile( | |
90 r'.*/(' + directory_regex_prior_to_src_url + r')(/.*)') | |
91 | |
92 version_info = (lastchange.FetchSVNRevision(directory, svn_url_regex) or | |
93 lastchange.FetchGitSVNRevision(directory, svn_url_regex) or | |
94 FetchGitCommitPosition(directory)) | |
95 if not version_info: | |
96 version_info = lastchange.VersionInfo(None, None) | |
97 return version_info | |
98 | |
bradn
2014/08/26 23:51:40
two lines
binji
2014/08/26 23:53:42
Done.
| |
99 def FetchGitCommitPosition(directory=None): | |
100 """ | |
101 Return the "commit-position" of the Chromium git repo. This should be | |
102 equivalent to the SVN revision if one eixsts. | |
103 | |
104 This is a copy of the (recently reverted) change in lastchange.py. | |
105 TODO(binji): Move this logic to lastchange.py when the dust settles. | |
106 (see crbug.com/406783) | |
107 """ | |
108 proc = lastchange.RunGitCommand(directory, | |
109 ['show', '-s', '--format=%B', 'HEAD']) | |
110 pos = '' | |
111 if proc: | |
112 output = proc.communicate()[0] | |
113 if proc.returncode == 0 and output: | |
114 for line in reversed(output.splitlines()): | |
115 match = re.search('Cr-Commit-Position: .*@{#(\d+)}', line) | |
116 if match: | |
117 pos = match.group(1) | |
118 if not pos: | |
119 return lastchange.VersionInfo(None, None) | |
120 return lastchange.VersionInfo('git', pos) | |
OLD | NEW |