infra update

Removing legacy linter.

Signed-off-by: Grzegorz Choinski <grzegorz.choinski@intel.com>
This commit is contained in:
Grzegorz Choinski
2022-01-03 08:59:23 +00:00
committed by Compute-Runtime-Automation
parent 7d18b845fa
commit 997d28f6b2
21 changed files with 2 additions and 691 deletions

View File

@ -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

View File

@ -20,7 +20,7 @@ components:
infra:
branch: master
dest_dir: infra
revision: 6e042b53d9a02531d260b678605ec9ef2b27ea61
revision: de0a04af85bc058241dd55db4424fa3741e2479a
type: git
internal:
branch: master

View File

@ -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}
)

View File

@ -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 <files>')
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()))

View File

@ -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

View File

@ -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

View File

@ -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()

View File

@ -1,273 +0,0 @@
#!/usr/bin/env python3
#
# Copyright (C) 2018-2021 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
"""Usage: ./scripts/lint/set_copyright.py <files>"""
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 <files>')
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()))

View File

@ -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

View File

@ -1,3 +0,0 @@
/*
* No copyright at all
*/

View File

@ -1,4 +0,0 @@
#!/bin/bash
echo 123

View File

@ -1,3 +0,0 @@
/*
* Copyright (C) 2017 XYZ
*/

View File

@ -1,2 +0,0 @@
#
# Copyright (C) 2017 XYZ

View File

@ -1,3 +0,0 @@
//
// This comment shouldn't be removed
//

View File

@ -1,3 +0,0 @@
#
# This comment shouldn't be removed
#

View File

@ -1,7 +0,0 @@
/*
* No copyright at all
*/
#include "file.h"
class C;

View File

@ -1,7 +0,0 @@
#
# No copyright at all
#
echo "file.h"
exit 1

View File

@ -1,5 +0,0 @@
/*
* Copyright (C) 2012 - 2016 Intel Corporation
*
* No spdx header
*/

View File

@ -1,3 +0,0 @@
#pragma once
// header file with # in first line

View File

@ -1,3 +0,0 @@
#include <cstdint>
// header file with # in first line

View File

@ -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