SWDEV-123456 auto clang-format (#482)

* SWDEV-123456 - add clang-format script and pre-commit hook

[ROCm/clr commit: 580a8759dd]
Tá an tiomantas seo le fáil i:
Lytovchenko, Danylo
2025-06-05 14:28:12 +02:00
tiomanta ag GitHub
tuismitheoir 2001b250b5
tiomantas 89b5c1d9bf
D'athraigh 4 comhad le 70 breiseanna agus 7 scriosta
+39
Féach ar an gComhad
@@ -0,0 +1,39 @@
#!/usr/bin/env bash
set -euo pipefail
RANGE=""
while [[ $# -gt 0 ]]; do
echo $1
echo $2
case "$1" in
--range)
RANGE="$2"
shift 2
;;
*)
echo "Unknown arg $1" >&2
exit 64
;;
esac
done
regex='\.(c|cc|cpp|cxx|h|hh|hpp|hxx)$'
if [[ -n $RANGE ]]; then
files=$(git diff --name-only "$RANGE" | grep -E "$regex" || true)
else
files=$(git diff --cached --name-only --diff-filter=ACMR | grep -E "$regex" || true)
fi
echo "Checking $files"
[[ -z $files ]] && exit 0
clang_bin="${CLANG_FORMAT:-clang-format}"
if ! command -v "$clang_bin" >/dev/null 2>&1; then
if [[ -x "/c/Program Files/LLVM/bin/clang-format.exe" ]]; then
clang_bin="/c/Program Files/LLVM/bin/clang-format.exe"
fi
fi
"$clang_bin" -style=file --dry-run -fallback-style=none -n -Werror $files
+2
Féach ar an gComhad
@@ -0,0 +1,2 @@
#!/usr/bin/env bash
exec "$(git rev-parse --show-toplevel)/.github/hooks/clang-format-check.sh"
+22
Féach ar an gComhad
@@ -0,0 +1,22 @@
name: Clang format check
on:
push:
jobs:
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install clang-format
run: |
sudo apt update && sudo apt install -y clang-format
- name: Run clang-format-check
id: clang-format
run: |
chmod +x .github/hooks/clang-format-check.sh
./.github/hooks/clang-format-check.sh --range "${{ github.event.before }}..${{ github.sha }}"
+7 -7
Féach ar an gComhad
@@ -28,6 +28,7 @@
#include <cstring> #include <cstring>
#include <utility> #include <utility>
RUNTIME_ENTRY(cl_int, clGetDeviceIDsFromDX9MediaAdapterKHR, RUNTIME_ENTRY(cl_int, clGetDeviceIDsFromDX9MediaAdapterKHR,
(cl_platform_id platform, cl_uint num_media_adapters, (cl_platform_id platform, cl_uint num_media_adapters,
cl_dx9_media_adapter_type_khr* media_adapters_type, void* media_adapters, cl_dx9_media_adapter_type_khr* media_adapters_type, void* media_adapters,
@@ -182,8 +183,7 @@ RUNTIME_ENTRY_RET(cl_mem, clCreateFromDX9MediaSurfaceKHR,
D3DSURFACE_DESC Desc; D3DSURFACE_DESC Desc;
pD3D9Resource->GetDesc(&Desc); pD3D9Resource->GetDesc(&Desc);
if ((Desc.Format != D3DFMT_NV_12) && if ((Desc.Format != D3DFMT_NV_12) && (Desc.Format != D3DFMT_P010) &&
(Desc.Format != D3DFMT_P010) &&
(Desc.Format != D3DFMT_YV_12) && (plane != 0)) { (Desc.Format != D3DFMT_YV_12) && (plane != 0)) {
*not_null(errcode_ret) = CL_INVALID_VALUE; *not_null(errcode_ret) = CL_INVALID_VALUE;
LogWarning("The plane has to be Zero if the surface format is non-planar !"); LogWarning("The plane has to be Zero if the surface format is non-planar !");
@@ -232,15 +232,16 @@ RUNTIME_EXIT
// clCreateImage2DFromD3D9ResourceAMD // clCreateImage2DFromD3D9ResourceAMD
// //
cl_mem amd::clCreateImage2DFromD3D9ResourceAMD(amd::Context& amdContext, cl_mem_flags flags, cl_mem amd::clCreateImage2DFromD3D9ResourceAMD(amd::Context& amdContext, cl_mem_flags flags,
cl_dx9_media_adapter_type_khr adapter_type, cl_dx9_media_adapter_type_khr adapter_type,
cl_dx9_surface_info_khr* surface_info, cl_uint plane, cl_dx9_surface_info_khr* surface_info, cl_uint plane,
int* errcode_ret) { int* errcode_ret) {
cl_dx9_surface_info_khr* cl_surf_info = reinterpret_cast<cl_dx9_surface_info_khr*>(surface_info); cl_dx9_surface_info_khr* cl_surf_info = reinterpret_cast<cl_dx9_surface_info_khr*>(surface_info);
IDirect3DSurface9* pD3D9Resource = cl_surf_info->resource; IDirect3DSurface9* pD3D9Resource = cl_surf_info->resource;
HANDLE shared_handle = cl_surf_info->shared_handle; HANDLE shared_handle = cl_surf_info->shared_handle;
amd::D3D9Object obj; amd::D3D9Object obj;
cl_int errcode = amd::D3D9Object::initD3D9Object(amdContext, adapter_type, surface_info, plane, obj); cl_int errcode =
amd::D3D9Object::initD3D9Object(amdContext, adapter_type, surface_info, plane, obj);
if (CL_SUCCESS != errcode) { if (CL_SUCCESS != errcode) {
*not_null(errcode_ret) = errcode; *not_null(errcode_ret) = errcode;
return (cl_mem)0; return (cl_mem)0;
@@ -293,5 +294,4 @@ void amd::SyncD3D9Objects(std::vector<amd::Memory*>& memObjects) {
} }
#endif //_WIN32 #endif //_WIN32