diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..10a6a31 --- /dev/null +++ b/.clang-format @@ -0,0 +1,36 @@ +# This file determines clang-format's style settings; for details, refer to +# http://clang.llvm.org/docs/ClangFormatStyleOptions.html + +BasedOnStyle: Google +ColumnLimit: 120 + +DerivePointerAlignment: false +PointerAlignment: Left + +# Specify the #include statement order. This implements the order mandated by +# the Google C++ Style Guide: related header, C headers, C++ headers, library +# headers, and finally the project headers. +# +# To obtain updated lists of system headers used in the below expressions, see: +# http://stackoverflow.com/questions/2027991/list-of-standard-header-files-in-c-and-c/2029106#2029106. +IncludeCategories: + - Regex: '^$' + Priority: 15 + - Regex: '^$' + Priority: 25 + - Regex: '^$' + Priority: 35 + - Regex: '^$' + Priority: 45 + # C system headers. + - Regex: '^[<"](aio|arpa/inet|assert|complex|cpio|ctype|curses|dirent|dlfcn|errno|fcntl|fenv|float|fmtmsg|fnmatch|ftw|glob|grp|iconv|inttypes|iso646|langinfo|libgen|limits|locale|math|monetary|mqueue|ndbm|netdb|net/if|netinet/in|netinet/tcp|nl_types|poll|pthread|pwd|regex|sched|search|semaphore|setjmp|signal|spawn|stdalign|stdarg|stdatomic|stdbool|stddef|stdint|stdio|stdlib|stdnoreturn|string|strings|stropts|sys/ipc|syslog|sys/mman|sys/msg|sys/resource|sys/select|sys/sem|sys/shm|sys/socket|sys/stat|sys/statvfs|sys/time|sys/times|sys/types|sys/uio|sys/un|sys/utsname|sys/wait|tar|term|termios|tgmath|threads|time|trace|uchar|ulimit|uncntrl|unistd|utime|utmpx|wchar|wctype|wordexp)\.h[">]$' + Priority: 20 + # C++ system headers (as of C++17). + - Regex: '^[<"](algorithm|array|atomic|bitset|cassert|ccomplex|cctype|cerrno|cfenv|cfloat|chrono|cinttypes|ciso646|climits|clocale|cmath|codecvt|complex|condition_variable|csetjmp|csignal|cstdalign|cstdarg|cstdbool|cstddef|cstdint|cstdio|cstdlib|cstring|ctgmath|ctime|cuchar|cwchar|cwctype|deque|exception|forward_list|fstream|functional|future|initializer_list|iomanip|ios|iosfwd|iostream|istream|iterator|limits|list|locale|map|memory|mutex|new|numeric|optional|ostream|queue|random|ratio|regex|scoped_allocator|set|shared_mutex|sstream|stack|stdexcept|streambuf|string|strstream|system_error|thread|tuple|type_traits|typeindex|typeinfo|unordered_map|unordered_set|utility|valarray|variant|vector)[">]$' + Priority: 30 + # Other libraries' h files (with angles). + - Regex: '^<' + Priority: 40 + # Other libraries' h files (with quotes). + - Regex: '^"' + Priority: 41 diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..4ba787e --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,89 @@ +# Copyright 2022 Toyota Research Institute. All rights reserved. +# +# clang-tidy lists all rules in a single YAML string, which makes it +# hard to have inline comments. Thus we'll add comments out-of-line +# up here. +# +# Disabled checks have rationale documented here. + +# * cert-err58-cpp - This verifies that exceptions are not thrown +# during static initialization or destruction. However, boost::test +# violates this, so we leave it off for now. + +# * cert-err60-cpp - This requires that exception types have noexcept +# copy constructors. SystemError could do so, except that it +# contains a std::string, which can throw std::bad_alloc. Hopefully +# soon C++ will delete std::bad_alloc entirely, but in the meantime, +# we disable this check. + +# * cppcoreguidelines-pro-type-vararg,hicpp-vararg - boost::test uses +# varargs, so for now we leave this disabled globally + +# * cppcoreguidelines-pro-bounds-array-to-pointer-decay, +# hicpp-no-array-decay - every call to BOOST_ASSERT_MSG triggers +# this along with things like using std::cout + +# * cppcoreguidelines-pro-type-reinterpret-cast - we currently have a +# lot of reinterpret_casts that are required in order to perform low +# level bit manipulation. It probably isn't worth annotating all of +# them yet. + +# * cppcoreguidelines-pro-bounds-pointer-arithmetic - until we get +# C++20's span or some similar construct, this will be difficult to +# satisfy. + +# * fuchsia-default-arguments - we currently permit C++ default +# arguments + +# * fuchsia-multiple-inheritance - we currently permit inheriting +# implementation and multiple inheritance + +# * fuchsia-overloaded-operator - we (and GSG) consider operator +# overloading fine + +# * fuchsia-statically-constructed-objects - boost::test uses +# statically constructed objects, so we leave this around. + +# * google-runtime-references - boost::asio widely uses the convention +# of passing io_service by mutable reference, as does the C++ +# iostreams library + +# * hicpp-exception-baseclass - either boost::system::system_error +# doesn't inherit from std::exception or clang can't discover that +# it does. In either case, this isn't important enough to figure +# out. + +# * readability-named-parameter - This requires that all parameters be +# named. This rule seems to be of dubious value, since often the +# type alone of an argument is sufficient documentation. + +# * readability-redundant-declaration - C++14 requires static +# constexpr class members to have a separate definition. Until we +# drop C++14 support, it is easiest to just ignore this warning. + +# * performance-unnecessary-copy-initialization, +# performance-unnecessary-value-param - These checks seem to be of +# dubious value, as the conditions they warn about would all likely +# be optimized away by a sane compiler and they require moderate +# contortions to satisfy. + +Checks: > + *, + -cert-err58-cpp, + -cert-err60-cpp, + -cppcoreguidelines-pro-type-vararg, + -hicpp-vararg, + -cppcoreguidelines-pro-bounds-array-to-pointer-decay, + -hicpp-no-array-decay, + -cppcoreguidelines-pro-type-reinterpret-cast, + -cppcoreguidelines-pro-bounds-pointer-arithmetic, + -fuchsia-default-arguments, + -fuchsia-multiple-inheritance, + -fuchsia-overloaded-operator, + -fuchsia-statically-constructed-objects, + -google-runtime-references, + -hicpp-exception-baseclass, + -readability-named-parameter, + -readability-redundant-declaration, + -performance-unnecessary-copy-initialization, + -performance-unnecessary-value-param, diff --git a/.github/clang_suite_installation.sh b/.github/clang_suite_installation.sh new file mode 100755 index 0000000..c40ba00 --- /dev/null +++ b/.github/clang_suite_installation.sh @@ -0,0 +1,28 @@ +#! /bin/bash + +####################################### +# Installs clang suite packages. +# Arguments: +# Version of the clang suite package. +# Returns: +# 0 if no error was detected, non-zero otherwise. +####################################### +function install_clang_suite() { + local version=$1 + + apt install -y \ + clang-${version} \ + lldb-${version} \ + lld-${version} \ + clang-format-${version} \ + clang-tidy-${version} \ + libc++-${version}-dev \ + libc++abi-${version}-dev +} + +####################################### +# Modify clang suite version as required. +####################################### +CLANG_SUITE_VERSION=8 + +install_clang_suite ${CLANG_SUITE_VERSION} diff --git a/.github/dependencies.repos b/.github/dependencies.repos new file mode 100644 index 0000000..5eff6f7 --- /dev/null +++ b/.github/dependencies.repos @@ -0,0 +1,9 @@ +repositories: + ament_cmake_doxygen: + type: git + url: https://github.com/ToyotaResearchInstitute/ament_cmake_doxygen + version: main + maliput: + type: git + url: https://github.com/maliput/maliput + version: main diff --git a/.github/run_scan_build b/.github/run_scan_build new file mode 100755 index 0000000..9e06f8a --- /dev/null +++ b/.github/run_scan_build @@ -0,0 +1,144 @@ +#!/usr/bin/python3 + +# BSD 3-Clause License +# +# Copyright (c) 2022, Woven Planet. All rights reserved. +# Copyright (c) 2020-2022, Toyota Research Institute. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import os +import sys + +EXTRA_EXCLUDE_ARGS = " --exclude src/pybind11 --exclude /usr/include/eigen3 " + +def get_package_dependencies_names(packages_up_to = None): + ''' + Returns a set of dependencies by name of all the `packages-up-to` argument. + When None is provided, all the packages are returned. + ''' + stream = os.popen('colcon graph') if not packages_up_to else os.popen('colcon graph --packages-up-to ' + packages_up_to) + + colcon_graph = stream.read().splitlines() + result = set() + for line in colcon_graph: + result.add(line[:line.find(' ')]) + return result + +def get_exclusion_paths_from_file(filepath, store): + ''' + Get the paths located in the `filepath` and save them in the `store` set. + ''' + if(os.path.exists(filepath)): + with open(filepath) as fp: + for line in fp.readlines(): + store.add(line.replace('\n', ' ')) + +def convert_in_exclude_argument(paths): + ''' + Convert a set of paths in a `--exclude`s arguments of scan-build command. + ''' + final_string = '' + for path in paths: + final_string = final_string + " --exclude " + str(path) + return final_string + +def get_effective_key(args): + class Key: + def __init__(self, name): + self.name = name + self.counter = 0 + self.index = 0 + + keys = [Key("--packages-select"), Key("--packages-up-to")] + for i, potential_key in enumerate(keys): + keys[i].counter = args.count(potential_key.name) + if (keys[i].counter > 0): + keys[i].index = args.index(potential_key.name) + + if (keys[0].counter == 0 and keys[1].counter == 0): + return '' + elif (keys[0].counter == keys[1].counter): + # When there are two keys present, it just cares about the first one as colcon does. + return keys[0].name if keys[0].index < keys[1].index else keys[1].name + else: + return keys[0].name if keys[0].counter else keys[1].name + +def is_colcon_option(arg): + return True if (arg[0:2] == '--') else False + +def get_packages_from_args(args): + key = get_effective_key(args) + if not key: + return set() + index_of_key = args.index(key) + + packages = set() + indexer = 1 + while (len(args) > (index_of_key + indexer)) and (not is_colcon_option(args[index_of_key + indexer])): + packages.add(args[index_of_key + indexer]) + indexer += 1 + return packages + +def get_packages_to_get_excludes_file_of(packages): + packages_to_get_exclude_file_of = set() + if not packages: + packages_to_get_exclude_file_of = packages_to_get_exclude_file_of.union(get_package_dependencies_names()) + else: + for package_from_arg in packages: + packages_to_get_exclude_file_of = packages_to_get_exclude_file_of.union(get_package_dependencies_names(package_from_arg)) + return packages_to_get_exclude_file_of + + +def generate_exclude_args(argv): + packages_from_arg = get_packages_from_args(argv) + packages_to_get_exclude_file_of = get_packages_to_get_excludes_file_of(packages_from_arg) + + exclusion_paths = set() + for package in packages_to_get_exclude_file_of: + package_path = os.popen('colcon list --packages-select ' + package + ' --paths-only') + command = 'find ' + package_path.read().splitlines()[0] + ' -name scan_build.supp' + find = os.popen(command) + supp_filepaths = find.read().splitlines() + for filepath in supp_filepaths: + get_exclusion_paths_from_file(filepath, exclusion_paths) + return convert_in_exclude_argument(exclusion_paths) + +def main(argv): + excludes_args = generate_exclude_args(argv) + excludes_args += EXTRA_EXCLUDE_ARGS + + colcon_extra_build_args = " ".join(argv[1:]) if(len(argv) > 1) else "" + cmd = "scan-build-8 --status-bugs --use-cc=clang-8 --use-c++=clang++-8 {} colcon build {} ".format(excludes_args, colcon_extra_build_args) + print("scan-build command...\n--> " + cmd) + return_code = os.system(cmd) + if return_code > 255 : + sys.exit(1) + else: + sys.exit(0) + +if __name__ == "__main__": + main(sys.argv) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..d93de63 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,28 @@ +name: gcc + +on: + push: + pull_request: + branches: + - main + workflow_dispatch: + +env: + PACKAGE_NAME: maliput_sparse + ROS_DISTRO: foxy + +jobs: + compile_and_test: + name: Compile and test + runs-on: ubuntu-latest + container: + image: ubuntu:20.04 + steps: + - uses: actions/checkout@v3 + - uses: ros-tooling/setup-ros@v0.3 + - uses: ros-tooling/action-ros-ci@v0.2 + id: action_ros_ci_step + with: + package-name: ${{ env.PACKAGE_NAME }} + target-ros2-distro: ${{ env.ROS_DISTRO }} + vcs-repo-file-url: ${GITHUB_WORKSPACE}/.github/dependencies.repos diff --git a/.github/workflows/sanitizers.yml b/.github/workflows/sanitizers.yml new file mode 100644 index 0000000..bfdafac --- /dev/null +++ b/.github/workflows/sanitizers.yml @@ -0,0 +1,81 @@ +name: clang + +on: + pull_request: + types: [labeled] + workflow_dispatch: + +env: + PACKAGE_NAME: maliput_sparse + ROS_DISTRO: foxy + ROS_WS: maliput_ws + UBSAN_OPTIONS: halt_on_error=1 + +jobs: + compile_and_test: + if: contains(github.event.pull_request.labels.*.name, 'do-clang-test') + name: Compile and test with sanitizer + runs-on: ubuntu-latest + container: + image: ubuntu:20.04 + strategy: + matrix: + sanitizer: [none, asan, ubsan, tsan] + include: + - sanitizer: none + COMPILER_FLAG: '' + - sanitizer: asan + COMPILER_FLAG: ' -DADDRESS_SANITIZER=On' + - sanitizer: tsan + COMPILER_FLAG: ' -DTHREAD_SANITIZER=On' + - sanitizer: ubsan + COMPILER_FLAG: ' -DUNDEFINED_SANITIZER=On' + env: + CC: clang-8 + CXX: clang++-8 + LDFLAGS: -fuse-ld=lld-8 + steps: + - uses: actions/checkout@v3 + with: + path: ${{ env.ROS_WS }}/src/${{ env.PACKAGE_NAME }} + # use setup-ros action to get vcs, rosdep, and colcon + - uses: ros-tooling/setup-ros@v0.3 + env: + ACTIONS_ALLOW_UNSECURE_COMMANDS: true + - name: clang 8 install + shell: bash + run: ${{ env.ROS_WS }}/src/${{ env.PACKAGE_NAME }}/.github/clang_suite_installation.sh + - name: vcs import + shell: bash + working-directory: ${{ env.ROS_WS }} + run: vcs import src < src/${PACKAGE_NAME}/.github/dependencies.repos + - name: check if dependencies have a matching branch + shell: bash + working-directory: ${{ env.ROS_WS }}/src + run: ./${PACKAGE_NAME}/.github/try_vcs_checkout ${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} . + - run: colcon graph + shell: bash + working-directory: ${{ env.ROS_WS }} + - name: rosdep install + shell: bash + working-directory: ${{ env.ROS_WS }} + run: | + rosdep update --include-eol-distros; + rosdep install -i -y --rosdistro ${ROS_DISTRO} --skip-keys "pybind11" --from-paths src + - name: colcon build + shell: bash + working-directory: ${{ env.ROS_WS }} + env: + COMPILER_FLAG: ${{ matrix.COMPILER_FLAG }} + run: | + . /opt/ros/${ROS_DISTRO}/setup.bash; + colcon build --packages-up-to ${PACKAGE_NAME} \ + --event-handlers=console_direct+ \ + --cmake-args ${COMPILER_FLAG} + - name: colcon test + shell: bash + working-directory: ${{ env.ROS_WS }} + run: | + . /opt/ros/${ROS_DISTRO}/setup.bash; + colcon test --packages-select ${PACKAGE_NAME} --event-handlers=console_direct+; + colcon test-result --verbose; diff --git a/.github/workflows/scan_build.yml b/.github/workflows/scan_build.yml new file mode 100644 index 0000000..1db902f --- /dev/null +++ b/.github/workflows/scan_build.yml @@ -0,0 +1,67 @@ +name: scan_build + +on: + pull_request: + types: [labeled] + workflow_dispatch: + +env: + PACKAGE_NAME: maliput_sparse + ROS_DISTRO: foxy + ROS_WS: maliput_ws + +jobs: + static_analysis: + if: contains(github.event.pull_request.labels.*.name, 'do-static-analyzer-test') + name: Static analysis + runs-on: ubuntu-latest + container: + image: ubuntu:20.04 + env: + CC: clang-8 + CXX: clang++-8 + LDFLAGS: -fuse-ld=lld-8 + steps: + - uses: actions/checkout@v3 + with: + path: ${{ env.ROS_WS }}/src/${{ env.PACKAGE_NAME }} + # use setup-ros action to get vcs, rosdep, and colcon + - uses: ros-tooling/setup-ros@v0.3 + env: + ACTIONS_ALLOW_UNSECURE_COMMANDS: true + - name: clang 8 install + shell: bash + run: ${{ env.ROS_WS }}/src/${{ env.PACKAGE_NAME }}/.github/clang_suite_installation.sh + - name: vcs import + shell: bash + working-directory: ${{ env.ROS_WS }} + run: vcs import src < src/${PACKAGE_NAME}/.github/dependencies.repos + - name: check if dependencies have a matching branch + shell: bash + working-directory: ${{ env.ROS_WS }}/src + run: ./${PACKAGE_NAME}/.github/try_vcs_checkout ${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} . + - run: colcon graph + shell: bash + working-directory: ${{ env.ROS_WS }} + - name: rosdep install + shell: bash + working-directory: ${{ env.ROS_WS }} + run: | + rosdep update + rosdep install -i -y --rosdistro ${ROS_DISTRO} --skip-keys "pybind11" --from-paths src + - name: colcon build up-to + shell: bash + working-directory: ${{ env.ROS_WS }} + run: | + . /opt/ros/${ROS_DISTRO}/setup.bash; + colcon build --packages-up-to ${PACKAGE_NAME} \ + --packages-skip ${PACKAGE_NAME} \ + --event-handlers=console_direct+ + - name: scan_build + shell: bash + working-directory: ${{ env.ROS_WS }} + run: | + . /opt/ros/${ROS_DISTRO}/setup.bash; + ./src/${PACKAGE_NAME}/.github/run_scan_build \ + --packages-select ${PACKAGE_NAME} \ + --event-handlers=console_direct+; diff --git a/.github/workflows/triage.yml b/.github/workflows/triage.yml new file mode 100644 index 0000000..48f1d83 --- /dev/null +++ b/.github/workflows/triage.yml @@ -0,0 +1,18 @@ +name: Triage + +on: + issues: + types: + - opened + pull_request: + types: + - opened + +jobs: + add-ticket-to-project: + name: Core Development project + uses: maliput/.github/.github/workflows/triage.yml@main + with: + number_of_project: "1" + secrets: + github-token: ${{ secrets.ADD_TO_PROJECT_PAT }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3b6e4cd --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +# Python caches +__pycache__ +*.pyc diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..dec815a --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,76 @@ +############################################################################## +# Project +############################################################################## + +cmake_minimum_required(VERSION 3.5 FATAL_ERROR) +project(maliput_sparse LANGUAGES C CXX VERSION 3.0.0) + +############################################################################## +# Find 3rd Party Packages +############################################################################## + +message(STATUS "\n\n====== Finding 3rd Party Packages ======\n") + +find_package(ament_cmake REQUIRED) +find_package(maliput REQUIRED) + +############################################################################## +# Project Configuration +############################################################################## + +message(STATUS "\n\n========= Project Configuration ========\n") + +set(BUILD_SHARED_LIBS true) + +include(${PROJECT_SOURCE_DIR}/cmake/DefaultCFlags.cmake) +include(${PROJECT_SOURCE_DIR}/cmake/SanitizersConfig.cmake) + +ament_environment_hooks( + "${ament_cmake_package_templates_ENVIRONMENT_HOOK_LIBRARY_PATH}" +) + +############################################################################## +# Docs +############################################################################## + +if(BUILD_DOCS) + message(STATUS "Doxygen generation - Enabled") + find_package(ament_cmake_doxygen REQUIRED) + ament_doxygen_generate(doxygen_maliput + CONFIG_OVERLAY doc/Doxyfile.overlay.in + TEST_ON_WARNS + ) + add_definitions(-DBUILD_DOCS) +else() + message(STATUS "Doxygen generation - Disabled") +endif() + +############################################################################## +# Sources +############################################################################## +add_subdirectory(src) + +############################################################################## +# Tests +############################################################################## + +if(BUILD_TESTING) + find_package(ament_cmake_clang_format REQUIRED) + enable_testing() + add_subdirectory(test) + ament_clang_format(CONFIG_FILE ${CMAKE_CURRENT_SOURCE_DIR}/.clang-format) +endif() + +############################################################################## +# Export +############################################################################## + +install( + DIRECTORY include/ + DESTINATION include +) + +ament_export_include_directories(include) +ament_export_dependencies(ament_cmake) +ament_export_targets(${PROJECT_NAME}-targets HAS_LIBRARY_TARGET) +ament_package() diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d6ab385 --- /dev/null +++ b/LICENSE @@ -0,0 +1,29 @@ +BSD 3-Clause License + +Copyright (c) 2022, Woven Planet. All rights reserved. +Copyright (c) 2019-2022, Toyota Research Institute. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/cmake/DefaultCFlags.cmake b/cmake/DefaultCFlags.cmake new file mode 100644 index 0000000..afe3e1a --- /dev/null +++ b/cmake/DefaultCFlags.cmake @@ -0,0 +1,19 @@ +# C++ Version +set (CMAKE_CXX_STANDARD 17) +set (CMAKE_CXX_STANDARD_REQUIRED ON) +set (CMAKE_CXX_EXTENSIONS OFF) + +# Compiler-specific C++17 activation. +if ("${CMAKE_CXX_COMPILER_ID} " MATCHES "GNU ") + execute_process( + COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION) + if (NOT (GCC_VERSION VERSION_GREATER 6.9)) + message(FATAL_ERROR "${PROJECT_NAME} requires g++ 7.0 or greater.") + else () + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdata-sections -fdiagnostics-color=always -ffunction-sections -fopenmp -fPIC -fstack-protector -fno-omit-frame-pointer -no-canonical-prefixes -O2 -std=c++17 -Wall -Wno-builtin-macro-redefined -Wno-missing-field-initializers -Wregister -Wstrict-overflow -Wno-unused-const-variable") + endif () +elseif ("${CMAKE_CXX_COMPILER_ID} " MATCHES "Clang ") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdata-sections -fdiagnostics-color=always -ffunction-sections -fPIC -fstack-protector -fno-omit-frame-pointer -no-canonical-prefixes -O2 -std=c++17 -Wall -Wno-builtin-macro-redefined -Wno-deprecated-dynamic-exception-spec -Wno-enum-compare-switch -Wno-gnu-designator -Wno-missing-field-initializers -Wno-register -Wno-strict-overflow -Wno-unknown-warning-option -Wno-unneeded-internal-declaration -Wno-unused-const-variable -Wno-missing-braces") +else () + message(FATAL_ERROR "Your C++ compiler does not support C++17.") +endif () diff --git a/cmake/SanitizersConfig.cmake b/cmake/SanitizersConfig.cmake new file mode 100644 index 0000000..a5fcef8 --- /dev/null +++ b/cmake/SanitizersConfig.cmake @@ -0,0 +1,65 @@ +############################################################################## +# Useful Macros +############################################################################## + +# It will throw an error if more than one sanitizer is enabled. +macro(check_sanitizers_exclusivity) + set(SANITIZER_COUNT 0) + set(SANITIZER_LIST) + foreach(sanitizer IN ITEMS ${ARGN}) + if(${${sanitizer}}) + math(EXPR SANITIZER_COUNT "1 + ${SANITIZER_COUNT}") + list(APPEND SANITIZER_LIST ${sanitizer}) + endif() + endforeach() + + if(${SANITIZER_COUNT} GREATER 1) + message(FATAL_ERROR "Can only enable one of ${SANITIZER_LIST} at a time.") + endif() +endmacro() + +############################################################################## +# Sanitizers Configuration +############################################################################## + +set(SANITIZERS off) +if ("${CMAKE_CXX_COMPILER_ID} " MATCHES "Clang ") + option(ADDRESS_SANITIZER "Enable Clang Address Sanitizer" OFF) + option(THREAD_SANITIZER "Enable Clang Thread Sanitizer" OFF) + option(UNDEFINED_SANITIZER "Enable Clang Undefined Behaviour Sanitizer" OFF) + + check_sanitizers_exclusivity(ADDRESS_SANITIZER THREAD_SANITIZER UNDEFINED_SANITIZER) + + # Address Sanitizer Configuration + if (ADDRESS_SANITIZER) + message(STATUS "Address Sanitizer - enabled") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fsanitize=address -fno-optimize-sibling-calls -fsanitize-address-use-after-scope") + set(LDFLAGS "${LDFLAGS} -fsanitize=address -fno-optimize-sibling-calls -fsanitize-address-use-after-scope") + set(SANITIZERS on) + else() + message(STATUS "Address Sanitizer - disabled") + endif() + + # Thread Sanitizer Configuration + if (THREAD_SANITIZER) + message(STATUS "Thread Sanitizer - enabled") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fsanitize=thread") + set(LDFLAGS "${LDFLAGS} -fsanitize=thread") + set(SANITIZERS on) + else() + message(STATUS "Thread Sanitizer - disabled") + endif() + + # Undefined Behaviour Sanitizer Configuration + if (UNDEFINED_SANITIZER) + message(STATUS "Undefined Behaviour Sanitizer - enabled") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined") + set(LDFLAGS "${LDFLAGS} -fsanitize=undefined") + set(SANITIZERS on) + else() + message(STATUS "Undefined Behaviour Sanitizer - disabled") + endif() + +else () + message(STATUS "Compiler Id:${CMAKE_CXX_COMPILER_ID} - Sanitizers disabled.") +endif () diff --git a/doc/Doxyfile.overlay.in b/doc/Doxyfile.overlay.in new file mode 100644 index 0000000..6a0c738 --- /dev/null +++ b/doc/Doxyfile.overlay.in @@ -0,0 +1 @@ +EXCLUDE_PATTERNS = @INPUT_DIRECTORY@/test/** diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt new file mode 100644 index 0000000..e69de29 diff --git a/package.xml b/package.xml new file mode 100644 index 0000000..6b328f9 --- /dev/null +++ b/package.xml @@ -0,0 +1,22 @@ + + + + maliput_sparse + 0.0.1 + Maliput sparse is a maliput backend built on top of waypoints without any analytical model of the surface + Daniel Stonier + BSD Clause 3 + + ament_cmake + ament_cmake_doxygen + + maliput + + ament_cmake_clang_format + ament_cmake_gmock + ament_cmake_gtest + + + ament_cmake + + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..933ff88 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(geometry) diff --git a/src/geometry/CMakeLists.txt b/src/geometry/CMakeLists.txt new file mode 100644 index 0000000..8742b54 --- /dev/null +++ b/src/geometry/CMakeLists.txt @@ -0,0 +1,41 @@ +############################################################################## +# Sources +############################################################################## + +set(GEOMETRY_SOURCES + dummy.cc +) + +add_library(geometry ${GEOMETRY_SOURCES}) + +add_library(maliput_sparse::geometry ALIAS geometry) + +set_target_properties(geometry + PROPERTIES + OUTPUT_NAME maliput_sparse_geometry +) + +target_include_directories(geometry + PUBLIC + $ + $) + +target_link_libraries(geometry + PUBLIC + maliput::common + maliput::math +) + +############################################################################## +# Export +############################################################################## + +include(CMakePackageConfigHelpers) + +install( + TARGETS geometry + EXPORT ${PROJECT_NAME}-targets + ARCHIVE DESTINATION lib + LIBRARY DESTINATION lib + RUNTIME DESTINATION bin +) diff --git a/src/geometry/dummy.cc b/src/geometry/dummy.cc new file mode 100644 index 0000000..e69de29 diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..e69de29 diff --git a/tools/reformat_code.sh b/tools/reformat_code.sh new file mode 100644 index 0000000..e69de29