1
0
mirror of https://github.com/clementine-player/Clementine synced 2024-12-16 19:31:02 +01:00
Clementine-audio-player-Mac.../dist/macdeploy.py

391 lines
11 KiB
Python
Raw Normal View History

#!/usr/bin/python
# This file is part of Clementine.
#
# Clementine is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Clementine is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Clementine. If not, see <http://www.gnu.org/licenses/>.
import os
import re
import subprocess
import sys
import traceback
FRAMEWORK_SEARCH_PATH=[
2011-05-18 16:56:53 +02:00
'/target',
'/Library/Frameworks',
os.path.join(os.environ['HOME'], 'Library/Frameworks')
]
LIBRARY_SEARCH_PATH=['/target/lib', '/usr/local/lib', '/sw/lib']
2010-04-12 14:36:30 +02:00
GSTREAMER_PLUGINS=[
# Core plugins
2011-11-30 13:29:18 +01:00
'libgstapp.so',
2010-04-12 14:36:30 +02:00
'libgstaudioconvert.so',
'libgstaudiofx.so',
'libgstaudiotestsrc.so',
2010-04-12 14:36:30 +02:00
'libgstaudioresample.so',
'libgstautodetect.so',
'libgstcoreelements.so',
2010-06-22 17:50:42 +02:00
'libgstdecodebin2.so',
2010-07-13 19:13:33 +02:00
'libgstequalizer.so',
'libgstgdp.so',
2010-04-12 14:36:30 +02:00
'libgstosxaudio.so',
2011-04-27 00:35:31 +02:00
'libgsttcp.so',
2010-04-12 14:36:30 +02:00
'libgsttypefindfunctions.so',
2010-06-22 17:50:42 +02:00
'libgstudp.so',
2010-04-12 14:36:30 +02:00
'libgstvolume.so',
# Codecs
2010-05-25 13:12:35 +02:00
'libgstapetag.so',
2010-08-18 18:12:16 +02:00
'libgstasf.so',
2010-04-12 14:36:30 +02:00
'libgstfaac.so',
'libgstfaad.so',
2010-06-18 16:21:13 +02:00
'libgstffmpeg.so',
2010-04-12 14:36:30 +02:00
'libgstflac.so',
2010-06-22 17:50:42 +02:00
'libgstgio.so',
2010-04-12 14:36:30 +02:00
'libgstid3demux.so',
2010-06-22 17:50:42 +02:00
'libgstlame.so',
2010-04-12 14:36:30 +02:00
'libgstmad.so',
2010-06-23 13:07:39 +02:00
'libgstmms.so',
'libgstmpegaudioparse.so',
2010-04-12 14:36:30 +02:00
'libgstmusepack.so',
'libgstogg.so',
2010-06-22 17:50:42 +02:00
'libgstqtdemux.so',
'libgstreplaygain.so',
'libgstspeex.so',
'libgsttaglib.so',
2010-04-12 14:36:30 +02:00
'libgstvorbis.so',
'libgstwavpack.so',
'libgstwavparse.so',
2010-04-12 14:36:30 +02:00
# HTTP src support
'libgstsouphttpsrc.so',
2010-05-25 13:07:06 +02:00
# Icecast support
'libgsticydemux.so',
# CD support
'libgstcdio.so',
2010-04-12 14:36:30 +02:00
]
GSTREAMER_SEARCH_PATH=[
'/target/lib/gstreamer-0.10',
'/target/libexec/gstreamer-0.10',
'/sw/lib/gstreamer-0.10',
'/usr/local/lib/gstreamer-0.10',
2010-04-12 14:36:30 +02:00
]
2010-03-01 13:13:11 +01:00
QT_PLUGINS = [
'accessible/libqtaccessiblewidgets.dylib',
'codecs/libqcncodecs.dylib',
'codecs/libqjpcodecs.dylib',
'codecs/libqkrcodecs.dylib',
'codecs/libqtwcodecs.dylib',
'iconengines/libqsvgicon.dylib',
'imageformats/libqgif.dylib',
'imageformats/libqico.dylib',
'imageformats/libqjpeg.dylib',
'imageformats/libqmng.dylib',
'imageformats/libqsvg.dylib',
'imageformats/libqtiff.dylib',
]
QT_PLUGINS_SEARCH_PATH=[
'/usr/local/Trolltech/Qt-4.7.0/plugins',
2010-03-01 13:13:11 +01:00
'/Developer/Applications/Qt/plugins',
]
class Error(Exception):
pass
class CouldNotFindFrameworkError(Error):
pass
class InstallNameToolError(Error):
pass
class CouldNotFindXinePluginError(Error):
pass
2010-03-01 13:13:11 +01:00
class CouldNotFindQtPluginError(Error):
pass
2010-04-12 14:36:30 +02:00
class CouldNotFindGstreamerPluginError(Error):
pass
2011-01-18 15:02:51 +01:00
class CouldNotFindScriptPluginError(Error):
pass
if len(sys.argv) < 2:
print 'Usage: %s <bundle.app>' % sys.argv[0]
bundle_dir = sys.argv[1]
2010-04-15 21:09:39 +02:00
bundle_name = os.path.basename(bundle_dir).split('.')[0]
2010-03-01 13:13:11 +01:00
commands = []
frameworks_dir = os.path.join(bundle_dir, 'Contents', 'Frameworks')
2010-03-01 13:13:11 +01:00
commands.append(['mkdir', '-p', frameworks_dir])
resources_dir = os.path.join(bundle_dir, 'Contents', 'Resources')
2010-03-01 13:13:11 +01:00
commands.append(['mkdir', '-p', resources_dir])
plugins_dir = os.path.join(bundle_dir, 'Contents', 'PlugIns')
binary = os.path.join(bundle_dir, 'Contents', 'MacOS', bundle_name)
fixed_libraries = []
fixed_frameworks = []
def GetBrokenLibraries(binary):
output = subprocess.Popen(['otool', '-L', binary], stdout=subprocess.PIPE).communicate()[0]
broken_libs = {
'frameworks': [],
'libs': []}
for line in [x.split(' ')[0].lstrip() for x in output.split('\n')[1:]]:
if not line: # skip empty lines
continue
if os.path.basename(binary) in line:
continue
if 'libiconv' in line:
broken_libs['libs'].append(line)
elif re.match(r'^\s*/System/', line):
continue # System framework
elif re.match(r'^\s*/usr/lib/', line):
continue # unix style system library
elif re.match(r'Breakpad', line):
continue # Manually added by cmake.
2010-04-15 18:00:11 +02:00
elif re.match(r'^\s*@executable_path', line) or re.match(r'^\s*@loader_path', line):
2010-03-01 13:13:11 +01:00
# Potentially already fixed library
relative_path = os.path.join(*line.split('/')[3:])
if not os.path.exists(os.path.join(frameworks_dir, relative_path)):
broken_libs['frameworks'].append(relative_path)
elif re.search(r'\w+\.framework', line):
broken_libs['frameworks'].append(line)
else:
broken_libs['libs'].append(line)
return broken_libs
def FindFramework(path):
for search_path in FRAMEWORK_SEARCH_PATH:
abs_path = os.path.join(search_path, path)
if os.path.exists(abs_path):
return abs_path
raise CouldNotFindFrameworkError(path)
def FindLibrary(path):
if os.path.exists(path):
return path
for search_path in LIBRARY_SEARCH_PATH:
abs_path = os.path.join(search_path, path)
if os.path.exists(abs_path):
return abs_path
raise CouldNotFindFrameworkError(path)
def FixAllLibraries(broken_libs):
for framework in broken_libs['frameworks']:
FixFramework(framework)
for lib in broken_libs['libs']:
FixLibrary(lib)
def FixFramework(path):
if path in fixed_libraries:
return
else:
fixed_libraries.append(path)
abs_path = FindFramework(path)
broken_libs = GetBrokenLibraries(abs_path)
FixAllLibraries(broken_libs)
new_path = CopyFramework(abs_path)
id = os.sep.join(new_path.split(os.sep)[3:])
FixFrameworkId(new_path, id)
for framework in broken_libs['frameworks']:
FixFrameworkInstallPath(framework, new_path)
for library in broken_libs['libs']:
FixLibraryInstallPath(library, new_path)
def FixLibrary(path):
if path in fixed_libraries or FindSystemLibrary(os.path.basename(path)) is not None:
return
else:
fixed_libraries.append(path)
abs_path = FindLibrary(path)
broken_libs = GetBrokenLibraries(abs_path)
FixAllLibraries(broken_libs)
new_path = CopyLibrary(abs_path)
FixLibraryId(new_path)
for framework in broken_libs['frameworks']:
FixFrameworkInstallPath(framework, new_path)
for library in broken_libs['libs']:
FixLibraryInstallPath(library, new_path)
2010-03-01 13:13:11 +01:00
def FixPlugin(abs_path, subdir):
broken_libs = GetBrokenLibraries(abs_path)
FixAllLibraries(broken_libs)
2010-03-01 13:13:11 +01:00
new_path = CopyPlugin(abs_path, subdir)
for framework in broken_libs['frameworks']:
FixFrameworkInstallPath(framework, new_path)
for library in broken_libs['libs']:
FixLibraryInstallPath(library, new_path)
def FixBinary(path):
broken_libs = GetBrokenLibraries(path)
FixAllLibraries(broken_libs)
for framework in broken_libs['frameworks']:
FixFrameworkInstallPath(framework, path)
for library in broken_libs['libs']:
FixLibraryInstallPath(library, path)
def CopyLibrary(path):
new_path = os.path.join(frameworks_dir, os.path.basename(path))
args = ['ditto', '--arch=x86_64', path, new_path]
2010-03-01 13:13:11 +01:00
commands.append(args)
return new_path
2010-03-01 13:13:11 +01:00
def CopyPlugin(path, subdir):
new_path = os.path.join(plugins_dir, subdir, os.path.basename(path))
args = ['mkdir', '-p', os.path.dirname(new_path)]
commands.append(args)
args = ['ditto', '--arch=x86_64', path, new_path]
2010-03-01 13:13:11 +01:00
commands.append(args)
return new_path
def CopyFramework(path):
parts = path.split(os.sep)
for i, part in enumerate(parts):
if re.match(r'\w+\.framework', part):
full_path = os.path.join(frameworks_dir, *parts[i:-1])
break
args = ['mkdir', '-p', full_path]
2010-03-01 13:13:11 +01:00
commands.append(args)
args = ['ditto', '--arch=x86_64', path, full_path]
2010-03-01 13:13:11 +01:00
commands.append(args)
menu_nib = os.path.join(os.path.split(path)[0], 'Resources', 'qt_menu.nib')
if os.path.exists(menu_nib):
args = ['cp', '-r', menu_nib, resources_dir]
commands.append(args)
return os.path.join(full_path, parts[-1])
def FixId(path, library_name):
id = '@executable_path/../Frameworks/%s' % library_name
args = ['install_name_tool', '-id', id, path]
2010-03-01 13:13:11 +01:00
commands.append(args)
def FixLibraryId(path):
library_name = os.path.basename(path)
FixId(path, library_name)
def FixFrameworkId(path, id):
FixId(path, id)
def FixInstallPath(library_path, library, new_path):
args = ['install_name_tool', '-change', library_path, new_path, library]
2010-03-01 13:13:11 +01:00
commands.append(args)
def FindSystemLibrary(library_name):
if 'iconv' in library_name:
return None
for path in ['/lib', '/usr/lib']:
full_path = os.path.join(path, library_name)
if os.path.exists(full_path):
return full_path
return None
def FixLibraryInstallPath(library_path, library):
system_library = FindSystemLibrary(os.path.basename(library_path))
if system_library is None:
new_path = '@executable_path/../Frameworks/%s' % os.path.basename(library_path)
FixInstallPath(library_path, library, new_path)
else:
FixInstallPath(library_path, library, system_library)
def FixFrameworkInstallPath(library_path, library):
parts = library_path.split(os.sep)
for i, part in enumerate(parts):
if re.match(r'\w+\.framework', part):
full_path = os.path.join(*parts[i:])
break
new_path = '@executable_path/../Frameworks/%s' % full_path
FixInstallPath(library_path, library, new_path)
def FindXinePlugin(name):
for path in XINEPLUGIN_SEARCH_PATH:
if os.path.exists(path):
for dir, dirs, files in os.walk(path):
if name in files:
return os.path.join(dir, name)
raise CouldNotFindXinePluginError(name)
2010-03-01 13:13:11 +01:00
def FindQtPlugin(name):
for path in QT_PLUGINS_SEARCH_PATH:
if os.path.exists(path):
if os.path.exists(os.path.join(path, name)):
return os.path.join(path, name)
raise CouldNotFindQtPluginError(name)
2010-04-12 14:36:30 +02:00
def FindGstreamerPlugin(name):
for path in GSTREAMER_SEARCH_PATH:
if os.path.exists(path):
for dir, dirs, files in os.walk(path):
if name in files:
return os.path.join(dir, name)
raise CouldNotFindGstreamerPluginError(name)
FixBinary(binary)
2010-04-12 14:36:30 +02:00
for plugin in GSTREAMER_PLUGINS:
FixPlugin(FindGstreamerPlugin(plugin), 'gstreamer')
FixPlugin(FindGstreamerPlugin('gst-plugin-scanner'), '.')
2010-03-01 13:13:11 +01:00
try:
FixPlugin('clementine-spotifyblob', '.')
2012-01-09 12:24:34 +01:00
FixPlugin('clementine-tagreader', '.')
except:
print 'Failed to find blob: %s' % traceback.format_exc()
2010-03-01 13:13:11 +01:00
for plugin in QT_PLUGINS:
FixPlugin(FindQtPlugin(plugin), os.path.dirname(plugin))
2010-04-15 21:09:39 +02:00
if len(sys.argv) <= 2:
2010-12-04 21:43:06 +01:00
print 'Would run %d commands:' % len(commands)
for command in commands:
print ' '.join(command)
2010-04-15 21:09:39 +02:00
print 'OK?'
raw_input()
2010-03-01 13:13:11 +01:00
for command in commands:
p = subprocess.Popen(command)
os.waitpid(p.pid, 0)