From e3c0f0b6d79807fec3118e3dcfc652a8fd232e44 Mon Sep 17 00:00:00 2001 From: Jacob Kahn Date: Thu, 22 Apr 2021 16:58:32 -0700 Subject: [PATCH] Add coverage build (#560) Summary: tl;dr -- our coverage can be better. Wanted to check out codecov - this is what came of it. Code coverage reports are enabled for the org - add them in CI. - Codecov is capable of generating super cool reports like https://github.com/flashlight/flashlight/pull/560#issuecomment-825121381 in PR comments, but I've disabled those for now - View coverage details like https://codecov.io/gh/flashlight/flashlight/tree/17c14502a3c99550e69973e9d0cb1e9374e9ed3e/flashlight - codecov checks appear in CI which will yell at people if they are landing untested code Pull Request resolved: https://github.com/flashlight/flashlight/pull/560 Test Plan: CI PR comments [disabled for now] like Screen Shot 2021-04-22 at 5 55 33 PM cool visualizations of what we have tests for like ![screencapture-codecov-io-gh-flashlight-flashlight-src-17c14502a3c99550e69973e9d0cb1e9374e9ed3e-flashlight-fl-autograd-Functions-cpp-2021-04-22-17_53_25](https://user-images.githubusercontent.com/7871817/115796181-fe315580-a396-11eb-9dda-fafad249f9de.png) Reviewed By: tlikhomanenko Differential Revision: D27954344 Pulled By: jacobkahn fbshipit-source-id: 30cff2176c97ffdf499fe2bbc41a2feba2b1cb69 --- .gitignore | 19 +++++++++++++++++++ CMakeLists.txt | 11 ++++++++++- README.md | 2 ++ cmake/InternalUtils.cmake | 24 ++++++++++++++++++++++++ codecov.yml | 1 + 5 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 codecov.yml diff --git a/.gitignore b/.gitignore index 50b3eb10..84e13479 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,22 @@ eggs/ .installed.cfg *.egg wheels/ + +# Coverage +*.info + +# Precompiled Headers +*.gch +*.pch + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib diff --git a/CMakeLists.txt b/CMakeLists.txt index 9d9eacb9..be2a4a2d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,13 +8,15 @@ include(CMakeDependentOption) # ----------------------------- Setup ----------------------------- find_program(CCACHE_PROGRAM ccache) if(CCACHE_PROGRAM) - set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}") + set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}") endif() set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) +option(FL_CODE_COVERAGE "Enable coverage reporting" OFF) + # Default directories for installation set(FL_INSTALL_INC_DIR "include" CACHE PATH "Install path for headers") set(FL_INSTALL_INC_DIR_HEADER_LOC ${FL_INSTALL_INC_DIR}/flashlight) @@ -136,6 +138,9 @@ if (FL_BUILD_LIBRARIES OR (FL_BUILD_CORE AND FL_BUILD_TESTS)) endif () setup_install_headers(${FL_LIB_DIR} ${FL_INSTALL_INC_DIR_HEADER_LOC}) + if (FL_CODE_COVERAGE) + add_coverage_to_target(TARGET fl-libraries) + endif() endif() # if FL_BUILD_LIBRARIES # --------------------------- flashlight --------------------------- @@ -157,6 +162,10 @@ if (FL_BUILD_CORE) target_link_libraries(flashlight PUBLIC fl-libraries) endif() + if (FL_CODE_COVERAGE) + add_coverage_to_target(TARGET flashlight) + endif() + # ------------------------ Global External Dependencies ------------------------ # ArrayFire find_package(ArrayFire REQUIRED) diff --git a/README.md b/README.md index 74f9fd9d..34196081 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,8 @@ [![Docker Image Build Status](https://img.shields.io/github/workflow/status/flashlight/flashlight/Publish%20Docker%20images?label=docker%20image%20build)](https://hub.docker.com/r/flml/flashlight/tags) [![Join the chat at https://gitter.im/flashlight-ml/community](https://img.shields.io/gitter/room/flashlight-ml/community)](https://gitter.im/flashlight-ml/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) +[![codecov](https://codecov.io/gh/flashlight/flashlight/branch/master/graph/badge.svg?token=rBp4AilMc0)](https://codecov.io/gh/flashlight/flashlight) + [![Docker Image for CUDA backend](https://img.shields.io/docker/image-size/flml/flashlight/cuda-latest?label=docker%20%28cuda%29&logo=docker)](https://hub.docker.com/r/flml/flashlight/tags?page=1&ordering=last_updated&name=cuda-latest) [![Docker Image for CPU backend](https://img.shields.io/docker/image-size/flml/flashlight/cpu-latest?label=docker%20%28cpu%29&logo=docker)](https://hub.docker.com/r/flml/flashlight/tags?page=1&ordering=last_updated&name=cpu-latest) diff --git a/cmake/InternalUtils.cmake b/cmake/InternalUtils.cmake index 8b9c3f6e..31637698 100644 --- a/cmake/InternalUtils.cmake +++ b/cmake/InternalUtils.cmake @@ -1,3 +1,27 @@ +function(add_coverage_to_target) + set(oneValueArgs TARGET) + cmake_parse_arguments(add_coverage_to_target "${options}" "${oneValueArgs}" + "${multiValueArgs}" ${ARGN}) + + if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") + # Add required flags (GCC & LLVM/Clang) + target_compile_options(${add_coverage_to_target_TARGET} PUBLIC + -O0 # TODO: reconcile this with CMake modes for something cleaner + -g + $<$:--coverage> + ) + if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.13) + target_link_options(${add_coverage_to_target_TARGET} + PUBLIC + $<$:--coverage>) + else() + target_link_libraries(${add_coverage_to_target_TARGET} + PUBLIC + --coverage) + endif() + endif() +endfunction() + function(setup_install_targets) set(multiValueArgs INSTALL_TARGETS INSTALL_HEADERS) cmake_parse_arguments(setup_install_targets "${options}" "${oneValueArgs}" diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 00000000..69cb7601 --- /dev/null +++ b/codecov.yml @@ -0,0 +1 @@ +comment: false