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

120 lines
4.7 KiB
Python
Raw Normal View History

2022-01-04 10:12:03 +01:00
#!/usr/bin/python3
2021-05-16 13:09:32 +02:00
import argparse
2022-01-04 10:12:03 +01:00
import shutil
from platform import system
from pathlib import Path
2021-05-16 13:09:32 +02:00
from execute_util import execute
from download_ffmpeg import download_prebuild_ffmpeg
2021-05-16 13:09:32 +02:00
2022-01-04 10:12:03 +01:00
vcpkg_version = "1085a57da0725c19e19586025438e8c16f34c890" # Master 31.12.2021
vcpkg_packages_list = [
"openssl",
"curl",
"sentry-native",
"doctest",
"benchmark",
"cpp-httplib"
]
class commands_list():
def __init__(self):
self.commands = []
def add(self, command, cwd=".", ignore_error=False, use_shell=True, print_command=True):
self.commands.append({
"command": command,
"cwd": cwd,
"ignore_error": ignore_error,
"use_shell": use_shell,
"print_command": print_command
})
def get_commands(self):
return self.commands
def execute_commands(self):
'''
This function execute all commands added to the list.
'''
for command in self.commands:
# Check if the command if a string.
if isinstance(command["command"], str):
execute(command["command"], command["cwd"], command["ignore_error"], command["use_shell"], command["print_command"])
else:
# Function call
command["command"]()
2021-05-16 13:09:32 +02:00
if __name__ == "__main__":
parser = argparse.ArgumentParser(
2022-01-04 10:12:03 +01:00
description='Install ScreenPlay dependencies.')
2021-05-16 13:09:32 +02:00
parser.add_argument(
2022-01-04 10:12:03 +01:00
'--path', help='Manually set the vcpkg path. The path must be an absolute path \
without the ScreenPlay-vcpkg folder (E.g. py .\setup.py --path "D:/Backup/Code/Qt/")')
2021-05-16 13:09:32 +02:00
args = parser.parse_args()
# ScreenPlay source and ScreenPlay-vcpkg have to be on the same file system hierarchy
project_source_parent_path = ""
2022-01-04 10:12:03 +01:00
project_source_path = Path.cwd().resolve()
if project_source_path.name == "Tools":
project_source_path = project_source_path.parent
2021-05-16 13:09:32 +02:00
2021-05-16 14:10:37 +02:00
if args.path is not None:
2022-01-04 10:12:03 +01:00
project_source_parent_path = Path(args.path).resolve()
2021-05-16 13:09:32 +02:00
else:
2022-01-04 10:12:03 +01:00
print("No --path provided, using default path.")
project_source_parent_path = project_source_path.parent
2021-05-16 13:09:32 +02:00
2022-01-04 10:12:03 +01:00
print("project_source_parent_path: {}".format(project_source_parent_path))
print("project_source_path: {}".format(project_source_path))
2021-05-16 13:09:32 +02:00
2022-01-04 10:12:03 +01:00
vcpkg_path = project_source_parent_path.joinpath("ScreenPlay-vcpkg")
2021-05-16 13:09:32 +02:00
print("vcpkg_path: ", vcpkg_path)
print("Build vcpkg ", vcpkg_version)
vcpkg_triplet = ""
2022-01-04 10:12:03 +01:00
vcpkg_command = ""
platform_command = commands_list()
2021-05-16 13:09:32 +02:00
2022-01-04 10:12:03 +01:00
if system() == "Windows":
2021-06-25 12:32:19 +02:00
vcpkg_command = "vcpkg.exe"
2021-05-16 13:09:32 +02:00
vcpkg_packages_list.append("infoware[d3d]")
2022-01-04 10:12:03 +01:00
if shutil.which("pwsh"):
print("Using experimental pwsh, may not work properly.")
platform_command.add("pwsh.exe -NoProfile -ExecutionPolicy Bypass .\scripts\\bootstrap.ps1", vcpkg_path)
else:
platform_command.add("bootstrap-vcpkg.bat", vcpkg_path, False)
platform_command.add("download_ffmpeg.bat", project_source_path.joinpath("Tools"), False)
2021-05-16 16:34:05 +02:00
vcpkg_triplet = "x64-windows"
2022-01-04 10:12:03 +01:00
elif system() == "Darwin":
2021-06-25 12:32:19 +02:00
vcpkg_command = "./vcpkg"
2021-05-16 13:09:32 +02:00
vcpkg_packages_list.append("infoware[opencl]")
vcpkg_packages_list.append("curl") # Hidden dependency from sentry
2022-01-04 10:12:03 +01:00
platform_command.add("chmod +x bootstrap-vcpkg.sh", vcpkg_path)
platform_command.add("./bootstrap-vcpkg.sh", vcpkg_path, False)
platform_command.add("chmod +x vcpkg", vcpkg_path)
2021-06-12 14:42:55 +02:00
vcpkg_triplet = "x64-osx"
2022-01-04 10:12:03 +01:00
platform_command.add(download_prebuild_ffmpeg)
elif system() == "Linux":
2021-06-25 12:32:19 +02:00
vcpkg_command = "./vcpkg"
#vcpkg_packages_list.append("infoware[opengl]")
2022-01-04 10:12:03 +01:00
platform_command.add("chmod +x bootstrap-vcpkg.sh", vcpkg_path)
platform_command.add("./bootstrap-vcpkg.sh", vcpkg_path, False)
platform_command.add("chmod +x vcpkg", vcpkg_path)
2021-06-12 14:42:55 +02:00
vcpkg_triplet = "x64-linux"
2022-01-04 10:12:03 +01:00
else:
raise NotImplementedError("Unknown system: {}".format(system()))
2021-05-16 13:09:32 +02:00
2022-01-04 10:12:03 +01:00
execute("git clone https://github.com/microsoft/vcpkg.git ScreenPlay-vcpkg", project_source_parent_path, True)
execute("git fetch", vcpkg_path)
execute("git checkout {}".format(vcpkg_version), vcpkg_path)
platform_command.execute_commands() # Execute platform specific commands.
2021-05-16 16:38:04 +02:00
vcpkg_packages = " ".join(vcpkg_packages_list)
2022-01-04 10:12:03 +01:00
execute("{} remove --outdated --recurse".format(vcpkg_command), vcpkg_path, False)
2021-06-25 12:32:19 +02:00
execute("{} update".format(vcpkg_command), vcpkg_path, False)
execute("{} upgrade --no-dry-run".format(vcpkg_command),
2021-05-16 13:09:32 +02:00
vcpkg_path, False)
2021-06-25 12:32:19 +02:00
execute("{} install {} --triplet {} --recurse".format(vcpkg_command,
2021-05-16 13:09:32 +02:00
vcpkg_packages, vcpkg_triplet), vcpkg_path, False)