Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RHEL-65784: CI: Enable code style checking with clang-format [CI-NO-BUILD] #1192

Merged
merged 3 commits into from
Nov 20, 2024
Merged
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
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DisableFormat: true
25 changes: 25 additions & 0 deletions .github/workflows/clang-format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: clang-format check
on: [push, pull_request]

jobs:
clang-format:
name: Code style check for ${{ matrix.path['check'] }}
runs-on: ubuntu-24.04
strategy:
matrix:
path:
- check: '.'
exclude: './VirtIO'
- check: 'VirtIO'
exclude: ''

steps:
- uses: actions/checkout@v4
- name: Run clang-format style check for C/C++ programs.
run: |
sudo apt-get update
sudo apt-get install --no-install-recommends -y clang-format-16
bash Tools/clang-format-helper.sh ${CHECK_PATH} "" ${EXCLUDE_REGEX}
env:
CHECK_PATH: ${{ matrix.path['check'] }}
EXCLUDE_REGEX: ${{ matrix.path['exclude'] }}
1 change: 0 additions & 1 deletion NetKVM/CoInstaller/Exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,3 @@ class neTKVMW32ErrorException : public neTKVMNumErrorException
static tstring GetErrorString(DWORD dwErrorCode);
};
#endif

1 change: 0 additions & 1 deletion NetKVM/CoInstaller/NetKVMAux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,3 @@ wstring NetKVMGetKeyPathFromKKEY(HKEY hKey)
}
return wstrKeyPath;
}

1 change: 0 additions & 1 deletion NetKVM/CoInstaller/RegAccess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,4 +543,3 @@ VOID neTKVMRegAccess::FormatFullRegPath(LPTSTR lpzFullPathBuff, DWORD_PTR dwNumb
}
}
}

2 changes: 0 additions & 2 deletions NetKVM/CoInstaller/RegParam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,5 +403,3 @@ void neTKVMRegEditParam::FillExInfo(neTKVMRegParamExInfoList &ExInfoList)
ExInfoList.push_back(neTKVMRegParamExInfo(NETKVM_RPIID_EDIT_TEXT_LIMIT, tss.str()));
}
}


1 change: 0 additions & 1 deletion NetKVM/CoInstaller/RegParam.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,3 @@ class neTKVMRegEditParam : public neTKVMRegParam
DWORD m_nLimitText;
bool m_bUpperCase;
};

2 changes: 0 additions & 2 deletions NetKVM/CoInstaller/tstrings.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,3 @@ wstring __string2wstring(const string& str);
typedef list<tstring, allocator<tstring>> neTKVMTStrList;

#define TBUF_SIZEOF(a) ARRAY_SIZE(a)


1 change: 0 additions & 1 deletion NetKVM/Common/ParaNdis-RSS.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,3 @@ class PARANDIS_RSS_PARAMS
#endif

#endif

2 changes: 1 addition & 1 deletion NetKVM/Common/ParaNdis_GuestAnnounce.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ class CGuestAnnouncePackets : public CPlacementAllocatable
EthernetNSMFrame *CreateIPv6Packet(USHORT *IPV6);
};

bool CallCompletionForNBL(PARANDIS_ADAPTER * pContext, PNET_BUFFER_LIST NBL);
bool CallCompletionForNBL(PARANDIS_ADAPTER * pContext, PNET_BUFFER_LIST NBL);
2 changes: 1 addition & 1 deletion NetKVM/Common/ParaNdis_LockFreeQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,4 +342,4 @@ class CLockFreeDynamicQueue : public CPlacementAllocatable
volatile LONG m_QueueFullListIsEmpty;
volatile LONG m_ElementCount;
volatile LONG m_Size;
};
};
2 changes: 1 addition & 1 deletion NetKVM/Common/Trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@
//
// FUNC TraceNoPrefix{Flags=TRACE_DRIVER}(LEVEL, MSG, ...);
// end_wpp
//
//
3 changes: 1 addition & 2 deletions NetKVM/Common/netkvmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ typedef struct _NETKVMD_ADAPTER
UCHAR MacAddress[6];
UCHAR Virtio;
UCHAR IsStandby;

UCHAR VirtioLink;
UCHAR SuppressLink;
UCHAR Started;
Expand All @@ -60,4 +60,3 @@ typedef struct _NETKVMD_SET_LINK

// input buffer = NETKVMD_SET_LINK
#define IOCTL_NETKVMD_SET_LINK CTL_CODE(FILE_DEVICE_NETWORK, 0x802, METHOD_BUFFERED, FILE_READ_ACCESS)

4 changes: 1 addition & 3 deletions NetKVM/DebugTools/Netchecksum/netchecksum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,8 @@ int _tmain(int argc, _TCHAR* argv[])
}

DPrintf(0, ("Unit test %s", bOK ? "PASSED" : "FAILED"));

//getchar();

return 0;
}


2 changes: 0 additions & 2 deletions NetKVM/DebugTools/RSS-Toeplitz/WinToeplitz.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,3 @@ UINT32 ToeplitzHash(const PHASH_CALC_SG_BUF_ENTRY sgBuff, int sgEntriesNum, UINT
#undef TOEPLITZ_BYTE_BIT_STATE
#undef TOEPLITZ_MAX_BIT_NUM
}


1 change: 0 additions & 1 deletion NetKVM/ProtocolService/Log.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@

#define ELEMENTS_IN(a) sizeof(a)/sizeof(a[0])
#define Log(fmt, ...) { CStringA _s_; _s_.Format(fmt "\n", __VA_ARGS__); OutputDebugStringA(_s_); }

1 change: 0 additions & 1 deletion NetKVM/linux/if_ether.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@
#define ETH_ALEN 6

#endif

2 changes: 1 addition & 1 deletion NetKVM/wlh/ParaNdis6_Driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
#include "ndis56common.h"

VOID ParaNdis6_SendNBLInternal(NDIS_HANDLE miniportAdapterContext, PNET_BUFFER_LIST pNBL,
NDIS_PORT_NUMBER portNumber, ULONG flags);
NDIS_PORT_NUMBER portNumber, ULONG flags);
78 changes: 78 additions & 0 deletions Tools/clang-format-helper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/usr/bin/env bash

set -e

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

# Default to the root of the repository
CHECK_PATH="${1:-"${SCRIPT_DIR}/.."}"
CLANG_FORMAT_STYLE="${2:-"${CHECK_PATH}/.clang-format"}"
EXCLUDE_REGEX="$3"
INCLUDE_REGEX="$4"

CLANG_FORMAT_STYLE="$(realpath "${CLANG_FORMAT_STYLE}")"

# Let's think that script will be used on Linux and Windows (msys or cygwin env only)
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
# Linux
clang_format="$(which clang-format)"
else
# Windows
# Load clang-format from the EWDK 24H2
EWDK11_24H2_DIR="${EWDK11_24H2_DIR:-c:\\ewdk11_24h2}"
clang_format_ewdk="${EWDK11_24H2_DIR}\\Program Files\\Microsoft Visual Studio\\2022\\BuildTools\\VC\\Tools\\Llvm\\x64\\bin\\clang-format.exe"
clang_format="$(cygpath "${clang_format_ewdk}")"
# Convert the path to OS specific format
CLANG_FORMAT_STYLE="$(cygpath -w "${CLANG_FORMAT_STYLE}")"
fi

echo "Using clang-format version: $("${clang_format}" --version)"
echo "Running clang-format on $(realpath ${CHECK_PATH})"
echo "Using clang-format style file: ${CLANG_FORMAT_STYLE}"

if [[ -z $EXCLUDE_REGEX ]]; then
EXCLUDE_REGEX="^$"
fi

# Set the filetype regex if nothing was provided.
# Find all C/C++ files:
# h, H, hpp, hh, h++, hxx
# c, C, cpp, cc, c++, cxx
if [[ -z $INCLUDE_REGEX ]]; then
INCLUDE_REGEX='^.*\.((((c|C)(c|pp|xx|\+\+)?$)|((h|H)h?(pp|xx|\+\+)?$)))$'
fi

# initialize exit code
exit_code=0

cd "${CHECK_PATH}"
src_files=$(find "." -name .git -prune -o -regextype posix-egrep -regex "$INCLUDE_REGEX" -print)

# check formatting in each source file
IFS=$'\n' # Loop below should separate on new lines, not spaces.
for file in $src_files; do
# Only check formatting if the path doesn't match the regex
if ! [[ ${file} =~ $EXCLUDE_REGEX ]]; then
# Convert the path to OS specific format
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
file_path="${file}"
else
file_path="$(cygpath -w "${file}")"
fi

formatted_code="$("${clang_format}" --style=file:"${CLANG_FORMAT_STYLE}" --verbose --Werror "${file_path}")"
if [[ -z "$formatted_code" ]]; then
continue
fi

local_format="$(diff <(cat "${file}") <(echo "${formatted_code}") || true)"
if [[ -n "${local_format}" ]]; then
echo "The file ${file} is not formatted correctly"
echo "${local_format}"
exit_code=1
fi
fi
done

echo "clang-format check finished with exit code: ${exit_code}"
exit $exit_code
1 change: 1 addition & 0 deletions VirtIO/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DisableFormat: true
2 changes: 1 addition & 1 deletion VirtIO/virtio_pci_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,4 @@ bool vp_notify(struct virtqueue *vq);
NTSTATUS vio_legacy_initialize(VirtIODevice *vdev);
NTSTATUS vio_modern_initialize(VirtIODevice *vdev);

#endif
#endif
1 change: 0 additions & 1 deletion fwcfg64/driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,3 @@ NTSTATUS VMCoreInfoFill(PDEVICE_CONTEXT ctx);
NTSTATUS VMCoreInfoSend(PDEVICE_CONTEXT ctx);

NTSTATUS GetKdbg(PDEVICE_CONTEXT ctx);

2 changes: 1 addition & 1 deletion ivshmem/Driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ NTSTATUS IVSHMEMEvtDeviceAdd(_In_ WDFDRIVER Driver, _Inout_ PWDFDEVICE_INIT Devi

status = IVSHMEMCreateDevice(DeviceInit);
return status;
}
}
1 change: 0 additions & 1 deletion pvpanic/pvpanic/trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,3 @@
// FUNC TraceEvents(LEVEL, FLAGS, MSG, ...);
// end_wpp
//

1 change: 0 additions & 1 deletion viocrypt/dll/dllmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@ BOOL APIENTRY DllMain( HMODULE hModule,
}
return TRUE;
}

4 changes: 2 additions & 2 deletions viocrypt/sys/driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,6 @@ EVT_WDF_INTERRUPT_ISR VioCryptInterruptIsr;
EVT_WDF_INTERRUPT_DPC VioCryptInterruptDpc;
EVT_WDF_INTERRUPT_ENABLE VioCryptInterruptEnable;
EVT_WDF_INTERRUPT_DISABLE VioCryptInterruptDisable;

EVT_WDF_IO_QUEUE_IO_DEVICE_CONTROL VioCryptIoControl;
EVT_WDF_IO_QUEUE_IO_STOP VioCryptIoStop;
EVT_WDF_IO_QUEUE_IO_STOP VioCryptIoStop;
2 changes: 1 addition & 1 deletion viogpu/common/edid.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,4 @@ bool GetStandardTimingResolution(PSTANDARD_TIMING_DESCRIPTOR desc, PVIOGPU_DISP_
bool GetVICResolution(USHORT idx, PVIOGPU_DISP_MODE mode);

extern VIOGPU_DISP_MODE gpu_disp_modes[64];
extern UCHAR g_gpu_edid[EDID_V1_BLOCK_SIZE];
extern UCHAR g_gpu_edid[EDID_V1_BLOCK_SIZE];
1 change: 0 additions & 1 deletion viogpu/common/viogpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,4 +311,3 @@ typedef struct _COLOR_CHARACTERISTICS {
#define ISR_REASON_DISPLAY 1
#define ISR_REASON_CURSOR 2
#define ISR_REASON_CHANGE 4

1 change: 0 additions & 1 deletion viogpu/common/viogpu_pci.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,3 @@ NTSTATUS
UnmapFrameBuffer(
_In_reads_bytes_(Length) VOID* VirtualAddress,
_In_ ULONG Length);

3 changes: 1 addition & 2 deletions viogpu/common/viogpu_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class VioGpuQueue
VioGpuQueue();
~VioGpuQueue();
BOOLEAN Init(
_In_ VirtIODevice* pVIODevice,
_In_ VirtIODevice* pVIODevice,
_In_ struct virtqueue* pVirtQueue,
_In_ UINT index);
void Close(void);
Expand Down Expand Up @@ -201,4 +201,3 @@ class CrsrQueue : public VioGpuQueue
UINT QueueCursor(PGPU_VBUFFER buf);
PGPU_VBUFFER DequeueCursor(_Out_ UINT* len);
};

1 change: 0 additions & 1 deletion viogpu/viogpudo/driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -716,4 +716,3 @@ void DebugPrintFuncKdPrint(const char *format, ...)

#endif
#pragma code_seg(pop) // End Non-Paged Code

1 change: 0 additions & 1 deletion viogpu/viogpudo/driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,3 @@ VioGpuDodSystemDisplayWrite(
_In_ UINT SourceStride,
_In_ UINT PositionX,
_In_ UINT PositionY);

1 change: 0 additions & 1 deletion viogpu/viogpudo/viogpudo.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,4 +319,3 @@ class VioGpuDod {
NTSTATUS GetRegisterInfo(void);
VOID BuildVideoSignalInfo(D3DKMDT_VIDEO_SIGNAL_INFO* pVideoSignalInfo, PVIDEO_MODE_INFORMATION pModeInfo);
};

Loading