From 997d28f6b26f93536f052349a8cc4ac700bbba0c Mon Sep 17 00:00:00 2001 From: Grzegorz Choinski Date: Mon, 3 Jan 2022 08:59:23 +0000 Subject: [PATCH] infra update Removing legacy linter. Signed-off-by: Grzegorz Choinski --- CMakeLists.txt | 6 +- manifests/manifest.yml | 2 +- scripts/format/CMakeLists.txt | 23 --- scripts/format/cmake_format.py | 159 ---------------- scripts/format/format.bat | 62 ------ scripts/format/format.sh | 47 ----- scripts/lint/CMakeLists.txt | 27 --- scripts/lint/set_copyright.py | 273 --------------------------- scripts/lint/set_copyright.sh | 22 --- scripts/tests/copyright/in/file1.cpp | 3 - scripts/tests/copyright/in/file1.sh | 4 - scripts/tests/copyright/in/file2.cpp | 3 - scripts/tests/copyright/in/file2.sh | 2 - scripts/tests/copyright/in/file3.cpp | 3 - scripts/tests/copyright/in/file3.sh | 3 - scripts/tests/copyright/in/file4.cpp | 7 - scripts/tests/copyright/in/file4.sh | 7 - scripts/tests/copyright/in/file5.cpp | 5 - scripts/tests/copyright/in/file6.cpp | 3 - scripts/tests/copyright/in/file7.cpp | 3 - scripts/tests/copyright/test.sh | 29 --- 21 files changed, 2 insertions(+), 691 deletions(-) delete mode 100644 scripts/format/CMakeLists.txt delete mode 100755 scripts/format/cmake_format.py delete mode 100644 scripts/format/format.bat delete mode 100644 scripts/format/format.sh delete mode 100644 scripts/lint/CMakeLists.txt delete mode 100755 scripts/lint/set_copyright.py delete mode 100755 scripts/lint/set_copyright.sh delete mode 100644 scripts/tests/copyright/in/file1.cpp delete mode 100644 scripts/tests/copyright/in/file1.sh delete mode 100644 scripts/tests/copyright/in/file2.cpp delete mode 100644 scripts/tests/copyright/in/file2.sh delete mode 100644 scripts/tests/copyright/in/file3.cpp delete mode 100644 scripts/tests/copyright/in/file3.sh delete mode 100644 scripts/tests/copyright/in/file4.cpp delete mode 100644 scripts/tests/copyright/in/file4.sh delete mode 100644 scripts/tests/copyright/in/file5.cpp delete mode 100644 scripts/tests/copyright/in/file6.cpp delete mode 100644 scripts/tests/copyright/in/file7.cpp delete mode 100755 scripts/tests/copyright/test.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 8d17b0adba..205801626b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (C) 2018-2021 Intel Corporation +# Copyright (C) 2018-2022 Intel Corporation # # SPDX-License-Identifier: MIT # @@ -770,10 +770,6 @@ if(EXISTS ${NEO_SOURCE_DIR}/../internal) endif() set(NEO_SCRIPT_PROJECTS_FOLDER "neo scripts") -add_subdirectory_unique(scripts/lint) -if(EXISTS ${NEO_SOURCE_DIR}/scripts/format) - add_subdirectory_unique(scripts/format) -endif() configure_file(config.h.in ${NEO_BUILD_DIR}/config.h) configure_file(driver_version.h.in ${NEO_BUILD_DIR}/driver_version.h) # Put Driver version into define diff --git a/manifests/manifest.yml b/manifests/manifest.yml index 974385281e..b59672615d 100644 --- a/manifests/manifest.yml +++ b/manifests/manifest.yml @@ -20,7 +20,7 @@ components: infra: branch: master dest_dir: infra - revision: 6e042b53d9a02531d260b678605ec9ef2b27ea61 + revision: de0a04af85bc058241dd55db4424fa3741e2479a type: git internal: branch: master diff --git a/scripts/format/CMakeLists.txt b/scripts/format/CMakeLists.txt deleted file mode 100644 index b4c292a980..0000000000 --- a/scripts/format/CMakeLists.txt +++ /dev/null @@ -1,23 +0,0 @@ -# -# Copyright (C) 2019-2020 Intel Corporation -# -# SPDX-License-Identifier: MIT -# - -if(WIN32) - set(extension bat) -else() - set(extension sh) -endif() - -add_custom_target(format_files - ${NEO_SOURCE_DIR}/scripts/format/format.${extension} ${NEO_SOURCE_DIR} - WORKING_DIRECTORY ${NEO_SOURCE_DIR} - COMMENT "Formatting changed files" -) - -set_target_properties(format_files PROPERTIES - EXCLUDE_FROM_DEFAULT_BUILD TRUE - EXCLUDE_FROM_ALL TRUE - FOLDER ${NEO_SCRIPT_PROJECTS_FOLDER} -) diff --git a/scripts/format/cmake_format.py b/scripts/format/cmake_format.py deleted file mode 100755 index 0f1e946b7b..0000000000 --- a/scripts/format/cmake_format.py +++ /dev/null @@ -1,159 +0,0 @@ -#!/usr/bin/env python3 - -# -# Copyright (C) 2020-2021 Intel Corporation -# -# SPDX-License-Identifier: MIT -# - -import sys -import argparse -import re - - -def remove_end_args(line): - if line.startswith('endif('): - line = re.sub(r'endif\(.*\)', 'endif()', line) - elif line.startswith('endforeach('): - line = re.sub(r'endforeach\(.*\)', 'endforeach()', line) - elif line.startswith('endmacro('): - line = re.sub(r'endmacro\(.*\)', 'endmacro()', line) - elif line.startswith('endfunction('): - line = re.sub(r'endfunction\(.*\)', 'endfunction()', line) - - return line - - -def remove_extra_spaces(line): - line = re.sub(r' +', ' ', line) - line = re.sub(r' *\( *', '(', line) - line = re.sub(r' *\) *', ')', line) - line = re.sub(r'\)AND\(', ') AND (', line) - line = re.sub(r'\)OR\(', ') OR (', line) - line = re.sub(r'NOT\(', 'NOT (', line) - line = re.sub(r' *\) *(?=[A-Z])', ') ', line) - return line - - -def process_line(line): - split = line.split('"') - opening_bracket_count = 0 - closing_bracket_count = 0 - new_line = [] - is_string = False - is_first_part = True - for l in split: - if not is_string: - l = replace_tabs(l) - l = remove_extra_spaces(l) - l = remove_end_args(l) - if not is_first_part or not l.startswith('#'): - l = re.sub(r' *#', ' #', l) - opening_bracket_count += l.count('(') - closing_bracket_count += l.count(')') - new_line.append(l) - is_string = True - else: - new_line.append(l) - if not l.endswith('\\') or l.endswith('\\\\'): - is_string = False - - is_first_part = False - - return '"'.join(new_line), opening_bracket_count, closing_bracket_count - - -def replace_tabs(line): - return line.replace('\t', ' ') - - -def format_file(file): - indent_size = 2 - indent_depth = 0 - extra_indent = '' - previous_is_new_line = False - lines = None - with open(file) as fin: - lines = fin.readlines() - - with open(file, 'w') as fout: - for line in lines: - indent = '' - line = line.strip() - if line.startswith('#'): - indent = ' ' * indent_size * indent_depth - fout.write(f'{indent}{extra_indent}{line}\n') - previous_is_new_line = False - continue - - line, opening_bracket_count, closing_bracket_count = process_line( - line) - if line.startswith('endif('): - indent_depth -= 1 - elif line.startswith('else('): - indent_depth -= 1 - elif line.startswith('elseif('): - indent_depth -= 1 - elif line.startswith('endforeach('): - indent_depth -= 1 - elif line.startswith('endmacro('): - indent_depth -= 1 - elif line.startswith('endfunction('): - indent_depth -= 1 - - if line: - indent = ' ' * indent_size * indent_depth - previous_is_new_line = False - else: - if not previous_is_new_line: - fout.write('\n') - - previous_is_new_line = True - continue - - if closing_bracket_count > opening_bracket_count: - if not line.startswith(')'): - line = line.replace(')', f'\n{indent})', 1) - line = f'{indent}{extra_indent}{line}' - indent = '' - - extra_indent = '' - - fout.write(f'{indent}{extra_indent}{line}\n') - - if line.startswith('if('): - indent_depth += 1 - elif line.startswith('else('): - indent_depth += 1 - elif line.startswith('elseif('): - indent_depth += 1 - elif line.startswith('foreach('): - indent_depth += 1 - elif line.startswith('macro('): - indent_depth += 1 - elif line.startswith('function('): - indent_depth += 1 - - if opening_bracket_count > closing_bracket_count: - extra_indent = ' ' * \ - len(re.match(r'.*\(', line).group(0)) - - -def _parse_args(): - parser = argparse.ArgumentParser( - description='Usage: ./scripts/format/cmake_format.py ') - parser.add_argument('files', nargs='*') - args = parser.parse_args() - - return vars(args) - - -def main(args): - for file in args['files']: - format_file(file) - - return 0 - - -if __name__ == '__main__': - sys.exit(main(_parse_args())) diff --git a/scripts/format/format.bat b/scripts/format/format.bat deleted file mode 100644 index df4bafb1be..0000000000 --- a/scripts/format/format.bat +++ /dev/null @@ -1,62 +0,0 @@ -:: -:: Copyright (C) 2019-2021 Intel Corporation -:: -:: SPDX-License-Identifier: MIT -:: - -@echo off -setlocal EnableDelayedExpansion - -IF NOT EXIST "%1" ( - echo Directory "%1" does not exist. - exit /b 1 -) - -call clang-format --version -set err=%ERRORLEVEL% - -if not "%err%"=="0" ( - echo clang-format not found - exit /b 1 -) - -git --version -set err=%ERRORLEVEL% - -if not "%err%"=="0" ( - echo git not found - exit /b 1 -) - -pushd . -cd %1 -git rev-parse --git-dir > NUL -set err=%ERRORLEVEL% - -if not "%err%"=="0" ( - echo Not a git repository. - exit /b 1 -) - -for /f %%i in ('git diff HEAD --name-only') do ( - set file="%%i" - call :get_extension %%i - call :test_extension !ext! - if "!test!" == "1" ( - clang-format -i -style=file !file! - ) -) - -popd -exit /b - -:get_extension -set ext=%~x1 -exit /b - -:test_extension -set test=0 -if "%1"==".h" set test=1 -if "%1"==".cpp" set test=1 -if "%1"==".inl" set test=1 -exit /b diff --git a/scripts/format/format.sh b/scripts/format/format.sh deleted file mode 100644 index 4a4f40eff5..0000000000 --- a/scripts/format/format.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/bash - -# -# Copyright (C) 2019-2021 Intel Corporation -# -# SPDX-License-Identifier: MIT -# - -if [ ! -d "$1" ]; then - echo "Directory "$1" does not exist." - exit 1 -fi - -clang-format --version -err=$? -if [$err -ne 0] - then - echo "clang-format not found" - exit 1 -fi - -git --version -err=$? -if [$err -ne 0] - then - echo "git not found" - exit 1 -fi - -pushd $1 - -if git rev-parse --git-dir > /dev/null 2>&1; - then - files=$(git diff HEAD --name-only) - for i in $files; do - if [[ $i =~ .*\.(h|cpp|inl) ]] - then - clang-format -i -style=file $i - fi - done -else - echo Not a git repository. - exit 1 -fi - -popd -exit 0 diff --git a/scripts/lint/CMakeLists.txt b/scripts/lint/CMakeLists.txt deleted file mode 100644 index bffc49a657..0000000000 --- a/scripts/lint/CMakeLists.txt +++ /dev/null @@ -1,27 +0,0 @@ -# -# Copyright (C) 2018-2021 Intel Corporation -# -# SPDX-License-Identifier: MIT -# - -if(IS_DIRECTORY ${NEO_SOURCE_DIR}/.git) - add_custom_target(lint - ${NEO_SOURCE_DIR}/scripts/lint${BRANCH_DIR_SUFFIX}set_copyright.sh - WORKING_DIRECTORY ${NEO_SOURCE_DIR} - ) - set_target_properties(lint PROPERTIES - EXCLUDE_FROM_DEFAULT_BUILD TRUE - EXCLUDE_FROM_ALL TRUE - FOLDER ${NEO_SCRIPT_PROJECTS_FOLDER} - ) - add_custom_target(lint_head - ${NEO_SOURCE_DIR}/scripts/lint${BRANCH_DIR_SUFFIX}set_copyright.sh HEAD - WORKING_DIRECTORY ${NEO_SOURCE_DIR} - ) - set_target_properties(lint_head PROPERTIES - EXCLUDE_FROM_DEFAULT_BUILD TRUE - EXCLUDE_FROM_ALL TRUE - FOLDER ${NEO_SCRIPT_PROJECTS_FOLDER} - ) -endif() - diff --git a/scripts/lint/set_copyright.py b/scripts/lint/set_copyright.py deleted file mode 100755 index b5eb79bd4b..0000000000 --- a/scripts/lint/set_copyright.py +++ /dev/null @@ -1,273 +0,0 @@ -#!/usr/bin/env python3 - -# -# Copyright (C) 2018-2021 Intel Corporation -# -# SPDX-License-Identifier: MIT -# - -"""Usage: ./scripts/lint/set_copyright.py """ - -import re -import sys -import os -import datetime -import stat -import argparse - - -def is_banned(path): - """Check if path is banned.""" - - banned_paths = [ - 'scripts/tests/copyright/in', - 'scripts/tests/copyright/out', - 'third_party' - ] - - banned_files = [ - 'scripts/lint/set_copyright.sh' - ] - - path_banned = False - - for banned_file in banned_files: - if os.path.normpath(path) == os.path.normpath(banned_file): - path_banned = True - break - - if not path_banned: - dirname = os.path.dirname(path) - for banned_path in banned_paths: - if dirname.startswith(banned_path): - path_banned = True - break - - return path_banned - - -def can_be_scanned(path): - """Check whether we should scan this file""" - - allowed_extensions = [ - 'cpp', 'h', 'inl', 'hpp', 'm', - 'cmake', - 'py', 'sh', - 'cl', - 'exports' - ] - - allowed_extensions_2 = [ - 'h.in', 'rc.in', - 'options.txt' - ] - - allowed_files = [ - 'CMakeLists.txt' - ] - - path_ext = path.split('.') - path_ok = False - filename = os.path.basename(path) - - if not os.path.isfile(path): - print(f'Cannot find file {path}, skipping') - path_ok = False - - elif is_banned(path): - path_ok = False - - elif filename in allowed_files: - path_ok = True - - elif path_ext[-1].lower() in allowed_extensions: - path_ok = True - - elif '.'.join(path_ext[-2:]) in allowed_extensions_2: - path_ok = True - - if not path_ok: - print(f'[MIT] Ignoring file: {path}') - - return path_ok - - -def _parse_args(): - parser = argparse.ArgumentParser(description='Usage: ./scripts/lint/set_copyright.py ') - parser.add_argument('-c', '--check', action='store_true', help='Checks only, not changing files, fails if wrong copyright') - parser.add_argument('files', nargs='*') - args = parser.parse_args() - - return vars(args) - - -def main(args): - header_cpp = """/* - * Copyright (C) {} Intel Corporation - * - * SPDX-License-Identifier: MIT - * - */ -""" - - header_bash_style = """# -# Copyright (C) {} Intel Corporation -# -# SPDX-License-Identifier: MIT -# -""" - - cpp_sharp_lines = [ - '#pragma', - '#include' - ] - - status = 0 - - for path in args['files']: - - # avoid self scan - if os.path.abspath(path) == os.path.abspath(sys.argv[0]): - continue - - if not can_be_scanned(path): - continue - - print(f'[MIT] Processing file: {path}') - - gathered_lines = [] - gathered_header = [] - start_year = None - header = header_cpp - header_start = '/*' - header_end = '*/' - comment_char = r'\*' - - # now read line by line - with open(path) as fin: - - # take care of hashbang - first_line = fin.readline() - if not first_line.startswith('#!'): - line = first_line - first_line = '' - else: - line = fin.readline() - while(line == '\n'): - line = fin.readline() - - is_cpp = False - - # check whether comment type is '#' - if first_line or line.startswith('#'): - for i in cpp_sharp_lines: - print(f'a: {i} ~ {line}') - if line.startswith(i): - is_cpp = True - break - - if not is_cpp: - header_start = '#' - header_end = '\n' - header = header_bash_style - comment_char = '#' - - curr_comment = [] - - is_header = None - is_header_end = None - - # copyright have to be first comment in file - if line.startswith(header_start): - is_header = True - is_header_end = False - else: - is_header = False - is_header_end = True - - is_copyright = False - - while line: - if is_header: - if header_end == '\n' and len(line.strip()) == 0: - is_header = False - is_header_end = True - elif line.strip().endswith(header_end): - is_header = False - is_header_end = True - elif 'Copyright' in line: - expr = (rf'^{comment_char} Copyright \([Cc]\) (\d+)( *- *\d+)?') - match = re.match(expr, line.strip()) - if match: - start_year = match.groups()[0] - curr_comment = [] - is_copyright = True - if not is_copyright: - curr_comment.append(line) - gathered_header.append(line) - - elif is_copyright and is_header_end: - if len(line.strip()) > 0: - gathered_lines.append(line) - is_header_end = False - else: - gathered_header.append(line) - else: - gathered_lines.append(line) - - line = fin.readline() - - year = datetime.datetime.now().year - if start_year is None: - start_year = str(year) - elif int(start_year) < year: - start_year += '-' - start_year += str(year) - - written_header = [header.format(start_year)] - - if len(curr_comment) > 0 or len(gathered_lines) > 0: - written_header.append('\n') - - if len(curr_comment) > 0: - written_header.append(''.join(curr_comment)) - - if not args['check']: - # store file mode because we want to preserve this - old_mode = os.stat(path)[stat.ST_MODE] - os.remove(path) - with open(path, 'w') as fout: - if first_line: - fout.write(f'{first_line}\n') - - fout.write(''.join(written_header)) - contents = ''.join(gathered_lines) - fout.write(contents) - - # chmod to original value - os.chmod(path, old_mode) - - if args['check'] and ''.join(gathered_header) != ''.join(written_header): - _tmp = [] - for _itm in written_header: - _tmp.extend(f'{_aa}\n' for _aa in _itm.split('\n')) - print('--- source') - print('+++ updated') - print('@@') - - for idx, shl in enumerate(gathered_header): - if idx>=len(_tmp): - print('-%s' % shl.strip()) - elif shl != _tmp[idx]: - print('-%s' % shl.strip()) - print('+%s' % _tmp[idx].strip()) - else: - print(' %s' % shl.strip()) - - status = 1 - - return status - - -if __name__ == '__main__': - sys.exit(main(_parse_args())) diff --git a/scripts/lint/set_copyright.sh b/scripts/lint/set_copyright.sh deleted file mode 100755 index 88a3aa30ad..0000000000 --- a/scripts/lint/set_copyright.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash - -# -# Copyright (C) 2018-2020 Intel Corporation -# -# SPDX-License-Identifier: MIT -# - -python_interpreter="python3" - -if [[ "$OSTYPE" == "msys" ]]; then - python_interpreter="python" -fi - -converter=$(dirname $(readlink -f $0))/set_copyright.py - -if [ "${1:-STAGED}" = "HEAD" ]; then - git diff-tree --no-commit-id --name-only -r HEAD | xargs -n 1 $python_interpreter $converter -else - git diff --cached --name-only | xargs -n 1 $python_interpreter $converter - git diff --name-only | xargs -n 1 echo "Not scanned: " -fi diff --git a/scripts/tests/copyright/in/file1.cpp b/scripts/tests/copyright/in/file1.cpp deleted file mode 100644 index 584d75348a..0000000000 --- a/scripts/tests/copyright/in/file1.cpp +++ /dev/null @@ -1,3 +0,0 @@ -/* - * No copyright at all - */ diff --git a/scripts/tests/copyright/in/file1.sh b/scripts/tests/copyright/in/file1.sh deleted file mode 100644 index 47b70926a4..0000000000 --- a/scripts/tests/copyright/in/file1.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - - -echo 123 diff --git a/scripts/tests/copyright/in/file2.cpp b/scripts/tests/copyright/in/file2.cpp deleted file mode 100644 index b8fc5e1005..0000000000 --- a/scripts/tests/copyright/in/file2.cpp +++ /dev/null @@ -1,3 +0,0 @@ -/* - * Copyright (C) 2017 XYZ - */ diff --git a/scripts/tests/copyright/in/file2.sh b/scripts/tests/copyright/in/file2.sh deleted file mode 100644 index 53dd8c0db2..0000000000 --- a/scripts/tests/copyright/in/file2.sh +++ /dev/null @@ -1,2 +0,0 @@ -# -# Copyright (C) 2017 XYZ diff --git a/scripts/tests/copyright/in/file3.cpp b/scripts/tests/copyright/in/file3.cpp deleted file mode 100644 index 913647a4d6..0000000000 --- a/scripts/tests/copyright/in/file3.cpp +++ /dev/null @@ -1,3 +0,0 @@ -// -// This comment shouldn't be removed -// diff --git a/scripts/tests/copyright/in/file3.sh b/scripts/tests/copyright/in/file3.sh deleted file mode 100644 index 07a1ee74ed..0000000000 --- a/scripts/tests/copyright/in/file3.sh +++ /dev/null @@ -1,3 +0,0 @@ -# -# This comment shouldn't be removed -# diff --git a/scripts/tests/copyright/in/file4.cpp b/scripts/tests/copyright/in/file4.cpp deleted file mode 100644 index 2b2ef8eb73..0000000000 --- a/scripts/tests/copyright/in/file4.cpp +++ /dev/null @@ -1,7 +0,0 @@ -/* - * No copyright at all - */ - -#include "file.h" - -class C; diff --git a/scripts/tests/copyright/in/file4.sh b/scripts/tests/copyright/in/file4.sh deleted file mode 100644 index b734e957ea..0000000000 --- a/scripts/tests/copyright/in/file4.sh +++ /dev/null @@ -1,7 +0,0 @@ -# -# No copyright at all -# - -echo "file.h" - -exit 1 diff --git a/scripts/tests/copyright/in/file5.cpp b/scripts/tests/copyright/in/file5.cpp deleted file mode 100644 index 494e38ed1d..0000000000 --- a/scripts/tests/copyright/in/file5.cpp +++ /dev/null @@ -1,5 +0,0 @@ -/* - * Copyright (C) 2012 - 2016 Intel Corporation - * - * No spdx header - */ diff --git a/scripts/tests/copyright/in/file6.cpp b/scripts/tests/copyright/in/file6.cpp deleted file mode 100644 index 633a521486..0000000000 --- a/scripts/tests/copyright/in/file6.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -// header file with # in first line diff --git a/scripts/tests/copyright/in/file7.cpp b/scripts/tests/copyright/in/file7.cpp deleted file mode 100644 index 573e043978..0000000000 --- a/scripts/tests/copyright/in/file7.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include - -// header file with # in first line diff --git a/scripts/tests/copyright/test.sh b/scripts/tests/copyright/test.sh deleted file mode 100755 index 2d2b444ce3..0000000000 --- a/scripts/tests/copyright/test.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/sh - -# -# Copyright (C) 2018-2021 Intel Corporation -# -# SPDX-License-Identifier: MIT -# - -# -# Simple, file based tests for copyright script -# script return non-zero error code if something went wrong. -# diff output is printed -# - -script_directory=$(dirname "$0") - -python_interpreter="python3" - -if [[ "$OSTYPE" == "msys" ]]; then - python_interpreter="python" -fi - -$python_interpreter "${script_directory}/../../lint/set_copyright.py" "${script_directory}"/in/* - -for i in "${script_directory}"/in/* -do - fn=$(basename $i) - diff -du "${script_directory}/in/${fn}" "${script_directory}/out/${fn}" -done