update helper script

This commit is contained in:
Robin Müller 2022-02-02 09:56:12 +01:00
parent 371ff931bf
commit fed39defd3
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC

View File

@ -9,36 +9,44 @@ import webbrowser
import shutil import shutil
import sys import sys
import time import time
from shutil import which
from typing import List from typing import List
UNITTEST_FOLDER_NAME = 'build-tests' UNITTEST_FOLDER_NAME = "build-tests"
DOCS_FOLDER_NAME = 'build-docs' DOCS_FOLDER_NAME = "build-docs"
def main(): def main():
parser = argparse.ArgumentParser(description="FSFW helper script") parser = argparse.ArgumentParser(description="FSFW helper script")
choices = ('docs', 'tests') choices = ("docs", "tests")
parser.add_argument( parser.add_argument(
'type', metavar='type', choices=choices, "type", metavar="type", choices=choices, help=f"Target type. Choices: {choices}"
help=f'Target type. Choices: {choices}'
) )
parser.add_argument( parser.add_argument(
'-a', '--all', action='store_true', "-a", "--all", action="store_true", help="Create, build and open specified type"
help='Create, build and open specified type'
) )
parser.add_argument( parser.add_argument(
'-c', '--create', action='store_true', "-c",
help='Create docs or test build configuration' "--create",
action="store_true",
help="Create docs or test build configuration",
) )
parser.add_argument( parser.add_argument(
'-b', '--build', action='store_true', "-b", "--build", action="store_true", help="Build the specified type"
help='Build the specified type'
) )
parser.add_argument( parser.add_argument(
'-o', '--open', action='store_true', "-o",
help='Open test or documentation data in webbrowser' "--open",
action="store_true",
help="Open test or documentation data in webbrowser",
)
parser.add_argument(
"-v",
"--valgrind",
action="store_true",
help="Run valgrind on generated test binary",
) )
args = parser.parse_args() args = parser.parse_args()
@ -46,26 +54,26 @@ def main():
args.build = True args.build = True
args.create = True args.create = True
args.open = True args.open = True
elif not args.build and not args.create and not args.open: elif not args.build and not args.create and not args.open and not args.valgrind:
print( print(
'Please select at least one operation to perform. ' "Please select at least one operation to perform. "
'Use helper.py -h for more information' "Use helper.py -h for more information"
) )
sys.exit(1) sys.exit(1)
# This script can be called from root and from script folder # This script can be called from root and from script folder
if not os.path.isfile('README.md'): if not os.path.isfile("README.md"):
os.chdir('..') os.chdir("..")
build_dir_list = [] build_dir_list = []
if not args.create: if not args.create:
build_dir_list = build_build_dir_list() build_dir_list = build_build_dir_list()
if args.type == 'tests': if args.type == "tests":
handle_tests_type(args, build_dir_list) handle_tests_type(args, build_dir_list)
elif args.type == 'docs': elif args.type == "docs":
handle_docs_type(args, build_dir_list) handle_docs_type(args, build_dir_list)
else: else:
print('Invalid or unknown type') print("Invalid or unknown type")
sys.exit(1) sys.exit(1)
@ -76,7 +84,9 @@ def handle_docs_type(args, build_dir_list: list):
create_docs_build_cfg() create_docs_build_cfg()
build_directory = DOCS_FOLDER_NAME build_directory = DOCS_FOLDER_NAME
elif len(build_dir_list) == 0: elif len(build_dir_list) == 0:
print('No valid CMake docs build directory found. Trying to set up docs build system') print(
"No valid CMake docs build directory found. Trying to set up docs build system"
)
shutil.rmtree(DOCS_FOLDER_NAME) shutil.rmtree(DOCS_FOLDER_NAME)
create_docs_build_cfg() create_docs_build_cfg()
build_directory = DOCS_FOLDER_NAME build_directory = DOCS_FOLDER_NAME
@ -87,18 +97,18 @@ def handle_docs_type(args, build_dir_list: list):
build_directory = determine_build_dir(build_dir_list) build_directory = determine_build_dir(build_dir_list)
os.chdir(build_directory) os.chdir(build_directory)
if args.build: if args.build:
os.system('cmake --build . -j') os.system("cmake --build . -j")
if args.open: if args.open:
if not os.path.isfile('docs/sphinx/index.html'): if not os.path.isfile("docs/sphinx/index.html"):
# try again.. # try again..
os.system('cmake --build . -j') os.system("cmake --build . -j")
if not os.path.isfile('docs/sphinx/index.html'): if not os.path.isfile("docs/sphinx/index.html"):
print( print(
"No Sphinx documentation file detected. " "No Sphinx documentation file detected. "
"Try to build it first with the -b argument" "Try to build it first with the -b argument"
) )
sys.exit(1) sys.exit(1)
webbrowser.open('docs/sphinx/index.html') webbrowser.open("docs/sphinx/index.html")
def handle_tests_type(args, build_dir_list: list): def handle_tests_type(args, build_dir_list: list):
@ -109,8 +119,8 @@ def handle_tests_type(args, build_dir_list: list):
build_directory = UNITTEST_FOLDER_NAME build_directory = UNITTEST_FOLDER_NAME
elif len(build_dir_list) == 0: elif len(build_dir_list) == 0:
print( print(
'No valid CMake tests build directory found. ' "No valid CMake tests build directory found. "
'Trying to set up test build system' "Trying to set up test build system"
) )
create_tests_build_cfg() create_tests_build_cfg()
build_directory = UNITTEST_FOLDER_NAME build_directory = UNITTEST_FOLDER_NAME
@ -123,26 +133,33 @@ def handle_tests_type(args, build_dir_list: list):
if args.build: if args.build:
perform_lcov_operation(build_directory, False) perform_lcov_operation(build_directory, False)
if args.open: if args.open:
if not os.path.isdir('fsfw-tests_coverage'): if not os.path.isdir("fsfw-tests_coverage"):
print("No Unittest folder detected. Try to build them first with the -b argument") print(
"No Unittest folder detected. Try to build them first with the -b argument"
)
sys.exit(1) sys.exit(1)
webbrowser.open('fsfw-tests_coverage/index.html') webbrowser.open("fsfw-tests_coverage/index.html")
if args.valgrind:
if which("valgrind") is None:
print("Please install valgrind first")
sys.exit(1)
os.chdir(UNITTEST_FOLDER_NAME)
os.system("valgrind --leak-check=full ./fsfw-tests")
os.chdir("..")
def create_tests_build_cfg(): def create_tests_build_cfg():
os.mkdir(UNITTEST_FOLDER_NAME) os.mkdir(UNITTEST_FOLDER_NAME)
os.chdir(UNITTEST_FOLDER_NAME) os.chdir(UNITTEST_FOLDER_NAME)
cmake_cmd = "cmake -DFSFW_OSAL=host -DFSFW_BUILD_UNITTESTS=ON .." os.system("cmake -DFSFW_OSAL=host -DFSFW_BUILD_UNITTESTS=ON ..")
print(f"Executing CMake command {cmake_cmd}") os.chdir("..")
os.system(cmake_cmd)
os.chdir('..')
def create_docs_build_cfg(): def create_docs_build_cfg():
os.mkdir(DOCS_FOLDER_NAME) os.mkdir(DOCS_FOLDER_NAME)
os.chdir(DOCS_FOLDER_NAME) os.chdir(DOCS_FOLDER_NAME)
os.system('cmake -DFSFW_OSAL=host -DFSFW_BUILD_DOCS=ON ..') os.system("cmake -DFSFW_OSAL=host -DFSFW_BUILD_DOCS=ON ..")
os.chdir('..') os.chdir("..")
def build_build_dir_list() -> list: def build_build_dir_list() -> list: