Skip to content

Commit b670976

Browse files
committed
Merge branch 'main' into clang-tidy-target-level
2 parents de51204 + 64f2e39 commit b670976

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+999
-520
lines changed

.github/workflows/website-build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ jobs:
1616
- run: >
1717
cmake -S . -B ./build
1818
-DCMAKE_BUILD_TYPE:STRING=Release
19+
-DSOURCEMETA_CORE_LANG_IO:BOOL=OFF
1920
-DSOURCEMETA_CORE_TIME:BOOL=OFF
2021
-DSOURCEMETA_CORE_UUID:BOOL=OFF
2122
-DSOURCEMETA_CORE_GZIP:BOOL=OFF

.github/workflows/website-deploy.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ jobs:
2626
- run: >
2727
cmake -S . -B ./build
2828
-DCMAKE_BUILD_TYPE:STRING=Release
29+
-DSOURCEMETA_CORE_LANG_IO:BOOL=OFF
2930
-DSOURCEMETA_CORE_TIME:BOOL=OFF
3031
-DSOURCEMETA_CORE_UUID:BOOL=OFF
3132
-DSOURCEMETA_CORE_GZIP:BOOL=OFF

CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ project(core VERSION 0.0.0 LANGUAGES C CXX DESCRIPTION "Sourcemeta Core")
33
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
44

55
# Options
6+
option(SOURCEMETA_CORE_LANG_IO "Build the Sourcemeta Core language I/O library" ON)
67
option(SOURCEMETA_CORE_TIME "Build the Sourcemeta Core time library" ON)
78
option(SOURCEMETA_CORE_UUID "Build the Sourcemeta Core UUID library" ON)
89
option(SOURCEMETA_CORE_GZIP "Build the Sourcemeta Core GZIP library" ON)
@@ -51,6 +52,10 @@ if(SOURCEMETA_CORE_INSTALL)
5152
COMPONENT sourcemeta_${PROJECT_NAME}_dev)
5253
endif()
5354

55+
if(SOURCEMETA_CORE_LANG_IO)
56+
add_subdirectory(src/lang/io)
57+
endif()
58+
5459
if(SOURCEMETA_CORE_TIME)
5560
add_subdirectory(src/core/time)
5661
endif()
@@ -137,6 +142,10 @@ endif()
137142
if(SOURCEMETA_CORE_TESTS)
138143
enable_testing()
139144

145+
if(SOURCEMETA_CORE_LANG_IO)
146+
add_subdirectory(test/io)
147+
endif()
148+
140149
if(SOURCEMETA_CORE_TIME)
141150
add_subdirectory(test/time)
142151
endif()

cmake/common/clang-tidy.cmake

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,9 @@ function(sourcemeta_clang_tidy_attempt_enable)
105105
OUTPUT_VARIABLE MACOSX_RESOURCE_PATH OUTPUT_STRIP_TRAILING_WHITESPACE)
106106
set(SOURCEMETA_CXX_CLANG_TIDY
107107
"${CLANG_TIDY_BIN};--config-file=${CLANG_TIDY_CONFIG};-header-filter=${PROJECT_SOURCE_DIR}/src/*"
108-
"--extra-arg=-std=c++${CMAKE_CXX_STANDARD}"
109108
"--extra-arg=-isysroot"
110109
"--extra-arg=${MACOSX_SDK_PATH}"
111-
"--extra-arg=-resource-dir=${MACOSX_RESOURCE_PATH}"
110+
"--extra-arg=-resource-dir=${MACOSX_RESOURCE_PATH}"
112111
CACHE STRING "CXX_CLANG_TIDY")
113112
endif()
114113

cmake/common/clang-tidy.config

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,6 @@
1-
---
2-
# See https://clang.llvm.org/extra/clang-tidy/index.html
3-
# First disable all default checks (with -*)
4-
Checks: '-*,
5-
modernize-*'
6-
# TODO(bavulapati): iterate through the rules and enable them incrementally inorder to send smaller PRs
7-
# bugprone-*,-bugprone-branch-clone,-bugprone-easily-swappable-parameters,-bugprone-empty-catch,
8-
# clang-analyzer-*,
9-
# clang-diagnostic-*,
10-
# modernize-*,
11-
# concurrency-*,
12-
# cppcoreguidelines-*,-cppcoreguidelines-rvalue-reference-param-not-moved,
13-
# performance-*,-performance-enum-size,
14-
# portability-*,
15-
# objc-*,
16-
# misc-*,-misc-no-recursion,-misc-unused-parameters,-misc-const-correctness'
17-
WarningsAsErrors: '*'
18-
FormatStyle: none
19-
UseColor: true
1+
{
2+
"Checks": "-*, concurrency-*, modernize-*, performance-*, portability-*",
3+
"WarningsAsErrors": "*",
4+
"FormatStyle": "none",
5+
"UseColor": true
6+
}

config.cmake.in

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
list(APPEND SOURCEMETA_CORE_COMPONENTS ${Core_FIND_COMPONENTS})
55
list(APPEND SOURCEMETA_CORE_COMPONENTS ${core_FIND_COMPONENTS})
66
if(NOT SOURCEMETA_CORE_COMPONENTS)
7+
list(APPEND SOURCEMETA_CORE_COMPONENTS io)
78
list(APPEND SOURCEMETA_CORE_COMPONENTS time)
89
list(APPEND SOURCEMETA_CORE_COMPONENTS uuid)
910
list(APPEND SOURCEMETA_CORE_COMPONENTS gzip)
@@ -21,7 +22,9 @@ endif()
2122
include(CMakeFindDependencyMacro)
2223

2324
foreach(component ${SOURCEMETA_CORE_COMPONENTS})
24-
if(component STREQUAL "time")
25+
if(component STREQUAL "io")
26+
include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_core_io.cmake")
27+
elseif(component STREQUAL "time")
2528
include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_core_time.cmake")
2629
elseif(component STREQUAL "uuid")
2730
include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_core_uuid.cmake")
@@ -38,6 +41,7 @@ foreach(component ${SOURCEMETA_CORE_COMPONENTS})
3841
find_dependency(uriparser CONFIG)
3942
include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_core_uri.cmake")
4043
elseif(component STREQUAL "json")
44+
include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_core_io.cmake")
4145
include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_core_json.cmake")
4246
elseif(component STREQUAL "jsonl")
4347
include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_core_json.cmake")
@@ -57,6 +61,7 @@ foreach(component ${SOURCEMETA_CORE_COMPONENTS})
5761
elseif(component STREQUAL "yaml")
5862
include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_core_json.cmake")
5963
find_dependency(yaml CONFIG)
64+
include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_core_io.cmake")
6065
include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_core_yaml.cmake")
6166
elseif(component STREQUAL "alterschema")
6267
find_dependency(uriparser CONFIG)

src/core/json/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ sourcemeta_library(NAMESPACE sourcemeta PROJECT core NAME json
55
if(SOURCEMETA_CORE_INSTALL)
66
sourcemeta_library_install(NAMESPACE sourcemeta PROJECT core NAME json)
77
endif()
8+
9+
target_link_libraries(sourcemeta_core_json PRIVATE sourcemeta::core::io)

src/core/json/include/sourcemeta/core/json.h

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -132,29 +132,6 @@ SOURCEMETA_CORE_JSON_EXPORT
132132
auto read_json(const std::filesystem::path &path,
133133
const JSON::ParseCallback &callback = nullptr) -> JSON;
134134

135-
// TODO: Move this function to a system integration component, as it
136-
// is not JSON specific
137-
138-
/// @ingroup json
139-
///
140-
/// A convenience function to read a document from a file. For example:
141-
///
142-
/// ```cpp
143-
/// #include <sourcemeta/core/json.h>
144-
/// #include <cassert>
145-
/// #include <iostream>
146-
///
147-
/// auto stream = sourcemeta::core::read_file("/tmp/foo.json");
148-
/// const auto document = sourcemeta::core::parse_json(stream);
149-
/// sourcemeta::core::stringify(document, std::cout);
150-
/// std::cout << std::endl;
151-
/// ```
152-
///
153-
/// If parsing fails, sourcemeta::core::JSONParseError will be thrown.
154-
SOURCEMETA_CORE_JSON_EXPORT
155-
auto read_file(const std::filesystem::path &path)
156-
-> std::basic_ifstream<JSON::Char, JSON::CharTraits>;
157-
158135
/// @ingroup json
159136
///
160137
/// Stringify the input JSON document into a given C++ standard output stream in

src/core/json/include/sourcemeta/core/json_auto.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ auto from_json(const JSON &value) -> std::optional<T> {
161161
// JSON?
162162
/// @ingroup json
163163
template <typename T>
164-
requires std::is_same_v<T, JSON::Object::Container::hash_type>
164+
requires std::is_same_v<T, JSON::Object::hash_type>
165165
auto to_json(const T &hash) -> JSON {
166166
auto result{JSON::make_array()};
167167
#if defined(__SIZEOF_INT128__)
@@ -182,7 +182,7 @@ auto to_json(const T &hash) -> JSON {
182182
// JSON?
183183
/// @ingroup json
184184
template <typename T>
185-
requires std::is_same_v<T, JSON::Object::Container::hash_type>
185+
requires std::is_same_v<T, JSON::Object::hash_type>
186186
auto from_json(const JSON &value) -> std::optional<T> {
187187
if (!value.is_array() || value.size() != 4 || !value.at(0).is_integer() ||
188188
!value.at(1).is_integer() || !value.at(2).is_integer() ||
@@ -209,11 +209,20 @@ auto from_json(const JSON &value) -> std::optional<T> {
209209

210210
/// @ingroup json
211211
template <typename T>
212-
requires std::constructible_from<JSON, T>
212+
requires(std::constructible_from<JSON, T> &&
213+
// Otherwise MSVC gets confused
214+
!std::is_same_v<T, unsigned long long>)
213215
auto to_json(const T &value) -> JSON {
214216
return JSON{value};
215217
}
216218

219+
/// @ingroup json
220+
template <typename T>
221+
requires std::is_same_v<T, unsigned long long>
222+
auto to_json(const T value) -> JSON {
223+
return JSON{static_cast<std::int64_t>(value)};
224+
}
225+
217226
/// @ingroup json
218227
template <typename T>
219228
requires std::is_same_v<T, JSON>

0 commit comments

Comments
 (0)