mirror of
https://gitea.windcorp.ru/Wind-Corporation/Progressia.git
synced 2025-04-21 16:10:47 +03:00
TMP / cl-tidy & pre-commit.py start
This commit is contained in:
parent
678025b803
commit
93a514cc43
@ -2,3 +2,6 @@ BasedOnStyle: LLVM
|
|||||||
|
|
||||||
# Use larger indentation
|
# Use larger indentation
|
||||||
IndentWidth: 4
|
IndentWidth: 4
|
||||||
|
|
||||||
|
# clang-tidy suppression markers
|
||||||
|
CommentPragmas: 'NOLINT'
|
||||||
|
@ -1,12 +1,17 @@
|
|||||||
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)
|
||||||
|
|
||||||
#list(APPEND clang_tidy_command "${clang_tidy_EXECUTABLE}")
|
list(APPEND clang_tidy_command "${clang_tidy_EXECUTABLE}"
|
||||||
message(NOTICE ${clang_tidy_EXECUTABLE})
|
"--config-file=${CMAKE_CURRENT_LIST_DIR}/clang-tidy.yml"
|
||||||
|
"--format-style=${clang_format_style}"
|
||||||
|
"--warnings-as-errors=*"
|
||||||
|
"--use-color")
|
||||||
|
|
||||||
|
set_target_properties(progressia
|
||||||
|
PROPERTIES CXX_CLANG_TIDY "${clang_tidy_command}")
|
||||||
|
|
||||||
add_custom_command(TARGET progressia PRE_BUILD
|
add_custom_command(TARGET progressia PRE_BUILD
|
||||||
COMMAND ${CMAKE_COMMAND} -E echo
|
COMMAND ${CMAKE_COMMAND} -E echo
|
||||||
"Clang-tidy is enabled")
|
"Clang-tidy is enabled")
|
||||||
|
|
||||||
|
|
||||||
endif()
|
endif()
|
||||||
|
7
tools/clang-tidy/clang-tidy.yml
Normal file
7
tools/clang-tidy/clang-tidy.yml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
Checks: "-*,\
|
||||||
|
clang-analyzer-*,\
|
||||||
|
cppcoreguidelines-*,\
|
||||||
|
modernize-*,\
|
||||||
|
performance-*,\
|
||||||
|
readability-*"
|
||||||
|
|
@ -1,2 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
|
|
@ -90,62 +90,3 @@ function(compile_embeds target)
|
|||||||
COMMENT "Embedding assets"
|
COMMENT "Embedding assets"
|
||||||
)
|
)
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
|
||||||
## Global variables. Yikes. FIXME
|
|
||||||
#set(tools ${PROJECT_SOURCE_DIR}/tools)
|
|
||||||
#set(generated ${PROJECT_BINARY_DIR}/generated)
|
|
||||||
#set(assets_to_embed "")
|
|
||||||
#set(assets_to_embed_args "")
|
|
||||||
#
|
|
||||||
#file(MAKE_DIRECTORY ${generated})
|
|
||||||
#
|
|
||||||
#find_package(Vulkan COMPONENTS glslc REQUIRED)
|
|
||||||
#find_program(glslc_executable NAMES glslc HINTS Vulkan::glslc)
|
|
||||||
#set(shaders ${generated}/shaders)
|
|
||||||
#file(MAKE_DIRECTORY ${shaders})
|
|
||||||
#
|
|
||||||
## Shedules compilation of shaders
|
|
||||||
## Adapted from https://stackoverflow.com/a/60472877/4463352
|
|
||||||
#macro(compile_shader)
|
|
||||||
# foreach(source ${ARGV})
|
|
||||||
# get_filename_component(source_basename ${source} NAME)
|
|
||||||
# set(tmp "${shaders}/${source_basename}.spv")
|
|
||||||
# add_custom_command(
|
|
||||||
# OUTPUT ${tmp}
|
|
||||||
# DEPENDS ${source}
|
|
||||||
# COMMAND ${glslc_executable}
|
|
||||||
# -o ${tmp}
|
|
||||||
# ${CMAKE_CURRENT_SOURCE_DIR}/${source}
|
|
||||||
# COMMENT "Compiling shader ${source}"
|
|
||||||
# )
|
|
||||||
# list(APPEND assets_to_embed_args "${tmp};as;${source_basename}.spv")
|
|
||||||
# list(APPEND assets_to_embed "${tmp}")
|
|
||||||
# unset(tmp)
|
|
||||||
# unset(source_basename)
|
|
||||||
# endforeach()
|
|
||||||
#endmacro()
|
|
||||||
#
|
|
||||||
#compile_shader(
|
|
||||||
# desktop/graphics/shaders/shader.frag
|
|
||||||
# desktop/graphics/shaders/shader.vert
|
|
||||||
#)
|
|
||||||
#
|
|
||||||
## Generate embed files
|
|
||||||
#add_custom_command(
|
|
||||||
# OUTPUT ${generated}/embedded_resources.cpp
|
|
||||||
# ${generated}/embedded_resources.h
|
|
||||||
#
|
|
||||||
# COMMAND ${tools}/embed/embed.py
|
|
||||||
# --cpp ${generated}/embedded_resources.cpp
|
|
||||||
# --header ${generated}/embedded_resources.h
|
|
||||||
# --
|
|
||||||
# ${assets_to_embed_args}
|
|
||||||
#
|
|
||||||
# DEPENDS "${assets_to_embed}"
|
|
||||||
# ${tools}/embed/embed.py
|
|
||||||
#
|
|
||||||
# WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
|
||||||
# COMMENT "Embedding assets"
|
|
||||||
#)
|
|
||||||
#
|
|
||||||
|
@ -51,62 +51,3 @@ function(compile_glsl target)
|
|||||||
target_embeds(${target} ${spv_path} AS "${source_basename}.spv")
|
target_embeds(${target} ${spv_path} AS "${source_basename}.spv")
|
||||||
endforeach()
|
endforeach()
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
|
||||||
## Global variables. Yikes. FIXME
|
|
||||||
#set(tools ${PROJECT_SOURCE_DIR}/tools)
|
|
||||||
#set(generated ${PROJECT_BINARY_DIR}/generated)
|
|
||||||
#set(assets_to_embed "")
|
|
||||||
#set(assets_to_embed_args "")
|
|
||||||
#
|
|
||||||
#file(MAKE_DIRECTORY ${generated})
|
|
||||||
#
|
|
||||||
#find_package(Vulkan COMPONENTS glslc REQUIRED)
|
|
||||||
#find_program(glslc_executable NAMES glslc HINTS Vulkan::glslc)
|
|
||||||
#set(shaders ${generated}/shaders)
|
|
||||||
#file(MAKE_DIRECTORY ${shaders})
|
|
||||||
#
|
|
||||||
## Shedules compilation of shaders
|
|
||||||
## Adapted from https://stackoverflow.com/a/60472877/4463352
|
|
||||||
#macro(compile_shader)
|
|
||||||
# foreach(source ${ARGV})
|
|
||||||
# get_filename_component(source_basename ${source} NAME)
|
|
||||||
# set(tmp "${shaders}/${source_basename}.spv")
|
|
||||||
# add_custom_command(
|
|
||||||
# OUTPUT ${tmp}
|
|
||||||
# DEPENDS ${source}
|
|
||||||
# COMMAND ${glslc_executable}
|
|
||||||
# -o ${tmp}
|
|
||||||
# ${CMAKE_CURRENT_SOURCE_DIR}/${source}
|
|
||||||
# COMMENT "Compiling shader ${source}"
|
|
||||||
# )
|
|
||||||
# list(APPEND assets_to_embed_args "${tmp};as;${source_basename}.spv")
|
|
||||||
# list(APPEND assets_to_embed "${tmp}")
|
|
||||||
# unset(tmp)
|
|
||||||
# unset(source_basename)
|
|
||||||
# endforeach()
|
|
||||||
#endmacro()
|
|
||||||
#
|
|
||||||
#compile_shader(
|
|
||||||
# desktop/graphics/shaders/shader.frag
|
|
||||||
# desktop/graphics/shaders/shader.vert
|
|
||||||
#)
|
|
||||||
#
|
|
||||||
## Generate embed files
|
|
||||||
#add_custom_command(
|
|
||||||
# OUTPUT ${generated}/embedded_resources.cpp
|
|
||||||
# ${generated}/embedded_resources.h
|
|
||||||
#
|
|
||||||
# COMMAND ${tools}/embed/embed.py
|
|
||||||
# --cpp ${generated}/embedded_resources.cpp
|
|
||||||
# --header ${generated}/embedded_resources.h
|
|
||||||
# --
|
|
||||||
# ${assets_to_embed_args}
|
|
||||||
#
|
|
||||||
# DEPENDS "${assets_to_embed}"
|
|
||||||
# ${tools}/embed/embed.py
|
|
||||||
#
|
|
||||||
# WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
|
||||||
# COMMENT "Embedding assets"
|
|
||||||
#)
|
|
||||||
#
|
|
||||||
|
116
tools/pre-commit.py
Executable file
116
tools/pre-commit.py
Executable file
@ -0,0 +1,116 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
usage = \
|
||||||
|
'''Usage: %(me)s [--dry-run] [--verbose] [--dont-update]
|
||||||
|
or: %(me)s restore
|
||||||
|
or: %(me)s update
|
||||||
|
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 3rd form, only update git pre-commit hook
|
||||||
|
|
||||||
|
--dry-run do not change anything in git or in the working tree
|
||||||
|
--verbose print commands and diagnostics
|
||||||
|
--dont-update do not update git pre-commit hook
|
||||||
|
--help display this help and exit
|
||||||
|
|
||||||
|
Currently, the pre-commit procedure performs the following:
|
||||||
|
1. format staged changes
|
||||||
|
2. attempt to compile with staged changes only'''
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
def fail(*args):
|
||||||
|
print(my_name + ':', *args, file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
def invoke(*cmd, result_when_dry=None, quiet=True):
|
||||||
|
|
||||||
|
if verbose:
|
||||||
|
print(my_name + ': command "' + '" "'.join(cmd) + '"')
|
||||||
|
|
||||||
|
if dry_run and result_when_dry != None:
|
||||||
|
print(my_name + ': skipped: --dry-run')
|
||||||
|
return result_when_dry
|
||||||
|
|
||||||
|
output = ''
|
||||||
|
popen = subprocess.Popen(cmd,
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
text=True,
|
||||||
|
universal_newlines=True)
|
||||||
|
|
||||||
|
for line in popen.stdout:
|
||||||
|
if (not quiet):
|
||||||
|
print(line, end='')
|
||||||
|
output += line
|
||||||
|
|
||||||
|
popen.stdout.close()
|
||||||
|
|
||||||
|
return_code = popen.wait()
|
||||||
|
if return_code != 0:
|
||||||
|
raise subprocess.CalledProcessError(return_code, cmd)
|
||||||
|
|
||||||
|
return output
|
||||||
|
|
||||||
|
STASH_NAME = 'progressia_pre_commit_stash'
|
||||||
|
|
||||||
|
def run_safety_checks():
|
||||||
|
if invoke('git', 'stash', 'list', '--grep', f"^{STASH_NAME}$") != '':
|
||||||
|
fail(f"Cannot run pre-commit checks: stash {STASH_NAME} exists. " +
|
||||||
|
f"Use `{my_name} restore` to restore workspace and repository " +
|
||||||
|
f"state")
|
||||||
|
|
||||||
|
# Let's hope there are no files with weird names
|
||||||
|
indexed_changes = \
|
||||||
|
set(invoke('git', 'diff', '--name-only', '--cached') \
|
||||||
|
.strip().split('\n'))
|
||||||
|
unindexed_changes = \
|
||||||
|
set(invoke('git', 'diff', '--name-only') \
|
||||||
|
.strip().split('\n'))
|
||||||
|
|
||||||
|
both_changes = indexed_changes & unindexed_changes
|
||||||
|
|
||||||
|
if len(both_changes) != 0:
|
||||||
|
fail(f"Cannot run pre-commit checks: files with indexed and " +
|
||||||
|
"unindexed changes exist:\n\n\t" +
|
||||||
|
"\n\t".join(both_changes) +
|
||||||
|
"\n")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
my_name = os.path.basename(sys.argv[0])
|
||||||
|
verbose = False
|
||||||
|
dry_run = False
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
verbose = True
|
||||||
|
dry_run = True
|
||||||
|
run_safety_checks()
|
||||||
|
#update()
|
||||||
|
|
||||||
|
unindexed_changes = invoke('git', 'diff', '--name-status')
|
||||||
|
if unindexed_changes != '':
|
||||||
|
print('Unindexed changes found in files:')
|
||||||
|
print(unindexed_changes)
|
||||||
|
print('These changes will be ignored')
|
||||||
|
|
||||||
|
invoke('git', 'stash', 'push',
|
||||||
|
'--keep-index',
|
||||||
|
'--include-untracked',
|
||||||
|
'--message', STASH_NAME,
|
||||||
|
result_when_dry='')
|
||||||
|
|
||||||
|
# check that ORIGINAL does not exist
|
||||||
|
# check that staged files & files with unstaged changes = 0
|
||||||
|
# update pre-commit hook
|
||||||
|
# if any unstaged changes:
|
||||||
|
# stash ORIGINAL
|
||||||
|
# remove unstaged changes
|
||||||
|
# format staged files
|
||||||
|
# compile
|
||||||
|
# git add
|
||||||
|
# if any unstaged changes:
|
||||||
|
# unstash ORIGINAL
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user