This is an automated email from the ASF dual-hosted git repository.
westonpace pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-cookbook.git
The following commit(s) were added to refs/heads/main by this push:
new 4f086b0 Added clang-format and clang-tidy files. Added clang-tidy to
the build. (#54)
4f086b0 is described below
commit 4f086b0f0c77dd0654bc8c626af92349dba5583e
Author: Weston Pace <[email protected]>
AuthorDate: Tue Aug 31 16:18:26 2021 -1000
Added clang-format and clang-tidy files. Added clang-tidy to the build.
(#54)
* Added clang-format and clang-tidy files. Added clang-tidy to the build.
* Added copyright to .clang-tidy
* Wrapped duplicated cmake code into helper function. Got rid of defunct
lint target
---
cpp/.clang-format | 20 ++++++++++++++++++
cpp/code/.clang-tidy | 21 +++++++++++++++++++
cpp/code/CMakeLists.txt | 56 +++++++++++++++++++++++++------------------------
cpp/code/common.cc | 9 ++++----
cpp/code/common.h | 11 +++++-----
5 files changed, 81 insertions(+), 36 deletions(-)
diff --git a/cpp/.clang-format b/cpp/.clang-format
new file mode 100644
index 0000000..06453df
--- /dev/null
+++ b/cpp/.clang-format
@@ -0,0 +1,20 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+---
+BasedOnStyle: Google
+DerivePointerAlignment: false
+ColumnLimit: 90
diff --git a/cpp/code/.clang-tidy b/cpp/code/.clang-tidy
new file mode 100644
index 0000000..d933431
--- /dev/null
+++ b/cpp/code/.clang-tidy
@@ -0,0 +1,21 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+---
+Checks:
'*,-llvmlibc*,-cert-err58-cpp,-modernize-use-trailing-return-type,-fuchsia-*,-cppcoreguidelines-*,
+
-readability-magic-numbers,-clang-analyzer-cplusplus.NewDelete,-clang-analyzer-cplusplus.NewDeleteLeaks'
+WarningsAsErrors: '*'
+FormatStyle: 'file'
diff --git a/cpp/code/CMakeLists.txt b/cpp/code/CMakeLists.txt
index 213d48a..8080271 100644
--- a/cpp/code/CMakeLists.txt
+++ b/cpp/code/CMakeLists.txt
@@ -6,9 +6,9 @@ set(CMAKE_CXX_STANDARD 17)
# Add googletest
include(FetchContent)
FetchContent_Declare(
- googletest
- GIT_REPOSITORY https://github.com/google/googletest.git
- GIT_TAG e2239ee6043f73722e7aa812a459f54a28552929 # release-1.11.0
+ googletest
+ GIT_REPOSITORY https://github.com/google/googletest.git
+ GIT_TAG e2239ee6043f73722e7aa812a459f54a28552929 # release-1.11.0
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
@@ -17,31 +17,33 @@ FetchContent_MakeAvailable(googletest)
# Add Arrow
find_package(Arrow REQUIRED)
+set(CMAKE_CXX_CLANG_TIDY "clang-tidy")
+
# Create test targets
enable_testing()
+
include(GoogleTest)
-add_executable(
- creating_arrow_objects
- creating_arrow_objects.cc
- common.cc
- main.cc
-)
-target_link_libraries(
- creating_arrow_objects
- arrow_shared
- gtest
-)
-gtest_discover_tests(creating_arrow_objects)
-add_executable(
- basic_arrow
- basic_arrow.cc
- common.cc
- main.cc
-)
-target_link_libraries(
- basic_arrow
- arrow_shared
- gtest
-)
-gtest_discover_tests(basic_arrow)
+function(RECIPE TARGET)
+ add_executable(
+ ${TARGET}
+ ${TARGET}.cc
+ common.cc
+ main.cc
+ )
+ target_link_libraries(
+ ${TARGET}
+ arrow_shared
+ gtest
+ )
+ if (MSVC)
+ target_compile_options(${TARGET} PRIVATE /W4 /WX)
+ else ()
+ target_compile_options(${TARGET} PRIVATE -Wall -Wextra -Wpedantic
-Werror)
+ endif ()
+
+ gtest_discover_tests(${TARGET})
+endfunction()
+
+recipe(basic_arrow)
+recipe(creating_arrow_objects)
diff --git a/cpp/code/common.cc b/cpp/code/common.cc
index 0024c4c..43f27c0 100644
--- a/cpp/code/common.cc
+++ b/cpp/code/common.cc
@@ -15,6 +15,8 @@
// specific language governing permissions and limitations
// under the License.
+#include "common.h"
+
#include <sstream>
#include <unordered_map>
@@ -23,8 +25,6 @@
#include "arrow/ipc/api.h"
#include "gtest/gtest.h"
-#include "common.h"
-
static arrow::StringBuilder test_names_builder;
static arrow::StringBuilder test_output_builder;
static std::string current_recipe;
@@ -121,13 +121,14 @@ void PopulateMap(const arrow::Table& table,
}
arrow::Result<std::shared_ptr<arrow::Table>> MergeRecipeTables(
- std::shared_ptr<arrow::Table> old_table, std::shared_ptr<arrow::Table>
new_table) {
+ const std::shared_ptr<arrow::Table>& old_table,
+ const std::shared_ptr<arrow::Table>& new_table) {
std::unordered_map<std::string, std::string> values;
PopulateMap(*old_table, &values);
PopulateMap(*new_table, &values);
arrow::StringBuilder names_builder;
arrow::StringBuilder outputs_builder;
- for (auto pair : values) {
+ for (const auto& pair : values) {
ARROW_RETURN_NOT_OK(names_builder.Append(pair.first));
ARROW_RETURN_NOT_OK(outputs_builder.Append(pair.second));
}
diff --git a/cpp/code/common.h b/cpp/code/common.h
index f7fef1a..e9f5d9e 100644
--- a/cpp/code/common.h
+++ b/cpp/code/common.h
@@ -18,19 +18,20 @@
#ifndef ARROW_COOKBOOK_COMMON_H
#define ARROW_COOKBOOK_COMMON_H
-#include <sstream>
-#include <string>
-
#include <arrow/result.h>
#include <arrow/status.h>
+#include <sstream>
+#include <string>
+
#define ARROW_STRINGIFY(x) #x
#define ARROW_CONCAT(x, y) x##y
#define ARROW_ASSIGN_OR_RAISE_NAME(x, y) ARROW_CONCAT(x, y)
-#define ASSERT_OK(expr)
\
- for (::arrow::Status _st = ::arrow::internal::GenericToStatus((expr));
!_st.ok();) \
+#define ASSERT_OK(expr)
\
+ for (const ::arrow::Status& _st =
::arrow::internal::GenericToStatus((expr)); \
+ !_st.ok();)
\
FAIL() << "'" ARROW_STRINGIFY(expr) "' failed with " << _st.ToString()
#define ASSIGN_OR_HANDLE_ERROR_IMPL(handle_error, status_name, lhs, rexpr) \