wip updating build script
This commit is contained in:
parent
522c304b32
commit
49b23040c6
1 changed files with 51 additions and 20 deletions
69
build.py
69
build.py
|
@ -1,16 +1,26 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
import click
|
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import shutil
|
import shutil
|
||||||
import zipfile
|
import zipfile
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
|
import click
|
||||||
|
|
||||||
|
|
||||||
SCRIPT_PATH = os.path.dirname(os.path.abspath(__file__))
|
SCRIPT_PATH = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
|
||||||
|
def platform():
|
||||||
|
""" a name for the platform """
|
||||||
|
if sys.platform.startswith('win'):
|
||||||
|
return 'win'
|
||||||
|
elif sys.platform == 'darwin':
|
||||||
|
return 'osx'
|
||||||
|
elif sys.platform.startswith('linux'):
|
||||||
|
return 'linux'
|
||||||
|
raise Exception('Unsupported platform ' + sys.platform)
|
||||||
|
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def cd(new_dir):
|
def cd(new_dir):
|
||||||
|
@ -26,16 +36,41 @@ def cd(new_dir):
|
||||||
def mkdir_p(path):
|
def mkdir_p(path):
|
||||||
""" mkdir -p """
|
""" mkdir -p """
|
||||||
if not os.path.isdir(path):
|
if not os.path.isdir(path):
|
||||||
|
click.secho('Making ' + path, fg='yellow')
|
||||||
os.makedirs(path)
|
os.makedirs(path)
|
||||||
|
|
||||||
|
|
||||||
|
@click.group(invoke_without_command=True)
|
||||||
|
@click.pass_context
|
||||||
|
@click.option('--clean', is_flag=True)
|
||||||
|
def cli(ctx, clean):
|
||||||
|
if ctx.invoked_subcommand is None:
|
||||||
|
ctx.invoke(libs, clean=clean)
|
||||||
|
ctx.invoke(archive)
|
||||||
|
|
||||||
|
|
||||||
|
@cli.command()
|
||||||
|
def unity():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@cli.command()
|
||||||
|
def unreal():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def build_lib(build_name, generator, options):
|
def build_lib(build_name, generator, options):
|
||||||
|
""" Create a dir under builds, run build and install in it """
|
||||||
build_path = os.path.join(SCRIPT_PATH, 'builds', build_name)
|
build_path = os.path.join(SCRIPT_PATH, 'builds', build_name)
|
||||||
install_path = os.path.join(SCRIPT_PATH, 'builds', 'install', build_name)
|
install_path = os.path.join(SCRIPT_PATH, 'builds', 'install', build_name)
|
||||||
mkdir_p(build_path)
|
mkdir_p(build_path)
|
||||||
mkdir_p(install_path)
|
mkdir_p(install_path)
|
||||||
with cd(build_path):
|
with cd(build_path):
|
||||||
initial_cmake = ['cmake', SCRIPT_PATH, '-DCMAKE_INSTALL_PREFIX=%s' % os.path.join('..', 'install', build_name)]
|
initial_cmake = [
|
||||||
|
'cmake',
|
||||||
|
SCRIPT_PATH,
|
||||||
|
'-DCMAKE_INSTALL_PREFIX=%s' % os.path.join('..', 'install', build_name)
|
||||||
|
]
|
||||||
if generator:
|
if generator:
|
||||||
initial_cmake.extend(['-G', generator])
|
initial_cmake.extend(['-G', generator])
|
||||||
for key in options:
|
for key in options:
|
||||||
|
@ -46,8 +81,9 @@ def build_lib(build_name, generator, options):
|
||||||
subprocess.check_call(['cmake', '--build', '.', '--config', 'Release', '--target', 'install'])
|
subprocess.check_call(['cmake', '--build', '.', '--config', 'Release', '--target', 'install'])
|
||||||
|
|
||||||
|
|
||||||
def create_archive():
|
@cli.command()
|
||||||
archive_file_path = os.path.join(SCRIPT_PATH, 'builds', 'discord-rpc-%s.zip' % sys.platform)
|
def archive():
|
||||||
|
archive_file_path = os.path.join(SCRIPT_PATH, 'builds', 'discord-rpc-%s.zip' % platform())
|
||||||
archive_file = zipfile.ZipFile(archive_file_path, 'w', zipfile.ZIP_DEFLATED)
|
archive_file = zipfile.ZipFile(archive_file_path, 'w', zipfile.ZIP_DEFLATED)
|
||||||
archive_src_base_path = os.path.join(SCRIPT_PATH, 'builds', 'install')
|
archive_src_base_path = os.path.join(SCRIPT_PATH, 'builds', 'install')
|
||||||
archive_dst_base_path = 'discord-rpc'
|
archive_dst_base_path = 'discord-rpc'
|
||||||
|
@ -58,9 +94,9 @@ def create_archive():
|
||||||
archive_file.write(fpath, os.path.normpath(os.path.join(archive_dst_base_path, fpath)))
|
archive_file.write(fpath, os.path.normpath(os.path.join(archive_dst_base_path, fpath)))
|
||||||
|
|
||||||
|
|
||||||
@click.command()
|
@cli.command()
|
||||||
@click.option('--clean', is_flag=True)
|
@click.option('--clean', is_flag=True)
|
||||||
def main(clean):
|
def libs(clean):
|
||||||
os.chdir(SCRIPT_PATH)
|
os.chdir(SCRIPT_PATH)
|
||||||
|
|
||||||
if clean:
|
if clean:
|
||||||
|
@ -68,27 +104,22 @@ def main(clean):
|
||||||
|
|
||||||
mkdir_p('builds')
|
mkdir_p('builds')
|
||||||
|
|
||||||
if sys.platform.startswith('win'):
|
plat = platform()
|
||||||
|
|
||||||
|
if plat == 'win':
|
||||||
generator32 = 'Visual Studio 14 2015'
|
generator32 = 'Visual Studio 14 2015'
|
||||||
generator64 = 'Visual Studio 14 2015 Win64'
|
generator64 = 'Visual Studio 14 2015 Win64'
|
||||||
|
|
||||||
build_lib('win32-static', generator32, {})
|
build_lib('win32-static', generator32, {})
|
||||||
build_lib('win32-dynamic', generator32, {'BUILD_SHARED_LIBS': True, 'USE_STATIC_CRT': True})
|
build_lib('win32-dynamic', generator32, {'BUILD_SHARED_LIBS': True, 'USE_STATIC_CRT': True})
|
||||||
build_lib('win64-static', generator64, {})
|
build_lib('win64-static', generator64, {})
|
||||||
build_lib('win64-dynamic', generator64, {'BUILD_SHARED_LIBS': True, 'USE_STATIC_CRT': True})
|
build_lib('win64-dynamic', generator64, {'BUILD_SHARED_LIBS': True, 'USE_STATIC_CRT': True})
|
||||||
|
elif plat == 'osx':
|
||||||
# todo: this in some better way
|
|
||||||
src_dll = os.path.join(SCRIPT_PATH, 'builds', 'win64-dynamic', 'src', 'Release', 'discord-rpc.dll')
|
|
||||||
dst_dll = os.path.join(SCRIPT_PATH, 'examples', 'button-clicker', 'Assets', 'Resources', 'discord-rpc.dll')
|
|
||||||
shutil.copy(src_dll, dst_dll)
|
|
||||||
dst_dll = os.path.join(SCRIPT_PATH, 'examples', 'unrealstatus', 'Plugins', 'discordrpc', 'Binaries', 'ThirdParty', 'discordrpcLibrary', 'Win64', 'discord-rpc.dll')
|
|
||||||
shutil.copy(src_dll, dst_dll)
|
|
||||||
elif sys.platform == 'darwin':
|
|
||||||
build_lib('osx-static', None, {})
|
build_lib('osx-static', None, {})
|
||||||
build_lib('osx-dynamic', None, {'BUILD_SHARED_LIBS': True})
|
build_lib('osx-dynamic', None, {'BUILD_SHARED_LIBS': True})
|
||||||
|
elif plat == 'linux':
|
||||||
create_archive()
|
build_lib('linux-static', None, {})
|
||||||
|
build_lib('linux-dynamic', None, {'BUILD_SHARED_LIBS': True})
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
sys.exit(main())
|
sys.exit(cli())
|
||||||
|
|
Loading…
Reference in a new issue