Skip to content
Snippets Groups Projects
Commit 3f5afbbf authored by Daniel Hornung's avatar Daniel Hornung
Browse files

STY: Implemented style fixes.

parent 0e1ec5a6
Branches
Tags
1 merge request!1Initial functionality
Pipeline #11202 failed
...@@ -62,14 +62,14 @@ code_style_octave: ...@@ -62,14 +62,14 @@ code_style_octave:
stage: test stage: test
script: script:
- mh_style -v - mh_style -v
- mh_style --octave ./src ./doc - make style_octave
allow_failure: true allow_failure: true
code_style_cpp: code_style_cpp:
tags: [ docker ] tags: [ docker ]
stage: test stage: test
script: script:
- make style - make style_cpp
allow_failure: true allow_failure: true
unit_tests: unit_tests:
...@@ -91,7 +91,7 @@ linting_octave: ...@@ -91,7 +91,7 @@ linting_octave:
tags: [ docker ] tags: [ docker ]
stage: test stage: test
script: script:
- mh_lint --octave ./ - make linting_octave
allow_failure: true allow_failure: true
# linting with clang-tidy and include-what-you-use # linting with clang-tidy and include-what-you-use
...@@ -99,11 +99,7 @@ linting_cpp: ...@@ -99,11 +99,7 @@ linting_cpp:
tags: [ docker ] tags: [ docker ]
stage: test stage: test
script: script:
- cd src - make linting_cpp
- ./configure
- cd ../build
- cmake -D LINTING=On ..
- cmake --build .
allow_failure: true allow_failure: true
# trigger the integration tests # trigger the integration tests
......
...@@ -47,8 +47,9 @@ string(REGEX REPLACE ";grpc\\+?\\+?_unsecure" "" CONAN_PKG_LIBS ...@@ -47,8 +47,9 @@ string(REGEX REPLACE ";grpc\\+?\\+?_unsecure" "" CONAN_PKG_LIBS
####################################################### #######################################################
option(AUTOFORMATTING "call clang-format at configure time" ON) option(AUTOFORMATTING "call clang-format at configure time" ON)
if(AUTOFORMATTING) if(AUTOFORMATTING)
file(GLOB format_sources src/*.cpp) find_program(clang_format NAMES clang-format-11 clang-format)
execute_process(COMMAND clang-format -i --verbose ${format_sources} file(GLOB_RECURSE format_sources src/*.cpp)
execute_process(COMMAND ${clang_format} -i --verbose ${format_sources}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}) WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
endif() endif()
...@@ -77,7 +78,10 @@ get_property(_MAOX_LIB_DIR TARGET maoxdb PROPERTY LIBRARY_OUTPUT_DIRECTORY) ...@@ -77,7 +78,10 @@ get_property(_MAOX_LIB_DIR TARGET maoxdb PROPERTY LIBRARY_OUTPUT_DIRECTORY)
# Only files in src/private will be compiled. This is to separate the non-mex files in src/lib; if # Only files in src/private will be compiled. This is to separate the non-mex files in src/lib; if
# this is to change, the GLOB_RECURSE code needs to be changed. # this is to change, the GLOB_RECURSE code needs to be changed.
add_subdirectory(src) # Absolute paths to the cpp files.
file(GLOB_RECURSE OCTAVE_CAOSDB_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/private/*.cpp)
message("OCTAVE_CAOSDB_SRC: ${OCTAVE_CAOSDB_SRC}")
set(PKG_INST_DIR "${PROJECT_SOURCE_DIR}/inst") set(PKG_INST_DIR "${PROJECT_SOURCE_DIR}/inst")
file(MAKE_DIRECTORY ${PKG_INST_DIR}) file(MAKE_DIRECTORY ${PKG_INST_DIR})
...@@ -113,20 +117,19 @@ endforeach(sourcefile) ...@@ -113,20 +117,19 @@ endforeach(sourcefile)
####################################################### #######################################################
option(LINTING "clang-tidy and iwyu" OFF) option(LINTING "clang-tidy and iwyu" OFF)
if(LINTING) if(LINTING)
find_program(clang_tidy NAMES clang-tidy clang-tidy-11) find_program(clang_tidy NAMES clang-tidy-11 clang-tidy)
if(NOT clang_tidy) if(NOT clang_tidy)
message(WARNING "clang-tidy: Not found") message(WARNING "clang-tidy: Not found")
else() else()
message(STATUS "clang-tidy: ${clang_tidy}") message(STATUS "clang-tidy: ${clang_tidy}")
set(_CMAKE_CXX_CLANG_TIDY set(_CMAKE_CXX_CLANG_TIDY
"--warnings-as-errors=*" "--warnings-as-errors=*"
"--header-filter=caosdb/.*[^\\\(\.pb\.h\\\)]$"
"--fix") "--fix")
set(_CMAKE_CXX_CLANG_TIDY_CHECKS set(_CMAKE_CXX_CLANG_TIDY_CHECKS
"--checks=*,-fuchsia-*,-llvmlibc-*,-llvm-else-after-return,-readability-else-after-return,-cppcoreguidelines-pro-type-vararg,-hicpp-vararg,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cert-err58-cpp") "--checks=*,-fuchsia-*,-llvmlibc-*,-llvm-else-after-return,-readability-else-after-return,-cppcoreguidelines-pro-type-vararg,-hicpp-vararg,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cert-err58-cpp")
add_custom_command( add_custom_command(
TARGET caosdb.mex TARGET mex
COMMAND ${clang_tidy} COMMAND ${clang_tidy}
ARGS ${_CMAKE_CXX_CLANG_TIDY} ${_CMAKE_CXX_CLANG_TIDY_CHECKS} ARGS ${_CMAKE_CXX_CLANG_TIDY} ${_CMAKE_CXX_CLANG_TIDY_CHECKS}
${OCTAVE_CAOSDB_SRC} "--" ${_MKOCTFILE_INCLUDES} "-I/usr/include" ${OCTAVE_CAOSDB_SRC} "--" ${_MKOCTFILE_INCLUDES} "-I/usr/include"
...@@ -146,7 +149,7 @@ if(LINTING) ...@@ -146,7 +149,7 @@ if(LINTING)
"-Xiwyu" "--cxx17ns") "-Xiwyu" "--cxx17ns")
add_custom_command( add_custom_command(
TARGET caosdb.mex TARGET mex
COMMAND ${iwyu} COMMAND ${iwyu}
ARGS ${_CMAKE_CXX_INCLUDE_WHAT_YOU_USE} "-I${OCTINCLUDEDIR}" ARGS ${_CMAKE_CXX_INCLUDE_WHAT_YOU_USE} "-I${OCTINCLUDEDIR}"
"-std=c++17" "-I/usr/include" ${_MKOCTFILE_INCLUDES} "-std=c++17" "-I/usr/include" ${_MKOCTFILE_INCLUDES}
......
...@@ -33,16 +33,49 @@ help: ...@@ -33,16 +33,49 @@ help:
doc: doc:
cd doc && $(MAKE) html cd doc && $(MAKE) html
style: ###############################################################################
mh_style --octave src doc test # Styling #
clang-format-11 --dry-run --verbose --Werror $(shell find test/ src/ -type f -iname "*.cpp" -o -iname "*.hpp" -o -iname "*.h" -o -iname "*.h.in") ###############################################################################
style: style_octave style_cpp
.PHONY: style .PHONY: style
style_octave:
mh_style --octave src doc test || echo "You may want to run `make style_fix`."
.PHONY: style_octave
style_cpp:
clang-format-11 --dry-run --verbose --Werror $(shell find test/ src/ -type f -iname "*.cpp" -o -iname "*.hpp" -o -iname "*.h" -o -iname "*.h.in") || echo "You may want to run `make style_fix`."
.PHONY: style_cpp
style_fix: style_fix:
mh_style --fix --octave src doc test mh_style --fix --octave src doc test
clang-format-11 -i --verbose --Werror $(shell find test/ src/ -type f -iname "*.cpp" -o -iname "*.hpp" -o -iname "*.h" -o -iname "*.h.in") clang-format-11 -i --verbose --Werror $(shell find test/ src/ -type f -iname "*.cpp" -o -iname "*.hpp" -o -iname "*.h" -o -iname "*.h.in")
.PHONY: style_fix .PHONY: style_fix
###############################################################################
# Linting #
###############################################################################
linting: linting_octave linting_cpp
.PHONY: linting
linting_octave:
mh_lint --octave ./
.PHONY: linting_octave
linting_cpp:
cd src \
&& ./configure \
&& cd ../build \
&& cmake -D LINTING=On .. \
&& cmake --build .
.PHONY: linting_cpp
###############################################################################
# Tests #
###############################################################################
.PHONY: test .PHONY: test
test: test:
cd test && octave Run_Test.m cd test && octave Run_Test.m
...@@ -56,7 +89,7 @@ pkg: dist/caosdb.tar.gz ...@@ -56,7 +89,7 @@ pkg: dist/caosdb.tar.gz
.PHONY: install .PHONY: install
install: pkg install: pkg
octave --eval "pkg -verbose install dist/caosdb.tar.gz" octave --eval "pkg install -verbose dist/caosdb.tar.gz"
.PHONY: caosdb.tar.gz .PHONY: caosdb.tar.gz
dist/caosdb.tar.gz: dist/ dist/caosdb.tar.gz: dist/
......
#
# This file is a part of the CaosDB Project.
#
# Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com>
# Copyright (C) 2021 IndiScale GmbH <info@indiscale.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# We want to compile all the _*.cpp files in `private`
set(OCTAVE_CAOSDB_SRC
${CMAKE_CURRENT_SOURCE_DIR}/private/_caosdb.cpp
)
# pass variable to parent scope
set(OCTAVE_CAOSDB_SRC ${OCTAVE_CAOSDB_SRC} PARENT_SCOPE)
#ifndef MAOXDB_H #ifndef MAOXDB_H // NOLINT
#define MAOXDB_H #define MAOXDB_H
#include "caosdb/exceptions.h" #include "caosdb/exceptions.h"
...@@ -9,28 +9,6 @@ ...@@ -9,28 +9,6 @@
// Macros ///////////////////////////////////////////////////////////////////// // Macros /////////////////////////////////////////////////////////////////////
/**
* mxSCALAR(type, name, value): Create a 1x1 mxArray of type TYPE and value
* VALUE. The NAME must be unique within each scope.
*
* Use it like so (note that the assignment to NAME is necessary):
*
* auto* scalar = mxSCALAR(UINT64, scalar, value);
*
* This will exand to:
*
* mxCreateNumericMatrix(1, 1, mxUINT64_CLASS, mxREAL);
* UINT64_T* scalar_data = (UINT64_T*) mxGetData(scalar);
* scalar_data[0] = value;
* mxSetData(scalar, scalar_data);
*
* TODO: This macro could be rewritten as a function now.
*/
#define mxSCALAR(type, name, value) \
mxCreateNumericMatrix(1, 1, mx##type##_CLASS, mxREAL); \
auto *__##name##_data = (type##_T *)mxGetData(name); \
__##name##_data[0] = value; \
mxSetData(name, __##name##_data)
// Utility functions ////////////////////////////////////////////////////////// // Utility functions //////////////////////////////////////////////////////////
namespace maoxdb { namespace maoxdb {
...@@ -39,7 +17,7 @@ using std::string; ...@@ -39,7 +17,7 @@ using std::string;
template <typename T> auto mxScalar(T value, mxClassID class_id) -> mxArray * { template <typename T> auto mxScalar(T value, mxClassID class_id) -> mxArray * {
mxArray *array = mxCreateNumericMatrix(1, 1, class_id, mxREAL); mxArray *array = mxCreateNumericMatrix(1, 1, class_id, mxREAL);
auto *data = (T *)mxGetData(array); auto *data = static_cast<T *>(mxGetData(array));
data[0] = value; data[0] = value;
return array; return array;
} }
...@@ -56,7 +34,7 @@ inline auto mxScalarDOUBLE(double value) -> mxArray * { ...@@ -56,7 +34,7 @@ inline auto mxScalarDOUBLE(double value) -> mxArray * {
return mxScalar<double>(value, mxDOUBLE_CLASS); return mxScalar<double>(value, mxDOUBLE_CLASS);
} }
inline auto mxScalarLOGICAL(bool value) -> mxArray * { inline auto mxScalarLOGICAL(bool value) -> mxArray * {
return mxScalar<UINT8_T>(value, mxLOGICAL_CLASS); return mxScalar<UINT8_T>(static_cast<unsigned char>(value), mxLOGICAL_CLASS);
} }
/** /**
...@@ -74,8 +52,8 @@ inline auto mxScalarLOGICAL(bool value) -> mxArray * { ...@@ -74,8 +52,8 @@ inline auto mxScalarLOGICAL(bool value) -> mxArray * {
* @note Additional utility functions should be easy to implement when the * @note Additional utility functions should be easy to implement when the
* libcaosdb error handling changes. * libcaosdb error handling changes.
*/ */
std::pair<string, string> auto
exceptionToMessage(const caosdb::exceptions::Exception &exc); exceptionToMessage(const caosdb::exceptions::Exception &exc) -> std::pair<string, string>;
/** /**
* @brief Throw a CaosDB Exception inside Octave. * @brief Throw a CaosDB Exception inside Octave.
......
...@@ -13,22 +13,23 @@ using caosdb::connection::Connection; ...@@ -13,22 +13,23 @@ using caosdb::connection::Connection;
using caosdb::connection::ConnectionManager; using caosdb::connection::ConnectionManager;
using std::string; using std::string;
mxArray *info(const string &connection_name); auto info(const string &connection_name) -> mxArray *;
/** /**
* The implementation of the info retrieval. * The implementation of the info retrieval.
*/ */
mxArray *info(string const &connection_name) { auto info(string const &connection_name) -> mxArray * {
std::shared_ptr<Connection> connection = NULL; std::shared_ptr<Connection> connection = nullptr;
if (connection_name == "") { if (connection_name.empty()) {
connection = ConnectionManager::GetDefaultConnection(); connection = ConnectionManager::GetDefaultConnection();
} else { } else {
connection = ConnectionManager::GetConnection(connection_name); connection = ConnectionManager::GetConnection(connection_name);
} }
const auto &version_info = connection->RetrieveVersionInfo(); const auto &version_info = connection->RetrieveVersionInfo();
const char *keys[] = {"major", "minor", "patch", "pre_release", "build"}; const char *keys[] = {"major", "minor", "patch", "pre_release", // NOLINT
mwSize dims[2] = {1, 1}; "build"};
mxArray *info_struct = mxCreateStructArray(2, dims, 5, keys); std::array<mwSize, 2> dims = {1, 1};
mxArray *info_struct = mxCreateStructArray(2, dims.data(), 5, keys); // NOLINT
mxSetField(info_struct, 0, "major", mxSetField(info_struct, 0, "major",
maoxdb::mxScalarUINT64(version_info.GetMajor())); maoxdb::mxScalarUINT64(version_info.GetMajor()));
...@@ -53,14 +54,15 @@ mxArray *info(string const &connection_name) { ...@@ -53,14 +54,15 @@ mxArray *info(string const &connection_name) {
* *
* @return return type * @return return type
*/ */
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { void mexFunction(int /*nlhs*/, mxArray *plhs[], int nrhs,
const mxArray *prhs[]) {
string conn_name(""); string conn_name;
if (nrhs >= 1 && mxGetNumberOfElements(prhs[0]) > 0) { if (nrhs >= 1 && mxGetNumberOfElements(prhs[0]) > 0) {
conn_name = mxGetChars(prhs[0]); conn_name = mxGetChars(prhs[0]);
} }
try { try {
auto info_struct = info(conn_name); auto *info_struct = info(conn_name);
plhs[0] = info_struct; plhs[0] = info_struct;
} catch (const caosdb::exceptions::Exception &exc) { } catch (const caosdb::exceptions::Exception &exc) {
mexPrintf("Some exception!"); mexPrintf("Some exception!");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment