1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-11-06 19:12:30 +01:00
ScreenPlay/Tools/build.py

204 lines
7.5 KiB
Python
Raw Normal View History

from sys import platform
2021-09-04 21:50:34 +02:00
from concurrent.futures import ThreadPoolExecutor
import os
import sys
import subprocess
import shutil
import argparse
2021-08-08 19:31:50 +02:00
from execute_util import execute
# Based on https://gist.github.com/l2m2/0d3146c53c767841c6ba8c4edbeb4c2c
2021-08-08 19:31:50 +02:00
def vs_env_dict():
vsvar32 = 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Auxiliary\\Build\\vcvars64.bat'
cmd = [vsvar32, '&&', 'set']
popen = subprocess.Popen(
cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = popen.communicate()
if popen.wait() != 0:
raise ValueError(stderr.decode("mbcs"))
output = stdout.decode("mbcs").split("\r\n")
return dict((e[0].upper(), e[1]) for e in [p.rstrip().split("=", 1) for p in output] if len(e) == 2)
2021-09-04 21:50:34 +02:00
# Based on https://stackoverflow.com/questions/7207309/how-to-run-functions-in-parallel
2021-11-12 15:32:30 +01:00
2021-09-04 21:50:34 +02:00
def run_io_tasks_in_parallel(tasks):
with ThreadPoolExecutor() as executor:
running_tasks = [executor.submit(task) for task in tasks]
for running_task in running_tasks:
running_task.result()
# MAIN
parser = argparse.ArgumentParser(description='Build and Package ScreenPlay')
2021-08-14 12:44:32 +02:00
parser.add_argument('-t', action="store", dest="build_type",
help="Build type. This is either debug or release.")
parser.add_argument('-sign', action="store", dest="sign_build",
2021-11-12 15:32:30 +01:00
help="Enable if you want to sign the apps. This is macos only for now.")
parser.add_argument('-steam', action="store", dest="steam_build",
help="Enable if you want to build the Steam workshop plugin.")
2021-12-04 10:41:21 +01:00
parser.add_argument('-tests', action="store", dest="build_tests",
help="Build tests.")
parser.add_argument('-installer', action="store", dest="create_installer",
help="Create a installer.")
args = parser.parse_args()
if not args.build_type:
print("Build type argument is missing (release,debug). Example: python build.py -t release -steam=True")
sys.exit(1)
qt_version = "6.2.2"
steam_build = "OFF"
2021-12-04 10:41:21 +01:00
build_tests = "OFF"
create_installer = "OFF"
if args.steam_build:
2021-12-04 10:41:21 +01:00
steam_build = "ON"
if args.build_tests:
build_tests = "ON"
if args.create_installer:
create_installer = "ON"
print("Starting build with type %s. Qt Version: %s" %
(args.build_type, qt_version))
cmake_prefix_path = ""
cmake_target_triplet = ""
2020-11-08 15:17:59 +01:00
cmake_build_type = ""
executable_file_ending = ""
2020-11-08 15:17:59 +01:00
deploy_command = ""
2021-08-08 19:31:50 +02:00
if platform == "win32":
print("Loading MSVC env variables via vsvars32.bat")
2020-11-08 15:17:59 +01:00
cmake_build_type = args.build_type
2021-08-08 19:31:50 +02:00
windows_msvc = "msvc2019_64"
executable_file_ending = ".exe"
2020-11-08 15:17:59 +01:00
deploy_command = "windeployqt.exe --{type} --qmldir ../../{app}/qml {app}{executable_file_ending}"
dict = vs_env_dict()
2021-08-08 19:31:50 +02:00
dict["PATH"] = dict["PATH"] + ";C:\\Qt\\" + qt_version + \
"\\" + windows_msvc + "\\bin;C:\\Qt\\Tools\\QtCreator\\bin"
os.environ.update(dict)
cmake_prefix_path = "c:/Qt/" + qt_version + "/" + windows_msvc
cmake_target_triplet = "x64-windows"
elif platform == "darwin":
2021-11-12 15:32:30 +01:00
cmake_prefix_path = "~/Qt/" + qt_version + "/macos"
deploy_command = "{prefix_path}/bin/macdeployqt {app}.app -qmldir=../../{app}/qml -executable={app}.app/Contents/MacOS/{app}"
cmake_target_triplet = "x64-osx"
elif platform == "linux":
2021-12-04 10:41:21 +01:00
deploy_command = "cqtdeployer -qmlDir ../../{app}/qml -bin {app}"
2020-11-08 15:17:59 +01:00
cmake_prefix_path = "~/Qt/" + qt_version + "/gcc_64"
cmake_target_triplet = "x64-linux"
# REMOVE OLD BUILD FOLDER
cwd = os.getcwd()
root_path = os.path.abspath((cwd+"/../"))
os.chdir(root_path)
2021-08-08 19:31:50 +02:00
cmake_toolchain_file = (
"'{root_path}/../ScreenPlay-vcpkg/scripts/buildsystems/vcpkg.cmake'").format(root_path=root_path)
print("cmake_toolchain_file: %s " % cmake_toolchain_file)
2021-11-12 15:32:30 +01:00
build_folder = root_path + "/build-" + \
cmake_target_triplet + "-" + args.build_type
if os.path.isdir(build_folder):
print("Remove previous build folder: " + build_folder)
shutil.rmtree(build_folder)
os.mkdir(build_folder)
os.chdir(build_folder)
cmake_configure_command = """cmake ../
-DCMAKE_PREFIX_PATH={prefix_path}
-DCMAKE_BUILD_TYPE={type}
-DCMAKE_TOOLCHAIN_FILE={toolchain}
-DVCPKG_TARGET_TRIPLET={triplet}
-DSCREENPLAY_STEAM={steam}
2021-12-04 10:41:21 +01:00
-DSCREENPLAY_TESTS={tests}
-DSCREENPLAY_CREATE_INSTALLER={installer}
-G "CodeBlocks - Ninja"
-B.
""".format(
type=args.build_type,
prefix_path=cmake_prefix_path,
triplet=cmake_target_triplet,
toolchain=cmake_toolchain_file,
2021-12-04 10:41:21 +01:00
steam=steam_build,
tests = build_tests,
installer= create_installer
).replace("\n", "")
2021-08-08 19:31:50 +02:00
execute(cmake_configure_command)
execute("cmake --build . --target all")
os.chdir("bin")
2021-08-08 19:31:50 +02:00
execute(deploy_command.format(
type=cmake_build_type,
prefix_path=cmake_prefix_path,
app="ScreenPlay",
executable_file_ending=executable_file_ending))
2020-10-31 19:30:27 +01:00
2021-08-08 19:31:50 +02:00
execute(deploy_command.format(
type=cmake_build_type,
prefix_path=cmake_prefix_path,
app="ScreenPlayWidget",
executable_file_ending=executable_file_ending))
2020-10-31 19:30:27 +01:00
2021-08-08 19:31:50 +02:00
execute(deploy_command.format(
type=cmake_build_type,
prefix_path=cmake_prefix_path,
app="ScreenPlayWallpaper",
executable_file_ending=executable_file_ending))
2021-08-14 12:44:32 +02:00
if platform == "darwin" and args.sign_build:
execute("codesign --deep -f -s \"Developer ID Application: Elias Steurer (V887LHYKRH)\" --timestamp --options \"runtime\" -f --entitlements \"../../ScreenPlay/entitlements.plist\" --deep \"ScreenPlay.app/\"")
execute("codesign --deep -f -s \"Developer ID Application: Elias Steurer (V887LHYKRH)\" --timestamp --options \"runtime\" -f --deep \"ScreenPlayWallpaper.app/\"")
execute("codesign --deep -f -s \"Developer ID Application: Elias Steurer (V887LHYKRH)\" --timestamp --options \"runtime\" -f --deep \"ScreenPlayWidget.app/\"")
execute("codesign --verify --verbose=4 \"ScreenPlay.app/\"")
execute("codesign --verify --verbose=4 \"ScreenPlayWallpaper.app/\"")
execute("codesign --verify --verbose=4 \"ScreenPlayWidget.app/\"")
2021-09-04 21:50:34 +02:00
run_io_tasks_in_parallel([
2021-11-12 15:32:30 +01:00
lambda: execute(
"xcnotary notarize ScreenPlay.app -d kelteseth@gmail.com -k ScreenPlay"),
lambda: execute(
"xcnotary notarize ScreenPlayWallpaper.app -d kelteseth@gmail.com -k ScreenPlay"),
lambda: execute(
"xcnotary notarize ScreenPlayWidget.app -d kelteseth@gmail.com -k ScreenPlay")
2021-09-04 21:50:34 +02:00
])
2021-08-08 19:31:50 +02:00
execute("spctl --assess --verbose \"ScreenPlay.app/\"")
execute("spctl --assess --verbose \"ScreenPlayWallpaper.app/\"")
execute("spctl --assess --verbose \"ScreenPlayWidget.app/\"")
2021-10-03 17:45:44 +02:00
# Some dlls like openssl do no longer get copied automatically.
# Lets just copy all of them into bin.
if platform == "win32":
2021-11-12 15:32:30 +01:00
vcpkg_bin_path = os.path.abspath(
("{root_path}/../ScreenPlay-vcpkg/installed/x64-windows/bin").format(root_path=root_path))
2021-10-03 17:45:44 +02:00
print(vcpkg_bin_path)
for basename in os.listdir(vcpkg_bin_path):
if basename.endswith('.dll'):
pathname = os.path.join(vcpkg_bin_path, basename)
print(pathname, os.getcwd())
if os.path.isfile(pathname):
shutil.copy2(pathname, os.getcwd())
2021-08-08 19:31:50 +02:00
file_endings = [".ninja_deps", ".ninja", ".ninja_log", ".lib", ".a", ".dylib", ".exp",
".manifest", ".cmake", ".cbp", "CMakeCache.txt"]
for filename in os.listdir(os.getcwd()):
for ending in file_endings:
if filename.endswith(ending):
full_file_path = os.path.join(os.getcwd(), filename)
print("Remove: %s" % full_file_path)
os.remove(full_file_path)
2021-12-04 10:41:21 +01:00
if args.create_installer:
os.chdir("..")
execute("cpack")