赞
踩
- vim /etc/bashrc 增加全用户系统命令
- function sky() {
- ( sh /opt/sky/hook.sh $* )
- }
- mkdir -p /opt/sky
- cd /opt/sky
- vim hook.sh
- chmod -R 755 /opt/sky
-
- #!/bin/bash
-
- set -e
-
- TOOLS_PATH=~/.sky
- TOOLS_BRANCH=main
- TOOLS_REMOTE=git@gitlab.raina.tech:zhangxinze/sky.git
- current_path=$(pwd)
-
- if [ -d ${TOOLS_PATH}/.git ]; then
-
- cd ${TOOLS_PATH}
-
- git reset --hard ${TOOLS_BRANCH} --quiet
-
- git checkout ${TOOLS_BRANCH} > /dev/null 2>&1
-
- git pull --quiet
-
- git pull --quiet origin ${TOOLS_BRANCH}
-
- # git log -1
- echo 'Successfully updated sky'
-
- else
-
- git clone ${TOOLS_REMOTE} -b ${TOOLS_BRANCH} ${TOOLS_PATH} --quiet
- echo 'Successfully updated sky'
-
- fi
-
- cd "$current_path"
- sh ~/.sky/sky.sh $*

- #!/bin/bash
- set -e
-
- # Function to run cppcheck on changed files
- run_cppcheck() {
- changed_files=$(git diff --cached --name-only)
- echo "About to detect files:"
- echo "$changed_files"
- python3 ~/.sky/Cppcheck.py --appoint_path "$changed_files"
- python3 ~/.sky/Cppcheck.py --check ON
- echo '###'
- exit 1
- }
-
- # Check if the git command is "commit"
- if [[ $* =~ "commit" ]]; then
- run_cppcheck
- fi
-
- # Run the actual git command with all the passed arguments
- git $*

- import os
- import argparse
-
-
- def cppcheck(path):
- args="cppcheck -v -j 12 --suppress=doubleFree --suppress=resourceLeak --suppress=leakNoVarFunctionCall --suppress=integerOverflow --suppress=objectIndex --suppress=unknownMacro --suppress=syntaxError --suppress=memleak --suppress=memleakOnRealloc --xml --xml-version=2 --output-file=cppcheck_result.xml {} -i Tpl -i Physical -i build".format(path)
- print(args,'\n')
- if path != '':
- os.system(args)
- else:
- print('No files need cppcheck\n')
-
- def get_all_check_files_appoint(appoint_path):
- file_path_list=[]
- Cpplint_Checkpath_str=''
- for file_path in appoint_path.split('\n'):
- try:
- if file_path.endswith(tuple([".cpp",".h",".cc",".c",".hpp"])) and 'Tpl' not in file_path and 'Physical'not in file_path:
- file_path_list.append(file_path)
- Cpplint_Checkpath_str=Cpplint_Checkpath_str+' '+file_path
- except:
- pass
- print('Cpplint_Checkpath_list:', file_path_list, '\n')
- # print('Cpplint_Checkpath_str:', Cpplint_Checkpath_str, '\n')
-
- return Cpplint_Checkpath_str
-
- def check_on():
- try:
- with open('cppcheck_result.xml', 'r') as file:
- content = file.read() # 读取文件内容到变量content
- except FileNotFoundError:
- print("file not find!")
- content = ''
-
- if args.check=='ON':
- if 'error id' in content:
- print("Cppcheck found the problem\n\n\nresult_xml:{}".format(content))
- exit(1)
- print("Cppcheck not found the problem\n\n\n")
- else:
- print("Cppcheck is not enabled\n\n\nresult_xml:{}".format(content))
-
-
-
- def args_parse():
-
- parser = argparse.ArgumentParser(description='get cpp arg')
- parser.add_argument('--path', type=str)
- parser.add_argument('--appoint_path', type=str)
- parser.add_argument('--check', type=str)
- args = parser.parse_args()
-
- return args
-
-
-
- def start(args):
- if args.path:
- print('\n############Start Check Cppcheck!############\n')
-
- cppcheck(args.path)
-
- print('############CPPCHECK END!############\n')
-
- elif args.appoint_path:
- print('\n############Start Check Cppcheck!############\n')
-
- check_files_appoint=get_all_check_files_appoint(args.appoint_path)
- cppcheck(check_files_appoint)
-
- print('############CPPCHECK END!############\n')
-
- elif args.check:
- check_on()
-
- else:
- print('Please set parameters for Cppcheck\n')
-
- if __name__ == '__main__':
-
- args = args_parse()
-
- start(args)
-

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。