-
Notifications
You must be signed in to change notification settings - Fork 28
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
ci: Add clang-tidy to CI #95
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Copyright 2023 The Khronos Group Inc. | ||
# Copyright 2023 Valve Corporation | ||
# Copyright 2023 LunarG, Inc. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
Checks: "-*,\ | ||
google*,\ | ||
readability-identifier-naming,\ | ||
-google-readability-todo,\ | ||
-google-readability-avoid-underscore-in-googletest-name,\ | ||
-google-runtime-references,\ | ||
" | ||
WarningsAsErrors: "*" | ||
HeaderFilterRegex: ".*" | ||
CheckOptions: | ||
- { key: readability-identifier-naming.VariableCase, value: lower_case } | ||
- { key: readability-identifier-naming.GlobalConstantCase, value: CamelCase } | ||
- { key: readability-identifier-naming.GlobalConstantPrefix, value: k } |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,15 @@ if (VUL_WERROR) | |
endif() | ||
endif() | ||
|
||
option(VVL_CLANG_TIDY "Use clang-tidy") | ||
if (VUL_CLANG_TIDY) | ||
find_program(CLANG_TIDY NAMES clang-tidy) | ||
if(NOT CLANG_TIDY) | ||
message(FATAL_ERROR "clang-tidy not found!") | ||
endif() | ||
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CMAKE_<LANG>_CLANG_TIDY only works on the makefile / ninja generator. Given how popular the visual studio generator is within our team this is likely only going to cause confusion. |
||
endif() | ||
|
||
if(${CMAKE_CXX_COMPILER_ID} MATCHES "(GNU|Clang)") | ||
add_compile_options( | ||
-Wall | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,7 +79,7 @@ static inline bool IsHighIntegrity() { | |
DWORD buffer_size; | ||
if (GetTokenInformation(process_token, TokenIntegrityLevel, mandatory_label_buffer, sizeof(mandatory_label_buffer), | ||
&buffer_size) != 0) { | ||
const TOKEN_MANDATORY_LABEL *mandatory_label = (const TOKEN_MANDATORY_LABEL *)mandatory_label_buffer; | ||
const TOKEN_MANDATORY_LABEL *mandatory_label = reinterpret_cast<const TOKEN_MANDATORY_LABEL *>(mandatory_label_buffer); | ||
const DWORD sub_authority_count = *GetSidSubAuthorityCount(mandatory_label->Label.Sid); | ||
const DWORD integrity_level = *GetSidSubAuthority(mandatory_label->Label.Sid, sub_authority_count - 1); | ||
|
||
|
@@ -150,17 +150,17 @@ std::filesystem::path LayerSettings::FindSettingsFile() { | |
LSTATUS err = RegOpenKeyEx(hives[hive_index], TEXT("Software\\Khronos\\Vulkan\\Settings"), 0, KEY_READ, &key); | ||
if (err == ERROR_SUCCESS) { | ||
TCHAR name[2048]; | ||
DWORD i = 0, name_size, type, pValues, value_size; | ||
DWORD i = 0, name_size, type, p_values, value_size; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have never seen this convention before. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I grabbed the clang-tidy file from the vulkan validation layers. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have no preference tbh. Just a matter of changing the clang-tidy file.
|
||
while (ERROR_SUCCESS == RegEnumValue(key, i++, name, &(name_size = sizeof(name)), nullptr, &type, | ||
reinterpret_cast<LPBYTE>(&pValues), &(value_size = sizeof(pValues)))) { | ||
reinterpret_cast<LPBYTE>(&p_values), &(value_size = sizeof(p_values)))) { | ||
// Check if the registry entry is a dword with a value of zero | ||
if (type != REG_DWORD || pValues != 0) { | ||
if (type != REG_DWORD || p_values != 0) { | ||
continue; | ||
} | ||
|
||
// Check if this actually points to a file | ||
DWORD fileAttrib = GetFileAttributes(name); | ||
if ((fileAttrib == INVALID_FILE_ATTRIBUTES) || (fileAttrib & FILE_ATTRIBUTE_DIRECTORY)) { | ||
DWORD file_attrib = GetFileAttributes(name); | ||
if ((file_attrib == INVALID_FILE_ATTRIBUTES) || (file_attrib & FILE_ATTRIBUTE_DIRECTORY)) { | ||
continue; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,10 +41,10 @@ std::string GetFileSettingName(const char *pLayerName, const char *pSettingName) | |
assert(pLayerName != nullptr); | ||
assert(pSettingName != nullptr); | ||
|
||
std::stringstream settingName; | ||
settingName << vl::ToLower(TrimPrefix(pLayerName)) << "." << pSettingName; | ||
std::stringstream setting_name; | ||
setting_name << vl::ToLower(TrimPrefix(pLayerName)) << "." << pSettingName; | ||
|
||
return settingName.str(); | ||
return setting_name.str(); | ||
} | ||
|
||
std::string GetEnvSettingName(const char *layer_key, const char *setting_key, TrimMode trim_mode) { | ||
|
@@ -145,15 +145,15 @@ std::string TrimVendor(const std::string &layer_key) { | |
std::string ToLower(const std::string &s) { | ||
std::string result = s; | ||
for (auto &c : result) { | ||
c = (char)std::tolower(c); | ||
c = static_cast<char>(std::tolower(c)); | ||
} | ||
return result; | ||
} | ||
|
||
std::string ToUpper(const std::string &s) { | ||
std::string result = s; | ||
for (auto &c : result) { | ||
c = (char)std::toupper(c); | ||
c = static_cast<char>(std::toupper(c)); | ||
} | ||
return result; | ||
} | ||
|
@@ -230,34 +230,34 @@ std::vector<VlFrameset> ToFrameSets(const std::string &s) { | |
} | ||
|
||
bool IsFrameSets(const std::string &s) { | ||
static const std::regex FRAME_REGEX("^([0-9]+([-][0-9]+){0,2})(,([0-9]+([-][0-9]+){0,2}))*$"); | ||
static const std::regex frame_regex("^([0-9]+([-][0-9]+){0,2})(,([0-9]+([-][0-9]+){0,2}))*$"); | ||
|
||
return std::regex_search(s, FRAME_REGEX); | ||
return std::regex_search(s, frame_regex); | ||
} | ||
|
||
bool IsInteger(const std::string &s) { | ||
static const std::regex FRAME_REGEX("^-?([0-9]*|0x[0-9|a-z|A-Z]*)$"); | ||
static const std::regex frame_regex("^-?([0-9]*|0x[0-9|a-z|A-Z]*)$"); | ||
|
||
return std::regex_search(s, FRAME_REGEX); | ||
return std::regex_search(s, frame_regex); | ||
} | ||
|
||
bool IsFloat(const std::string &s) { | ||
static const std::regex FRAME_REGEX("^-?[0-9]*([.][0-9]*f?)?$"); | ||
static const std::regex frame_regex("^-?[0-9]*([.][0-9]*f?)?$"); | ||
|
||
return std::regex_search(s, FRAME_REGEX); | ||
return std::regex_search(s, frame_regex); | ||
} | ||
|
||
std::string FormatString(const char *message, ...) { | ||
std::size_t const STRING_BUFFER(4096); | ||
std::size_t const string_buffer(4096); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. string_buffer is a confusing name since its the length of the buffer, not the buffer itself. |
||
|
||
assert(message != nullptr); | ||
assert(strlen(message) >= 1 && strlen(message) < STRING_BUFFER); | ||
assert(strlen(message) >= 1 && strlen(message) < string_buffer); | ||
|
||
char buffer[STRING_BUFFER]; | ||
char buffer[string_buffer]; | ||
va_list list; | ||
|
||
va_start(list, message); | ||
vsnprintf(buffer, STRING_BUFFER, message, list); | ||
vsnprintf(buffer, string_buffer, message, list); | ||
va_end(list); | ||
|
||
return buffer; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is it disabled by default? It seems much better for me to hit issues on my system than on C.I., consume more C.I. resource and have to iterate, taking more development time. This is especially true that I don't see how the developer would even now what the rules are.
I would argu the same with VUL_WERROR being OFF by default.
I think we need to be more consious when we add new checks how this is going to affect the developers productivity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's off by default to avoid issues with package managers, machines that don't have clang-tidy installed by default, FetchContent/add_subdirectory users, etc.
Having it on by default is more complicated than having it on. That's just the way it is with open source projects.