1# 2# Copyright 2015-2016 Nest Labs Inc. All Rights Reserved. 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15# 16 17# 18# Description: 19# This file defines a GNU autoconf M4-style macro that adds an 20# --enable-coverage configuration option to the package and 21# controls whether the package will be built for code coverage 22# reporting, using the LCOV package. 23# 24 25# 26# NL_ENABLE_COVERAGE_REPORTS(default) 27# 28# default - Whether the option should be automatic (auto), enabled 29# (yes), or disabled (no) by default. 30# 31# Adds an --enable-coverage-reports configuration option to the 32# package with a default value of 'default' (should be 'auto', 'no' or 33# 'yes') and controls whether the package will be built with or 34# without code coverage reports, using the LCOV package. 35# 36# The value 'nl_cv_build_coverage_reports' will be set to the result. In 37# addition, LCOV will be set to the path of the 'lcov' tool and GENHTML will be set to the path of the 'genhtml' tool. 38# 39# NOTE: The behavior of this is influenced by nl_cv_build_coverage from 40# NL_ENABLE_COVERAGE. 41# 42#------------------------------------------------------------------------------ 43AC_DEFUN([NL_ENABLE_COVERAGE_REPORTS], 44[ 45 # Check whether or not a default value has been passed in. 46 47 m4_case([$1], 48 [auto],[], 49 [yes],[], 50 [no],[], 51 [m4_fatal([$0: invalid default value '$1'; must be 'auto', 'yes' or 'no'])]) 52 53 # Check for the presence of lcov and genhtml, required 54 # to build and generate the coverage reports. 55 56 AC_PATH_PROG(LCOV, lcov) 57 AC_PATH_PROG(GENHTML, genhtml) 58 59 AC_CACHE_CHECK([whether to build graphical code coverage reports], 60 nl_cv_build_coverage_reports, 61 [ 62 AC_ARG_ENABLE(coverage-reports, 63 [AS_HELP_STRING([--enable-coverage-reports],[Enable the generation of code coverage reports (requires lcov) @<:@default=$1@:>@.])], 64 [ 65 case "${enableval}" in 66 67 auto|no|yes) 68 nl_cv_build_coverage_reports=${enableval} 69 ;; 70 71 *) 72 AC_MSG_ERROR([Invalid value ${enableval} for --enable-coverage]) 73 ;; 74 75 esac 76 ], 77 [ 78 nl_cv_build_coverage_reports=$1 79 ]) 80 81 # If coverage is not enabled, then coverage reports 82 # defaults to 'no' if it is 'auto' or fails if it is 83 # 'yes'. Otherwise, availability of lcov and genhtml 84 # condition behavior. Lack of availability for 'yes' 85 # results in failure; however, for 'auto' then coverage 86 # reports default to 'no'. 87 88 case "${nl_cv_build_coverage}" in 89 90 no) 91 case "${nl_cv_build_coverage_reports}" in 92 93 auto) 94 nl_cv_build_coverage_reports="no" 95 ;; 96 97 yes) 98 AC_MSG_ERROR([--enable-coverage must be asserted to use --enable-coverage-reports.]) 99 ;; 100 101 no) 102 ;; 103 104 esac 105 ;; 106 107 yes) 108 case "${nl_cv_build_coverage_reports}" in 109 110 auto) 111 # Both lcov and genhtml must exist to successfully 112 # enable coverage reports. 113 114 if test "x${LCOV}" = "x" || test "x${GENHTML}" = "x"; then 115 nl_cv_build_coverage_reports="no" 116 117 else 118 nl_cv_build_coverage_reports="yes" 119 120 fi 121 ;; 122 123 yes) 124 # Both lcov and genhtml must exist to successfully 125 # enable coverage reports. Since the default or user 126 # ask is 'yes', we must fail if lcov or genhtml cannot 127 # be found. 128 129 if test "x${LCOV}" = "x"; then 130 AC_MSG_ERROR([Cannot find 'lcov'. You must have the lcov package installed to use coverage reports.]) 131 132 elif test "x${GENHTML}" = "x"; then 133 AC_MSG_ERROR([Cannot find 'genhtml'. You must have the lcov package installed to use coverage reports.]) 134 135 elif test "${nl_cv_build_coverage_reports}" = "auto"; then 136 nl_cv_build_coverage_reports="yes" 137 138 fi 139 ;; 140 141 no) 142 ;; 143 144 esac 145 ;; 146 147 esac 148 ]) 149]) 150