From e05567c702a4d3c2e47d7f0d1c13b5e8ecd62317 Mon Sep 17 00:00:00 2001 From: Balakrishna Avulapati Date: Thu, 17 Jul 2025 12:44:08 +0530 Subject: [PATCH 01/16] Enable clang-tidy at target level Signed-off-by: Balakrishna Avulapati --- CMakeLists.txt | 2 -- cmake/common/clang-tidy.cmake | 54 ++++++++++++++++++----------------- src/core/time/CMakeLists.txt | 1 + 3 files changed, 29 insertions(+), 28 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 515621160..ea9da006a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,7 +31,6 @@ include(Sourcemeta) # Don't force downstream consumers on this if(PROJECT_IS_TOP_LEVEL) sourcemeta_enable_simd() - sourcemeta_clang_tidy_attempt_enable() endif() # TODO: Turn this into a re-usable utility CMake function @@ -119,7 +118,6 @@ endif() if(PROJECT_IS_TOP_LEVEL) # TODO: Try once more to enable this per target, # so, we don't need to manually disable it here - sourcemeta_clang_tidy_attempt_disable() sourcemeta_target_clang_format(SOURCES src/*.h src/*.cc benchmark/*.h benchmark/*.cc diff --git a/cmake/common/clang-tidy.cmake b/cmake/common/clang-tidy.cmake index f4b3d657f..30fea7538 100644 --- a/cmake/common/clang-tidy.cmake +++ b/cmake/common/clang-tidy.cmake @@ -77,7 +77,11 @@ function(sourcemeta_clang_tidy_attempt_install) endfunction() function(sourcemeta_clang_tidy_attempt_enable) - cmake_parse_arguments(SOURCEMETA_TARGET_CLANG_TIDY "REQUIRED" "" "" ${ARGN}) + # TODO: Support other platforms too, like Linux + if(NOT APPLE) + message(STATUS "Ignoring ClangTidy setup on OS other than APPLE") + return() + endif() if(SOURCEMETA_COMPILER_LLVM) message(STATUS "Enabling ClangTidy alongside compilation") @@ -86,40 +90,38 @@ function(sourcemeta_clang_tidy_attempt_enable) return() endif() - sourcemeta_clang_tidy_attempt_install(OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin") + cmake_parse_arguments(PARSE_ARGV 0 SOURCEMETA_CLANG_TIDY "" "TARGET_NAME" "") + if(NOT SOURCEMETA_CLANG_TIDY_TARGET_NAME) + message(STATUS "ClangTidy runs at target level. TARGET_NAME is required.") + return() + endif() - if(SOURCEMETA_TARGET_CLANG_TIDY_REQUIRED) - find_program(CLANG_TIDY_BIN NAMES clang-tidy NO_DEFAULT_PATH - PATHS "${CMAKE_CURRENT_BINARY_DIR}/bin") - if(NOT CLANG_TIDY_BIN) - find_program(CLANG_TIDY_BIN NAMES clang-tidy REQUIRED) - endif() - else() - find_program(CLANG_TIDY_BIN NAMES clang-tidy NO_DEFAULT_PATH - PATHS "${CMAKE_CURRENT_BINARY_DIR}/bin") - if(NOT CLANG_TIDY_BIN) - find_program(CLANG_TIDY_BIN NAMES clang-tidy) - endif() + sourcemeta_clang_tidy_attempt_install( + OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin") + + if(SOURCEMETA_CXX_CLANG_TIDY) + set_target_properties("${SOURCEMETA_CLANG_TIDY_TARGET_NAME}" + PROPERTIES CXX_CLANG_TIDY "${SOURCEMETA_CXX_CLANG_TIDY}") + return() endif() - set(CLANG_TIDY_CONFIG "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/clang-tidy.config") + find_program(CLANG_TIDY_BIN NAMES clang-tidy + NO_DEFAULT_PATH + PATHS "${PROJECT_BINARY_DIR}/bin" + REQUIRED) - # TODO: Support other platforms too, like Linux - if(APPLE) - execute_process(COMMAND xcrun --show-sdk-path + set(CLANG_TIDY_CONFIG "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/clang-tidy.config") + execute_process(COMMAND xcrun --show-sdk-path OUTPUT_VARIABLE MACOSX_SDK_PATH OUTPUT_STRIP_TRAILING_WHITESPACE) - execute_process(COMMAND "${CMAKE_CXX_COMPILER}" -print-resource-dir + execute_process(COMMAND "${CMAKE_CXX_COMPILER}" -print-resource-dir OUTPUT_VARIABLE MACOSX_RESOURCE_PATH OUTPUT_STRIP_TRAILING_WHITESPACE) - set(CMAKE_CXX_CLANG_TIDY + set(SOURCEMETA_CXX_CLANG_TIDY "${CLANG_TIDY_BIN};--config-file=${CLANG_TIDY_CONFIG};-header-filter=${PROJECT_SOURCE_DIR}/src/*" "--extra-arg=-std=c++${CMAKE_CXX_STANDARD}" "--extra-arg=-isysroot" "--extra-arg=${MACOSX_SDK_PATH}" - "--extra-arg=-resource-dir=${MACOSX_RESOURCE_PATH}" - PARENT_SCOPE) - endif() -endfunction() + "--extra-arg=-resource-dir=${MACOSX_RESOURCE_PATH}") -function(sourcemeta_clang_tidy_attempt_disable) - unset(CMAKE_CXX_CLANG_TIDY PARENT_SCOPE) + set_target_properties("${SOURCEMETA_CLANG_TIDY_TARGET_NAME}" + PROPERTIES CXX_CLANG_TIDY "${SOURCEMETA_CXX_CLANG_TIDY}") endfunction() diff --git a/src/core/time/CMakeLists.txt b/src/core/time/CMakeLists.txt index 0b001806b..2909b373f 100644 --- a/src/core/time/CMakeLists.txt +++ b/src/core/time/CMakeLists.txt @@ -1,4 +1,5 @@ sourcemeta_library(NAMESPACE sourcemeta PROJECT core NAME time SOURCES gmt.cc) +sourcemeta_clang_tidy_attempt_enable(TARGET_NAME "sourcemeta_core_time") if(SOURCEMETA_CORE_INSTALL) sourcemeta_library_install(NAMESPACE sourcemeta PROJECT core NAME time) From 8dfb57d899194ffb486d5726fb93b53ff61b5690 Mon Sep 17 00:00:00 2001 From: Balakrishna Avulapati Date: Thu, 17 Jul 2025 17:28:43 +0530 Subject: [PATCH 02/16] enable clang-tidy on all sourcemeta direct targets Signed-off-by: Balakrishna Avulapati --- src/core/gzip/CMakeLists.txt | 1 + src/core/json/CMakeLists.txt | 1 + src/core/jsonl/CMakeLists.txt | 1 + src/core/jsonpointer/CMakeLists.txt | 1 + src/core/jsonschema/CMakeLists.txt | 1 + src/core/md5/CMakeLists.txt | 1 + src/core/regex/CMakeLists.txt | 1 + src/core/uri/CMakeLists.txt | 1 + src/core/uuid/CMakeLists.txt | 1 + src/core/yaml/CMakeLists.txt | 1 + src/extension/alterschema/CMakeLists.txt | 1 + 11 files changed, 11 insertions(+) diff --git a/src/core/gzip/CMakeLists.txt b/src/core/gzip/CMakeLists.txt index 1613eca1e..a3b93299a 100644 --- a/src/core/gzip/CMakeLists.txt +++ b/src/core/gzip/CMakeLists.txt @@ -1,4 +1,5 @@ sourcemeta_library(NAMESPACE sourcemeta PROJECT core NAME gzip SOURCES gzip.cc) +sourcemeta_clang_tidy_attempt_enable(TARGET_NAME "sourcemeta_core_gzip") if(SOURCEMETA_CORE_INSTALL) sourcemeta_library_install(NAMESPACE sourcemeta PROJECT core NAME gzip) diff --git a/src/core/json/CMakeLists.txt b/src/core/json/CMakeLists.txt index 7f1ad992d..dc73f9334 100644 --- a/src/core/json/CMakeLists.txt +++ b/src/core/json/CMakeLists.txt @@ -1,6 +1,7 @@ sourcemeta_library(NAMESPACE sourcemeta PROJECT core NAME json PRIVATE_HEADERS array.h error.h object.h value.h hash.h auto.h SOURCES grammar.h parser.h stringify.h json.cc json_value.cc) +sourcemeta_clang_tidy_attempt_enable(TARGET_NAME "sourcemeta_core_json") if(SOURCEMETA_CORE_INSTALL) sourcemeta_library_install(NAMESPACE sourcemeta PROJECT core NAME json) diff --git a/src/core/jsonl/CMakeLists.txt b/src/core/jsonl/CMakeLists.txt index 8ffb53c50..69470cdbd 100644 --- a/src/core/jsonl/CMakeLists.txt +++ b/src/core/jsonl/CMakeLists.txt @@ -1,6 +1,7 @@ sourcemeta_library(NAMESPACE sourcemeta PROJECT core NAME jsonl PRIVATE_HEADERS iterator.h SOURCES jsonl.cc iterator.cc grammar.h) +sourcemeta_clang_tidy_attempt_enable(TARGET_NAME "sourcemeta_core_jsonl") if(SOURCEMETA_CORE_INSTALL) sourcemeta_library_install(NAMESPACE sourcemeta PROJECT core NAME jsonl) diff --git a/src/core/jsonpointer/CMakeLists.txt b/src/core/jsonpointer/CMakeLists.txt index 2e1edae9e..d2d48c424 100644 --- a/src/core/jsonpointer/CMakeLists.txt +++ b/src/core/jsonpointer/CMakeLists.txt @@ -2,6 +2,7 @@ sourcemeta_library(NAMESPACE sourcemeta PROJECT core NAME jsonpointer PRIVATE_HEADERS pointer.h position.h error.h token.h walker.h subpointer_walker.h template.h SOURCES jsonpointer.cc stringify.h parser.h grammar.h position.cc) +sourcemeta_clang_tidy_attempt_enable(TARGET_NAME "sourcemeta_core_jsonpointer") if(SOURCEMETA_CORE_INSTALL) sourcemeta_library_install(NAMESPACE sourcemeta PROJECT core NAME jsonpointer) diff --git a/src/core/jsonschema/CMakeLists.txt b/src/core/jsonschema/CMakeLists.txt index a9161376b..028fa7b0d 100644 --- a/src/core/jsonschema/CMakeLists.txt +++ b/src/core/jsonschema/CMakeLists.txt @@ -7,6 +7,7 @@ sourcemeta_library(NAMESPACE sourcemeta PROJECT core NAME jsonschema SOURCES jsonschema.cc official_walker.cc frame.cc resolver.cc walker.cc bundle.cc transformer.cc "${CMAKE_CURRENT_BINARY_DIR}/official_resolver.cc") +sourcemeta_clang_tidy_attempt_enable(TARGET_NAME "sourcemeta_core_jsonschema") if(SOURCEMETA_CORE_INSTALL) sourcemeta_library_install(NAMESPACE sourcemeta PROJECT core NAME jsonschema) diff --git a/src/core/md5/CMakeLists.txt b/src/core/md5/CMakeLists.txt index 87882cbe4..5a9d47610 100644 --- a/src/core/md5/CMakeLists.txt +++ b/src/core/md5/CMakeLists.txt @@ -1,4 +1,5 @@ sourcemeta_library(NAMESPACE sourcemeta PROJECT core NAME md5 SOURCES md5.cc) +sourcemeta_clang_tidy_attempt_enable(TARGET_NAME "sourcemeta_core_md5") if(SOURCEMETA_CORE_INSTALL) sourcemeta_library_install(NAMESPACE sourcemeta PROJECT core NAME md5) diff --git a/src/core/regex/CMakeLists.txt b/src/core/regex/CMakeLists.txt index ef0e01f2d..896980f98 100644 --- a/src/core/regex/CMakeLists.txt +++ b/src/core/regex/CMakeLists.txt @@ -1,4 +1,5 @@ sourcemeta_library(NAMESPACE sourcemeta PROJECT core NAME regex) +sourcemeta_clang_tidy_attempt_enable(TARGET_NAME "sourcemeta_core_regex") if(SOURCEMETA_CORE_INSTALL) sourcemeta_library_install(NAMESPACE sourcemeta PROJECT core NAME regex) diff --git a/src/core/uri/CMakeLists.txt b/src/core/uri/CMakeLists.txt index 75f4d82d3..b99698523 100644 --- a/src/core/uri/CMakeLists.txt +++ b/src/core/uri/CMakeLists.txt @@ -1,6 +1,7 @@ sourcemeta_library(NAMESPACE sourcemeta PROJECT core NAME uri PRIVATE_HEADERS escape.h error.h SOURCES uri.cc escaping.cc) +sourcemeta_clang_tidy_attempt_enable(TARGET_NAME "sourcemeta_core_uri") if(SOURCEMETA_CORE_INSTALL) sourcemeta_library_install(NAMESPACE sourcemeta PROJECT core NAME uri) diff --git a/src/core/uuid/CMakeLists.txt b/src/core/uuid/CMakeLists.txt index 324b05a72..d4c0a0564 100644 --- a/src/core/uuid/CMakeLists.txt +++ b/src/core/uuid/CMakeLists.txt @@ -1,4 +1,5 @@ sourcemeta_library(NAMESPACE sourcemeta PROJECT core NAME uuid SOURCES uuid.cc) +sourcemeta_clang_tidy_attempt_enable(TARGET_NAME "sourcemeta_core_uuid") if(SOURCEMETA_CORE_INSTALL) sourcemeta_library_install(NAMESPACE sourcemeta PROJECT core NAME uuid) diff --git a/src/core/yaml/CMakeLists.txt b/src/core/yaml/CMakeLists.txt index 7b6bd8028..b59d4ddfd 100644 --- a/src/core/yaml/CMakeLists.txt +++ b/src/core/yaml/CMakeLists.txt @@ -1,6 +1,7 @@ sourcemeta_library(NAMESPACE sourcemeta PROJECT core NAME yaml PRIVATE_HEADERS error.h SOURCES yaml.cc) +sourcemeta_clang_tidy_attempt_enable(TARGET_NAME "sourcemeta_core_yaml") if(SOURCEMETA_CORE_INSTALL) sourcemeta_library_install(NAMESPACE sourcemeta PROJECT core NAME yaml) diff --git a/src/extension/alterschema/CMakeLists.txt b/src/extension/alterschema/CMakeLists.txt index 995e528cd..8f0dfae23 100644 --- a/src/extension/alterschema/CMakeLists.txt +++ b/src/extension/alterschema/CMakeLists.txt @@ -61,6 +61,7 @@ sourcemeta_library(NAMESPACE sourcemeta PROJECT core NAME alterschema linter/min_contains_without_contains.h linter/modern_official_dialect_with_empty_fragment.h linter/then_without_if.h) +sourcemeta_clang_tidy_attempt_enable(TARGET_NAME "sourcemeta_core_alterschema") if(SOURCEMETA_CORE_INSTALL) sourcemeta_library_install(NAMESPACE sourcemeta PROJECT core NAME alterschema) From 42c2e97240cb3f6bbcc17e2deb9e5fb59fcd0ebb Mon Sep 17 00:00:00 2001 From: Balakrishna Avulapati Date: Thu, 17 Jul 2025 18:17:34 +0530 Subject: [PATCH 03/16] add target name to the log message Signed-off-by: Balakrishna Avulapati --- cmake/common/clang-tidy.cmake | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/cmake/common/clang-tidy.cmake b/cmake/common/clang-tidy.cmake index 30fea7538..1bf2abbe9 100644 --- a/cmake/common/clang-tidy.cmake +++ b/cmake/common/clang-tidy.cmake @@ -77,24 +77,26 @@ function(sourcemeta_clang_tidy_attempt_install) endfunction() function(sourcemeta_clang_tidy_attempt_enable) + cmake_parse_arguments(PARSE_ARGV 0 SOURCEMETA_CLANG_TIDY "" "TARGET_NAME" "") + if(NOT SOURCEMETA_CLANG_TIDY_TARGET_NAME) + message(STATUS "ClangTidy runs at target level. TARGET_NAME is required.") + return() + endif() + # TODO: Support other platforms too, like Linux if(NOT APPLE) - message(STATUS "Ignoring ClangTidy setup on OS other than APPLE") + message(STATUS "Ignoring ClangTidy setup on OS other than APPLE for target ${SOURCEMETA_CLANG_TIDY_TARGET_NAME}") return() endif() + if(SOURCEMETA_COMPILER_LLVM) - message(STATUS "Enabling ClangTidy alongside compilation") + message(STATUS "Enabling ClangTidy alongside compilation for target ${SOURCEMETA_CLANG_TIDY_TARGET_NAME}") else() - message(STATUS "Ignoring ClangTidy setup on a compiler other than LLVM") + message(STATUS "Ignoring ClangTidy setup on a compiler other than LLVM for target ${SOURCEMETA_CLANG_TIDY_TARGET_NAME}") return() endif() - cmake_parse_arguments(PARSE_ARGV 0 SOURCEMETA_CLANG_TIDY "" "TARGET_NAME" "") - if(NOT SOURCEMETA_CLANG_TIDY_TARGET_NAME) - message(STATUS "ClangTidy runs at target level. TARGET_NAME is required.") - return() - endif() sourcemeta_clang_tidy_attempt_install( OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin") From 734416442f77c708485d77a74fb4bef621d86f16 Mon Sep 17 00:00:00 2001 From: Balakrishna Avulapati Date: Fri, 18 Jul 2025 16:21:01 +0530 Subject: [PATCH 04/16] enable clang-tidy from sourcemeta_library() definition Signed-off-by: Balakrishna Avulapati --- cmake/common/targets/library.cmake | 3 +++ src/core/gzip/CMakeLists.txt | 1 - src/core/json/CMakeLists.txt | 1 - src/core/jsonl/CMakeLists.txt | 1 - src/core/jsonpointer/CMakeLists.txt | 1 - src/core/jsonschema/CMakeLists.txt | 1 - src/core/md5/CMakeLists.txt | 1 - src/core/regex/CMakeLists.txt | 1 - src/core/time/CMakeLists.txt | 1 - src/core/uri/CMakeLists.txt | 1 - src/core/uuid/CMakeLists.txt | 1 - src/core/yaml/CMakeLists.txt | 1 - src/extension/alterschema/CMakeLists.txt | 1 - 13 files changed, 3 insertions(+), 12 deletions(-) diff --git a/cmake/common/targets/library.cmake b/cmake/common/targets/library.cmake index e2f2ebe60..18e89aa26 100644 --- a/cmake/common/targets/library.cmake +++ b/cmake/common/targets/library.cmake @@ -115,6 +115,9 @@ function(sourcemeta_library) target_include_directories(${TARGET_NAME} PUBLIC "$") endif() + + sourcemeta_clang_tidy_attempt_enable(TARGET_NAME "${TARGET_NAME}") + endfunction() function(sourcemeta_library_install) diff --git a/src/core/gzip/CMakeLists.txt b/src/core/gzip/CMakeLists.txt index a3b93299a..1613eca1e 100644 --- a/src/core/gzip/CMakeLists.txt +++ b/src/core/gzip/CMakeLists.txt @@ -1,5 +1,4 @@ sourcemeta_library(NAMESPACE sourcemeta PROJECT core NAME gzip SOURCES gzip.cc) -sourcemeta_clang_tidy_attempt_enable(TARGET_NAME "sourcemeta_core_gzip") if(SOURCEMETA_CORE_INSTALL) sourcemeta_library_install(NAMESPACE sourcemeta PROJECT core NAME gzip) diff --git a/src/core/json/CMakeLists.txt b/src/core/json/CMakeLists.txt index dc73f9334..7f1ad992d 100644 --- a/src/core/json/CMakeLists.txt +++ b/src/core/json/CMakeLists.txt @@ -1,7 +1,6 @@ sourcemeta_library(NAMESPACE sourcemeta PROJECT core NAME json PRIVATE_HEADERS array.h error.h object.h value.h hash.h auto.h SOURCES grammar.h parser.h stringify.h json.cc json_value.cc) -sourcemeta_clang_tidy_attempt_enable(TARGET_NAME "sourcemeta_core_json") if(SOURCEMETA_CORE_INSTALL) sourcemeta_library_install(NAMESPACE sourcemeta PROJECT core NAME json) diff --git a/src/core/jsonl/CMakeLists.txt b/src/core/jsonl/CMakeLists.txt index 69470cdbd..8ffb53c50 100644 --- a/src/core/jsonl/CMakeLists.txt +++ b/src/core/jsonl/CMakeLists.txt @@ -1,7 +1,6 @@ sourcemeta_library(NAMESPACE sourcemeta PROJECT core NAME jsonl PRIVATE_HEADERS iterator.h SOURCES jsonl.cc iterator.cc grammar.h) -sourcemeta_clang_tidy_attempt_enable(TARGET_NAME "sourcemeta_core_jsonl") if(SOURCEMETA_CORE_INSTALL) sourcemeta_library_install(NAMESPACE sourcemeta PROJECT core NAME jsonl) diff --git a/src/core/jsonpointer/CMakeLists.txt b/src/core/jsonpointer/CMakeLists.txt index d2d48c424..2e1edae9e 100644 --- a/src/core/jsonpointer/CMakeLists.txt +++ b/src/core/jsonpointer/CMakeLists.txt @@ -2,7 +2,6 @@ sourcemeta_library(NAMESPACE sourcemeta PROJECT core NAME jsonpointer PRIVATE_HEADERS pointer.h position.h error.h token.h walker.h subpointer_walker.h template.h SOURCES jsonpointer.cc stringify.h parser.h grammar.h position.cc) -sourcemeta_clang_tidy_attempt_enable(TARGET_NAME "sourcemeta_core_jsonpointer") if(SOURCEMETA_CORE_INSTALL) sourcemeta_library_install(NAMESPACE sourcemeta PROJECT core NAME jsonpointer) diff --git a/src/core/jsonschema/CMakeLists.txt b/src/core/jsonschema/CMakeLists.txt index 028fa7b0d..a9161376b 100644 --- a/src/core/jsonschema/CMakeLists.txt +++ b/src/core/jsonschema/CMakeLists.txt @@ -7,7 +7,6 @@ sourcemeta_library(NAMESPACE sourcemeta PROJECT core NAME jsonschema SOURCES jsonschema.cc official_walker.cc frame.cc resolver.cc walker.cc bundle.cc transformer.cc "${CMAKE_CURRENT_BINARY_DIR}/official_resolver.cc") -sourcemeta_clang_tidy_attempt_enable(TARGET_NAME "sourcemeta_core_jsonschema") if(SOURCEMETA_CORE_INSTALL) sourcemeta_library_install(NAMESPACE sourcemeta PROJECT core NAME jsonschema) diff --git a/src/core/md5/CMakeLists.txt b/src/core/md5/CMakeLists.txt index 5a9d47610..87882cbe4 100644 --- a/src/core/md5/CMakeLists.txt +++ b/src/core/md5/CMakeLists.txt @@ -1,5 +1,4 @@ sourcemeta_library(NAMESPACE sourcemeta PROJECT core NAME md5 SOURCES md5.cc) -sourcemeta_clang_tidy_attempt_enable(TARGET_NAME "sourcemeta_core_md5") if(SOURCEMETA_CORE_INSTALL) sourcemeta_library_install(NAMESPACE sourcemeta PROJECT core NAME md5) diff --git a/src/core/regex/CMakeLists.txt b/src/core/regex/CMakeLists.txt index 896980f98..ef0e01f2d 100644 --- a/src/core/regex/CMakeLists.txt +++ b/src/core/regex/CMakeLists.txt @@ -1,5 +1,4 @@ sourcemeta_library(NAMESPACE sourcemeta PROJECT core NAME regex) -sourcemeta_clang_tidy_attempt_enable(TARGET_NAME "sourcemeta_core_regex") if(SOURCEMETA_CORE_INSTALL) sourcemeta_library_install(NAMESPACE sourcemeta PROJECT core NAME regex) diff --git a/src/core/time/CMakeLists.txt b/src/core/time/CMakeLists.txt index 2909b373f..0b001806b 100644 --- a/src/core/time/CMakeLists.txt +++ b/src/core/time/CMakeLists.txt @@ -1,5 +1,4 @@ sourcemeta_library(NAMESPACE sourcemeta PROJECT core NAME time SOURCES gmt.cc) -sourcemeta_clang_tidy_attempt_enable(TARGET_NAME "sourcemeta_core_time") if(SOURCEMETA_CORE_INSTALL) sourcemeta_library_install(NAMESPACE sourcemeta PROJECT core NAME time) diff --git a/src/core/uri/CMakeLists.txt b/src/core/uri/CMakeLists.txt index b99698523..75f4d82d3 100644 --- a/src/core/uri/CMakeLists.txt +++ b/src/core/uri/CMakeLists.txt @@ -1,7 +1,6 @@ sourcemeta_library(NAMESPACE sourcemeta PROJECT core NAME uri PRIVATE_HEADERS escape.h error.h SOURCES uri.cc escaping.cc) -sourcemeta_clang_tidy_attempt_enable(TARGET_NAME "sourcemeta_core_uri") if(SOURCEMETA_CORE_INSTALL) sourcemeta_library_install(NAMESPACE sourcemeta PROJECT core NAME uri) diff --git a/src/core/uuid/CMakeLists.txt b/src/core/uuid/CMakeLists.txt index d4c0a0564..324b05a72 100644 --- a/src/core/uuid/CMakeLists.txt +++ b/src/core/uuid/CMakeLists.txt @@ -1,5 +1,4 @@ sourcemeta_library(NAMESPACE sourcemeta PROJECT core NAME uuid SOURCES uuid.cc) -sourcemeta_clang_tidy_attempt_enable(TARGET_NAME "sourcemeta_core_uuid") if(SOURCEMETA_CORE_INSTALL) sourcemeta_library_install(NAMESPACE sourcemeta PROJECT core NAME uuid) diff --git a/src/core/yaml/CMakeLists.txt b/src/core/yaml/CMakeLists.txt index b59d4ddfd..7b6bd8028 100644 --- a/src/core/yaml/CMakeLists.txt +++ b/src/core/yaml/CMakeLists.txt @@ -1,7 +1,6 @@ sourcemeta_library(NAMESPACE sourcemeta PROJECT core NAME yaml PRIVATE_HEADERS error.h SOURCES yaml.cc) -sourcemeta_clang_tidy_attempt_enable(TARGET_NAME "sourcemeta_core_yaml") if(SOURCEMETA_CORE_INSTALL) sourcemeta_library_install(NAMESPACE sourcemeta PROJECT core NAME yaml) diff --git a/src/extension/alterschema/CMakeLists.txt b/src/extension/alterschema/CMakeLists.txt index 8f0dfae23..995e528cd 100644 --- a/src/extension/alterschema/CMakeLists.txt +++ b/src/extension/alterschema/CMakeLists.txt @@ -61,7 +61,6 @@ sourcemeta_library(NAMESPACE sourcemeta PROJECT core NAME alterschema linter/min_contains_without_contains.h linter/modern_official_dialect_with_empty_fragment.h linter/then_without_if.h) -sourcemeta_clang_tidy_attempt_enable(TARGET_NAME "sourcemeta_core_alterschema") if(SOURCEMETA_CORE_INSTALL) sourcemeta_library_install(NAMESPACE sourcemeta PROJECT core NAME alterschema) From de512049e7a4ed0a9c16d35e76d238c344d904ea Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Fri, 18 Jul 2025 18:19:01 -0400 Subject: [PATCH 05/16] Misc minor improvements Signed-off-by: Juan Cruz Viotti --- cmake/common/clang-tidy.cmake | 66 ++++++++++++------------------ cmake/common/targets/library.cmake | 3 +- 2 files changed, 28 insertions(+), 41 deletions(-) diff --git a/cmake/common/clang-tidy.cmake b/cmake/common/clang-tidy.cmake index 1bf2abbe9..30d0e7ebd 100644 --- a/cmake/common/clang-tidy.cmake +++ b/cmake/common/clang-tidy.cmake @@ -77,53 +77,41 @@ function(sourcemeta_clang_tidy_attempt_install) endfunction() function(sourcemeta_clang_tidy_attempt_enable) - cmake_parse_arguments(PARSE_ARGV 0 SOURCEMETA_CLANG_TIDY "" "TARGET_NAME" "") - if(NOT SOURCEMETA_CLANG_TIDY_TARGET_NAME) - message(STATUS "ClangTidy runs at target level. TARGET_NAME is required.") - return() + cmake_parse_arguments(SOURCEMETA_TARGET_CLANG_TIDY_ATTEMPT_ENABLE "" "TARGET" "" ${ARGN}) + if(NOT SOURCEMETA_TARGET_CLANG_TIDY_ATTEMPT_ENABLE_TARGET) + message(FATAL_ERROR "You must pass the target name using the TARGET option") endif() # TODO: Support other platforms too, like Linux - if(NOT APPLE) - message(STATUS "Ignoring ClangTidy setup on OS other than APPLE for target ${SOURCEMETA_CLANG_TIDY_TARGET_NAME}") - return() - endif() - - - if(SOURCEMETA_COMPILER_LLVM) - message(STATUS "Enabling ClangTidy alongside compilation for target ${SOURCEMETA_CLANG_TIDY_TARGET_NAME}") + if(APPLE AND SOURCEMETA_COMPILER_LLVM) + message(STATUS "Enabling ClangTidy alongside compilation for target ${SOURCEMETA_TARGET_CLANG_TIDY_ATTEMPT_ENABLE_TARGET}") else() - message(STATUS "Ignoring ClangTidy setup on a compiler other than LLVM for target ${SOURCEMETA_CLANG_TIDY_TARGET_NAME}") return() endif() - - sourcemeta_clang_tidy_attempt_install( - OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin") - - if(SOURCEMETA_CXX_CLANG_TIDY) - set_target_properties("${SOURCEMETA_CLANG_TIDY_TARGET_NAME}" - PROPERTIES CXX_CLANG_TIDY "${SOURCEMETA_CXX_CLANG_TIDY}") - return() + # We rely on this cache variable to not pre-compute the ClangTidy + # setup over and over again for every single target + if(NOT SOURCEMETA_CXX_CLANG_TIDY) + sourcemeta_clang_tidy_attempt_install( + OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin") + find_program(CLANG_TIDY_BIN NAMES clang-tidy + NO_DEFAULT_PATH + PATHS "${PROJECT_BINARY_DIR}/bin" + REQUIRED) + set(CLANG_TIDY_CONFIG "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/clang-tidy.config") + execute_process(COMMAND xcrun --show-sdk-path + OUTPUT_VARIABLE MACOSX_SDK_PATH OUTPUT_STRIP_TRAILING_WHITESPACE) + execute_process(COMMAND "${CMAKE_CXX_COMPILER}" -print-resource-dir + OUTPUT_VARIABLE MACOSX_RESOURCE_PATH OUTPUT_STRIP_TRAILING_WHITESPACE) + set(SOURCEMETA_CXX_CLANG_TIDY + "${CLANG_TIDY_BIN};--config-file=${CLANG_TIDY_CONFIG};-header-filter=${PROJECT_SOURCE_DIR}/src/*" + "--extra-arg=-std=c++${CMAKE_CXX_STANDARD}" + "--extra-arg=-isysroot" + "--extra-arg=${MACOSX_SDK_PATH}" + "--extra-arg=-resource-dir=${MACOSX_RESOURCE_PATH}" + CACHE STRING "CXX_CLANG_TIDY") endif() - find_program(CLANG_TIDY_BIN NAMES clang-tidy - NO_DEFAULT_PATH - PATHS "${PROJECT_BINARY_DIR}/bin" - REQUIRED) - - set(CLANG_TIDY_CONFIG "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/clang-tidy.config") - execute_process(COMMAND xcrun --show-sdk-path - OUTPUT_VARIABLE MACOSX_SDK_PATH OUTPUT_STRIP_TRAILING_WHITESPACE) - execute_process(COMMAND "${CMAKE_CXX_COMPILER}" -print-resource-dir - OUTPUT_VARIABLE MACOSX_RESOURCE_PATH OUTPUT_STRIP_TRAILING_WHITESPACE) - set(SOURCEMETA_CXX_CLANG_TIDY - "${CLANG_TIDY_BIN};--config-file=${CLANG_TIDY_CONFIG};-header-filter=${PROJECT_SOURCE_DIR}/src/*" - "--extra-arg=-std=c++${CMAKE_CXX_STANDARD}" - "--extra-arg=-isysroot" - "--extra-arg=${MACOSX_SDK_PATH}" - "--extra-arg=-resource-dir=${MACOSX_RESOURCE_PATH}") - - set_target_properties("${SOURCEMETA_CLANG_TIDY_TARGET_NAME}" + set_target_properties("${SOURCEMETA_TARGET_CLANG_TIDY_ATTEMPT_ENABLE_TARGET}" PROPERTIES CXX_CLANG_TIDY "${SOURCEMETA_CXX_CLANG_TIDY}") endfunction() diff --git a/cmake/common/targets/library.cmake b/cmake/common/targets/library.cmake index 18e89aa26..c13a25185 100644 --- a/cmake/common/targets/library.cmake +++ b/cmake/common/targets/library.cmake @@ -116,8 +116,7 @@ function(sourcemeta_library) PUBLIC "$") endif() - sourcemeta_clang_tidy_attempt_enable(TARGET_NAME "${TARGET_NAME}") - + sourcemeta_clang_tidy_attempt_enable(TARGET "${TARGET_NAME}") endfunction() function(sourcemeta_library_install) From 2a03d4161cf44ebed3e4ef89a748d9b804ad53f9 Mon Sep 17 00:00:00 2001 From: Balakrishna Avulapati Date: Mon, 21 Jul 2025 18:32:11 +0530 Subject: [PATCH 06/16] Use json file format Signed-off-by: Balakrishna Avulapati --- cmake/common/clang-tidy.cmake | 11 ++++++----- cmake/common/clang-tidy.json | 6 ++++++ cmake/common/targets/clang-format.cmake | 2 +- cmake/common/targets/clang-format.config | 3 --- cmake/common/targets/clang-format.json | 4 ++++ 5 files changed, 17 insertions(+), 9 deletions(-) create mode 100644 cmake/common/clang-tidy.json delete mode 100644 cmake/common/targets/clang-format.config create mode 100644 cmake/common/targets/clang-format.json diff --git a/cmake/common/clang-tidy.cmake b/cmake/common/clang-tidy.cmake index 025251e37..2a4ac41e1 100644 --- a/cmake/common/clang-tidy.cmake +++ b/cmake/common/clang-tidy.cmake @@ -98,18 +98,19 @@ function(sourcemeta_clang_tidy_attempt_enable) NO_DEFAULT_PATH PATHS "${PROJECT_BINARY_DIR}/bin" REQUIRED) - set(CLANG_TIDY_CONFIG "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/clang-tidy.config") - execute_process(COMMAND xcrun --show-sdk-path + endif() + + set(CLANG_TIDY_CONFIG "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/clang-tidy.json") + execute_process(COMMAND xcrun --show-sdk-path OUTPUT_VARIABLE MACOSX_SDK_PATH OUTPUT_STRIP_TRAILING_WHITESPACE) - execute_process(COMMAND "${CMAKE_CXX_COMPILER}" -print-resource-dir + execute_process(COMMAND "${CMAKE_CXX_COMPILER}" -print-resource-dir OUTPUT_VARIABLE MACOSX_RESOURCE_PATH OUTPUT_STRIP_TRAILING_WHITESPACE) - set(SOURCEMETA_CXX_CLANG_TIDY + set(SOURCEMETA_CXX_CLANG_TIDY "${CLANG_TIDY_BIN};--config-file=${CLANG_TIDY_CONFIG};-header-filter=${PROJECT_SOURCE_DIR}/src/*" "--extra-arg=-isysroot" "--extra-arg=${MACOSX_SDK_PATH}" "--extra-arg=-resource-dir=${MACOSX_RESOURCE_PATH}" CACHE STRING "CXX_CLANG_TIDY") - endif() set_target_properties("${SOURCEMETA_TARGET_CLANG_TIDY_ATTEMPT_ENABLE_TARGET}" PROPERTIES CXX_CLANG_TIDY "${SOURCEMETA_CXX_CLANG_TIDY}") diff --git a/cmake/common/clang-tidy.json b/cmake/common/clang-tidy.json new file mode 100644 index 000000000..9be7d5830 --- /dev/null +++ b/cmake/common/clang-tidy.json @@ -0,0 +1,6 @@ +{ + "Checks": "-*, concurrency-*, modernize-*, portability-*", + "WarningsAsErrors": "*", + "FormatStyle": "none", + "UseColor": true +} diff --git a/cmake/common/targets/clang-format.cmake b/cmake/common/targets/clang-format.cmake index 55fbb6cdc..7868fceb0 100644 --- a/cmake/common/targets/clang-format.cmake +++ b/cmake/common/targets/clang-format.cmake @@ -101,7 +101,7 @@ function(sourcemeta_target_clang_format) file(GLOB_RECURSE SOURCEMETA_TARGET_CLANG_FORMAT_FILES ${SOURCEMETA_TARGET_CLANG_FORMAT_SOURCES}) - set(CLANG_FORMAT_CONFIG "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/clang-format.config") + set(CLANG_FORMAT_CONFIG "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/clang-format.json") if(CMAKE_SYSTEM_NAME STREQUAL "MSYS") # Because `clang-format` is typically a Windows `.exe`, transform the path accordingly execute_process(COMMAND cygpath -w "${CLANG_FORMAT_CONFIG}" diff --git a/cmake/common/targets/clang-format.config b/cmake/common/targets/clang-format.config deleted file mode 100644 index d9c695cc9..000000000 --- a/cmake/common/targets/clang-format.config +++ /dev/null @@ -1,3 +0,0 @@ ---- -BasedOnStyle: LLVM -IndentCaseLabels: true diff --git a/cmake/common/targets/clang-format.json b/cmake/common/targets/clang-format.json new file mode 100644 index 000000000..7e760c01e --- /dev/null +++ b/cmake/common/targets/clang-format.json @@ -0,0 +1,4 @@ +{ + "BasedOnStyle": "LLVM", + "IndentCaseLabels": true +} From 333c824e925d467e89080bc0cdeccb480f9f598f Mon Sep 17 00:00:00 2001 From: Balakrishna Avulapati Date: Tue, 22 Jul 2025 01:51:38 +0530 Subject: [PATCH 07/16] remove performance-* Signed-off-by: Balakrishna Avulapati --- cmake/common/clang-tidy.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/common/clang-tidy.config b/cmake/common/clang-tidy.config index c69b9009c..9be7d5830 100644 --- a/cmake/common/clang-tidy.config +++ b/cmake/common/clang-tidy.config @@ -1,5 +1,5 @@ { - "Checks": "-*, concurrency-*, modernize-*, performance-*, portability-*", + "Checks": "-*, concurrency-*, modernize-*, portability-*", "WarningsAsErrors": "*", "FormatStyle": "none", "UseColor": true From 773e2f52da86194cd1e57ae5025581a95516e61d Mon Sep 17 00:00:00 2001 From: Balakrishna Avulapati Date: Tue, 22 Jul 2025 02:06:06 +0530 Subject: [PATCH 08/16] remove irrelevant changes Signed-off-by: Balakrishna Avulapati --- cmake/common/clang-tidy.cmake | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cmake/common/clang-tidy.cmake b/cmake/common/clang-tidy.cmake index 2a4ac41e1..7967f1044 100644 --- a/cmake/common/clang-tidy.cmake +++ b/cmake/common/clang-tidy.cmake @@ -98,19 +98,19 @@ function(sourcemeta_clang_tidy_attempt_enable) NO_DEFAULT_PATH PATHS "${PROJECT_BINARY_DIR}/bin" REQUIRED) - endif() - set(CLANG_TIDY_CONFIG "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/clang-tidy.json") - execute_process(COMMAND xcrun --show-sdk-path + set(CLANG_TIDY_CONFIG "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/clang-tidy.json") + execute_process(COMMAND xcrun --show-sdk-path OUTPUT_VARIABLE MACOSX_SDK_PATH OUTPUT_STRIP_TRAILING_WHITESPACE) - execute_process(COMMAND "${CMAKE_CXX_COMPILER}" -print-resource-dir + execute_process(COMMAND "${CMAKE_CXX_COMPILER}" -print-resource-dir OUTPUT_VARIABLE MACOSX_RESOURCE_PATH OUTPUT_STRIP_TRAILING_WHITESPACE) - set(SOURCEMETA_CXX_CLANG_TIDY + set(SOURCEMETA_CXX_CLANG_TIDY "${CLANG_TIDY_BIN};--config-file=${CLANG_TIDY_CONFIG};-header-filter=${PROJECT_SOURCE_DIR}/src/*" "--extra-arg=-isysroot" "--extra-arg=${MACOSX_SDK_PATH}" "--extra-arg=-resource-dir=${MACOSX_RESOURCE_PATH}" CACHE STRING "CXX_CLANG_TIDY") + endif() set_target_properties("${SOURCEMETA_TARGET_CLANG_TIDY_ATTEMPT_ENABLE_TARGET}" PROPERTIES CXX_CLANG_TIDY "${SOURCEMETA_CXX_CLANG_TIDY}") From fe14e7dc29084f9f5b04155233f51d0358c788e5 Mon Sep 17 00:00:00 2001 From: Balakrishna Avulapati Date: Tue, 22 Jul 2025 02:08:17 +0530 Subject: [PATCH 09/16] remove .config file Signed-off-by: Balakrishna Avulapati --- cmake/common/clang-tidy.config | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 cmake/common/clang-tidy.config diff --git a/cmake/common/clang-tidy.config b/cmake/common/clang-tidy.config deleted file mode 100644 index 9be7d5830..000000000 --- a/cmake/common/clang-tidy.config +++ /dev/null @@ -1,6 +0,0 @@ -{ - "Checks": "-*, concurrency-*, modernize-*, portability-*", - "WarningsAsErrors": "*", - "FormatStyle": "none", - "UseColor": true -} From 3acd087d032bd37da883ef6ecd6658fcd7dff205 Mon Sep 17 00:00:00 2001 From: Balakrishna Avulapati Date: Tue, 22 Jul 2025 02:28:28 +0530 Subject: [PATCH 10/16] add performance-* back Signed-off-by: Balakrishna Avulapati --- cmake/common/clang-tidy.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/common/clang-tidy.json b/cmake/common/clang-tidy.json index 9be7d5830..c69b9009c 100644 --- a/cmake/common/clang-tidy.json +++ b/cmake/common/clang-tidy.json @@ -1,5 +1,5 @@ { - "Checks": "-*, concurrency-*, modernize-*, portability-*", + "Checks": "-*, concurrency-*, modernize-*, performance-*, portability-*", "WarningsAsErrors": "*", "FormatStyle": "none", "UseColor": true From 13e98962a930b44ad8284f37b22805dcf9666159 Mon Sep 17 00:00:00 2001 From: Balakrishna Avulapati Date: Tue, 22 Jul 2025 13:27:53 +0530 Subject: [PATCH 11/16] Enable bugprone-* clang-tidy checks Disabling `bugprone-easily-swappable-parameters` for now. We could skip exising usage and enable this in a separate PR. Signed-off-by: Balakrishna Avulapati --- cmake/common/clang-tidy.config | 2 +- src/core/gzip/gzip.cc | 3 +- .../include/sourcemeta/core/json_object.h | 4 +-- src/core/json/parser.h | 6 ++-- src/core/jsonschema/frame.cc | 14 ++++---- src/core/jsonschema/official_resolver.in.cc | 35 +++++++------------ src/core/uri/uri.cc | 2 -- 7 files changed, 25 insertions(+), 41 deletions(-) diff --git a/cmake/common/clang-tidy.config b/cmake/common/clang-tidy.config index c69b9009c..e3c0421cc 100644 --- a/cmake/common/clang-tidy.config +++ b/cmake/common/clang-tidy.config @@ -1,5 +1,5 @@ { - "Checks": "-*, concurrency-*, modernize-*, performance-*, portability-*", + "Checks": "-*, bugprone-*, -bugprone-easily-swappable-parameters, concurrency-*, modernize-*, performance-*, portability-*", "WarningsAsErrors": "*", "FormatStyle": "none", "UseColor": true diff --git a/src/core/gzip/gzip.cc b/src/core/gzip/gzip.cc index 5207af117..e0f30b5d0 100644 --- a/src/core/gzip/gzip.cc +++ b/src/core/gzip/gzip.cc @@ -29,7 +29,8 @@ auto gzip(std::string_view input) -> std::optional { stream.next_out = reinterpret_cast(buffer.data()); stream.avail_out = sizeof(buffer); code = deflate(&stream, Z_FINISH); - compressed.write(buffer.data(), sizeof(buffer) - stream.avail_out); + compressed.write(buffer.data(), + static_cast(sizeof(buffer)) - stream.avail_out); } while (code == Z_OK); if (code != Z_STREAM_END) { diff --git a/src/core/json/include/sourcemeta/core/json_object.h b/src/core/json/include/sourcemeta/core/json_object.h index d48b5dda4..8815b779a 100644 --- a/src/core/json/include/sourcemeta/core/json_object.h +++ b/src/core/json/include/sourcemeta/core/json_object.h @@ -91,9 +91,7 @@ template class JSONObject { for (const auto &entry : this->data) { const auto *result{other.try_at(entry.first, entry.hash)}; - if (!result) { - return false; - } else if (*result != entry.second) { + if (!result || *result != entry.second) { return false; } } diff --git a/src/core/json/parser.h b/src/core/json/parser.h index 1c932cc49..c728309e4 100644 --- a/src/core/json/parser.h +++ b/src/core/json/parser.h @@ -650,21 +650,21 @@ auto parse_number( #define CALLBACK_PRE(value_type, value) \ if (callback) { \ - assert(value.is_null() || value.is_string() || value.is_integer()); \ + assert((value).is_null() || (value).is_string() || (value).is_integer()); \ callback(JSON::ParsePhase::Pre, JSON::Type::value_type, line, column, \ value); \ } #define CALLBACK_PRE_WITH_POSITION(value_type, line, column, value) \ if (callback) { \ - assert(value.is_null() || value.is_string() || value.is_integer()); \ + assert((value).is_null() || (value).is_string() || (value).is_integer()); \ callback(JSON::ParsePhase::Pre, JSON::Type::value_type, line, column, \ value); \ } #define CALLBACK_POST(value_type, value) \ if (callback) { \ - assert(value.type() == JSON::Type::value_type); \ + assert((value).type() == JSON::Type::value_type); \ callback(JSON::ParsePhase::Post, JSON::Type::value_type, line, column, \ value); \ } diff --git a/src/core/jsonschema/frame.cc b/src/core/jsonschema/frame.cc index 8a92de4cb..183c4dc61 100644 --- a/src/core/jsonschema/frame.cc +++ b/src/core/jsonschema/frame.cc @@ -77,10 +77,9 @@ auto find_anchors(const sourcemeta::core::JSON &schema, if (identifier.is_fragment_only()) { result.insert( {sourcemeta::core::JSON::String{ - identifier.fragment() - .value()}, // NOLINT(bugprone-unchecked-optional-access): - // Check for optional is happening - // inside is_fragment_only() + // Check for optional is happening inside is_fragment_only() + // NOLINTNEXTLINE(bugprone-unchecked-optional-access) + identifier.fragment().value()}, AnchorType::Static}); } } @@ -96,10 +95,9 @@ auto find_anchors(const sourcemeta::core::JSON &schema, if (identifier.is_fragment_only()) { result.insert( {sourcemeta::core::JSON::String{ - identifier.fragment() - .value()}, // NOLINT(bugprone-unchecked-optional-access): - // Check for optional is happening - // inside is_fragment_only() + // Check for optional is happening inside is_fragment_only() + // NOLINTNEXTLINE(bugprone-unchecked-optional-access) + identifier.fragment().value()}, AnchorType::Static}); } } diff --git a/src/core/jsonschema/official_resolver.in.cc b/src/core/jsonschema/official_resolver.in.cc index d3796f9a3..bd14e1afa 100644 --- a/src/core/jsonschema/official_resolver.in.cc +++ b/src/core/jsonschema/official_resolver.in.cc @@ -3,11 +3,15 @@ auto sourcemeta::core::schema_official_resolver(std::string_view identifier) -> std::optional { // JSON Schema 2020-12 - if (identifier == "https://json-schema.org/draft/2020-12/schema") { + if (identifier == "https://json-schema.org/draft/2020-12/schema" || + // Just for compatibility given that this is such a common issue + identifier == "https://json-schema.org/draft/2020-12/schema#") { return sourcemeta::core::parse_json( R"EOF(@METASCHEMA_JSONSCHEMA_2020_12@)EOF"); } else if (identifier == - "https://json-schema.org/draft/2020-12/hyper-schema") { + "https://json-schema.org/draft/2020-12/hyper-schema" || + identifier == + "https://json-schema.org/draft/2020-12/hyper-schema#") { return sourcemeta::core::parse_json( R"EOF(@METASCHEMA_HYPERSCHEMA_2020_12@)EOF"); } else if (identifier == @@ -52,21 +56,16 @@ auto sourcemeta::core::schema_official_resolver(std::string_view identifier) return sourcemeta::core::parse_json( R"EOF(@METASCHEMA_JSONSCHEMA_2020_12_OUTPUT@)EOF"); - // Just for compatibility given that this is such a common issue - } else if (identifier == "https://json-schema.org/draft/2020-12/schema#") { - return sourcemeta::core::parse_json( - R"EOF(@METASCHEMA_JSONSCHEMA_2020_12@)EOF"); - } else if (identifier == - "https://json-schema.org/draft/2020-12/hyper-schema#") { - return sourcemeta::core::parse_json( - R"EOF(@METASCHEMA_HYPERSCHEMA_2020_12@)EOF"); - // JSON Schema 2019-09 - } else if (identifier == "https://json-schema.org/draft/2019-09/schema") { + } else if (identifier == "https://json-schema.org/draft/2019-09/schema" || + // Just for compatibility given that this is such a common issue + identifier == "https://json-schema.org/draft/2019-09/schema#") { return sourcemeta::core::parse_json( R"EOF(@METASCHEMA_JSONSCHEMA_2019_09@)EOF"); } else if (identifier == - "https://json-schema.org/draft/2019-09/hyper-schema") { + "https://json-schema.org/draft/2019-09/hyper-schema" || + identifier == + "https://json-schema.org/draft/2019-09/hyper-schema#") { return sourcemeta::core::parse_json( R"EOF(@METASCHEMA_HYPERSCHEMA_2019_09@)EOF"); } else if (identifier == @@ -106,16 +105,6 @@ auto sourcemeta::core::schema_official_resolver(std::string_view identifier) "https://json-schema.org/draft/2019-09/output/hyper-schema") { return sourcemeta::core::parse_json( R"EOF(@METASCHEMA_HYPERSCHEMA_2019_09_OUTPUT@)EOF"); - - // Just for compatibility given that this is such a common issue - } else if (identifier == "https://json-schema.org/draft/2019-09/schema#") { - return sourcemeta::core::parse_json( - R"EOF(@METASCHEMA_JSONSCHEMA_2019_09@)EOF"); - } else if (identifier == - "https://json-schema.org/draft/2019-09/hyper-schema#") { - return sourcemeta::core::parse_json( - R"EOF(@METASCHEMA_HYPERSCHEMA_2019_09@)EOF"); - // JSON Schema Draft7 } else if (identifier == "http://json-schema.org/draft-07/schema#" || identifier == "http://json-schema.org/draft-07/schema") { diff --git a/src/core/uri/uri.cc b/src/core/uri/uri.cc index 303d36ee7..7744e87b2 100644 --- a/src/core/uri/uri.cc +++ b/src/core/uri/uri.cc @@ -688,8 +688,6 @@ auto URI::try_resolve_from(const URI &base) -> URI & { this->scheme_ = base.scheme_; this->query_ = base.query_; return *this; - } else if (base.path().has_value() && base.path().value().starts_with("..")) { - return *this; } else if (base.is_relative() && this->is_relative() && base.path_.has_value() && this->path_.has_value() && this->path_.value().find('/') == std::string::npos && From 549f7c00193b777eccff95f93ed87863a66bb1cf Mon Sep 17 00:00:00 2001 From: Balakrishna Avulapati Date: Tue, 22 Jul 2025 14:45:50 +0530 Subject: [PATCH 12/16] fix a bug reported on CI Signed-off-by: Balakrishna Avulapati --- src/core/uri/uri.cc | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/core/uri/uri.cc b/src/core/uri/uri.cc index 7744e87b2..7f40da3d2 100644 --- a/src/core/uri/uri.cc +++ b/src/core/uri/uri.cc @@ -212,23 +212,25 @@ auto URI::parse() -> void { // URNs and tags have a single path segment by definition if (this->is_urn() || this->is_tag()) { const auto part{uri_text_range(&segment->text)}; - assert(part.has_value()); - path << part.value(); + if (part) { + path << part.value(); + } } else { bool first{true}; while (segment) { const auto part{uri_text_range(&segment->text)}; - assert(part.has_value()); - const auto value{part.value()}; + if (part) { + const auto value{part.value()}; - if (first) { - path << value; - } else { - path << "/" << value; - } + if (first) { + path << value; + } else { + path << "/" << value; + } - segment = segment->next; - first = false; + segment = segment->next; + first = false; + } } } this->path_ = path.str(); From a8f491e523bff680f3dc820e7f968aa1c880049f Mon Sep 17 00:00:00 2001 From: Balakrishna Avulapati Date: Tue, 22 Jul 2025 15:20:00 +0530 Subject: [PATCH 13/16] fix a warning reported on CI Signed-off-by: Balakrishna Avulapati --- src/core/jsonschema/jsonschema.cc | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/core/jsonschema/jsonschema.cc b/src/core/jsonschema/jsonschema.cc index 0c523e084..84cf73885 100644 --- a/src/core/jsonschema/jsonschema.cc +++ b/src/core/jsonschema/jsonschema.cc @@ -624,10 +624,11 @@ auto sourcemeta::core::reference_visit( } assert(property.second.is_string()); - assert(walker_result.vocabulary.has_value()); - sourcemeta::core::URI reference{property.second.to_string()}; - callback(subschema, base, walker_result.vocabulary.value(), - property.first, reference); + if (walker_result.vocabulary) { + sourcemeta::core::URI reference{property.second.to_string()}; + callback(subschema, base, walker_result.vocabulary.value(), + property.first, reference); + } } } } @@ -685,7 +686,9 @@ auto sourcemeta::core::unidentify( } assert(entry.base_dialect.has_value()); - sourcemeta::core::anonymize(subschema, entry.base_dialect.value()); + if (entry.base_dialect) { + sourcemeta::core::anonymize(subschema, entry.base_dialect.value()); + } if (entry.vocabularies.contains( "https://json-schema.org/draft/2020-12/vocab/core")) { From 450e11ba7dc8710c998e5fa57a4a105f1dcb0577 Mon Sep 17 00:00:00 2001 From: Balakrishna Avulapati Date: Tue, 22 Jul 2025 16:58:13 +0530 Subject: [PATCH 14/16] disable optional_acess for now Signed-off-by: Balakrishna Avulapati --- cmake/common/clang-tidy.config | 2 +- src/core/jsonschema/jsonschema.cc | 13 +++++-------- src/core/uri/uri.cc | 24 +++++++++++------------- 3 files changed, 17 insertions(+), 22 deletions(-) diff --git a/cmake/common/clang-tidy.config b/cmake/common/clang-tidy.config index e3c0421cc..49abc79ba 100644 --- a/cmake/common/clang-tidy.config +++ b/cmake/common/clang-tidy.config @@ -1,5 +1,5 @@ { - "Checks": "-*, bugprone-*, -bugprone-easily-swappable-parameters, concurrency-*, modernize-*, performance-*, portability-*", + "Checks": "-*, bugprone-*, -bugprone-easily-swappable-parameters,-bugprone-unchecked-optional-access, concurrency-*, modernize-*, performance-*, portability-*", "WarningsAsErrors": "*", "FormatStyle": "none", "UseColor": true diff --git a/src/core/jsonschema/jsonschema.cc b/src/core/jsonschema/jsonschema.cc index 84cf73885..0c523e084 100644 --- a/src/core/jsonschema/jsonschema.cc +++ b/src/core/jsonschema/jsonschema.cc @@ -624,11 +624,10 @@ auto sourcemeta::core::reference_visit( } assert(property.second.is_string()); - if (walker_result.vocabulary) { - sourcemeta::core::URI reference{property.second.to_string()}; - callback(subschema, base, walker_result.vocabulary.value(), - property.first, reference); - } + assert(walker_result.vocabulary.has_value()); + sourcemeta::core::URI reference{property.second.to_string()}; + callback(subschema, base, walker_result.vocabulary.value(), + property.first, reference); } } } @@ -686,9 +685,7 @@ auto sourcemeta::core::unidentify( } assert(entry.base_dialect.has_value()); - if (entry.base_dialect) { - sourcemeta::core::anonymize(subschema, entry.base_dialect.value()); - } + sourcemeta::core::anonymize(subschema, entry.base_dialect.value()); if (entry.vocabularies.contains( "https://json-schema.org/draft/2020-12/vocab/core")) { diff --git a/src/core/uri/uri.cc b/src/core/uri/uri.cc index 7f40da3d2..7744e87b2 100644 --- a/src/core/uri/uri.cc +++ b/src/core/uri/uri.cc @@ -212,25 +212,23 @@ auto URI::parse() -> void { // URNs and tags have a single path segment by definition if (this->is_urn() || this->is_tag()) { const auto part{uri_text_range(&segment->text)}; - if (part) { - path << part.value(); - } + assert(part.has_value()); + path << part.value(); } else { bool first{true}; while (segment) { const auto part{uri_text_range(&segment->text)}; - if (part) { - const auto value{part.value()}; - - if (first) { - path << value; - } else { - path << "/" << value; - } + assert(part.has_value()); + const auto value{part.value()}; - segment = segment->next; - first = false; + if (first) { + path << value; + } else { + path << "/" << value; } + + segment = segment->next; + first = false; } } this->path_ = path.str(); From cb48e8c0729676327df2a57e2a2be99cc8e49db1 Mon Sep 17 00:00:00 2001 From: Balakrishna Avulapati Date: Tue, 22 Jul 2025 16:59:59 +0530 Subject: [PATCH 15/16] Squash merge rename-config-files-as-json-files into enable-bugprone-clang-tidy-checks Signed-off-by: Balakrishna Avulapati --- cmake/common/clang-tidy.cmake | 3 ++- cmake/common/{clang-tidy.config => clang-tidy.json} | 0 cmake/common/targets/clang-format.cmake | 2 +- cmake/common/targets/clang-format.config | 3 --- cmake/common/targets/clang-format.json | 4 ++++ 5 files changed, 7 insertions(+), 5 deletions(-) rename cmake/common/{clang-tidy.config => clang-tidy.json} (100%) delete mode 100644 cmake/common/targets/clang-format.config create mode 100644 cmake/common/targets/clang-format.json diff --git a/cmake/common/clang-tidy.cmake b/cmake/common/clang-tidy.cmake index 025251e37..7967f1044 100644 --- a/cmake/common/clang-tidy.cmake +++ b/cmake/common/clang-tidy.cmake @@ -98,7 +98,8 @@ function(sourcemeta_clang_tidy_attempt_enable) NO_DEFAULT_PATH PATHS "${PROJECT_BINARY_DIR}/bin" REQUIRED) - set(CLANG_TIDY_CONFIG "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/clang-tidy.config") + + set(CLANG_TIDY_CONFIG "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/clang-tidy.json") execute_process(COMMAND xcrun --show-sdk-path OUTPUT_VARIABLE MACOSX_SDK_PATH OUTPUT_STRIP_TRAILING_WHITESPACE) execute_process(COMMAND "${CMAKE_CXX_COMPILER}" -print-resource-dir diff --git a/cmake/common/clang-tidy.config b/cmake/common/clang-tidy.json similarity index 100% rename from cmake/common/clang-tidy.config rename to cmake/common/clang-tidy.json diff --git a/cmake/common/targets/clang-format.cmake b/cmake/common/targets/clang-format.cmake index 55fbb6cdc..7868fceb0 100644 --- a/cmake/common/targets/clang-format.cmake +++ b/cmake/common/targets/clang-format.cmake @@ -101,7 +101,7 @@ function(sourcemeta_target_clang_format) file(GLOB_RECURSE SOURCEMETA_TARGET_CLANG_FORMAT_FILES ${SOURCEMETA_TARGET_CLANG_FORMAT_SOURCES}) - set(CLANG_FORMAT_CONFIG "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/clang-format.config") + set(CLANG_FORMAT_CONFIG "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/clang-format.json") if(CMAKE_SYSTEM_NAME STREQUAL "MSYS") # Because `clang-format` is typically a Windows `.exe`, transform the path accordingly execute_process(COMMAND cygpath -w "${CLANG_FORMAT_CONFIG}" diff --git a/cmake/common/targets/clang-format.config b/cmake/common/targets/clang-format.config deleted file mode 100644 index d9c695cc9..000000000 --- a/cmake/common/targets/clang-format.config +++ /dev/null @@ -1,3 +0,0 @@ ---- -BasedOnStyle: LLVM -IndentCaseLabels: true diff --git a/cmake/common/targets/clang-format.json b/cmake/common/targets/clang-format.json new file mode 100644 index 000000000..7e760c01e --- /dev/null +++ b/cmake/common/targets/clang-format.json @@ -0,0 +1,4 @@ +{ + "BasedOnStyle": "LLVM", + "IndentCaseLabels": true +} From 6aeaf797fc6e74384508706e69da008d55a4234e Mon Sep 17 00:00:00 2001 From: Balakrishna Avulapati Date: Tue, 22 Jul 2025 17:30:27 +0530 Subject: [PATCH 16/16] Enable bugprone-easily-swappable-parameters This PR skips the check for existing usage, as fixing it can break the API. But this also makes sure that the new usage will be warned/signalled from now on. Signed-off-by: Balakrishna Avulapati --- cmake/common/clang-tidy.json | 2 +- src/core/json/include/sourcemeta/core/json_error.h | 2 ++ .../include/sourcemeta/core/jsonpointer_pointer.h | 1 + src/core/jsonschema/frame.cc | 12 +++++++----- src/core/jsonschema/jsonschema.cc | 1 + src/core/jsonschema/walker.cc | 1 + src/core/regex/include/sourcemeta/core/regex.h | 1 + src/core/uri/uri.cc | 1 + 8 files changed, 15 insertions(+), 6 deletions(-) diff --git a/cmake/common/clang-tidy.json b/cmake/common/clang-tidy.json index 49abc79ba..e010d9f31 100644 --- a/cmake/common/clang-tidy.json +++ b/cmake/common/clang-tidy.json @@ -1,5 +1,5 @@ { - "Checks": "-*, bugprone-*, -bugprone-easily-swappable-parameters,-bugprone-unchecked-optional-access, concurrency-*, modernize-*, performance-*, portability-*", + "Checks": "-*, bugprone-*, -bugprone-unchecked-optional-access, concurrency-*, modernize-*, performance-*, portability-*", "WarningsAsErrors": "*", "FormatStyle": "none", "UseColor": true diff --git a/src/core/json/include/sourcemeta/core/json_error.h b/src/core/json/include/sourcemeta/core/json_error.h index 53ec4b732..ba810667d 100644 --- a/src/core/json/include/sourcemeta/core/json_error.h +++ b/src/core/json/include/sourcemeta/core/json_error.h @@ -25,10 +25,12 @@ namespace sourcemeta::core { class SOURCEMETA_CORE_JSON_EXPORT JSONParseError : public std::exception { public: /// Create a parsing error + // NOLINTNEXTLINE(bugprone-easily-swappable-parameters) JSONParseError(const std::uint64_t line, const std::uint64_t column) : line_{line}, column_{column} {} /// Create a parsing error with a custom error + // NOLINTNEXTLINE(bugprone-easily-swappable-parameters) JSONParseError(const std::uint64_t line, const std::uint64_t column, std::string message) : line_{line}, column_{column}, message_{std::move(message)} {} diff --git a/src/core/jsonpointer/include/sourcemeta/core/jsonpointer_pointer.h b/src/core/jsonpointer/include/sourcemeta/core/jsonpointer_pointer.h index 1442d3e1f..f11797b82 100644 --- a/src/core/jsonpointer/include/sourcemeta/core/jsonpointer_pointer.h +++ b/src/core/jsonpointer/include/sourcemeta/core/jsonpointer_pointer.h @@ -536,6 +536,7 @@ template class GenericPointer { /// sourcemeta::core::Pointer{"qux", "baz"}); /// ``` [[nodiscard]] auto + // NOLINTNEXTLINE(bugprone-easily-swappable-parameters) rebase(const GenericPointer &prefix, const GenericPointer &replacement) const -> GenericPointer { diff --git a/src/core/jsonschema/frame.cc b/src/core/jsonschema/frame.cc index 183c4dc61..c55d4902e 100644 --- a/src/core/jsonschema/frame.cc +++ b/src/core/jsonschema/frame.cc @@ -407,11 +407,13 @@ auto SchemaFrame::to_json() const -> JSON { return root; } -auto SchemaFrame::analyse(const JSON &root, const SchemaWalker &walker, - const SchemaResolver &resolver, - const std::optional &default_dialect, - const std::optional &default_id, - const SchemaFrame::Paths &paths) -> void { +auto SchemaFrame::analyse( + const JSON &root, const SchemaWalker &walker, + const SchemaResolver &resolver, + // NOLINTNEXTLINE(bugprone-easily-swappable-parameters) + const std::optional &default_dialect, + const std::optional &default_id, + const SchemaFrame::Paths &paths) -> void { std::vector subschema_entries; std::map subschemas; std::map> base_uris; diff --git a/src/core/jsonschema/jsonschema.cc b/src/core/jsonschema/jsonschema.cc index 0c523e084..21a63dff3 100644 --- a/src/core/jsonschema/jsonschema.cc +++ b/src/core/jsonschema/jsonschema.cc @@ -70,6 +70,7 @@ static auto id_keyword(const std::string &base_dialect) -> std::string { auto sourcemeta::core::identify( const sourcemeta::core::JSON &schema, const SchemaResolver &resolver, const SchemaIdentificationStrategy strategy, + // NOLINTNEXTLINE(bugprone-easily-swappable-parameters) const std::optional &default_dialect, const std::optional &default_id) -> std::optional { diff --git a/src/core/jsonschema/walker.cc b/src/core/jsonschema/walker.cc index 1e19a2602..cea64f756 100644 --- a/src/core/jsonschema/walker.cc +++ b/src/core/jsonschema/walker.cc @@ -14,6 +14,7 @@ auto walk(const std::optional &parent, const sourcemeta::core::JSON &subschema, const sourcemeta::core::SchemaWalker &walker, const sourcemeta::core::SchemaResolver &resolver, + // NOLINTNEXTLINE(bugprone-easily-swappable-parameters) const std::string &dialect, const std::string &base_dialect, const SchemaWalkerType_t type, const std::size_t level, const bool orphan) -> void { diff --git a/src/core/regex/include/sourcemeta/core/regex.h b/src/core/regex/include/sourcemeta/core/regex.h index 10fc44ac2..c9b2e2706 100644 --- a/src/core/regex/include/sourcemeta/core/regex.h +++ b/src/core/regex/include/sourcemeta/core/regex.h @@ -217,6 +217,7 @@ auto matches(const Regex ®ex, const T &value) -> bool { /// assert(sourcemeta::core::matches_if_valid("^foo", "foo bar")); /// ``` template +// NOLINTNEXTLINE(bugprone-easily-swappable-parameters) auto matches_if_valid(const T &pattern, const T &value) -> bool { const auto regex{to_regex(pattern)}; return regex.has_value() && matches(regex.value(), value); diff --git a/src/core/uri/uri.cc b/src/core/uri/uri.cc index 7744e87b2..eec9d6aa8 100644 --- a/src/core/uri/uri.cc +++ b/src/core/uri/uri.cc @@ -641,6 +641,7 @@ auto URI::relative_to(const URI &base) -> URI & { return *this; } +// NOLINTNEXTLINE(bugprone-easily-swappable-parameters) auto URI::rebase(const URI &base, const URI &new_base) -> URI & { this->relative_to(base); if (!this->is_relative()) {