Re-enable WEBRTC_SVNREVISION script

Message:
Another try to enable the script to get svn revision number. Most code borrowed from
lastchange.py, I simplified and modified to make it work with webrtc. The bottom line
of this script is 1. not breake any existing builds 2. get correct svn revision number
in a typical engineering setup, so it doesn't deal with some corner cases that lastchange.py
does, just simply returns "n/a" since these corner cases will most likely not happen, and
it also make this script simple.

Description:
This script runs "svn info" or "git svn info" to get svn revision number returns "n/a" if
both fail.

BUG=
TEST=try bots
Review URL: https://webrtc-codereview.appspot.com/671004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@2502 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
leozwang@webrtc.org 2012-07-10 20:36:29 +00:00
parent adf8ddf4aa
commit 475c26634e
2 changed files with 62 additions and 10 deletions

View File

@ -99,16 +99,7 @@
'..','../..', # common_types.h, typedefs.h
],
'defines': [
# TODO(leozwang): Temporally disable it because we cannot assume svn
# is installed by default, it will break Chromium build. The problem
# could happen on Gentoo which download and build tar ball directly,
# it also could happen when developer downloads Chromium tar ball and
# build inside source tree without svn installed. The solution is to
# have a script to deal with these cases and support git-svn.
# Two similar issues have been filed at
# WebRTC http://code.google.com/p/webrtc/issues/detail?id=496
# Chromium http://code.google.com/p/chromium/issues/detail?id=126452
'WEBRTC_SVNREVISION="n/a"',
'WEBRTC_SVNREVISION="<!(python <(webrtc_root)/build/version.py)"',
],
'conditions': [
['build_with_chromium==1', {

61
src/build/version.py Executable file
View File

@ -0,0 +1,61 @@
#!/usr/bin/env python
# Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
#
# Use of this source code is governed by a BSD-style license
# that can be found in the LICENSE file in the root of the source
# tree. An additional intellectual property rights grant can be found
# in the file PATENTS. All contributing project authors may
# be found in the AUTHORS file in the root of the source tree.
"""Get svn revision of working copy
This script tries to get the svn revision as much as it can. It supports
both git-svn and svn. It will fail if not in a git-svn or svn repository;
in this case the script will return "n/a".
This script is a simplified version of lastchange.py which is in Chromium's
src/build/util folder.
"""
import os
import subprocess
import sys
def popen_cmd_and_get_output(cmd, directory):
"""Return (status, output) of executing cmd in a shell."""
try:
proc = subprocess.Popen(cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
cwd=directory,
shell=(sys.platform=='win32'))
except OSError:
# command is apparently either not installed or not executable.
return None
if not proc:
return None
for line in proc.stdout:
line = line.strip()
if not line:
continue
words = line.split()
for index, word in enumerate(words):
if word == "Revision:":
return words[index+1]
# return None if cannot find keyword Revision
return None
def main():
directory = os.path.dirname(sys.argv[0]);
version = popen_cmd_and_get_output(['git', 'svn', 'info'], directory)
if version == None:
version = popen_cmd_and_get_output(['svn', 'info'], directory)
if version == None:
print "n/a"
return 0
print version
return 0
if __name__ == '__main__':
sys.exit(main())