Use cross version of otool if available.

This commit is contained in:
John Maguire 2016-12-19 12:54:23 +00:00
parent 6901c9b1b6
commit f829fd2d0d

60
dist/macdeploy.py vendored
View File

@ -23,19 +23,16 @@ import subprocess
import sys import sys
import traceback import traceback
LOGGER = logging.getLogger("macdeploy") LOGGER = logging.getLogger('macdeploy')
FRAMEWORK_SEARCH_PATH=[ FRAMEWORK_SEARCH_PATH = [
'/target', '/target', '/target/lib', '/Library/Frameworks',
'/target/lib',
'/Library/Frameworks',
os.path.join(os.environ['HOME'], 'Library/Frameworks') os.path.join(os.environ['HOME'], 'Library/Frameworks')
] ]
LIBRARY_SEARCH_PATH=['/target', '/target/lib', '/usr/local/lib', '/sw/lib'] LIBRARY_SEARCH_PATH = ['/target', '/target/lib', '/usr/local/lib', '/sw/lib']
GSTREAMER_PLUGINS = [
GSTREAMER_PLUGINS=[
# Core plugins # Core plugins
'libgstapp.so', 'libgstapp.so',
'libgstaudioconvert.so', 'libgstaudioconvert.so',
@ -90,7 +87,7 @@ GSTREAMER_PLUGINS=[
'libgstrtsp.so', 'libgstrtsp.so',
] ]
GSTREAMER_SEARCH_PATH=[ GSTREAMER_SEARCH_PATH = [
'/target/lib/gstreamer-1.0', '/target/lib/gstreamer-1.0',
'/target/libexec/gstreamer-1.0', '/target/libexec/gstreamer-1.0',
] ]
@ -121,6 +118,10 @@ INSTALL_NAME_TOOL_CROSS = 'x86_64-apple-darwin-%s' % INSTALL_NAME_TOOL_APPLE
INSTALL_NAME_TOOL = INSTALL_NAME_TOOL_CROSS if spawn.find_executable( INSTALL_NAME_TOOL = INSTALL_NAME_TOOL_CROSS if spawn.find_executable(
INSTALL_NAME_TOOL_CROSS) else INSTALL_NAME_TOOL_APPLE INSTALL_NAME_TOOL_CROSS) else INSTALL_NAME_TOOL_APPLE
OTOOL_APPLE = 'otool'
OTOOL_CROSS = 'x86_64-apple-darwin-%s' % OTOOL_APPLE
OTOOL = OTOOL_CROSS if spawn.find_executable(OTOOL_CROSS) else OTOOL_APPLE
class Error(Exception): class Error(Exception):
pass pass
@ -154,7 +155,6 @@ class CouldNotParseFrameworkNameError(Error):
pass pass
if len(sys.argv) < 2: if len(sys.argv) < 2:
print 'Usage: %s <bundle.app>' % sys.argv[0] print 'Usage: %s <bundle.app>' % sys.argv[0]
@ -174,11 +174,11 @@ binary = os.path.join(bundle_dir, 'Contents', 'MacOS', bundle_name)
fixed_libraries = set() fixed_libraries = set()
fixed_frameworks = set() fixed_frameworks = set()
def GetBrokenLibraries(binary): def GetBrokenLibraries(binary):
output = subprocess.Popen(['otool', '-L', binary], stdout=subprocess.PIPE).communicate()[0] output = subprocess.Popen(
broken_libs = { [OTOOL, '-L', binary], stdout=subprocess.PIPE).communicate()[0]
'frameworks': [], broken_libs = {'frameworks': [], 'libs': []}
'libs': []}
for line in [x.split(' ')[0].lstrip() for x in output.split('\n')[1:]]: for line in [x.split(' ')[0].lstrip() for x in output.split('\n')[1:]]:
if not line: # skip empty lines if not line: # skip empty lines
continue continue
@ -190,7 +190,8 @@ def GetBrokenLibraries(binary):
continue # unix style system library continue # unix style system library
elif re.match(r'Breakpad', line): elif re.match(r'Breakpad', line):
continue # Manually added by cmake. continue # Manually added by cmake.
elif re.match(r'^\s*@executable_path', line) or re.match(r'^\s*@loader_path', line): elif re.match(r'^\s*@executable_path', line) or re.match(
r'^\s*@loader_path', line):
# Potentially already fixed library # Potentially already fixed library
relative_path = os.path.join(*line.split('/')[3:]) relative_path = os.path.join(*line.split('/')[3:])
if not os.path.exists(os.path.join(frameworks_dir, relative_path)): if not os.path.exists(os.path.join(frameworks_dir, relative_path)):
@ -202,6 +203,7 @@ def GetBrokenLibraries(binary):
return broken_libs return broken_libs
def FindFramework(path): def FindFramework(path):
for search_path in FRAMEWORK_SEARCH_PATH: for search_path in FRAMEWORK_SEARCH_PATH:
abs_path = os.path.join(search_path, path) abs_path = os.path.join(search_path, path)
@ -211,6 +213,7 @@ def FindFramework(path):
raise CouldNotFindFrameworkError(path) raise CouldNotFindFrameworkError(path)
def FindLibrary(path): def FindLibrary(path):
if os.path.exists(path): if os.path.exists(path):
return path return path
@ -222,12 +225,14 @@ def FindLibrary(path):
raise CouldNotFindFrameworkError(path) raise CouldNotFindFrameworkError(path)
def FixAllLibraries(broken_libs): def FixAllLibraries(broken_libs):
for framework in broken_libs['frameworks']: for framework in broken_libs['frameworks']:
FixFramework(framework) FixFramework(framework)
for lib in broken_libs['libs']: for lib in broken_libs['libs']:
FixLibrary(lib) FixLibrary(lib)
def FixFramework(path): def FixFramework(path):
if path in fixed_frameworks: if path in fixed_frameworks:
return return
@ -245,8 +250,10 @@ def FixFramework(path):
for library in broken_libs['libs']: for library in broken_libs['libs']:
FixLibraryInstallPath(library, new_path) FixLibraryInstallPath(library, new_path)
def FixLibrary(path): def FixLibrary(path):
if path in fixed_libraries or FindSystemLibrary(os.path.basename(path)) is not None: if path in fixed_libraries or FindSystemLibrary(os.path.basename(
path)) is not None:
return return
else: else:
fixed_libraries.add(path) fixed_libraries.add(path)
@ -261,6 +268,7 @@ def FixLibrary(path):
for library in broken_libs['libs']: for library in broken_libs['libs']:
FixLibraryInstallPath(library, new_path) FixLibraryInstallPath(library, new_path)
def FixPlugin(abs_path, subdir): def FixPlugin(abs_path, subdir):
broken_libs = GetBrokenLibraries(abs_path) broken_libs = GetBrokenLibraries(abs_path)
FixAllLibraries(broken_libs) FixAllLibraries(broken_libs)
@ -271,6 +279,7 @@ def FixPlugin(abs_path, subdir):
for library in broken_libs['libs']: for library in broken_libs['libs']:
FixLibraryInstallPath(library, new_path) FixLibraryInstallPath(library, new_path)
def FixBinary(path): def FixBinary(path):
broken_libs = GetBrokenLibraries(path) broken_libs = GetBrokenLibraries(path)
FixAllLibraries(broken_libs) FixAllLibraries(broken_libs)
@ -279,13 +288,15 @@ def FixBinary(path):
for library in broken_libs['libs']: for library in broken_libs['libs']:
FixLibraryInstallPath(library, path) FixLibraryInstallPath(library, path)
def CopyLibrary(path): def CopyLibrary(path):
new_path = os.path.join(frameworks_dir, os.path.basename(path)) new_path = os.path.join(frameworks_dir, os.path.basename(path))
args = ['cp', path, new_path] args = ['cp', path, new_path]
commands.append(args) commands.append(args)
LOGGER.info("Copying library '%s'", path) LOGGER.info("Copying library '%s'", path)
return new_path return new_path
def CopyPlugin(path, subdir): def CopyPlugin(path, subdir):
new_path = os.path.join(plugins_dir, subdir, os.path.basename(path)) new_path = os.path.join(plugins_dir, subdir, os.path.basename(path))
args = ['mkdir', '-p', os.path.dirname(new_path)] args = ['mkdir', '-p', os.path.dirname(new_path)]
@ -295,6 +306,7 @@ def CopyPlugin(path, subdir):
LOGGER.info("Copying plugin '%s'", path) LOGGER.info("Copying plugin '%s'", path)
return new_path return new_path
def CopyFramework(src_binary): def CopyFramework(src_binary):
while os.path.islink(src_binary): while os.path.islink(src_binary):
src_binary = os.path.realpath(src_binary) src_binary = os.path.realpath(src_binary)
@ -307,7 +319,7 @@ def CopyFramework(src_binary):
name = m.group(2) name = m.group(2)
version = m.group(3) version = m.group(3)
LOGGER.info("Copying framework %s version %s", name, version) LOGGER.info('Copying framework %s version %s', name, version)
dest_base = os.path.join(frameworks_dir, '%s.framework' % name) dest_base = os.path.join(frameworks_dir, '%s.framework' % name)
dest_dir = os.path.join(dest_base, 'Versions', version) dest_dir = os.path.join(dest_base, 'Versions', version)
@ -378,14 +390,17 @@ def FindSystemLibrary(library_name):
return full_path return full_path
return None return None
def FixLibraryInstallPath(library_path, library): def FixLibraryInstallPath(library_path, library):
system_library = FindSystemLibrary(os.path.basename(library_path)) system_library = FindSystemLibrary(os.path.basename(library_path))
if system_library is None: if system_library is None:
new_path = '@executable_path/../Frameworks/%s' % os.path.basename(library_path) new_path = '@executable_path/../Frameworks/%s' % os.path.basename(
library_path)
FixInstallPath(library_path, library, new_path) FixInstallPath(library_path, library, new_path)
else: else:
FixInstallPath(library_path, library, system_library) FixInstallPath(library_path, library, system_library)
def FixFrameworkInstallPath(library_path, library): def FixFrameworkInstallPath(library_path, library):
parts = library_path.split(os.sep) parts = library_path.split(os.sep)
for i, part in enumerate(parts): for i, part in enumerate(parts):
@ -395,6 +410,7 @@ def FixFrameworkInstallPath(library_path, library):
new_path = '@executable_path/../Frameworks/%s' % full_path new_path = '@executable_path/../Frameworks/%s' % full_path
FixInstallPath(library_path, library, new_path) FixInstallPath(library_path, library, new_path)
def FindXinePlugin(name): def FindXinePlugin(name):
for path in XINEPLUGIN_SEARCH_PATH: for path in XINEPLUGIN_SEARCH_PATH:
if os.path.exists(path): if os.path.exists(path):
@ -431,8 +447,10 @@ def FindGioModule(name):
def main(): def main():
logging.basicConfig(filename="macdeploy.log", level=logging.DEBUG, logging.basicConfig(
format='%(asctime)s %(levelname)-8s %(message)s') filename='macdeploy.log',
level=logging.DEBUG,
format='%(asctime)s %(levelname)-8s %(message)s')
FixBinary(binary) FixBinary(binary)