| OLD | NEW |
| (Empty) | |
| 1 #!/usr/bin/python2.4 |
| 2 # Copyright 2008, Google Inc. |
| 3 # All rights reserved. |
| 4 # |
| 5 # Redistribution and use in source and binary forms, with or without |
| 6 # modification, are permitted provided that the following conditions are |
| 7 # met: |
| 8 # |
| 9 # * Redistributions of source code must retain the above copyright |
| 10 # notice, this list of conditions and the following disclaimer. |
| 11 # * Redistributions in binary form must reproduce the above |
| 12 # copyright notice, this list of conditions and the following disclaimer |
| 13 # in the documentation and/or other materials provided with the |
| 14 # distribution. |
| 15 # * Neither the name of Google Inc. nor the names of its |
| 16 # contributors may be used to endorse or promote products derived from |
| 17 # this software without specific prior written permission. |
| 18 # |
| 19 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 20 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 21 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 22 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 23 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 24 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 25 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 26 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 27 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 |
| 31 """SCons tool for generating code coverage. |
| 32 |
| 33 This module enhances a debug environment to add code coverage. |
| 34 It is used as follows: |
| 35 coverage_env = dbg_env.Clone(tools = ['code_coverage']) |
| 36 """ |
| 37 |
| 38 |
| 39 def AddCoverageSetup(env): |
| 40 """Add coverage related build steps and dependency links. |
| 41 |
| 42 Args: |
| 43 env: a leaf environment ready to have coverage steps added. |
| 44 """ |
| 45 # Add a step to start coverage (for instance windows needs this). |
| 46 # This step should get run before and tests are run. |
| 47 if env.get('COVERAGE_START_CMD', None): |
| 48 start = env.Command('$COVERAGE_START_FILE', [], '$COVERAGE_START_CMD') |
| 49 env.AlwaysBuild(start) |
| 50 else: |
| 51 start = [] |
| 52 |
| 53 # Add a step to end coverage (used on basically all platforms). |
| 54 # This step should get after all the tests have run. |
| 55 if env.get('COVERAGE_STOP_CMD', None): |
| 56 stop = env.Command('$COVERAGE_OUTPUT_FILE', [], '$COVERAGE_STOP_CMD') |
| 57 env.AlwaysBuild(stop) |
| 58 else: |
| 59 stop = [] |
| 60 |
| 61 # start must happen before tests run, stop must happen after. |
| 62 for group in env.SubstList2('$COVERAGE_TARGETS'): |
| 63 group_alias = env.Alias(group) |
| 64 # Force each alias to happen after start but before stop. |
| 65 env.Requires(group_alias, start) |
| 66 env.Requires(stop, group_alias) |
| 67 # Force each source of the aliases to happen after start but before stop. |
| 68 # This is needed to work around non-standard aliases in some projects. |
| 69 for test in group_alias: |
| 70 for s in test.sources: |
| 71 env.Requires(s, start) |
| 72 env.Requires(stop, s) |
| 73 |
| 74 # Add an alias for coverage. |
| 75 env.Alias('coverage', [start, stop]) |
| 76 |
| 77 |
| 78 def generate(env): |
| 79 # NOTE: SCons requires the use of this name, which fails gpylint. |
| 80 """SCons entry point for this tool.""" |
| 81 |
| 82 env['COVERAGE_ENABLED'] = True |
| 83 |
| 84 env.SetDefault( |
| 85 # Setup up coverage related tool paths. |
| 86 # These can be overridden elsewhere, if needed, to relocate the tools. |
| 87 COVERAGE_MCOV='mcov', |
| 88 COVERAGE_GENHTML='genhtml', |
| 89 COVERAGE_ANALYZER='coverage_analyzer.exe', |
| 90 COVERAGE_VSPERFCMD='VSPerfCmd.exe', |
| 91 COVERAGE_VSINSTR='vsinstr.exe', |
| 92 |
| 93 # Setup coverage related locations. |
| 94 COVERAGE_DIR='$TARGET_ROOT/coverage', |
| 95 COVERAGE_HTML_DIR='$COVERAGE_DIR/html', |
| 96 COVERAGE_START_FILE='$COVERAGE_DIR/start.junk', |
| 97 COVERAGE_OUTPUT_FILE='$COVERAGE_DIR/coverage.lcov', |
| 98 |
| 99 # The list of aliases containing test execution targets. |
| 100 COVERAGE_TARGETS=['run_all_tests'], |
| 101 ) |
| 102 |
| 103 # Add in coverage flags. These come from target_platform_xxx. |
| 104 env.Append( |
| 105 CCFLAGS='$COVERAGE_CCFLAGS', |
| 106 LIBS='$COVERAGE_LIBS', |
| 107 LINKFLAGS='$COVERAGE_LINKFLAGS', |
| 108 ) |
| 109 |
| 110 # Add on LINKCOM steps. |
| 111 # TODO(bradnelson): Ideally this would just get appended, but that seems to |
| 112 # cause it to blow up in the gather_inputs builder with a complaint about |
| 113 # "Can't creation Action from None". Once that builder is gone, then this |
| 114 # can change to be more general. |
| 115 if env.get('COVERAGE_LINKCOM_EXTRAS'): |
| 116 env['LINKCOM'] = env.Action([env['LINKCOM'], |
| 117 env['COVERAGE_LINKCOM_EXTRAS']]) |
| 118 |
| 119 # Add any extra paths. |
| 120 env.AppendENVPath('PATH', env.SubstList2('$COVERAGE_EXTRA_PATHS')) |
| 121 |
| 122 # Add coverage start/stop and processing in deferred steps. |
| 123 env.Defer(AddCoverageSetup) |
| OLD | NEW |