mirror of
https://gitlab.com/kelteseth/ScreenPlay.git
synced 2024-11-05 18:42:29 +01:00
Refacot setup and formatting tools
This commit is contained in:
parent
e54e0c2acb
commit
20be6ba4a9
@ -1,28 +1,25 @@
|
||||
# Developer Setup
|
||||
1. Install latest [git + git-lfs](https://git-scm.com/)
|
||||
2. Clone ScreenPlay
|
||||
2. Install [python 3](https://www.python.org/)
|
||||
3. Clone ScreenPlay
|
||||
``` bash
|
||||
git clone --recursive https://gitlab.com/kelteseth/ScreenPlay.git ScreenPlay
|
||||
```
|
||||
3. Download the latest __Qt 5.15.x__ for you platform. Earlier versions are not supported!
|
||||
4. Download the latest __Qt 5.15.x__ for you platform. Earlier versions are not supported!
|
||||
1. [Install instructions Windows](#windows)
|
||||
1. [Install instructions Linux](#linux)
|
||||
1. [Install instructions MacOSX](#macosx)
|
||||
4. Start the following script to download all needed dependencies automatically. This will create a ScreenPlay-vcpkg folder in the same directory as your ScreenPlay source folder.
|
||||
5. Start the following script to download all needed dependencies automatically. This will create a ScreenPlay-vcpkg folder in the same directory as your ScreenPlay source folder.
|
||||
``` bash
|
||||
# Windows
|
||||
cd Tools
|
||||
.\install_dependencies_windows.bat
|
||||
|
||||
# Linux and MacOSX
|
||||
cd Tools
|
||||
chmod +x install_dependencies_linux_mac.sh
|
||||
.\install_dependencies_linux_mac.sh
|
||||
py setup.py
|
||||
```
|
||||
* This will install these dependencies via __vcpkg__
|
||||
* openSSL 1.1.1d
|
||||
* sentry-native
|
||||
* doctest
|
||||
* benchmark
|
||||
* infoware
|
||||
|
||||
<div>
|
||||
<img width="100%" height="auto" src="../.gitlab/media/QtCreator_kit.png">
|
||||
|
30
Tools/clang_format.py
Normal file
30
Tools/clang_format.py
Normal file
@ -0,0 +1,30 @@
|
||||
import os
|
||||
import subprocess
|
||||
import argparse
|
||||
from format_util import find_files
|
||||
from format_util import check_git_exit
|
||||
from format_util import execute_threaded
|
||||
|
||||
|
||||
def format_file_function(file):
|
||||
executable = "clang-format"
|
||||
if os.name == 'nt':
|
||||
executable = "clang-format.exe"
|
||||
process = subprocess.run(" %s -style=file -i %s" %
|
||||
(executable, file), capture_output=True, shell=True)
|
||||
print("Format: %s \t return: %s" % (file, process.returncode))
|
||||
|
||||
|
||||
def main(git_staged_only=False):
|
||||
file_list = find_files(('.cpp', '.h'), "", git_staged_only)
|
||||
execute_threaded(file_list, format_file_function)
|
||||
if not git_staged_only:
|
||||
check_git_exit("Clang Format")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('-s', action="store_true", dest="stage_only",
|
||||
default=False)
|
||||
args = parser.parse_args()
|
||||
main(args.stage_only)
|
25
Tools/cmake_format.py
Normal file
25
Tools/cmake_format.py
Normal file
@ -0,0 +1,25 @@
|
||||
import os
|
||||
import argparse
|
||||
from format_util import find_files
|
||||
from format_util import check_git_exit
|
||||
from format_util import execute_threaded
|
||||
|
||||
def format_file_function(file):
|
||||
executable = "cmake-format"
|
||||
if os.name == 'nt':
|
||||
executable = "cmake-format.exe"
|
||||
os.system(" %s -c ../.cmake-format.py -i %s" % (executable, file))
|
||||
print("Format: ", file)
|
||||
|
||||
def main(git_staged_only=False):
|
||||
file_list = find_files(('CMakeLists.txt'), "", git_staged_only)
|
||||
execute_threaded(file_list, format_file_function)
|
||||
if not git_staged_only:
|
||||
check_git_exit("CMake Format")
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('-s', action="store_true", dest="stage_only",
|
||||
default=False)
|
||||
args = parser.parse_args()
|
||||
main(args.stage_only)
|
@ -1,20 +1,4 @@
|
||||
git submodule update --init
|
||||
git submodule update --recursive
|
||||
cd ..
|
||||
cd ..
|
||||
git clone https://github.com/microsoft/vcpkg.git ScreenPlay-vcpkg
|
||||
cd ScreenPlay-vcpkg
|
||||
git pull
|
||||
rem master 12.05.2021 - 7b1016e10ef0434fe7045d320a9ee05b63e0efe9
|
||||
git checkout 7b1016e10ef0434fe7045d320a9ee05b63e0efe9
|
||||
call bootstrap-vcpkg.bat
|
||||
|
||||
rem Install vcpkg dependencies
|
||||
vcpkg.exe install openssl sentry-native doctest benchmark infoware[d3d] --triplet x64-windows --recurse
|
||||
vcpkg.exe upgrade --no-dry-run
|
||||
|
||||
cd ..
|
||||
cd ScreenPlay
|
||||
|
||||
rem Download 7-zip
|
||||
curl.exe -L https://www.7-zip.org/a/7z1900.msi --ssl-no-revoke --output 7z.msi
|
38
Tools/execute_util.py
Normal file
38
Tools/execute_util.py
Normal file
@ -0,0 +1,38 @@
|
||||
import subprocess
|
||||
|
||||
# Python program to print
|
||||
# colored text and background
|
||||
def printRed(skk): print("\033[91m {}\033[0;37;40m" .format(skk))
|
||||
def printGreen(skk): print("\033[92m {}\033[0;37;40m" .format(skk))
|
||||
def printYellow(skk): print("\033[93m {}\033[0;37;40m" .format(skk))
|
||||
def printLightPurple(skk): print("\033[94m {}\033[0;37;40m" .format(skk))
|
||||
def printPurple(skk): print("\033[95m {}\033[0;37;40m" .format(skk))
|
||||
def printCyan(skk): print("\033[96m {}\033[0;37;40m" .format(skk))
|
||||
def printLightGray(skk): print("\033[97m {}\033[0;37;40m" .format(skk))
|
||||
def printBlack(skk): print("\033[98m {}\033[0;37;40m" .format(skk))
|
||||
|
||||
def execute(command, workingDir=".", ignore_error=False, use_shell=True):
|
||||
process = subprocess.Popen(
|
||||
command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=use_shell, cwd=workingDir)
|
||||
|
||||
while True:
|
||||
if process.poll() is not None:
|
||||
break
|
||||
byte_line = process.stdout.readline()
|
||||
text_line = byte_line.decode('utf8', errors='ignore')
|
||||
if text_line:
|
||||
if ' warning' in text_line.lower():
|
||||
printYellow(text_line.strip())
|
||||
elif ' error' in text_line.lower():
|
||||
printRed(text_line.strip())
|
||||
else:
|
||||
print(text_line.strip())
|
||||
|
||||
process.communicate()
|
||||
exitCode = process.returncode
|
||||
if exitCode and ignore_error:
|
||||
printYellow("Ignore error ")
|
||||
return
|
||||
|
||||
if exitCode:
|
||||
raise subprocess.CalledProcessError(exitCode, command)
|
@ -1,17 +0,0 @@
|
||||
import fnmatch
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
|
||||
for root, dirnames, filenames in os.walk('..'):
|
||||
for filename in fnmatch.filter(filenames, 'CMakeLists.txt'):
|
||||
print("cmake-format -c ../.cmake-format.py -i " + root + "/" + filename)
|
||||
os.system("cmake-format -c ../.cmake-format.py -i %s" % ((root + "/" + filename)))
|
||||
|
||||
# Check if all files are formatter
|
||||
output = subprocess.check_output("git diff", shell=True)
|
||||
|
||||
if output:
|
||||
print("Git diff is not empty. This means your CMakeLists.txt file was not formatted!")
|
||||
#print(output)
|
||||
sys.exit(1)
|
@ -1,22 +0,0 @@
|
||||
import fnmatch
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
|
||||
executable = "clang-format"
|
||||
if os.name == 'nt':
|
||||
executable += ".exe"
|
||||
|
||||
for root, dirnames, files in os.walk('../'):
|
||||
for filename in files:
|
||||
if filename.endswith(('.cpp', '.h')):
|
||||
print(executable, root+"/"+filename)
|
||||
os.system(" %s -style=file -i %s" % (executable, (root + "/" + filename)))
|
||||
|
||||
# Check if all files are formatter
|
||||
output = subprocess.check_output("git diff", shell=True)
|
||||
|
||||
if output:
|
||||
print("Git diff is not empty. This means your code was not formatted via %s!" % executable)
|
||||
print(output)
|
||||
sys.exit(1)
|
90
Tools/format_util.py
Normal file
90
Tools/format_util.py
Normal file
@ -0,0 +1,90 @@
|
||||
import subprocess
|
||||
import sys
|
||||
import os
|
||||
from multiprocessing import cpu_count
|
||||
from multiprocessing import Pool
|
||||
from multiprocessing import dummy
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def find_all_files(path) -> []:
|
||||
file_list = []
|
||||
for root, dirnames, files in os.walk(path):
|
||||
for filename in files:
|
||||
file_list.append(os.path.join(root, filename))
|
||||
return file_list
|
||||
|
||||
|
||||
def find_all_git_staged_files() -> []:
|
||||
process = subprocess.run("git diff --name-only --staged",
|
||||
capture_output=True, shell=True)
|
||||
out = process.stdout.decode("utf-8")
|
||||
out = out.splitlines()
|
||||
return out
|
||||
|
||||
|
||||
def find_files(file_endings_tuple, path="", git_staged_only=False) -> []:
|
||||
file_list = []
|
||||
# Get the root folder by moving one up
|
||||
root = Path(__file__).parent.absolute()
|
||||
root = os.path.abspath(os.path.join(root, "../"))
|
||||
|
||||
root = os.path.join(root, path)
|
||||
print(root)
|
||||
|
||||
if git_staged_only:
|
||||
file_list = find_all_git_staged_files()
|
||||
else:
|
||||
file_list = find_all_files(root)
|
||||
|
||||
filtered_file_list = []
|
||||
for filename in file_list:
|
||||
if filename.endswith(file_endings_tuple):
|
||||
filtered_file_list.append(os.path.join(root, filename))
|
||||
|
||||
return filtered_file_list
|
||||
|
||||
|
||||
def execute_threaded(file_list, format_file_function):
|
||||
p = Pool(cpu_count())
|
||||
p.map(format_file_function, file_list)
|
||||
p.close()
|
||||
p.join()
|
||||
|
||||
|
||||
def check_git_exit(caller_name):
|
||||
# Check if all files are formatter
|
||||
process = subprocess.run("git --no-pager diff",
|
||||
capture_output=True, shell=True)
|
||||
|
||||
out = process.stdout.decode("utf-8")
|
||||
|
||||
if out != "":
|
||||
print("\n########### %s DONE ###########\n" % caller_name)
|
||||
print("Git diff is not empty. This means your files where not correctly formatted!")
|
||||
out.replace("\\n", "\n")
|
||||
# print(out)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def find_absolute_qt_path(qt_version) -> os.path:
|
||||
compiler = ""
|
||||
if os.name != 'nt':
|
||||
print("find_absolute_qt_path is only implemented for Windows!")
|
||||
sys.exit(1)
|
||||
|
||||
compiler = "msvc2019_64"
|
||||
|
||||
qt_base_path = "C:\\Qt"
|
||||
if not os.path.exists(qt_base_path):
|
||||
print("No suitable Qt version found! Searching for version %s" % qt_version)
|
||||
print("Path searches the root Qt version folder like: C:/Qt/6.0.0/msvc2019_64")
|
||||
sys.exit(1)
|
||||
|
||||
absolute_qt_path = os.path.join(qt_base_path, qt_version)
|
||||
if os.path.exists(absolute_qt_path):
|
||||
return os.path.join(absolute_qt_path, compiler)
|
||||
else:
|
||||
print("No suitable Qt version found! Searching for version %s" % qt_version)
|
||||
print("Path searches the root Qt version folder like: C:/Qt/6.0.0/msvc2019_64")
|
||||
sys.exit(1)
|
@ -1,20 +0,0 @@
|
||||
git submodule update --init
|
||||
git submodule update --recursive
|
||||
cd ..
|
||||
cd ..
|
||||
git clone https://github.com/microsoft/vcpkg.git ScreenPlay-vcpkg
|
||||
cd ScreenPlay-vcpkg
|
||||
git pull
|
||||
# master 12.05.2021 - 7b1016e10ef0434fe7045d320a9ee05b63e0efe9
|
||||
git checkout 7b1016e10ef0434fe7045d320a9ee05b63e0efe9
|
||||
chmod +x bootstrap-vcpkg.sh
|
||||
./bootstrap-vcpkg.sh
|
||||
chmod +x vcpkg
|
||||
|
||||
if [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
./vcpkg install openssl-unix sentry-native doctest benchmark infoware[opencl] --triplet x64-osx --recurse
|
||||
else
|
||||
./vcpkg install openssl-unix sentry-native doctest benchmark infoware[opencl] --triplet x64-linux --recurse
|
||||
fi
|
||||
|
||||
./vcpkg upgrade --no-dry-run
|
@ -1,13 +0,0 @@
|
||||
import fnmatch
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
|
||||
executable = "cmake-lint"
|
||||
if os.name == 'nt':
|
||||
executable += ".exe"
|
||||
|
||||
for root, dirnames, filenames in os.walk('../'):
|
||||
for filename in fnmatch.filter(filenames, 'CMakeLists.txt'):
|
||||
print(executable, root + "/" + filename)
|
||||
os.system(" %s %s" % (executable, (root + "/" + filename)))
|
39
Tools/qml_format.py
Normal file
39
Tools/qml_format.py
Normal file
@ -0,0 +1,39 @@
|
||||
import os
|
||||
import subprocess
|
||||
import argparse
|
||||
import sys
|
||||
from format_util import find_files
|
||||
from format_util import check_git_exit
|
||||
from format_util import execute_threaded
|
||||
from format_util import find_absolute_qt_path
|
||||
|
||||
|
||||
def format_file_function(file):
|
||||
executable = "qmlformat"
|
||||
if os.name == 'nt':
|
||||
executable = "qmlformat.exe"
|
||||
qt_bin_path = os.path.join(find_absolute_qt_path("5.15.2"), "bin")
|
||||
executable = os.path.join(qt_bin_path, executable)
|
||||
|
||||
process = subprocess.run(
|
||||
"%s -n -i %s" % (executable, file), capture_output=True, shell=True)
|
||||
print("Format: %s \t return: %s" % (file, process.returncode))
|
||||
|
||||
|
||||
def main(git_staged_only=False):
|
||||
if "" == find_absolute_qt_path("5.15.2"):
|
||||
print("No suitable qt version found!")
|
||||
sys.exit(1)
|
||||
|
||||
file_list = find_files(('.qml'), "Apps/Client/qml", git_staged_only)
|
||||
execute_threaded(file_list, format_file_function)
|
||||
if not git_staged_only:
|
||||
check_git_exit("QML Format")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('-s', action="store_true", dest="stage_only",
|
||||
default=False)
|
||||
args = parser.parse_args()
|
||||
main(args.stage_only)
|
70
Tools/setup.py
Normal file
70
Tools/setup.py
Normal file
@ -0,0 +1,70 @@
|
||||
import os
|
||||
import sys
|
||||
import argparse
|
||||
from execute_util import execute
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(
|
||||
description='Installs ScreenPlay dependencies.')
|
||||
parser.add_argument(
|
||||
'--path', help='You can manually set the vcpkg path via -p. This path must be an absolute path and without the ScreenPlay-vcpkg name! py.exe .\setup.py --path "D:/Backup/Code/Qt/" ')
|
||||
args = parser.parse_args()
|
||||
|
||||
# ScreenPlay source and ScreenPlay-vcpkg have to be on the same file system hierarchy
|
||||
project_source_parent_path = ""
|
||||
|
||||
project_source_path = os.path.abspath(os.path.join(os.getcwd(), "../"))
|
||||
if(args.path != ""):
|
||||
project_source_parent_path = os.path.abspath(args.path)
|
||||
else:
|
||||
print("No --path provided!")
|
||||
project_source_parent_path = os.path.abspath(
|
||||
os.path.join(os.getcwd(), "../../"))
|
||||
|
||||
print("\nproject_source_parent_path: ", project_source_parent_path,
|
||||
"\nproject_source_path: ", project_source_path,
|
||||
"\n")
|
||||
|
||||
execute("git clone https://github.com/microsoft/vcpkg.git ScreenPlay-vcpkg",
|
||||
project_source_parent_path, True)
|
||||
|
||||
vcpkg_path = os.path.join(project_source_parent_path, "ScreenPlay-vcpkg")
|
||||
print("vcpkg_path: ", vcpkg_path)
|
||||
vcpkg_version = "5568f11" # https://github.com/microsoft/vcpkg/releases/tag/2021.05.12
|
||||
print("Build vcpkg ", vcpkg_version)
|
||||
execute("git fetch", vcpkg_path)
|
||||
execute("git checkout {}".format(vcpkg_version), vcpkg_path)
|
||||
|
||||
vcpkg_packages_list = [
|
||||
"openssl-unix",
|
||||
"sentry-native",
|
||||
"doctest",
|
||||
"benchmark",
|
||||
]
|
||||
|
||||
vcpkg_packages = " ".join(vcpkg_packages_list)
|
||||
vcpkg_triplet = ""
|
||||
executable_file_suffix = ""
|
||||
|
||||
if sys.platform == "win32":
|
||||
vcpkg_packages_list.append("infoware[d3d]")
|
||||
executable_file_suffix = ".exe"
|
||||
execute("download_ffmpeg.bat", project_source_path + "/Tools", False)
|
||||
execute("bootstrap-vcpkg.bat", vcpkg_path, False)
|
||||
vcpkg_triplet = "x86-windows"
|
||||
elif sys.platform == "darwin":
|
||||
vcpkg_packages_list.append("infoware[opencl]")
|
||||
execute("bootstrap-vcpkg.sh", vcpkg_path, False)
|
||||
execute("chmod +x vcpkg", vcpkg_path)
|
||||
vcpkg_triplet = "x64-linux"
|
||||
elif sys.platform == "linux":
|
||||
vcpkg_packages_list.append("infoware[opencl]")
|
||||
execute("bootstrap-vcpkg.sh", vcpkg_path, False)
|
||||
execute("chmod +x vcpkg", vcpkg_path)
|
||||
vcpkg_triplet = "x64-osx"
|
||||
|
||||
execute("vcpkg{} update".format(executable_file_suffix), vcpkg_path, False)
|
||||
execute("vcpkg{} upgrade --no-dry-run".format(executable_file_suffix),
|
||||
vcpkg_path, False)
|
||||
execute("vcpkg{} install {} --triplet {} --recurse".format(executable_file_suffix,
|
||||
vcpkg_packages, vcpkg_triplet), vcpkg_path, False)
|
Loading…
Reference in New Issue
Block a user