diff --git a/CI/.gitlab-ci-for-lidarview.yml b/CI/.gitlab-ci-for-lidarview.yml index 352fd582ce8f06ee5f19991e66d7e2eabb5c1315..a304f63f7555cd12c76aeef131d0c52553d36c61 100644 --- a/CI/.gitlab-ci-for-lidarview.yml +++ b/CI/.gitlab-ci-for-lidarview.yml @@ -15,15 +15,28 @@ variables: # see https://gitlab.com/gitlab-org/gitlab-runner/issues/1280 superbuild_build_dir: $CI_BUILDS_DIR/SB/$CI_PROJECT_NAME lidarview_build_dir: $CI_BUILDS_DIR/SB/$CI_PROJECT_NAME/$rel_path_to_lidarview_build_dir + # This variable should set only if the script is trigger from a LidarView submodule + # This will enable to run the pipeline with the updated module + TRIGGER_MODULE_PATH: '' # path of the module that trigger the pipeline relative to LidarView + TRIGGER_MODULE_SHA: '' # commit sha of the module that trigger the pipeline stages: - superbuild + - configure + - analyze - build - test - package # default parameters for all jobs, see https://docs.gitlab.com/ee/ci/yaml/#setting-default-parameters default: + before_script: &default_before_script_anchor + # TRIGGER_MODULE_PATH and TRIGGER_MODULE_SHA, should be empty if the CI is triggered from LidarView + # so the next fetching and checkout will basically do nothing. + # "$git checkout " is a glorified no-op (no operation), see https://git-scm.com/docs/git-checkout#Documentation/git-checkout.txt-emgitcheckoutemltbranchgt + - cd $CI_PROJECT_DIR/$TRIGGER_MODULE_PATH + - git fetch + - git checkout $TRIGGER_MODULE_SHA retry: max: 2 when: runner_system_failure @@ -31,11 +44,11 @@ default: # create a pipeline only in some cases : merge_request, tag, master branch # see https://docs.gitlab.com/ee/ci/yaml/#workflowrules -workflow: - rules: - - if: $CI_MERGE_REQUEST_ID - - if: $CI_COMMIT_TAG - - if: $CI_COMMIT_BRANCH == "master" +# workflow: +# rules: +# - if: $CI_MERGE_REQUEST_ID +# - if: $CI_COMMIT_TAG +# - if: $CI_COMMIT_BRANCH == "master" # job starting with a . are not run, see https://docs.gitlab.com/ee/ci/yaml/#hidden-keys-jobs @@ -86,21 +99,19 @@ workflow: $CI_PROJECT_DIR/Superbuild - cmake --build . --parallel 8 +.configure: + stage: configure + extends: .default_rules + script: + - cd $lidarview_build_dir + # create a compilation database for the analize stage (clang-tidy) + - cmake -DBUILD_TESTING=True -DCMAKE_EXPORT_COMPILE_COMMANDS=True . + .build: stage: build - needs: [] extends: .default_rules script: - - cd $CI_PROJECT_DIR/LVCore - - git fetch - # Checking if $LVCore_COMMIT_SHA is defined should be performed here before using it. - # But there isn't a "IF" statement that is compatible on bash and powershell... - # However this variable is only defined if this job is triggered from LidarView-Core - # in the other case the command will result in a "git checkout" which is a glorified no-op (no operation) - # according to git documentation, see https://git-scm.com/docs/git-checkout#Documentation/git-checkout.txt-emgitcheckoutemltbranchgt - - git checkout $LVCore_COMMIT_SHA - cd $lidarview_build_dir - - cmake -DBUILD_TESTING=True . - cmake --build . --target install --parallel 8 .test: @@ -159,7 +170,8 @@ workflow: resource_group: osx_machine .windows_runner_config: - before_script: &windows_before_script + before_script: + - *default_before_script_anchor # to use the Microsoft C++ Toolset from the command line, some environment variable need to be set # To help with this, Microsoft provide the vcvarsall.bat script that set different environment see # https://docs.microsoft.com/en-us/cpp/build/building-on-the-command-line?view=vs-2019 @@ -216,6 +228,79 @@ windows_superbuild: - .windows_runner_config - .superbuild +############## +# Analize # +############## +linux_configure: + extends: + - .linux_runner_config + - .configure + +osx_configure: + extends: + - .osx_runner_config + - .configure + +windows_configure: + extends: + - .windows_runner_config + - .configure + +############## +# Analize # +############## +cpp-check: + stage: analyze + tags: [cpp-check] + needs: [linux_configure] + script: + - cppcheck . --enable=warning,performance,portability --quiet --std=c++11 --std=c++14 --error-exitcode=1 + rules: + - if: $DISABLE_LINUX + when: never + - when: always + +clang-tidy: + stage: analyze + tags: [clang-tidy] + needs: [linux_configure] + script: + - > + get_modified_files_in_current_git_repository() { + local current_SHA=$(git rev-parse HEAD) + local ancestor_SHA=$(git merge-base $current_SHA origin/master) + local modified_files=$(git diff --name-only $ancestor_SHA $current_SHA *.{h,cxx}) + echo $modified_files + } + # Run clang-tidy only on the modify file, because it's very time consuming + - cd $CI_PROJECT_DIR/$TRIGGER_MODULE_PATH + - file_to_analize=$(get_modified_files_in_current_git_repository) + - | + if [[ -z $file_to_analize ]]; then + echo "No file to analize" + exit 0 + fi + - echo 'The following file will be analized:' + - echo $file_to_analize | tr " " "\n" + # if you get an error about a missing yaml, either you install it. Otherwise you could just fix the scrip + # see https://reviews.llvm.org/D59734 + - /usr/lib/llvm-6.0/share/clang/run-clang-tidy.py -p $lidarview_build_dir $file_to_analize > output.txt + # clang-format do not report exit code, so the generated output will be parsed instead. + - | + if [[ -n $(grep "warning: " output.txt) ]] || [[ -n $(grep "error: " output.txt) ]]; then + echo "Clang tidy fail" + echo "" + grep --color -E '^|warning: |error: ' output.txt + exit -1; + else + echo -e "\033[1;32m\xE2\x9C\x93 passed:\033[0m $1"; + fi + rules: + - if: $DISABLE_LINUX + when: never + - when: always + + ############## # Build # ############## @@ -223,16 +308,18 @@ linux_build: extends: - .linux_runner_config - .build + needs: [linux_configure] osx_build: extends: - .osx_runner_config - .build - + needs: [osx_configure] windows_build: extends: - .windows_runner_config - .build + needs: [windows_configure] ############## # Test # diff --git a/CI/.gitlab-ci.yml b/CI/.gitlab-ci.yml index 8c056d48be6201bd118d517d4d4e1ee8dc8dd937..061a877a0b032f2ab42ff4d948c2cc6ec6209a31 100644 --- a/CI/.gitlab-ci.yml +++ b/CI/.gitlab-ci.yml @@ -1,12 +1,13 @@ # launch lidarview CI, see https://docs.gitlab.com/ee/ci/multi_project_pipelines.html launch_lidarview_CI: variables: - LVCore_COMMIT_SHA: $CI_COMMIT_SHA - only: - - master - - merge_requests - - tags + TRIGGER_MODULE_SHA: $CI_COMMIT_SHA + TRIGGER_MODULE_PATH: LVCore + # only: + # - master + # - merge_requests + # - tags trigger: project: lidarview/lidarview - branch: master + branch: enable_to_test_ci strategy: depend \ No newline at end of file