-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsetup.py
73 lines (59 loc) · 2.38 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import argparse
import os
import subprocess
import shutil
import glob
def run_command(command, shell=True, cwd=None):
if os.name == 'nt': # Check if the OS is Windows
command = f'powershell.exe -Command "{command}"'
result = subprocess.run(command, shell=shell, check=True, text=True, cwd=cwd)
return result
def main():
parser = argparse.ArgumentParser(description="CMake Build and Test Script")
parser.add_argument('--platform', required=True, choices=['linux_x64', 'linux_x86', 'osx', 'win32', 'win64', 'uwp'], help='Platform to build for')
parser.add_argument('--cfg', default='Debug', choices=['Release', 'Debug'], help='Configuration Type')
parser.add_argument('--build', action='store_true', help='Execute the build step')
parser.add_argument('--test', action='store_true', help='Execute the test step')
parser.add_argument('--coverage', action='store_true', help='Generate code coverage report')
args = parser.parse_args()
build_output_dir = os.path.join(os.getcwd(), 'build')
os.makedirs(build_output_dir, exist_ok=True)
# Configure
cmake_command = f'cmake -B {build_output_dir} -S {os.getcwd()}'
if args.platform == 'osx':
cmake_command += ' -G "Xcode"'
if args.platform:
cmake_command += f' -DPLATFORM:STRING={args.platform}'
if args.coverage:
cmake_command += ' -DENABLE_COVERAGE=ON'
run_command(cmake_command)
# Build
if args.build:
run_command(f'cmake --build {build_output_dir} --config {args.cfg}')
else:
exit(0)
# Test
if args.test:
run_command(f'ctest --build-config {args.cfg} --verbose --output-on-failure', cwd=build_output_dir)
else:
exit(0)
# Code Coverage
if args.coverage:
# Prepare coverage data
run_command(f'cmake --build {build_output_dir} --target cov', cwd=build_output_dir)
# Package Build Artifacts
package_dir = os.path.join(build_output_dir, 'package')
os.makedirs(package_dir, exist_ok=True)
files_to_copy = glob.glob(f'{build_output_dir}/{args.cfg}/*GameAnalytics.*')
for file in files_to_copy:
shutil.copy(file, package_dir)
shutil.copytree(os.path.join(os.getcwd(), 'include'), os.path.join(package_dir, 'include'), dirs_exist_ok=True)
# Print Package Contents
if args.platform.startswith('win'):
run_command(f'dir {package_dir}', shell=True)
else:
run_command(f'ls -la {package_dir}', shell=True)
if args.platform == 'osx':
run_command(f'lipo -info {package_dir}/*GameAnalytics.*')
if __name__ == "__main__":
main()