From a98cbc8518c59b4e8ff07bf938dbe6b7e9b3770e Mon Sep 17 00:00:00 2001 From: "azure-pipelines[bot]" Date: Tue, 18 Dec 2018 16:11:31 +0000 Subject: [PATCH 1/7] Set up CI with Azure Pipelines --- README.md | 2 ++ azure-pipelines.yml | 46 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 azure-pipelines.yml diff --git a/README.md b/README.md index 00c2ca9..232ba6a 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,8 @@ If you don't have a proper clang version installed, it can also be downloaded. For that you need to set `LLVM_DOWNLOAD_OS_NAME`. This is the name of the operating system used on the [LLVM pre-built binary archive](http://releases.llvm.org/download.html#4.0.0), e.g. `x86_64-linux-gnu-ubuntu-16.10` for Ubuntu 16.10. +You can also set `LLVM_DOWNLOAD_URL` to a custom url, to download a specific version or from a mirror. + If you don't have `llvm-config`, you need to pass the locations explictly. For that set the option `LLVM_VERSION_EXPLICIT` to the version you're using, `LIBCLANG_LIBRARY` to the location of the libclang library file, diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 0000000..0fc385d --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,46 @@ +name: 'CI build' +trigger: + branches: + include: + - master + - feature/* + paths: + exclude: + - README.md + +jobs: + - job: llvm_linux + pool: + vmImage: 'Ubuntu 16.04' + strategy: + matrix: + LLVM4: + IMAGE: 'foonathan/micro_cpp_llvm:llvm4' + LLVM5: + IMAGE: 'foonathan/micro_cpp_llvm:llvm5' + LLVM6: + IMAGE: 'foonathan/micro_cpp_llvm:llvm6' + LLVM7: + IMAGE: 'foonathan/micro_cpp_llvm:llvm7' + steps: + - script: docker run -u root -v "$PWD:/cppast" $(IMAGE) bash -c "cmake /cppast/ && cmake --build . && ctest --output-on-failure" + displayName: "Compiling using $(IMAGE)" + + - job: llvm_macos + pool: + vmImage: 'macOS-10.13' + strategy: + matrix: + LLVM4: + URL: 'http://releases.llvm.org/4.0.0/clang+llvm-4.0.0-x86_64-apple-darwin.tar.xz' + LLVM5: + URL: 'http://releases.llvm.org/5.0.2/clang+llvm-5.0.2-x86_64-apple-darwin.tar.xz' + LLVM6: + URL: 'http://releases.llvm.org/6.0.0/clang+llvm-6.0.0-x86_64-apple-darwin.tar.xz' + LLVM7: + URL: 'http://releases.llvm.org/7.0.0/clang+llvm-7.0.0-x86_64-apple-darwin.tar.xz' + steps: + - script: | + mkdir build && cd build/ + cmake -DLLVM_DOWNLOAD_URL=$URL ../ && cmake --build . && ctest --output-on-failure + displayName: "Compiling using $(URL)" \ No newline at end of file From d44571f1c8c5466b8f513d29e4a323defe377f80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20M=C3=BCller?= Date: Tue, 18 Dec 2018 17:49:26 +0100 Subject: [PATCH 2/7] Improve CMake --- CMakeLists.txt | 10 +--------- example/CMakeLists.txt | 1 - include/cppast/detail/assert.hpp | 14 +++++++------- src/CMakeLists.txt | 17 +++++++++-------- test/CMakeLists.txt | 4 ++-- 5 files changed, 19 insertions(+), 27 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 69ea6a8..f2cfa35 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,18 +2,10 @@ # This file is subject to the license terms in the LICENSE file # found in the top-level directory of this distribution. -cmake_minimum_required(VERSION 3.3) +cmake_minimum_required(VERSION 3.8) project(cppast VERSION 0.0) # options -if(CMAKE_BUILD_TYPE MATCHES Debug) - set(default_assertions ON) -else() - set(default_assertions OFF) -endif() -option(CPPAST_ENABLE_ASSERTIONS "whether or not to enable internal assertions for the cppast library" ${default_assertions}) -option(CPPAST_ENABLE_PRECONDITION_CHECKS "whether or not to enable precondition checks" ON) - option(CPPAST_BUILD_TEST "whether or not to build the tests" OFF) option(CPPAST_BUILD_EXAMPLE "whether or not to build the examples" OFF) option(CPPAST_BUILD_TOOL "whether or not to build the tool" OFF) diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 549873a..ff1d2b8 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -5,7 +5,6 @@ function(_cppast_example name) add_executable(cppast_example_${name} ${name}.cpp example_parser.hpp) target_link_libraries(cppast_example_${name} PUBLIC cppast) - set_target_properties(cppast_example_${name} PROPERTIES CXX_STANDARD 11) endfunction() _cppast_example(ast_printer) diff --git a/include/cppast/detail/assert.hpp b/include/cppast/detail/assert.hpp index fee744c..89f5ebb 100644 --- a/include/cppast/detail/assert.hpp +++ b/include/cppast/detail/assert.hpp @@ -7,16 +7,16 @@ #include -#ifdef CPPAST_ENABLE_ASSERTIONS -# define CPPAST_ASSERTION_LEVEL 1 -#else +#ifndef CPPAST_ASSERTION_LEVEL # define CPPAST_ASSERTION_LEVEL 0 #endif -#ifdef CPPAST_ENABLE_PRECONDITION_CHECKS -# define CPPAST_PRECONDITION_LEVEL 1 -#else -# define CPPAST_PRECONDITION_LEVEL 0 +#ifndef CPPAST_PRECONDITION_LEVEL +# ifdef NDEBUG +# define CPPAST_PRECONDITION_LEVEL 0 +# else +# define CPPAST_PRECONDITION_LEVEL 1 +# endif #endif namespace cppast diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fe00494..0a7c85e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -102,16 +102,17 @@ set(libclang_source libclang/variable_parser.cpp) add_library(cppast ${detail_header} ${header} ${source} ${libclang_source}) -set_target_properties(cppast PROPERTIES CXX_STANDARD 11) -target_include_directories(cppast PUBLIC ../include) +target_compile_features(cppast PUBLIC cxx_std_11) +target_include_directories(cppast PRIVATE ../include SYSTEM INTERFACE ../include) target_link_libraries(cppast PUBLIC type_safe _cppast_tiny_process _cppast_libclang) target_compile_definitions(cppast PUBLIC CPPAST_VERSION_MINOR="${cppast_VERSION_MINOR}" CPPAST_VERSION_MAJOR="${cppast_VERSION_MAJOR}" CPPAST_VERSION_STRING="${cppast_VERSION}") -if(CPPAST_ENABLE_ASSERTIONS) - target_compile_definitions(cppast PUBLIC CPPAST_ENABLE_ASSERTIONS) -endif() -if(CPPAST_ENABLE_PRECONDITION_CHECKS) - target_compile_definitions(cppast PUBLIC CPPAST_ENABLE_PRECONDITION_CHECKS) -endif() +target_compile_options(cppast PRIVATE + # clang/GCC warnings + $<$,$>: + -pedantic-errors -Werror -Wall -Wextra -Wconversion -Wsign-conversion> + # MSVC warnings + $<$: + /WX /W4>) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 03d9b6b..f9cad06 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -47,9 +47,9 @@ target_include_directories(cppast_test PRIVATE ${CMAKE_CURRENT_LIST_DIR}/../src) target_link_libraries(cppast_test PUBLIC cppast) target_compile_definitions(cppast_test PUBLIC CPPAST_INTEGRATION_FILE="${CMAKE_CURRENT_SOURCE_DIR}/integration.cpp" CPPAST_COMPILE_COMMANDS="${CMAKE_BINARY_DIR}") -set_target_properties(cppast_test PROPERTIES CXX_STANDARD 11) -add_test(NAME test COMMAND cppast_test) +add_test(NAME unit_test COMMAND cppast_test "~[integration]") +add_test(NAME integration_test COMMAND cppast_test "[integration]") if(CPPAST_TEST_GCOV AND (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")) setup_target_for_coverage( From 7d4794460ecab9a0daef59fa0f4f068ab49f3600 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20M=C3=BCller?= Date: Tue, 18 Dec 2018 17:58:42 +0100 Subject: [PATCH 3/7] Fix Windows warnings --- src/libclang/cxtokenizer.cpp | 8 ++++---- src/libclang/libclang_parser.cpp | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/libclang/cxtokenizer.cpp b/src/libclang/cxtokenizer.cpp index 4fd7db7..4a9cc3a 100644 --- a/src/libclang/cxtokenizer.cpp +++ b/src/libclang/cxtokenizer.cpp @@ -408,10 +408,10 @@ detail::cxtokenizer::cxtokenizer(const CXTranslationUnit& tu, const CXFile& file if (!clang_Range_isNull(extent.second_part)) { - simple_tokenizer tokenizer(tu, extent.second_part); - tokens_.reserve(tokens_.size() + tokenizer.size()); - for (auto i = 0u; i != tokenizer.size(); ++i) - tokens_.emplace_back(tu, tokenizer[i]); + simple_tokenizer second_tokenizer(tu, extent.second_part); + tokens_.reserve(tokens_.size() + second_tokenizer.size()); + for (auto i = 0u; i != second_tokenizer.size(); ++i) + tokens_.emplace_back(tu, second_tokenizer[i]); } } diff --git a/src/libclang/libclang_parser.cpp b/src/libclang/libclang_parser.cpp index 024a259..9eb4c78 100644 --- a/src/libclang/libclang_parser.cpp +++ b/src/libclang/libclang_parser.cpp @@ -520,7 +520,7 @@ detail::cxtranslation_unit get_cxunit(const diagnostic_logger& logger, const det CXUnsavedFile file; file.Filename = path; file.Contents = source.c_str(); - file.Length = source.length(); + file.Length = static_cast(source.length()); auto args = get_arguments(config); @@ -648,10 +648,10 @@ std::unique_ptr libclang_parser::do_parse(const cpp_entity_index& idx, for (; macro_iter != preprocessed.macros.end(); ++macro_iter) builder.add_child(std::move(macro_iter->macro)); - for (auto& c : preprocessed.comments) + for (auto& cur : preprocessed.comments) { - if (!c.comment.empty()) - builder.add_unmatched_comment(cpp_doc_comment(std::move(c.comment), c.line)); + if (!cur.comment.empty()) + builder.add_unmatched_comment(cpp_doc_comment(std::move(cur.comment), cur.line)); } if (context.error) From 6246ff27112de94b1da99a973fc4c2e7a50f7c7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20M=C3=BCller?= Date: Tue, 18 Dec 2018 17:59:03 +0100 Subject: [PATCH 4/7] Don't show download progress --- external/external.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/external.cmake b/external/external.cmake index 83e2c93..d299be0 100644 --- a/external/external.cmake +++ b/external/external.cmake @@ -72,7 +72,7 @@ function(_cppast_download_llvm url) if(NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/${folder}) message(STATUS "Downloading LLVM from ${url}") - file(DOWNLOAD ${url} ${CMAKE_CURRENT_BINARY_DIR}/${file} SHOW_PROGRESS + file(DOWNLOAD ${url} ${CMAKE_CURRENT_BINARY_DIR}/${file} STATUS status LOG log) From 70630ff6b385cdf710732924ba21efc42faf6351 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20M=C3=BCller?= Date: Tue, 18 Dec 2018 18:04:58 +0100 Subject: [PATCH 5/7] Workaround MacOS integration tests --- azure-pipelines.yml | 3 ++- src/cpp_entity_index.cpp | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 0fc385d..0f88703 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -33,6 +33,7 @@ jobs: matrix: LLVM4: URL: 'http://releases.llvm.org/4.0.0/clang+llvm-4.0.0-x86_64-apple-darwin.tar.xz' + EXCLUDE: 'integration' LLVM5: URL: 'http://releases.llvm.org/5.0.2/clang+llvm-5.0.2-x86_64-apple-darwin.tar.xz' LLVM6: @@ -42,5 +43,5 @@ jobs: steps: - script: | mkdir build && cd build/ - cmake -DLLVM_DOWNLOAD_URL=$URL ../ && cmake --build . && ctest --output-on-failure + cmake -DLLVM_DOWNLOAD_URL=$URL ../ && cmake --build . && ctest --output-on-failure -E $EXCLUDE displayName: "Compiling using $(URL)" \ No newline at end of file diff --git a/src/cpp_entity_index.cpp b/src/cpp_entity_index.cpp index 6ff8f83..6e6645c 100644 --- a/src/cpp_entity_index.cpp +++ b/src/cpp_entity_index.cpp @@ -26,7 +26,8 @@ void cpp_entity_index::register_definition(cpp_entity_id { // already in map, override declaration auto& value = result.first->second; - if (value.is_definition) + if (value.is_definition && !is_template_specialization(value.entity->kind())) + // allow duplicate definition of template specializations as a workaround for MacOS throw duplicate_definition_error(); value.is_definition = true; value.entity = entity; From facd7310ec25ee8c5850b028e56b27ad681c0512 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20M=C3=BCller?= Date: Tue, 18 Dec 2018 18:14:05 +0100 Subject: [PATCH 6/7] Move GCC compiler to azure --- .travis.yml | 70 ----------------------------------------- azure-pipelines.yml | 21 +++++++++++-- external/external.cmake | 2 +- src/CMakeLists.txt | 2 ++ 4 files changed, 22 insertions(+), 73 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 18917d4..0000000 --- a/.travis.yml +++ /dev/null @@ -1,70 +0,0 @@ -language: cpp - -matrix: - include: - - os: linux - dist: trusty - sudo: false - compiler: gcc - addons: - apt: - sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-4.0'] - packages: ['g++-5', 'lcov', 'llvm-4.0', 'clang-4.0', 'libclang-4.0-dev'] - env: TOOLSET=g++-5 CPPAST_TEST_GCOV=ON LLVM_CONFIG_BINARY=/usr/bin/llvm-config-4.0 - - - os: linux - dist: trusty - sudo: false - compiler: gcc - addons: - apt: - sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-5.0'] - packages: ['g++-5', 'lcov', 'llvm-5.0', 'clang-5.0', 'libclang-5.0-dev'] - env: TOOLSET=g++-5 LLVM_CONFIG_BINARY=/usr/bin/llvm-config-5.0 - - - os: linux - dist: trusty - sudo: false - compiler: clang - addons: - apt: - sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-4.0'] - packages: ['g++-4.9', 'g++-5', 'llvm-4.0', 'clang-4.0', 'libclang-4.0-dev'] - env: TOOLSET=clang++-4.0 LLVM_CONFIG_BINARY=/usr/bin/llvm-config-4.0 - - - os: osx - osx_image: xcode9.2 - compiler: clang - env: TOOLSET=clang++ - -install: - - cd ../ - - - if [[ "$CPPAST_TEST_GCOV" == "ON" ]]; then pip install --user cpp-coveralls; fi - - - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then wget --no-check-certificate https://www.cmake.org/files/v3.3/cmake-3.3.1-Linux-x86_64.tar.gz; fi - - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then tar -xzf cmake-3.3.1-Linux-x86_64.tar.gz; fi - - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then export CMAKE=$TRAVIS_BUILD_DIR/../cmake-3.3.1-Linux-x86_64/bin/cmake; fi - - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then wget --no-check-certificate https://cmake.org/files/v3.3/cmake-3.3.0-Darwin-x86_64.tar.gz; fi - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then tar -xzf cmake-3.3.0-Darwin-x86_64.tar.gz && ls && ls cmake-3.3.0-Darwin-x86_64; fi - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export CMAKE=$TRAVIS_BUILD_DIR/../cmake-3.3.0-Darwin-x86_64/CMake.app/Contents/bin/cmake; fi - - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then wget --no-check-certificate http://releases.llvm.org/5.0.0/clang+llvm-5.0.0-x86_64-apple-darwin.tar.xz; fi - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then tar -xzf clang+llvm-5.0.0-x86_64-apple-darwin.tar.xz; fi - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export LLVM_CONFIG_BINARY="$TRAVIS_BUILD_DIR/../clang+llvm-5.0.0-x86_64-apple-darwin/bin/llvm-config"; fi - - - export CXX=$TOOLSET - - $CXX --version - - $CMAKE --version - - - cd cppast/ - -script: - - mkdir build/ && cd build/ - - $CMAKE -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS="-Werror -pedantic -Wall -Wextra -Wconversion -Wsign-conversion -Wno-parentheses -Wno-assume" ../ -DCPPAST_TEST_GCOV=$CPPAST_TEST_GCOV -DLLVM_CONFIG_BINARY=$LLVM_CONFIG_BINARY - - $CMAKE --build . - - ./test/cppast_test \* - -after_script: - - if [[ "$CPPAST_TEST_GCOV" == "ON" ]]; then $CMAKE --build . --target cppast_coverage && cd ../ && coveralls --no-gcov --lcov-file build/cppast_coverage.info.cleaned; fi diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 0f88703..04972f5 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -9,6 +9,23 @@ trigger: - README.md jobs: + - job: compiler_linux + pool: + vmImage: 'Ubuntu 16.04' + strategy: + matrix: + GCC5: + IMAGE: 'conanio/gcc5' + GCC6: + IMAGE: 'conanio/gcc6' + GCC7: + IMAGE: 'conanio/gcc7' + GCC8: + IMAGE: 'conanio/gcc8' + steps: + - script: docker run --privileged -u root -v "$PWD:/cppast" $(IMAGE) bash -c "apt-get -qq update && apt-get -qq install -y --no-install-recommends llvm-4.0-dev clang-4.0 libclang-4.0-dev && cmake /cppast/ && cmake --build . && ctest --output-on-failure" + displayName: "Compiling using $(IMAGE)" + - job: llvm_linux pool: vmImage: 'Ubuntu 16.04' @@ -23,7 +40,7 @@ jobs: LLVM7: IMAGE: 'foonathan/micro_cpp_llvm:llvm7' steps: - - script: docker run -u root -v "$PWD:/cppast" $(IMAGE) bash -c "cmake /cppast/ && cmake --build . && ctest --output-on-failure" + - script: docker run -u root -v "$PWD:/cppast" $(IMAGE) bash -c "cmake -DCMAKE_CXX_COMPILER=clang++ /cppast/ && cmake --build . && ctest --output-on-failure" displayName: "Compiling using $(IMAGE)" - job: llvm_macos @@ -44,4 +61,4 @@ jobs: - script: | mkdir build && cd build/ cmake -DLLVM_DOWNLOAD_URL=$URL ../ && cmake --build . && ctest --output-on-failure -E $EXCLUDE - displayName: "Compiling using $(URL)" \ No newline at end of file + displayName: "Compiling using $(URL)" diff --git a/external/external.cmake b/external/external.cmake index d299be0..e31a385 100644 --- a/external/external.cmake +++ b/external/external.cmake @@ -103,7 +103,7 @@ function(_cppast_find_llvm_config) if (LLVM_DOWNLOAD_DIR) find_program(LLVM_CONFIG_BINARY "llvm-config" "${LLVM_DOWNLOAD_DIR}/bin" NO_DEFAULT_PATH) else() - find_program(LLVM_CONFIG_BINARY "llvm-config") + find_program(LLVM_CONFIG_BINARY NAMES llvm-config llvm-config-4.0 llvm-config-5.0 llvm-config-6.0 llvm-config-7) endif() if(NOT LLVM_CONFIG_BINARY) message(FATAL_ERROR "Unable to find llvm-config binary, please set option LLVM_CONFIG_BINARY yourself") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0a7c85e..a377ea4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -113,6 +113,8 @@ target_compile_options(cppast PRIVATE # clang/GCC warnings $<$,$>: -pedantic-errors -Werror -Wall -Wextra -Wconversion -Wsign-conversion> + # disable noexcept type warning on GCC + $<$: -Wno-noexcept-type> # MSVC warnings $<$: /WX /W4>) From d84ad81b8522e47a9bf619f1ab047572f04321c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20M=C3=BCller?= Date: Tue, 18 Dec 2018 18:14:46 +0100 Subject: [PATCH 7/7] Update Readme --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 232ba6a..8b7920c 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,7 @@ # cppast -[![Build Status](https://travis-ci.org/foonathan/cppast.svg?branch=master)](https://travis-ci.org/foonathan/cppast) +[![Build Status](https://dev.azure.com/foonathan/cppast/_apis/build/status/foonathan.cppast?branchName=master)](https://dev.azure.com/foonathan/cppast/_build/latest?definitionId=5?branchName=master) [![Build status](https://ci.appveyor.com/api/projects/status/8gp5btjq7eassvn7?svg=true)](https://ci.appveyor.com/project/foonathan/cppast) -[![Coverage Status](https://coveralls.io/repos/github/foonathan/cppast/badge.svg)](https://coveralls.io/github/foonathan/cppast) Library interface to the C++ AST — parse source files, synthesize entities, get documentation comments and generate code.