2012-08-13 10:08:22 +00:00
|
|
|
#!/usr/bin/env python
|
2020-02-27 19:46:42 +00:00
|
|
|
from __future__ import print_function
|
2012-08-13 10:08:22 +00:00
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
import sys
|
2014-12-13 00:29:57 +00:00
|
|
|
import fileinput
|
2013-04-08 19:44:46 +00:00
|
|
|
from optparse import OptionParser
|
2012-08-13 10:08:22 +00:00
|
|
|
|
|
|
|
def sh(command):
|
2019-04-22 10:45:04 +00:00
|
|
|
return os.popen(command).read().strip()
|
2012-08-13 10:08:22 +00:00
|
|
|
|
2013-07-16 11:28:28 +00:00
|
|
|
def bundle_path(binary_name):
|
2012-08-13 10:08:22 +00:00
|
|
|
return "%s.app" % binary_name
|
|
|
|
|
2013-07-16 11:28:28 +00:00
|
|
|
def bundle_name(binary_name):
|
|
|
|
return os.path.basename(bundle_path(binary_name))
|
|
|
|
|
2013-04-08 19:44:46 +00:00
|
|
|
def target_plist(binary_name):
|
2013-07-16 11:28:28 +00:00
|
|
|
return os.path.join(bundle_path(binary_name), 'Contents', 'Info.plist')
|
2012-08-13 10:08:22 +00:00
|
|
|
|
2013-04-08 19:44:46 +00:00
|
|
|
def target_directory(binary_name):
|
2013-07-16 11:28:28 +00:00
|
|
|
return os.path.join(bundle_path(binary_name), 'Contents', 'MacOS')
|
2012-08-13 10:08:22 +00:00
|
|
|
|
2013-04-08 19:44:46 +00:00
|
|
|
def target_binary(binary_name):
|
2013-07-16 11:28:28 +00:00
|
|
|
return os.path.join(target_directory(binary_name),
|
|
|
|
os.path.basename(binary_name))
|
2012-08-13 10:08:22 +00:00
|
|
|
|
2013-04-08 19:44:46 +00:00
|
|
|
def copy_bundle(binary_name):
|
2013-07-16 11:28:28 +00:00
|
|
|
if os.path.isdir(bundle_path(binary_name)):
|
|
|
|
shutil.rmtree(bundle_path(binary_name))
|
2012-08-13 10:08:22 +00:00
|
|
|
shutil.copytree(
|
2013-04-08 19:44:46 +00:00
|
|
|
os.path.join('TOOLS', 'osxbundle', bundle_name(binary_name)),
|
2013-07-16 11:28:28 +00:00
|
|
|
bundle_path(binary_name))
|
2012-08-13 10:08:22 +00:00
|
|
|
|
2013-04-08 19:44:46 +00:00
|
|
|
def copy_binary(binary_name):
|
|
|
|
shutil.copy(binary_name, target_binary(binary_name))
|
2012-08-13 10:08:22 +00:00
|
|
|
|
|
|
|
def apply_plist_template(plist_file, version):
|
2014-12-13 00:29:57 +00:00
|
|
|
for line in fileinput.input(plist_file, inplace=1):
|
2020-02-27 19:46:42 +00:00
|
|
|
print(line.rstrip().replace('${VERSION}', version))
|
2012-08-13 10:08:22 +00:00
|
|
|
|
2017-09-29 16:17:32 +00:00
|
|
|
def create_bundle_symlink(binary_name, symlink_name):
|
|
|
|
os.symlink(os.path.basename(binary_name),
|
|
|
|
os.path.join(target_directory(binary_name), symlink_name))
|
|
|
|
|
2016-01-05 11:24:50 +00:00
|
|
|
def bundle_version():
|
|
|
|
if os.path.exists('VERSION'):
|
|
|
|
x = open('VERSION')
|
|
|
|
version = x.read()
|
|
|
|
x.close()
|
|
|
|
else:
|
|
|
|
version = sh("./version.sh").strip()
|
|
|
|
return version
|
|
|
|
|
2013-04-08 19:44:46 +00:00
|
|
|
def main():
|
2016-01-05 11:24:50 +00:00
|
|
|
version = bundle_version().rstrip()
|
2012-08-13 10:08:22 +00:00
|
|
|
|
2013-04-08 19:44:46 +00:00
|
|
|
usage = "usage: %prog [options] arg"
|
|
|
|
parser = OptionParser(usage)
|
|
|
|
parser.add_option("-s", "--skip-deps", action="store_false", dest="deps",
|
|
|
|
default=True,
|
|
|
|
help="don't bundle the dependencies")
|
|
|
|
|
|
|
|
(options, args) = parser.parse_args()
|
|
|
|
|
|
|
|
if len(args) != 1:
|
|
|
|
parser.error("incorrect number of arguments")
|
|
|
|
else:
|
|
|
|
binary_name = args[0]
|
|
|
|
|
|
|
|
print("Creating Mac OS X application bundle (version: %s)..." % version)
|
|
|
|
print("> copying bundle skeleton")
|
|
|
|
copy_bundle(binary_name)
|
|
|
|
print("> copying binary")
|
|
|
|
copy_binary(binary_name)
|
2017-09-29 16:17:32 +00:00
|
|
|
print("> create bundle symlink")
|
|
|
|
create_bundle_symlink(binary_name, "mpv-bundle")
|
2013-04-08 19:44:46 +00:00
|
|
|
print("> generating Info.plist")
|
|
|
|
apply_plist_template(target_plist(binary_name), version)
|
|
|
|
|
|
|
|
if options.deps:
|
|
|
|
print("> bundling dependencies")
|
2019-04-22 10:45:04 +00:00
|
|
|
print(sh(" ".join(["TOOLS/dylib-unhell.py", target_binary(binary_name)])))
|
2013-04-08 19:44:46 +00:00
|
|
|
|
|
|
|
print("done.")
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|