diff --git a/PolyEngine/Scripts/commands/clean_engine_project.py b/PolyEngine/Scripts/commands/clean_engine_project.py new file mode 100644 index 00000000..d583b33f --- /dev/null +++ b/PolyEngine/Scripts/commands/clean_engine_project.py @@ -0,0 +1,19 @@ +import argparse +import sys + +import common.project_mgr as project_mgr + +def execute(*args): + PARSER = argparse.ArgumentParser(description='PolyEngine project build folder cleaner') + + PARSER.add_argument("-b", "--build-postfix", action='store', dest='build_postfix', + default=None, + help='postfix of the build folder') + + ARGS = PARSER.parse_args([*args]) + + mgr = project_mgr.EngineProject(build_postfix=ARGS.build_postfix) + mgr.clean_build() + +if __name__ == '__main__': + execute(*sys.argv[1:]) diff --git a/PolyEngine/Scripts/commands/clean_game_project.py b/PolyEngine/Scripts/commands/clean_game_project.py new file mode 100644 index 00000000..8c32c64a --- /dev/null +++ b/PolyEngine/Scripts/commands/clean_game_project.py @@ -0,0 +1,20 @@ +import argparse +import sys + +import common.project_mgr as project_mgr + +def execute(*args): + PARSER = argparse.ArgumentParser(description='PolyEngine game build folder cleaner') + + PARSER.add_argument("-b", "--build-postfix", action='store', dest='build_postfix', + default=None, + help='postfix of the game build folder') + PARSER.add_argument('project_path', action='store', help='Path to the project root') + + ARGS = PARSER.parse_args([*args]) + + mgr = project_mgr.GameProject(ARGS.project_path, create_if_absent=False, build_postfix=ARGS.build_postfix) + mgr.clean_build() + +if __name__ == '__main__': + execute(*sys.argv[1:]) diff --git a/PolyEngine/Scripts/common/project_mgr/game_project.py b/PolyEngine/Scripts/common/project_mgr/game_project.py index 56450a24..c70f72f5 100644 --- a/PolyEngine/Scripts/common/project_mgr/game_project.py +++ b/PolyEngine/Scripts/common/project_mgr/game_project.py @@ -23,7 +23,7 @@ SLN_CMAKE_IN_FILE = 'Sln-CMakeLists.txt.in' PROJ_CMAKE_IN_FILE = 'Proj-CMakeLists.txt.in' IN_FILE_REGEX = r'(\S+)\.(\S+)\.in' -CMKAE_LISTS_FILE_NAME = 'CMakeLists.txt' +CMAKE_LISTS_FILE_NAME = 'CMakeLists.txt' PROJECT_INIT_RESOURCES_DIR_NAME = 'project-init' PROJECT_INIT_RESOURCES_PATH = os.path.join(common.SCRIPT_ENV.script_resources_path, PROJECT_INIT_RESOURCES_DIR_NAME) @@ -241,8 +241,8 @@ def _create_fast_update_script(self): def _update_cmake_files(self): sln_cmake_in_file_path = os.path.join(PROJECT_INIT_RESOURCES_PATH, SLN_CMAKE_IN_FILE) proj_cmake_in_file_path = os.path.join(PROJECT_INIT_RESOURCES_PATH, PROJ_CMAKE_IN_FILE) - sln_cmake_out_file_path = os.path.join(self._root_path, CMKAE_LISTS_FILE_NAME) - proj_cmake_out_file_path = os.path.join(self._project_path, CMKAE_LISTS_FILE_NAME) + sln_cmake_out_file_path = os.path.join(self._root_path, CMAKE_LISTS_FILE_NAME) + proj_cmake_out_file_path = os.path.join(self._project_path, CMAKE_LISTS_FILE_NAME) shutil.copy(sln_cmake_in_file_path, sln_cmake_out_file_path) shutil.copy(proj_cmake_in_file_path, proj_cmake_out_file_path) @@ -278,4 +278,4 @@ def _replace_tags_in_file(self, file_to_search, tags_and_values): for line in file: for tag, val in tags_and_values.items(): line = line.replace(tag, val) - print(line, end='') \ No newline at end of file + print(line, end='') diff --git a/PolyEngine/Scripts/common/project_mgr/project_base.py b/PolyEngine/Scripts/common/project_mgr/project_base.py index 14482378..9ed3b3fe 100644 --- a/PolyEngine/Scripts/common/project_mgr/project_base.py +++ b/PolyEngine/Scripts/common/project_mgr/project_base.py @@ -1,4 +1,5 @@ import os +import shutil BUILD_DIR_NAME = 'Build' COMMON_BUILD_DIR_NAME = 'CommonBuild' @@ -13,6 +14,7 @@ def __init__(self, project_root_path, project_name, build_postfix=None): self._build_path = os.path.join(project_root_path, build_dir_fullname) self._build_postfix = build_postfix + self._common_build_path = os.path.join(project_root_path, COMMON_BUILD_DIR_NAME) self._dist_path = os.path.join(project_root_path, dist_dir_fullname) self._project_name = project_name @@ -29,6 +31,19 @@ def build(self): def save(self): self._save() + def clean_build(self): + print(f"Cleaning build files in {self._project_name}") + if os.path.exists(self._build_path): + print(f"Removing Build directory in {self._project_name}") + shutil.rmtree(self._build_path) + # CommonBuild is not present in games + if os.path.exists(self._common_build_path): + print(f"Removing CommonBuild directory in {self._project_name}") + shutil.rmtree(self._common_build_path) + if os.path.exists(self._dist_path): + print(f"Removing Dist directory in {self._project_name}") + shutil.rmtree(self._dist_path) + @property def name(self): return self._project_name @@ -65,4 +80,4 @@ def _run_cmake_generator(self): for k, v in cmake_kv_defines.items(): cmake_cmd += '-D{}={} '.format(k, v) - os.system(cmake_cmd) \ No newline at end of file + os.system(cmake_cmd)