Commit 29607010 authored by Sergey Berezin's avatar Sergey Berezin Committed by Commit Bot

generate_breakpad_symbols: ensure otool path exists on Mac

BUG=813163
TBR=jochen@chromium.org

Change-Id: I1fb5565b978fb38b39fb2ddf9f726f9a3c5bd794
Reviewed-on: https://chromium-review.googlesource.com/953591Reviewed-by: default avatarSergey Berezin <sergeyberezin@chromium.org>
Commit-Queue: Sergey Berezin <sergeyberezin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#541636}
parent ea0f08d5
......@@ -29,17 +29,20 @@ BINARY_INFO = collections.namedtuple('BINARY_INFO',
['platform', 'arch', 'hash', 'name'])
def GetCommandOutput(command):
"""Runs the command list, returning its output.
def GetCommandOutput(command, env=None):
"""Runs the command list, returning its output (stdout).
Prints the given command (which should be a list of one or more strings),
then runs it and returns its output (stdout) as a string.
Args:
command: (list of strings) a command with arguments
env: (dict or None) optional environment for the command. If None,
inherits the existing environment, otherwise completely overrides it.
From chromium_utils.
"""
devnull = open(os.devnull, 'w')
proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=devnull,
bufsize=1)
bufsize=1, env=env)
output = proc.communicate()[0]
return output
......@@ -89,19 +92,44 @@ def GetSharedLibraryDependenciesLinux(binary):
return result
def GetDeveloperDirMac():
"""Finds a good DEVELOPER_DIR value to run Mac dev tools.
It checks the existing DEVELOPER_DIR and `xcode-select -p` and uses
one of those if the folder exists, and falls back to one of the
existing system folders with dev tools.
Returns:
(string) path to assign to DEVELOPER_DIR env var.
"""
candidate_paths = []
if 'DEVELOPER_DIR' in os.environ:
candidate_paths.append(os.environ['DEVELOPER_DIR'])
candidate_paths.extend([
GetCommandOutput(['xcode-select', '-p']).strip(),
'/Library/Developer/CommandLineTools',
])
for path in candidate_paths:
if os.path.exists(path):
return path
print 'WARNING: no value found for DEVELOPER_DIR. Some commands may fail.'
def GetSharedLibraryDependenciesMac(binary, exe_path):
"""Return absolute paths to all shared library dependecies of the binary.
This implementation assumes that we're running on a Mac system."""
loader_path = os.path.dirname(binary)
otool = GetCommandOutput(['otool', '-l', binary]).splitlines()
env = os.environ.copy()
env['DEVELOPER_DIR'] = GetDeveloperDirMac()
otool = GetCommandOutput(['otool', '-l', binary], env=env).splitlines()
rpaths = []
for idx, line in enumerate(otool):
if line.find('cmd LC_RPATH') != -1:
m = re.match(' *path (.*) \(offset .*\)$', otool[idx+2])
rpaths.append(m.group(1))
otool = GetCommandOutput(['otool', '-L', binary]).splitlines()
otool = GetCommandOutput(['otool', '-L', binary], env=env).splitlines()
lib_re = re.compile('\t(.*) \(compatibility .*\)$')
deps = []
for line in otool:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment