diff --git a/tools/cef_version.py b/tools/cef_version.py index d63dc763f..10aebaaba 100644 --- a/tools/cef_version.py +++ b/tools/cef_version.py @@ -172,11 +172,18 @@ class VersionFormatter: cef_commit = self.get_cef_commit_components() cef_commit_hash = self._format_commit_hash(cef_commit['HASH']) - # Remove the remote name prefix, if any. - cef_branch_name = git.get_branch_name(self.cef_path).split('/')[-1] + # Determine whether the current commit is on a release branch. For example, + # if using Chrome build 3683, are we on CEF branch "3683" or "origin/3683"? + release_branch = chrome_version['BUILD'] + on_release_branch = ( + git.is_ancestor(self.cef_path, 'HEAD', release_branch) or + git.is_ancestor(self.cef_path, 'HEAD', 'origin/' + release_branch)) + + if not on_release_branch: + # Not on a commit that is part of an official named release branch. See + # if we can get the name of the branch we are on (may be just "HEAD"). + cef_branch_name = git.get_branch_name(self.cef_path).split('/')[-1] - if cef_branch_name != chrome_version['BUILD']: - # Not on an official named release branch. self._version_parts = {'MAJOR': int(chrome_major), 'MINOR': 0, 'PATCH': 0} self._version_string = '%s.0.0-%s.%s+%s+%s' % \ (chrome_major, cef_branch_name, cef_commit['NUMBER'], diff --git a/tools/exec_util.py b/tools/exec_util.py index ceabc5b09..6d7677d1c 100644 --- a/tools/exec_util.py +++ b/tools/exec_util.py @@ -10,6 +10,7 @@ def exec_cmd(cmd, path, input_string=None): """ Execute the specified command and return the result. """ out = '' err = '' + ret = -1 parts = cmd.split() try: if input_string is None: @@ -20,6 +21,7 @@ def exec_cmd(cmd, path, input_string=None): stderr=PIPE, shell=(sys.platform == 'win32')) out, err = process.communicate() + ret = process.returncode else: process = Popen( parts, @@ -29,8 +31,9 @@ def exec_cmd(cmd, path, input_string=None): stderr=PIPE, shell=(sys.platform == 'win32')) out, err = process.communicate(input=input_string) + ret = process.returncode except IOError, (errno, strerror): raise except: raise - return {'out': out, 'err': err} + return {'out': out, 'err': err, 'ret': ret} diff --git a/tools/git_util.py b/tools/git_util.py index 06a96337c..79db0455e 100644 --- a/tools/git_util.py +++ b/tools/git_util.py @@ -18,6 +18,13 @@ def is_checkout(path): return os.path.isdir(os.path.join(path, '.git')) +def is_ancestor(path='.', commit1='HEAD', commit2='master'): + """ Returns whether |commit1| is an ancestor of |commit2|. """ + cmd = "%s merge-base --is-ancestor %s %s" % (git_exe, commit1, commit2) + result = exec_cmd(cmd, path) + return result['ret'] == 0 + + def get_hash(path='.', branch='HEAD'): """ Returns the git hash for the specified branch/tag/hash. """ cmd = "%s rev-parse %s" % (git_exe, branch)