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
3 # found in the LICENSE file.
5 """Small utility library of python functions used during SDK building.
12 # pylint: disable=E0602
14 # Reuse last change utility code.
15 SCRIPT_DIR
= os
.path
.dirname(os
.path
.abspath(__file__
))
16 SRC_DIR
= os
.path
.dirname(os
.path
.dirname(os
.path
.dirname(SCRIPT_DIR
)))
17 sys
.path
.append(os
.path
.join(SRC_DIR
, 'build/util'))
21 # Location of chrome's version file.
22 VERSION_PATH
= os
.path
.join(SRC_DIR
, 'chrome', 'VERSION')
26 '''Extract chrome version from src/chrome/VERSION + svn.
29 Chrome version string or trunk + svn rev.
31 info
= FetchVersionInfo()
32 if info
.url
== 'refs/heads/master':
33 return 'trunk.%s' % info
.revision
35 return ChromeVersionNoTrunk()
38 def ChromeVersionNoTrunk():
39 '''Extract the chrome version from src/chrome/VERSION.
40 Ignore whether this is a trunk build.
43 Chrome version string.
45 exec(open(VERSION_PATH
).read())
46 return '%s.%s.%s.%s' % (MAJOR
, MINOR
, BUILD
, PATCH
)
49 def ChromeMajorVersion():
50 '''Extract chrome major version from src/chrome/VERSION.
55 exec(open(VERSION_PATH
, 'r').read())
60 '''Extract chrome revision from svn.
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.
67 The Chrome revision as a string. e.g. "12345"
69 return FetchVersionInfo().revision
73 '''Extract NaCl revision from svn.
76 The NaCl revision as a string. e.g. "12345"
78 nacl_dir
= os
.path
.join(SRC_DIR
, 'native_client')
79 return FetchVersionInfo(nacl_dir
, 'native_client').revision
82 def FetchVersionInfo(directory
=None,
83 directory_regex_prior_to_src_url
='chrome|blink|svn'):
85 Returns the last change (in the form of a branch, revision tuple),
86 from some appropriate revision control system.
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)
91 svn_url_regex
= re
.compile(
92 r
'.*/(' + directory_regex_prior_to_src_url
+ r
')(/.*)')
94 version_info
= (lastchange
.FetchSVNRevision(directory
, svn_url_regex
) or
95 lastchange
.FetchGitSVNRevision(directory
, svn_url_regex
) or
96 FetchGitCommitPosition(directory
))
98 version_info
= lastchange
.VersionInfo(None, None)
102 def FetchGitCommitPosition(directory
=None):
104 Return the "commit-position" of the Chromium git repo. This should be
105 equivalent to the SVN revision if one eixsts.
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)
111 proc
= lastchange
.RunGitCommand(directory
,
112 ['show', '-s', '--format=%B', 'HEAD'])
114 output
= proc
.communicate()[0]
115 if proc
.returncode
== 0 and output
:
116 for line
in reversed(output
.splitlines()):
117 match
= re
.search('Cr-Commit-Position: (.*)@{#(\d+)}', line
)
119 return lastchange
.VersionInfo(match
.group(1), match
.group(2))
120 return lastchange
.VersionInfo(None, None)