Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright (c) 2023-2026 Arm Limited.
# SPDX-FileCopyrightText: 2026 Yusuf Efe
#
# SPDX-License-Identifier: MIT
#
Expand Down Expand Up @@ -96,14 +97,17 @@ repos:
name: Commit Message Check
language: python
always_run: true
entry: bash -c "pip install -q commitizen && git log -1 --pretty=%s | cz check"
additional_dependencies: ['commitizen==4.18.0']
entry: bash -c "git log -1 --pretty=%s | cz check"
pass_filenames: false
stages: [pre-push]
- id: check-signoff
name: Check Signed-off-by
entry: >
bash -c 'git log -1 --pretty=%B |
grep -qiE "^Signed-off-by: .+ <.+@.+>$"'
always_run: true
pass_filenames: false
language: system
stages: [pre-push]
- repo: https://github.com/pre-commit/mirrors-clang-format
Expand Down
50 changes: 24 additions & 26 deletions scripts/check_bad_style.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash
#!/usr/bin/env bash
#
# SPDX-FileCopyrightText: 2017-2020, 2022, 2024-2025 Arm Limited
# SPDX-FileCopyrightText: 2026 Yusuf Efe
#
# SPDX-License-Identifier: MIT
#
Expand Down Expand Up @@ -35,63 +36,63 @@ else
FILES=$@
fi

grep -HrnP --exclude-dir=assembly --exclude-dir=convolution --exclude_dir=third_party --exclude-dir=arm_gemm --exclude-dir=arm_conv "/\*\*$" $FILES | tee bad_style.log
grep -HrnP --exclude-dir=assembly --exclude-dir=convolution --exclude-dir=third_party --exclude-dir=arm_gemm --exclude-dir=arm_conv "/\*\*$" $FILES | tee bad_style.log
if (( `cat bad_style.log | wc -l` > 0 ))
then
echo ""
echo "ERROR: Doxygen comments should start on the first line: \"/** My comment\""
exit -1
fi

grep -Hnr --exclude-dir=assembly --exclude-dir=convolution --exclude_dir=third_party --exclude-dir=arm_gemm --exclude-dir=arm_conv --exclude=Doxyfile "@brief" $FILES | tee bad_style.log
grep -Hnr --exclude-dir=assembly --exclude-dir=convolution --exclude-dir=third_party --exclude-dir=arm_gemm --exclude-dir=arm_conv --exclude=Doxyfile "@brief" $FILES | tee bad_style.log
if (( `cat bad_style.log | wc -l` > 0 ))
then
echo ""
echo "ERROR: Doxygen comments shouldn't use '@brief'"
exit -1
fi

grep -HnRE --exclude-dir=assembly --exclude-dir=convolution --exclude_dir=third_party --exclude-dir=arm_gemm --exclude-dir=arm_conv "\buint " --exclude-dir=cl_kernels --exclude-dir=cs_shaders $FILES | tee bad_style.log
grep -HnRE --exclude-dir=assembly --exclude-dir=convolution --exclude-dir=third_party --exclude-dir=arm_gemm --exclude-dir=arm_conv "\buint " --exclude-dir=cl_kernels --exclude-dir=cs_shaders $FILES | tee bad_style.log
if [[ $(cat bad_style.log | wc -l) > 0 ]]
then
echo ""
echo "ERROR: C/C++ don't define 'uint'. Use 'unsigned int' instead."
exit -1
fi

grep -HnR --exclude-dir=assembly --exclude-dir=convolution --exclude_dir=third_party --exclude-dir=arm_gemm --exclude-dir=arm_conv "/^float32_t/" $FILES | tee bad_style.log
grep -HnR --exclude-dir=assembly --exclude-dir=convolution --exclude-dir=third_party --exclude-dir=arm_gemm --exclude-dir=arm_conv "/^float32_t/" $FILES | tee bad_style.log
if [[ $(cat bad_style.log | wc -l) > 0 ]]
then
echo ""
echo "ERROR: C/C++ don't define 'float32_t'. Use 'float' instead."
exit -1
fi

grep -Hnir --exclude-dir=assembly --exclude-dir=convolution --exclude_dir=third_party --exclude-dir=arm_gemm --exclude-dir=arm_conv "arm[_ ]\?cv" $FILES | tee bad_style.log
grep -Hnir --exclude-dir=assembly --exclude-dir=convolution --exclude-dir=third_party --exclude-dir=arm_gemm --exclude-dir=arm_conv "arm[_ ]\?cv" $FILES | tee bad_style.log
if [[ $(cat bad_style.log | wc -l) > 0 ]]
then
echo ""
echo "ERROR: Reference to arm_cv detected in the files above (Replace with arm_compute)"
exit -1
fi

grep -Hnir --exclude-dir=assembly --exclude-dir=convolution --exclude_dir=third_party --exclude-dir=arm_gemm --exclude-dir=arm_conv "#.*if.*defined[^(]" $FILES | tee bad_style.log
grep -Hnir --exclude-dir=assembly --exclude-dir=convolution --exclude-dir=third_party --exclude-dir=arm_gemm --exclude-dir=arm_conv "#.*if.*defined[^(]" $FILES | tee bad_style.log
if [[ $(cat bad_style.log | wc -l) > 0 ]]
then
echo ""
echo "ERROR: use parenthesis after #if defined(MY_PREPROCESSOR)"
exit -1
fi

grep -Hnir --exclude-dir=assembly --exclude-dir=convolution --exclude_dir=third_party --exclude-dir=arm_gemm --exclude-dir=arm_conv "#else$\|#endif$" $FILES | tee bad_style.log
grep -Hnir --exclude-dir=assembly --exclude-dir=convolution --exclude-dir=third_party --exclude-dir=arm_gemm --exclude-dir=arm_conv "#else$\|#endif$" $FILES | tee bad_style.log
if [[ $(cat bad_style.log | wc -l) > 0 ]]
then
echo ""
echo "ERROR: #else and #endif should be followed by a comment of the guard they refer to (e.g /* ARM_COMPUTE_AARCH64_V8_2 */ )"
exit -1
fi

grep -Hnir --exclude-dir=assembly --exclude-dir=convolution --exclude_dir=third_party --exclude-dir=arm_gemm --exclude-dir=arm_conv "ARM_COMPUTE_AARCH64_V8_2" ./tests/validation/CL | tee bad_style.log
grep -Hnir --exclude-dir=assembly --exclude-dir=convolution --exclude-dir=third_party --exclude-dir=arm_gemm --exclude-dir=arm_conv "ARM_COMPUTE_AARCH64_V8_2" ./tests/validation/CL | tee bad_style.log
if [[ $(cat bad_style.log | wc -l) > 0 ]]
then
echo ""
Expand All @@ -100,24 +101,21 @@ then
fi

spdx_missing=0
for f in $(find $FILES -type f)
for f in $(find $FILES -type f -exec grep -L SPDX {} +)
do
if [[ $(grep SPDX $f | wc -l) == 0 ]]
then
# List of exceptions:
case `basename $f` in
"arm_compute_version.embed");;
"filelist.json");;
".clang-format");;
".clang-tidy");;
"README.md");;
#It's an error for other files to not contain the MIT header:
*)
spdx_missing=1
echo $f;
;;
esac
fi;
# List of exceptions:
case `basename $f` in
"arm_compute_version.embed");;
"filelist.json");;
".clang-format");;
".clang-tidy");;
"README.md");;
#It's an error for other files to not contain the MIT header:
*)
spdx_missing=1
echo $f;
;;
esac
done

if [[ $spdx_missing > 0 ]]
Expand Down
5 changes: 3 additions & 2 deletions scripts/check_header_guards.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2023 Arm Limited.
# SPDX-FileCopyrightText: 2026 Yusuf Efe
#
# SPDX-License-Identifier: MIT
#
Expand Down Expand Up @@ -193,12 +194,12 @@ def skip_file(filepath: str, extensions: List[str], exclude: List[str], include:

expected_header_guard : str = find_expected_header_guard(file, prefix, add_extension, drop_outermost_subdir)

with open(file, "r") as fd:
with open(file, "r", encoding="utf-8") as fd:
lines: List = fd.readlines()

new_lines, guards_updated = fix_header_guard(lines, expected_header_guard, comment_style)

with open(file, "w") as fd:
with open(file, "w", encoding="utf-8", newline='\n') as fd:
fd.writelines([f"{line}" for line in new_lines])

if guards_updated:
Expand Down
12 changes: 7 additions & 5 deletions scripts/format_code.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3

# Copyright (c) 2023-2025 Arm Limited.
# SPDX-FileCopyrightText: 2026 Yusuf Efe
#
# SPDX-License-Identifier: MIT
#
Expand Down Expand Up @@ -248,13 +249,14 @@ def run(self):
retval = 0
self.shell = Shell()
self.shell.save_cwd()
this_dir = os.path.dirname(__file__)
this_dir = os.path.dirname(os.path.abspath(__file__))

logger.debug("Running Android.bp check")
try:
self.shell.cd(self.folder)
cmd = "%s/generate_android_bp.py --folder %s --output_file %s" % (this_dir, self.folder, self.bp_output_file)
output = self.shell.run_single_to_str(cmd)
cmd = [sys.executable, os.path.join(this_dir, "generate_android_bp.py"),
"--folder", self.folder, "--output_file", self.bp_output_file]
output = subprocess.check_output(cmd, env=self.shell.env, stderr=subprocess.STDOUT, text=True)
if len(output) > 0:
logger.info(output)
except subprocess.CalledProcessError as e:
Expand All @@ -266,8 +268,8 @@ def run(self):
if not filecmp.cmp(self.bp_output_file, self.folder + "/Android.bp"):
is_mismatched = True

with open(self.bp_output_file, 'r') as generated_file:
with open(self.folder + "/Android.bp", 'r') as review_file:
with open(self.bp_output_file, 'r', encoding='utf-8') as generated_file:
with open(self.folder + "/Android.bp", 'r', encoding='utf-8') as review_file:
diff = list(difflib.unified_diff(generated_file.readlines(), review_file.readlines(),
fromfile='Generated_Android.bp', tofile='Android.bp'))

Expand Down
3 changes: 2 additions & 1 deletion scripts/format_doxygen.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# SPDX-FileCopyrightText: 2017-2018, 2023-2025 Arm Limited
#
# SPDX-License-Identifier: MIT
# SPDX-FileCopyrightText: 2026 Yusuf Efe
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -123,7 +124,7 @@ def main(*args):

n_file += 1

with open(path,'r+', encoding="utf-8") as fd:
with open(path,'r+', encoding="utf-8", newline='\n') as fd:
comment = list()
first_param = -1
last_param = -1
Expand Down
11 changes: 7 additions & 4 deletions scripts/generate_android_bp.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3

# Copyright (c) 2023-2025 Arm Limited.
# SPDX-FileCopyrightText: 2026 Yusuf Efe
#
# SPDX-License-Identifier: MIT
#
Expand Down Expand Up @@ -171,21 +172,23 @@ def list_all_files(repo_path):
:param repo_path: Path of the repository
:return: The filtered list of useful filess
"""
repo_path = repo_path.replace(os.sep, "/")
if not repo_path.endswith('/'):
repo_path = repo_path + "/"

# Get cpp files
cpp_files = []
cl_files = []
for path, subdirs, files in os.walk(repo_path):
path = path.replace(os.sep, "/")
for file in files:
if file.endswith(".cpp"):
cpp_files.append(os.path.join(path, file))
cpp_files.append(path + "/" + file)
elif file.endswith(".cl"):
cl_files.append(os.path.join(path, file))
cl_files.append(path + "/" + file)
# Include CL headers
if "src/core/CL/cl_kernels" in path and file.endswith(".h"):
cl_files.append(os.path.join(path, file))
cl_files.append(path + "/" + file)
# Filter out unused cpp files
filtered_cpp_files = []
for cpp_file in cpp_files:
Expand All @@ -212,5 +215,5 @@ def list_all_files(repo_path):
cpp_files, opencl_files = list_all_files(args.folder)
bp_file = generate_bp_file(cpp_files, opencl_files)

with open(args.output_file, 'w') as f:
with open(args.output_file, 'w', encoding='utf-8', newline='\n') as f:
f.write(bp_file)
6 changes: 4 additions & 2 deletions scripts/generate_build_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-

# Copyright (c) 2023-2026 Arm Limited.
# SPDX-FileCopyrightText: 2026 Yusuf Efe
#
# SPDX-License-Identifier: MIT
#
Expand Down Expand Up @@ -276,6 +277,7 @@ def gather_sources():
# -------------------------------------

def strip_prefix(filename, prefix = "src/"):
filename = filename.replace("\\", "/")
return filename[len(prefix):] if filename.startswith(prefix) else filename

graph_files = sorted([strip_prefix(path, "src/") for path in graph_files])
Expand All @@ -302,13 +304,13 @@ def strip_prefix(filename, prefix = "src/"):

bazel_build_string = build_from_template_bazel(
graph_files, lib_files_sve, lib_files_sve2, lib_files + lib_files_neon_fp16)
with open("src/BUILD.bazel", "w") as fp:
with open("src/BUILD.bazel", "w", newline='\n') as fp:
fp.write(bazel_build_string)

if args.cmake:
cmake_build_string = build_from_template_cmake(
graph_files, lib_files_sve, lib_files_sve2, lib_files, lib_files_neon_fp16)
with open("src/CMakeLists.txt", "w") as fp:
with open("src/CMakeLists.txt", "w", newline='\n') as fp:
fp.write(cmake_build_string)

if not args.cmake and not args.bazel:
Expand Down
5 changes: 3 additions & 2 deletions scripts/include_functions_kernels.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-

# Copyright (c) 2017-2018, 2020-2021, 2023, 2025 Arm Limited.
# SPDX-FileCopyrightText: 2026 Yusuf Efe
#
# SPDX-License-Identifier: MIT
#
Expand Down Expand Up @@ -55,7 +56,7 @@ def read_file(file):


def write_file(file, lines):
with open(file, "w") as f:
with open(file, "w", newline='\n') as f:
for line in lines:
f.write(line)

Expand All @@ -73,7 +74,7 @@ def add_updated_includes(lines, pos, includes):
def create_include_list(folder):
files_path = folder + "/*.h"
files = glob.glob(files_path)
updated_files = [include_str + folder + "/" + x.rsplit('/',1)[1] + "\"\n" for x in files]
updated_files = [include_str + folder + "/" + os.path.basename(x) + "\"\n" for x in files]
updated_files.sort(key=lambda x: x.lower())
return updated_files

Expand Down
Loading