2013-12-30 23:51:02 +01:00
|
|
|
# vim: ts=8 sts=2 sw=2 tw=99 et ft=python:
|
|
|
|
import sys
|
|
|
|
import subprocess
|
|
|
|
import os
|
|
|
|
try:
|
|
|
|
import urllib.request as urllib
|
|
|
|
except ImportError:
|
|
|
|
import urllib2 as urllib
|
|
|
|
|
|
|
|
if len(sys.argv) < 3:
|
|
|
|
sys.stderr.write('Usage: <symbol-file> <dump-syms-cmd> <args...>\n')
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
SYMBOL_SERVER = os.environ['BREAKPAD_SYMBOL_SERVER']
|
|
|
|
symbol_file = sys.argv[1]
|
|
|
|
cmd_argv = sys.argv[2:]
|
|
|
|
|
|
|
|
sys.stdout.write(' '.join(cmd_argv))
|
|
|
|
sys.stdout.write('\n')
|
|
|
|
|
|
|
|
p = subprocess.Popen(
|
|
|
|
args = cmd_argv,
|
|
|
|
stdout = subprocess.PIPE,
|
|
|
|
stderr = subprocess.PIPE,
|
|
|
|
shell = False
|
|
|
|
)
|
|
|
|
stdout, stderr = p.communicate()
|
|
|
|
out = stdout.decode('utf8')
|
|
|
|
err = stdout.decode('utf8')
|
|
|
|
|
|
|
|
with open(symbol_file, 'w') as fp:
|
2015-11-05 11:46:32 +01:00
|
|
|
fp.write(out)
|
|
|
|
fp.write(err)
|
2013-12-30 23:51:02 +01:00
|
|
|
|
2015-10-27 18:24:03 +01:00
|
|
|
lines = out.splitlines()
|
|
|
|
|
|
|
|
paths = set()
|
|
|
|
roots = {}
|
|
|
|
|
|
|
|
for line in lines:
|
|
|
|
line = line.strip().split(None, 2)
|
|
|
|
|
|
|
|
if line[0] != 'FILE':
|
|
|
|
continue
|
|
|
|
|
|
|
|
path = os.path.dirname(line[2])
|
|
|
|
|
|
|
|
if path in paths:
|
|
|
|
continue
|
|
|
|
|
|
|
|
paths.add(path)
|
|
|
|
|
|
|
|
root = None
|
|
|
|
url = None
|
|
|
|
rev = None
|
|
|
|
|
|
|
|
with open(os.devnull, 'w') as devnull:
|
2015-11-05 11:46:32 +01:00
|
|
|
def runCommand(argv):
|
|
|
|
proc = subprocess.Popen(argv, stdout=subprocess.PIPE, stderr=devnull, cwd=path, universal_newlines=True)
|
|
|
|
procout, procerr = proc.communicate()
|
|
|
|
if proc.returncode:
|
2015-11-05 11:54:35 +01:00
|
|
|
raise RuntimeError('Failed to execute \'' + ' '.join(argv) + '\' = ' + str(proc.returncode))
|
2015-11-05 11:46:32 +01:00
|
|
|
return procout.strip()
|
|
|
|
|
2015-10-27 18:24:03 +01:00
|
|
|
try:
|
2015-11-05 11:46:32 +01:00
|
|
|
root = runCommand(['git', 'rev-parse', '--show-toplevel'])
|
2015-10-28 14:31:02 +01:00
|
|
|
root = os.path.normcase(root)
|
2015-10-27 18:24:03 +01:00
|
|
|
|
|
|
|
if root in roots:
|
|
|
|
continue
|
|
|
|
|
2015-11-05 11:46:32 +01:00
|
|
|
url = runCommand(['git', 'ls-remote', '--get-url', 'origin'])
|
|
|
|
rev = runCommand(['git', 'log', '--pretty=format:%H', '-n', '1'])
|
2015-11-05 11:54:35 +01:00
|
|
|
except (OSError, RuntimeError) as e:
|
|
|
|
sys.stderr.write(str(e) + '\n')
|
2015-10-27 18:24:03 +01:00
|
|
|
continue
|
|
|
|
|
|
|
|
roots[root] = (url, rev)
|
|
|
|
|
|
|
|
index = 1
|
|
|
|
while lines[index].split(None, 1)[0] == 'INFO':
|
|
|
|
index += 1;
|
|
|
|
|
|
|
|
for root, info in roots.items():
|
2015-10-28 10:47:40 +01:00
|
|
|
lines.insert(index, 'INFO REPO ' + ' '.join([info[1], info[0], root]))
|
2015-10-27 18:24:03 +01:00
|
|
|
index += 1;
|
|
|
|
|
2015-11-05 11:46:32 +01:00
|
|
|
out = os.linesep.join(lines).encode('utf8')
|
2015-10-27 18:24:03 +01:00
|
|
|
|
2013-12-30 23:51:02 +01:00
|
|
|
request = urllib.Request(SYMBOL_SERVER, out)
|
|
|
|
request.add_header('Content-Type', 'text/plain')
|
2015-10-27 18:24:03 +01:00
|
|
|
server_response = urllib.urlopen(request).read().decode('utf8').strip()
|
2013-12-30 23:51:02 +01:00
|
|
|
print(server_response)
|