TMP / added REQUIRED to find_program; cmake is now detected by pre-commit.py; fixed makefile problem

This commit is contained in:
OLEGSHA 2023-03-09 21:34:08 +01:00
parent 854d3d3308
commit 15d41b60bd
4 changed files with 58 additions and 36 deletions

View File

@ -1,5 +1,5 @@
if (DEV_MODE) if (DEV_MODE)
find_program(clang_tidy_EXECUTABLE NAMES clang-tidy-13 clang-tidy) find_program(clang_tidy_EXECUTABLE NAMES clang-tidy-13 clang-tidy REQUIRED)
find_package(Python3 COMPONENTS Interpreter REQUIRED) find_package(Python3 COMPONENTS Interpreter REQUIRED)
# Setup clang-tidy # Setup clang-tidy
@ -15,27 +15,42 @@ if (DEV_MODE)
# Display the marker for pre-commit.py at build time # Display the marker for pre-commit.py at build time
add_custom_target(clang_tidy_marker ALL add_custom_target(clang_tidy_marker ALL
COMMAND ${CMAKE_COMMAND} -E echo COMMAND ${CMAKE_COMMAND} -E echo
"Clang-tidy is enabled (this is a marker for pre-commit.py)") "Clang-tidy is enabled. This is a marker for pre-commit.py")
# Notify pre-commit.py about CMAKE_BINARY_DIR # Notify pre-commit.py about CMake settings
execute_process(COMMAND ${Python3_EXECUTABLE} ${tools}/pre-commit.py execute_process(COMMAND ${Python3_EXECUTABLE} ${tools}/pre-commit.py
set-build-root -- "${CMAKE_BINARY_DIR}" set-build-info -- "${CMAKE_COMMAND}" "${CMAKE_BINARY_DIR}"
RESULT_VARIABLE set_build_root_RESULT) RESULT_VARIABLE set_build_info_RESULT)
if(${set_build_root_RESULT}) if(${set_build_info_RESULT})
message(FATAL_ERROR "pre-commit.py set-build-root failed") message(FATAL_ERROR "pre-commit.py set-build-info failed")
endif() endif()
# Setup pre-commit git hook # Setup pre-commit git hook
if (IS_DIRECTORY "${CMAKE_SOURCE_DIR}/.git/hooks") if (IS_DIRECTORY "${CMAKE_SOURCE_DIR}/.git/hooks")
if (NOT EXISTS "${CMAKE_SOURCE_DIR}/.git/hooks/pre-commit") set(pre_commit_hook "${CMAKE_SOURCE_DIR}/.git/hooks/pre-commit")
file(WRITE "${CMAKE_SOURCE_DIR}/.git/hooks/pre-commit" if (NOT EXISTS "${pre_commit_hook}")
file(WRITE "${pre_commit_hook}"
"#!/bin/sh\n" "#!/bin/sh\n"
"# Progressia autogenerated pre-commit hook\n" "# Progressia autogenerated pre-commit hook\n"
"# You may modify this hook freely " "# You may modify this hook freely "
"(just make sure the checks run)\n" "(just make sure the checks run)\n"
"/bin/env python3 ${CMAKE_SOURCE_DIR}/tools/pre-commit.py run") "/bin/env python3 ${CMAKE_SOURCE_DIR}/tools/pre-commit.py run")
if (${CMAKE_VERSION} VERSION_LESS "3.19.0")
if (${CMAKE_HOST_UNIX})
execute_process(COMMAND chmod "+x" "${pre_commit_hook}"
RESULT_VARIABLE chmod_RESULT)
if (${chmod_RESULT})
message(FATAL_ERROR "Could not make git pre-commit hook executable")
endif()
endif()
else()
file(CHMOD "${pre_commit_hook}"
PERMISSIONS OWNER_EXECUTE GROUP_EXECUTE WORLD_EXECUTE)
endif()
endif() endif()
unset(pre_commit_hook)
endif() endif()
endif() endif()

View File

@ -1,8 +1,11 @@
Checks: "-*,\ #Checks: "-*,\
clang-analyzer-*,\ # clang-analyzer-*,\
cppcoreguidelines-*,\ # cppcoreguidelines-*,\
modernize-*,\ # modernize-*,\
performance-*,\ # performance-*,\
readability-*,\ # readability-*,\
clang-diagnostic-*" # clang-diagnostic-*"
# OH SO TEMPORARY
# im gonna be mad BIG TIME if this makes it to a public repo
Checks: "-*,clang-analyzer-webkit.NoUncountedMemberChecker"

View File

@ -2,7 +2,7 @@
# Compiles GLSL shaders to SPV files # Compiles GLSL shaders to SPV files
find_package(Vulkan COMPONENTS glslc REQUIRED) find_package(Vulkan COMPONENTS glslc REQUIRED)
find_program(glslc_EXECUTABLE NAMES glslc HINTS Vulkan::glslc) find_program(glslc_EXECUTABLE NAMES glslc HINTS Vulkan::glslc REQUIRED)
macro (get_target_property_or var target prop default) macro (get_target_property_or var target prop default)
get_property(__is_set TARGET ${target} PROPERTY ${prop} SET) get_property(__is_set TARGET ${target} PROPERTY ${prop} SET)

View File

@ -3,10 +3,10 @@
usage = \ usage = \
'''Usage: %(me)s run [OPTIONS...] '''Usage: %(me)s run [OPTIONS...]
or: %(me)s restore [OPTIONS...] or: %(me)s restore [OPTIONS...]
or: %(me)s set-build-root CMAKE_BINARY_DIR or: %(me)s set-build-info CMAKE_EXECUTABLE CMAKE_BINARY_DIR
In the 1st form, run standard pre-commit procedure for Progressia. In the 1st form, run standard pre-commit procedure for Progressia.
In the 2nd form, attempt to restore workspace if the pre-commit hook failed. In the 2nd form, attempt to restore workspace if the pre-commit hook failed.
In the 3rd form, only update git pre-commit hook. In the 3rd form, update cached build settings.
--dry-run do not change anything in git or in the filesystem; --dry-run do not change anything in git or in the filesystem;
implies --verbose implies --verbose
@ -22,7 +22,7 @@ pre-commit-settings.json values:
build-root CMake binary dir to use (filled in by CMake) build-root CMake binary dir to use (filled in by CMake)
parallelism threads to use, default is 1 parallelism threads to use, default is 1
git git command, default is null git git command, default is null
cmake cmake command, default is null cmake cmake command, default is null (filled in by CMake)
clang-format-diff clang-format-diff command, default is null clang-format-diff clang-format-diff command, default is null
Use semicolons to separate arguments in git, cmake and clang-format-diff''' Use semicolons to separate arguments in git, cmake and clang-format-diff'''
@ -49,8 +49,8 @@ STASH_NAME = 'progressia_pre_commit_stash'
# Paths are relative to this script's directory, tools/ # Paths are relative to this script's directory, tools/
SETTINGS_PATH = 'pre-commit-settings.json' SETTINGS_PATH = 'pre-commit-settings.json'
CLANG_FORMAT_PATH = 'clang-format/clang-format.json' CLANG_FORMAT_PATH = 'clang-format/clang-format.json'
CLANG_TIDY_CHECK_MARKER = 'Clang-tidy is enabled ' \ CLANG_TIDY_CHECK_MARKER = 'Clang-tidy is enabled. ' \
'(this is a marker for pre-commit.py)' 'This is a marker for pre-commit.py'
def fail(*args, code=1): def fail(*args, code=1):
@ -265,15 +265,16 @@ def save_settings():
verbose(' skipped: --dry-run') verbose(' skipped: --dry-run')
def set_build_root(): def set_build_info():
"""Set last build root in tools/pre-commit-settings.json.""" """Set build info in tools/pre-commit-settings.json."""
settings['build_root'] = arg_build_root settings['build_root'] = arg_build_root
settings['cmake'] = arg_cmake_executable
save_settings() save_settings()
def parse_args(): def parse_args():
"""Parse sys.argv and environment variables; set corresponding globals. """Parse sys.argv and environment variables; set corresponding globals.
Return (action, argument for set-build-root). Return (action, arguments for set-build-root).
""" """
global action global action
global verbose_mode global verbose_mode
@ -282,10 +283,11 @@ def parse_args():
consider_options = True consider_options = True
action = None action = None
arg_cmake_executable = None
arg_build_root = None arg_build_root = None
for arg in sys.argv[1:]: for arg in sys.argv[1:]:
if arg == 'restore' or arg == 'set-build-root' or arg == 'run': if arg == 'restore' or arg == 'set-build-info' or arg == 'run':
if action is not None: if action is not None:
fail(f"Cannot use '{arg}' and '{action}' together") fail(f"Cannot use '{arg}' and '{action}' together")
action = arg action = arg
@ -305,21 +307,23 @@ def parse_args():
consider_options = False consider_options = False
else: else:
fail(f"Unknown option '{arg}'") fail(f"Unknown option '{arg}'")
elif action == 'set-build-root' and arg_build_root is None: elif action == 'set-build-info' and arg_cmake_executable is None:
arg_cmake_executable = arg
elif action == 'set-build-info' and arg_build_root is None:
arg_build_root = arg arg_build_root = arg
else: else:
fail(f"Unknown or unexpected argument '{arg}'") fail(f"Unknown or unexpected argument '{arg}'")
if not allow_update and action == 'update':
fail("Cannot use '--dont-update' and 'update' together")
if action is None: if action is None:
fail('No action specified') fail('No action specified')
if action == 'set-build-root' and arg_build_root is None: if action == 'set-build-info' and arg_cmake_executable is None:
fail('No path given') fail('No CMake executable given')
return action, arg_build_root if action == 'set-build-info' and arg_build_root is None:
fail('No build root given')
return action, arg_build_root, arg_cmake_executable
def load_settings(): def load_settings():
@ -376,7 +380,7 @@ if __name__ == '__main__':
dry_run = False dry_run = False
allow_update = True allow_update = True
action, arg_build_root = parse_args() action, arg_build_root, arg_cmake_executable = parse_args()
load_settings() load_settings()
if dry_run: if dry_run:
@ -384,8 +388,8 @@ if __name__ == '__main__':
'actually be performed') 'actually be performed')
try: try:
if action == 'set-build-root': if action == 'set-build-info':
set_build_root() set_build_info()
elif action == 'restore': elif action == 'restore':
do_restore() do_restore()
indexed, unindexed = get_file_sets() indexed, unindexed = get_file_sets()