2017-09-14 15:59:32 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2017-09-07 16:05:41 +00:00
|
|
|
import click
|
2017-08-30 22:17:47 +00:00
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
import shutil
|
2017-09-07 16:05:41 +00:00
|
|
|
import zipfile
|
2017-08-30 22:17:47 +00:00
|
|
|
from contextlib import contextmanager
|
|
|
|
|
|
|
|
|
|
|
|
SCRIPT_PATH = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
|
|
|
|
|
|
|
|
@contextmanager
|
|
|
|
def cd(new_dir):
|
|
|
|
""" Temporarily change current directory """
|
|
|
|
if new_dir:
|
|
|
|
old_dir = os.getcwd()
|
|
|
|
os.chdir(new_dir)
|
|
|
|
yield
|
|
|
|
if new_dir:
|
|
|
|
os.chdir(old_dir)
|
|
|
|
|
|
|
|
|
|
|
|
def mkdir_p(path):
|
|
|
|
""" mkdir -p """
|
|
|
|
if not os.path.isdir(path):
|
|
|
|
os.makedirs(path)
|
|
|
|
|
|
|
|
|
2017-09-07 16:05:41 +00:00
|
|
|
def build_lib(build_name, generator, options):
|
|
|
|
build_path = os.path.join(SCRIPT_PATH, 'builds', build_name)
|
|
|
|
install_path = os.path.join(SCRIPT_PATH, 'builds', 'install', build_name)
|
2017-08-30 22:17:47 +00:00
|
|
|
mkdir_p(build_path)
|
2017-09-07 16:05:41 +00:00
|
|
|
mkdir_p(install_path)
|
2017-08-30 22:17:47 +00:00
|
|
|
with cd(build_path):
|
2017-09-07 16:05:41 +00:00
|
|
|
initial_cmake = ['cmake', SCRIPT_PATH, '-DCMAKE_INSTALL_PREFIX=%s' % os.path.join('..', 'install', build_name)]
|
2017-08-30 22:17:47 +00:00
|
|
|
if generator:
|
|
|
|
initial_cmake.extend(['-G', generator])
|
|
|
|
for key in options:
|
|
|
|
val = 'ON' if options[key] else 'OFF'
|
|
|
|
initial_cmake.append('-D%s=%s' %(key, val))
|
|
|
|
subprocess.check_call(initial_cmake)
|
|
|
|
subprocess.check_call(['cmake', '--build', '.', '--config', 'Debug'])
|
2017-09-07 16:05:41 +00:00
|
|
|
subprocess.check_call(['cmake', '--build', '.', '--config', 'Release', '--target', 'install'])
|
2017-08-30 22:17:47 +00:00
|
|
|
|
|
|
|
|
2017-09-07 16:05:41 +00:00
|
|
|
def create_archive():
|
2017-09-14 15:59:32 +00:00
|
|
|
archive_file_path = os.path.join(SCRIPT_PATH, 'builds', 'discord-rpc-%s.zip' % sys.platform)
|
2017-09-07 16:05:41 +00:00
|
|
|
archive_file = zipfile.ZipFile(archive_file_path, 'w', zipfile.ZIP_DEFLATED)
|
|
|
|
archive_src_base_path = os.path.join(SCRIPT_PATH, 'builds', 'install')
|
|
|
|
archive_dst_base_path = 'discord-rpc'
|
|
|
|
with cd(archive_src_base_path):
|
|
|
|
for path, subdirs, filenames in os.walk('.'):
|
|
|
|
for fname in filenames:
|
|
|
|
fpath = os.path.join(path, fname)
|
|
|
|
archive_file.write(fpath, os.path.normpath(os.path.join(archive_dst_base_path, fpath)))
|
|
|
|
|
|
|
|
|
|
|
|
@click.command()
|
|
|
|
@click.option('--clean', is_flag=True)
|
|
|
|
def main(clean):
|
2017-08-30 22:17:47 +00:00
|
|
|
os.chdir(SCRIPT_PATH)
|
2017-09-07 16:05:41 +00:00
|
|
|
|
|
|
|
if clean:
|
|
|
|
shutil.rmtree('builds', ignore_errors=True)
|
|
|
|
|
2017-09-14 15:59:32 +00:00
|
|
|
mkdir_p('builds')
|
|
|
|
|
2017-08-30 22:17:47 +00:00
|
|
|
if sys.platform.startswith('win'):
|
2017-09-07 16:05:41 +00:00
|
|
|
generator32 = 'Visual Studio 14 2015'
|
|
|
|
generator64 = 'Visual Studio 14 2015 Win64'
|
|
|
|
|
|
|
|
build_lib('win32-static', generator32, {})
|
|
|
|
build_lib('win32-dynamic', generator32, {'BUILD_DYNAMIC_LIB': True})
|
|
|
|
build_lib('win64-static', generator64, {})
|
|
|
|
build_lib('win64-dynamic', generator64, {'BUILD_DYNAMIC_LIB': True})
|
|
|
|
|
2017-08-30 22:17:47 +00:00
|
|
|
# todo: this in some better way
|
|
|
|
src_dll = os.path.join(SCRIPT_PATH, 'builds', 'win64-dynamic', 'src', 'Release', 'discord-rpc.dll')
|
2017-09-07 16:05:41 +00:00
|
|
|
dst_dll = os.path.join(SCRIPT_PATH, 'examples', 'button-clicker', 'Assets', 'Resources', 'discord-rpc.dll')
|
2017-08-30 22:17:47 +00:00
|
|
|
shutil.copy(src_dll, dst_dll)
|
2017-09-07 16:05:41 +00:00
|
|
|
dst_dll = os.path.join(SCRIPT_PATH, 'examples', 'unrealstatus', 'Plugins', 'discordrpc', 'Binaries', 'ThirdParty', 'discordrpcLibrary', 'Win64', 'discord-rpc.dll')
|
2017-08-30 22:17:47 +00:00
|
|
|
shutil.copy(src_dll, dst_dll)
|
2017-09-14 15:59:32 +00:00
|
|
|
elif sys.platform == 'darwin':
|
|
|
|
build_lib('osx-static', None, {})
|
|
|
|
build_lib('osx-dynamic', None, {'BUILD_DYNAMIC_LIB': True})
|
2017-08-30 22:17:47 +00:00
|
|
|
|
2017-09-07 16:05:41 +00:00
|
|
|
create_archive()
|
|
|
|
|
2017-08-30 22:17:47 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2017-09-14 15:59:32 +00:00
|
|
|
sys.exit(main())
|