diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..784af77 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +scripts/__pycache__ +CMakeLists.txt.user +Session.vim +graph_info.json diff --git a/base.mk b/base.mk index 3fd6653..c733693 100644 --- a/base.mk +++ b/base.mk @@ -8,12 +8,12 @@ else HOST_ENV=${OS}-$(shell uname -m) endif -SCRIPTS=scripts -SETUP_BUILD=python3 ./${SCRIPTS}/setup-build.py +SCRIPTS=${BUILDCORE_PATH}/scripts +SETUP_BUILD=python3 ${SCRIPTS}/setup-build.py PYBB=python3 ${SCRIPTS}/pybb.py CMAKE_BUILD=${PYBB} cmake-build RM_RF=${PYBB} rm -SETUP_BUILD=python3 ./${SCRIPTS}/setup-build.py +SETUP_BUILD=python3 ${SCRIPTS}/setup-build.py PYBB=python3 ${SCRIPTS}/pybb.py CMAKE_BUILD=${PYBB} cmake-build RM_RF=${PYBB} rm diff --git a/scripts/pybb.py b/scripts/pybb.py new file mode 100644 index 0000000..e30894e --- /dev/null +++ b/scripts/pybb.py @@ -0,0 +1,46 @@ +#! /usr/bin/env python3 + +# "Python Busy Box" - adds cross platform equivalents to Unix commands that +# don't translate well to that other operating system + +import os +import shutil +import subprocess +import sys + + +def mkdir(path): + if not os.path.exists(path) and os.path.isdir(path): + os.mkdir(path) + +# this exists because Windows is utterly incapable of providing a proper rm -rf +def rm(path): + if (os.path.exists(path) or os.path.islink(path)) and not os.path.isdir(path): + os.remove(path) + elif os.path.isdir(path): + shutil.rmtree(path) + +def cmake_build(base_path, target): + for d in os.listdir(base_path): + args = ['cmake', '--build', os.path.join(base_path, d), '--target'] + if target is not None: + args.append(target) + err = subprocess.run(args).returncode + if err != 0: + sys.exit(err) + +def main(): + if sys.argv[1] == 'mkdir': + mkdir(sys.argv[2]) + elif sys.argv[1] == 'rm': + for i in range(2, len(sys.argv)): + rm(sys.argv[i]) + elif sys.argv[1] == 'cmake-build': + cmake_build(sys.argv[2], sys.argv[3] if len(sys.argv) > 3 else None) + +if __name__ == '__main__': + try: + main() + except KeyboardInterrupt: + sys.exit(1) + diff --git a/scripts/setup-build.py b/scripts/setup-build.py new file mode 100755 index 0000000..86f6fb4 --- /dev/null +++ b/scripts/setup-build.py @@ -0,0 +1,86 @@ +#! /usr/bin/env python3 + +import argparse +import os +import platform +import shutil +import subprocess +import sys + +from pybb import mkdir, rm + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('--target', help='Platform target', + default='{:s}-{:s}'.format(sys.platform, platform.machine())) + parser.add_argument('--build_type', help='Build type (asan,debug,release)', default='release') + parser.add_argument('--build_tool', help='Build tool (default,xcode)', default='') + parser.add_argument('--toolchain', help='Path to CMake toolchain file') + parser.add_argument('--current_build', help='Indicates whether or not to make this the active build', default=1) + args = parser.parse_args() + + if args.build_type == 'asan': + build_type_arg = 'Debug' + sanitizer_status = 'ON' + elif args.build_type == 'debug': + build_type_arg = 'Debug' + sanitizer_status = 'OFF' + elif args.build_type == 'release': + build_type_arg = 'Release' + sanitizer_status = 'OFF' + else: + print('Error: Invalid build tool') + sys.exit(1) + + if args.build_tool == 'xcode': + build_config = '{:s}-{:s}'.format(args.target, args.build_tool) + else: + build_config = '{:s}-{:s}'.format(args.target, args.build_type) + + if 'QTDIR' in os.environ: + qt_path = '-DQTDIR={:s}'.format(os.environ['QTDIR']) + else: + qt_path = '' + + if args.build_tool == '' or args.build_tool == 'default': + if shutil.which('ninja') is None: + build_tool = '' + else: + build_tool = '-GNinja' + elif args.build_tool == 'xcode': + build_tool = '-GXcode' + else: + print('Error: Invalid build tool') + sys.exit(1) + + project_dir = os.getcwd() + build_dir = '{:s}/build/{:s}'.format(project_dir, build_config) + rm(build_dir) + mkdir(build_dir) + subprocess.run(['cmake', '-S', project_dir, '-B', build_dir, build_tool, + '-DCMAKE_EXPORT_COMPILE_COMMANDS=ON', + '-DCMAKE_TOOLCHAIN_FILE={:s}'.format(args.toolchain), + '-DCMAKE_BUILD_TYPE={:s}'.format(build_type_arg), + '-DUSE_ASAN={:s}'.format(sanitizer_status), + '-DBUILDCORE_BUILD_CONFIG={:s}'.format(build_config), + '-DBUILDCORE_TARGET={:s}'.format(args.target), + qt_path, + ]) + + mkdir('dist') + if int(args.current_build) != 0: + cb = open('.current_build', 'w') + cb.write(args.build_type) + cb.close() + + rm('compile_commands.json') + if platform.system() != 'Windows': + os.symlink('build/{:s}/compile_commands.json'.format(build_config), 'compile_commands.json') + + +if __name__ == '__main__': + try: + main() + except KeyboardInterrupt: + sys.exit(1)