Takuto Ikuta | 3dab32e0 | 2023-01-12 18:52:00 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Avi Drissman | 73a09d1 | 2022-09-08 20:33:38 | [diff] [blame] | 2 | # Copyright 2018 The Chromium Authors |
Yuke Liao | bb571bd6 | 2018-10-31 21:51:52 | [diff] [blame] | 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
Sajjad Mirza | bf9e66a | 2019-03-07 21:49:06 | [diff] [blame] | 5 | """Removes code coverage flags from invocations of the Clang C/C++ compiler. |
Yuke Liao | bb571bd6 | 2018-10-31 21:51:52 | [diff] [blame] | 6 | |
Sajjad Mirza | bf9e66a | 2019-03-07 21:49:06 | [diff] [blame] | 7 | If the GN arg `use_clang_coverage=true`, this script will be invoked by default. |
| 8 | GN will add coverage instrumentation flags to almost all source files. |
| 9 | |
| 10 | This script is used to remove instrumentation flags from a subset of the source |
| 11 | files. By default, it will not remove flags from any files. If the option |
| 12 | --files-to-instrument is passed, this script will remove flags from all files |
| 13 | except the ones listed in --files-to-instrument. |
| 14 | |
| 15 | This script also contains hard-coded exclusion lists of files to never |
| 16 | instrument, indexed by target operating system. Files in these lists have their |
| 17 | flags removed in both modes. The OS can be selected with --target-os. |
Yuke Liao | bb571bd6 | 2018-10-31 21:51:52 | [diff] [blame] | 18 | |
Sajjad Mirza | 18f89f2 | 2019-12-20 21:18:12 | [diff] [blame] | 19 | This script also contains hard-coded force lists of files to always instrument, |
| 20 | indexed by target operating system. Files in these lists never have their flags |
| 21 | removed in either mode. The OS can be selected with --target-os. |
| 22 | |
| 23 | The order of precedence is: force list, exclusion list, --files-to-instrument. |
| 24 | |
Yuke Liao | bb571bd6 | 2018-10-31 21:51:52 | [diff] [blame] | 25 | The path to the coverage instrumentation input file should be relative to the |
| 26 | root build directory, and the file consists of multiple lines where each line |
| 27 | represents a path to a source file, and the specified paths must be relative to |
| 28 | the root build directory. e.g. ../../base/task/post_task.cc for build |
Sajjad Mirza | 18f89f2 | 2019-12-20 21:18:12 | [diff] [blame] | 29 | directory 'out/Release'. The paths should be written using OS-native path |
| 30 | separators for the current platform. |
Yuke Liao | bb571bd6 | 2018-10-31 21:51:52 | [diff] [blame] | 31 | |
| 32 | One caveat with this compiler wrapper is that it may introduce unexpected |
| 33 | behaviors in incremental builds when the file path to the coverage |
| 34 | instrumentation input file changes between consecutive runs, so callers of this |
| 35 | script are strongly advised to always use the same path such as |
| 36 | "${root_build_dir}/coverage_instrumentation_input.txt". |
| 37 | |
| 38 | It's worth noting on try job builders, if the contents of the instrumentation |
| 39 | file changes so that a file doesn't need to be instrumented any longer, it will |
| 40 | be recompiled automatically because if try job B runs after try job A, the files |
| 41 | that were instrumented in A will be updated (i.e., reverted to the checked in |
| 42 | version) in B, and so they'll be considered out of date by ninja and recompiled. |
| 43 | |
| 44 | Example usage: |
| 45 | clang_code_coverage_wrapper.py \\ |
| 46 | --files-to-instrument=coverage_instrumentation_input.txt |
Junji Watanabe | 9bd3364 | 2023-07-05 16:27:17 | [diff] [blame] | 47 | |
| 48 | Siso implements the same logic in |
| 49 | build/config/siso/clang_code_coverage_wrapper.star, which avoids the wrapper |
| 50 | invocations for remote execution and performance improvement. |
| 51 | Please update the Siso starlark file when updating this file. |
Yuke Liao | bb571bd6 | 2018-10-31 21:51:52 | [diff] [blame] | 52 | """ |
Richard Wang | 91cc90f | 2023-07-25 16:49:12 | [diff] [blame] | 53 | # LINT.IfChange |
Raul Tambre | 9e24293b | 2019-05-12 06:11:07 | [diff] [blame] | 54 | |
Yuke Liao | bb571bd6 | 2018-10-31 21:51:52 | [diff] [blame] | 55 | import argparse |
| 56 | import os |
| 57 | import subprocess |
| 58 | import sys |
| 59 | |
| 60 | # Flags used to enable coverage instrumentation. |
Sajjad Mirza | bf9e66a | 2019-03-07 21:49:06 | [diff] [blame] | 61 | # Flags should be listed in the same order that they are added in |
| 62 | # build/config/coverage/BUILD.gn |
Yuke Liao | 5eff782 | 2019-02-28 03:56:24 | [diff] [blame] | 63 | _COVERAGE_FLAGS = [ |
Sajjad Mirza | 18f89f2 | 2019-12-20 21:18:12 | [diff] [blame] | 64 | '-fprofile-instr-generate', |
| 65 | '-fcoverage-mapping', |
Alan Zhao | f8fa3130 | 2024-01-11 03:35:39 | [diff] [blame] | 66 | '-mllvm', |
| 67 | '-runtime-counter-relocation=true', |
Sajjad Mirza | 49c00e3 | 2019-03-01 22:46:52 | [diff] [blame] | 68 | # Following experimental flags remove unused header functions from the |
| 69 | # coverage mapping data embedded in the test binaries, and the reduction |
| 70 | # of binary size enables building Chrome's large unit test targets on |
| 71 | # MacOS. Please refer to crbug.com/796290 for more details. |
Sajjad Mirza | 18f89f2 | 2019-12-20 21:18:12 | [diff] [blame] | 72 | '-mllvm', |
| 73 | '-limited-coverage-experimental=true', |
Yuke Liao | 5eff782 | 2019-02-28 03:56:24 | [diff] [blame] | 74 | ] |
Yuke Liao | bb571bd6 | 2018-10-31 21:51:52 | [diff] [blame] | 75 | |
Sajjad Mirza | 750bd0b | 2019-10-16 23:39:51 | [diff] [blame] | 76 | # Files that should not be built with coverage flags by default. |
mikt | d60ced3 | 2024-09-18 03:17:22 | [diff] [blame] | 77 | _DEFAULT_COVERAGE_EXCLUSION_LIST = [ |
| 78 | # These files caused perf regressions, resulting in time-outs on some bots. |
| 79 | # TODO(https://crbug.com/356570413): Remove when the bug is fixed. |
| 80 | '../../base/allocator/partition_allocator/src/partition_alloc/address_pool_manager_bitmap.cc', #pylint: disable=line-too-long |
| 81 | '../../base/allocator/partition_allocator/src/partition_alloc/address_pool_manager.cc', #pylint: disable=line-too-long |
| 82 | '../../base/allocator/partition_allocator/src/partition_alloc/address_pool_manager_unittest.cc', #pylint: disable=line-too-long |
| 83 | '../../base/allocator/partition_allocator/src/partition_alloc/address_space_randomization.cc', #pylint: disable=line-too-long |
| 84 | '../../base/allocator/partition_allocator/src/partition_alloc/address_space_randomization_unittest.cc', #pylint: disable=line-too-long |
| 85 | '../../base/allocator/partition_allocator/src/partition_alloc/allocation_guard.cc', #pylint: disable=line-too-long |
| 86 | '../../base/allocator/partition_allocator/src/partition_alloc/compressed_pointer.cc', #pylint: disable=line-too-long |
| 87 | '../../base/allocator/partition_allocator/src/partition_alloc/compressed_pointer_unittest.cc', #pylint: disable=line-too-long |
| 88 | '../../base/allocator/partition_allocator/src/partition_alloc/dangling_raw_ptr_checks.cc', #pylint: disable=line-too-long |
| 89 | '../../base/allocator/partition_allocator/src/partition_alloc/extended_api.cc', #pylint: disable=line-too-long |
| 90 | '../../base/allocator/partition_allocator/src/partition_alloc/freeslot_bitmap_unittest.cc', #pylint: disable=line-too-long |
| 91 | '../../base/allocator/partition_allocator/src/partition_alloc/gwp_asan_support.cc', #pylint: disable=line-too-long |
| 92 | '../../base/allocator/partition_allocator/src/partition_alloc/hardening_unittest.cc', #pylint: disable=line-too-long |
| 93 | '../../base/allocator/partition_allocator/src/partition_alloc/internal_allocator.cc', #pylint: disable=line-too-long |
| 94 | '../../base/allocator/partition_allocator/src/partition_alloc/lightweight_quarantine.cc', #pylint: disable=line-too-long |
| 95 | '../../base/allocator/partition_allocator/src/partition_alloc/lightweight_quarantine_unittest.cc', #pylint: disable=line-too-long |
| 96 | '../../base/allocator/partition_allocator/src/partition_alloc/memory_reclaimer.cc', #pylint: disable=line-too-long |
| 97 | '../../base/allocator/partition_allocator/src/partition_alloc/memory_reclaimer_unittest.cc', #pylint: disable=line-too-long |
| 98 | '../../base/allocator/partition_allocator/src/partition_alloc/oom_callback.cc', #pylint: disable=line-too-long |
| 99 | '../../base/allocator/partition_allocator/src/partition_alloc/oom.cc', #pylint: disable=line-too-long |
| 100 | '../../base/allocator/partition_allocator/src/partition_alloc/page_allocator.cc', #pylint: disable=line-too-long |
| 101 | '../../base/allocator/partition_allocator/src/partition_alloc/page_allocator_internals_posix.cc', #pylint: disable=line-too-long |
| 102 | '../../base/allocator/partition_allocator/src/partition_alloc/page_allocator_unittest.cc', #pylint: disable=line-too-long |
| 103 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_address_space.cc', #pylint: disable=line-too-long |
| 104 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/apple/mach_logging.cc', #pylint: disable=line-too-long |
| 105 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/bits_pa_unittest.cc', #pylint: disable=line-too-long |
| 106 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/check.cc', #pylint: disable=line-too-long |
| 107 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/component_export_pa_unittest.cc', #pylint: disable=line-too-long |
| 108 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/cpu.cc', #pylint: disable=line-too-long |
| 109 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/cpu_pa_unittest.cc', #pylint: disable=line-too-long |
| 110 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/debug/alias.cc', #pylint: disable=line-too-long |
| 111 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/debug/proc_maps_linux.cc', #pylint: disable=line-too-long |
| 112 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/debug/stack_trace_android.cc', #pylint: disable=line-too-long |
| 113 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/debug/stack_trace.cc', #pylint: disable=line-too-long |
| 114 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/debug/stack_trace_linux.cc', #pylint: disable=line-too-long |
| 115 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/debug/stack_trace_mac.cc', #pylint: disable=line-too-long |
| 116 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/debug/stack_trace_posix.cc', #pylint: disable=line-too-long |
| 117 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/debug/stack_trace_win.cc', #pylint: disable=line-too-long |
| 118 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/files/file_path.cc', #pylint: disable=line-too-long |
| 119 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/files/file_path_pa_unittest.cc', #pylint: disable=line-too-long |
| 120 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/files/file_util_posix.cc', #pylint: disable=line-too-long |
| 121 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/fuchsia/fuchsia_logging.cc', #pylint: disable=line-too-long |
| 122 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/fuchsia/fuchsia_logging_pa_unittest.cc', #pylint: disable=line-too-long |
| 123 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/logging.cc', #pylint: disable=line-too-long |
| 124 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/logging_pa_unittest.cc', #pylint: disable=line-too-long |
| 125 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/log_message.cc', #pylint: disable=line-too-long |
| 126 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/memory/page_size_posix.cc', #pylint: disable=line-too-long |
| 127 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/memory/page_size_win.cc', #pylint: disable=line-too-long |
| 128 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/memory/ref_counted.cc', #pylint: disable=line-too-long |
| 129 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/native_library.cc', #pylint: disable=line-too-long |
| 130 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/native_library_pa_unittest.cc', #pylint: disable=line-too-long |
| 131 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/native_library_posix.cc', #pylint: disable=line-too-long |
| 132 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/no_destructor_pa_unittest.cc', #pylint: disable=line-too-long |
| 133 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/posix/safe_strerror.cc', #pylint: disable=line-too-long |
| 134 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/process/process_handle_posix.cc', #pylint: disable=line-too-long |
| 135 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/process/process_handle_win.cc', #pylint: disable=line-too-long |
| 136 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/rand_util.cc', #pylint: disable=line-too-long |
| 137 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/rand_util_fuchsia.cc', #pylint: disable=line-too-long |
| 138 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/rand_util_pa_unittest.cc', #pylint: disable=line-too-long |
| 139 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/rand_util_posix.cc', #pylint: disable=line-too-long |
| 140 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/rand_util_win.cc', #pylint: disable=line-too-long |
| 141 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/scoped_clear_last_error_pa_unittest.cc', #pylint: disable=line-too-long |
| 142 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/scoped_clear_last_error_win.cc', #pylint: disable=line-too-long |
| 143 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/strings/cstring_builder.cc', #pylint: disable=line-too-long |
| 144 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/strings/cstring_builder_pa_unittest.cc', #pylint: disable=line-too-long |
| 145 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/strings/safe_sprintf.cc', #pylint: disable=line-too-long |
| 146 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/strings/safe_sprintf_pa_unittest.cc', #pylint: disable=line-too-long |
| 147 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/strings/stringprintf.cc', #pylint: disable=line-too-long |
| 148 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/strings/stringprintf_pa_unittest.cc', #pylint: disable=line-too-long |
| 149 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/strings/string_util.cc', #pylint: disable=line-too-long |
| 150 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/strings/string_util_pa_unittest.cc', #pylint: disable=line-too-long |
| 151 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/thread_annotations_pa_unittest.cc', #pylint: disable=line-too-long |
| 152 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/threading/platform_thread_android_for_testing.cc', #pylint: disable=line-too-long |
| 153 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/threading/platform_thread.cc', #pylint: disable=line-too-long |
| 154 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/threading/platform_thread_fuchsia_for_testing.cc', #pylint: disable=line-too-long |
| 155 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/threading/platform_thread_linux_for_testing.cc', #pylint: disable=line-too-long |
| 156 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/threading/platform_thread_posix.cc', #pylint: disable=line-too-long |
| 157 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/threading/platform_thread_posix_for_testing.cc', #pylint: disable=line-too-long |
| 158 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/threading/platform_thread_win.cc', #pylint: disable=line-too-long |
| 159 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/threading/platform_thread_win_for_testing.cc', #pylint: disable=line-too-long |
| 160 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/time/time.cc', #pylint: disable=line-too-long |
| 161 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/time/time_conversion_posix.cc', #pylint: disable=line-too-long |
| 162 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/time/time_fuchsia.cc', #pylint: disable=line-too-long |
| 163 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/time/time_now_posix.cc', #pylint: disable=line-too-long |
| 164 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/time/time_override.cc', #pylint: disable=line-too-long |
| 165 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/time/time_win.cc', #pylint: disable=line-too-long |
| 166 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc.cc', #pylint: disable=line-too-long |
| 167 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_hooks.cc', #pylint: disable=line-too-long |
| 168 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_perftest.cc', #pylint: disable=line-too-long |
| 169 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_alloc_unittest.cc', #pylint: disable=line-too-long |
| 170 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_bucket.cc', #pylint: disable=line-too-long |
| 171 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_dcheck_helper.cc', #pylint: disable=line-too-long |
| 172 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_freelist_entry.cc', #pylint: disable=line-too-long |
| 173 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_lock_perftest.cc', #pylint: disable=line-too-long |
| 174 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_lock_unittest.cc', #pylint: disable=line-too-long |
| 175 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_oom.cc', #pylint: disable=line-too-long |
| 176 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_page.cc', #pylint: disable=line-too-long |
| 177 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_root.cc', #pylint: disable=line-too-long |
| 178 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_stats.cc', #pylint: disable=line-too-long |
| 179 | '../../base/allocator/partition_allocator/src/partition_alloc/partition_tls_win.cc', #pylint: disable=line-too-long |
| 180 | '../../base/allocator/partition_allocator/src/partition_alloc/pointers/empty.cc', #pylint: disable=line-too-long |
| 181 | '../../base/allocator/partition_allocator/src/partition_alloc/pointers/instance_tracer.cc', #pylint: disable=line-too-long |
| 182 | '../../base/allocator/partition_allocator/src/partition_alloc/pointers/raw_ptr_asan_unowned_impl.cc', #pylint: disable=line-too-long |
| 183 | '../../base/allocator/partition_allocator/src/partition_alloc/pointers/raw_ptr_backup_ref_impl.cc', #pylint: disable=line-too-long |
| 184 | '../../base/allocator/partition_allocator/src/partition_alloc/pointers/raw_ptr_hookable_impl.cc', #pylint: disable=line-too-long |
| 185 | '../../base/allocator/partition_allocator/src/partition_alloc/pointers/raw_ptr_unittest.cc', #pylint: disable=line-too-long |
| 186 | '../../base/allocator/partition_allocator/src/partition_alloc/pointers/raw_ref_unittest.cc', #pylint: disable=line-too-long |
| 187 | '../../base/allocator/partition_allocator/src/partition_alloc/random.cc', #pylint: disable=line-too-long |
| 188 | '../../base/allocator/partition_allocator/src/partition_alloc/reservation_offset_table.cc', #pylint: disable=line-too-long |
| 189 | '../../base/allocator/partition_allocator/src/partition_alloc/reverse_bytes_unittest.cc', #pylint: disable=line-too-long |
| 190 | '../../base/allocator/partition_allocator/src/partition_alloc/shim/allocator_shim_android.cc', #pylint: disable=line-too-long |
| 191 | '../../base/allocator/partition_allocator/src/partition_alloc/shim/allocator_shim_apple.cc', #pylint: disable=line-too-long |
| 192 | '../../base/allocator/partition_allocator/src/partition_alloc/shim/allocator_shim.cc', #pylint: disable=line-too-long |
| 193 | '../../base/allocator/partition_allocator/src/partition_alloc/shim/allocator_shim_default_dispatch_to_apple_zoned_malloc.cc', #pylint: disable=line-too-long |
| 194 | '../../base/allocator/partition_allocator/src/partition_alloc/shim/allocator_shim_default_dispatch_to_glibc.cc', #pylint: disable=line-too-long |
| 195 | '../../base/allocator/partition_allocator/src/partition_alloc/shim/allocator_shim_default_dispatch_to_linker_wrapped_symbols.cc', #pylint: disable=line-too-long |
| 196 | '../../base/allocator/partition_allocator/src/partition_alloc/shim/allocator_shim_default_dispatch_to_partition_alloc.cc', #pylint: disable=line-too-long |
| 197 | '../../base/allocator/partition_allocator/src/partition_alloc/shim/allocator_shim_default_dispatch_to_partition_alloc_unittest.cc', #pylint: disable=line-too-long |
| 198 | '../../base/allocator/partition_allocator/src/partition_alloc/shim/allocator_shim_default_dispatch_to_partition_alloc_with_advanced_checks.cc', #pylint: disable=line-too-long |
| 199 | '../../base/allocator/partition_allocator/src/partition_alloc/shim/allocator_shim_default_dispatch_to_winheap.cc', #pylint: disable=line-too-long |
| 200 | '../../base/allocator/partition_allocator/src/partition_alloc/shim/allocator_shim_dispatch_to_noop_on_free.cc', #pylint: disable=line-too-long |
| 201 | '../../base/allocator/partition_allocator/src/partition_alloc/shim/allocator_shim_functions_win_component.cc', #pylint: disable=line-too-long |
| 202 | '../../base/allocator/partition_allocator/src/partition_alloc/shim/allocator_shim_unittest.cc', #pylint: disable=line-too-long |
| 203 | '../../base/allocator/partition_allocator/src/partition_alloc/shim/allocator_shim_win_component.cc', #pylint: disable=line-too-long |
| 204 | '../../base/allocator/partition_allocator/src/partition_alloc/shim/allocator_shim_win_static.cc', #pylint: disable=line-too-long |
| 205 | '../../base/allocator/partition_allocator/src/partition_alloc/shim/empty.cc', #pylint: disable=line-too-long |
| 206 | '../../base/allocator/partition_allocator/src/partition_alloc/shim/malloc_zone_functions_apple.cc', #pylint: disable=line-too-long |
| 207 | '../../base/allocator/partition_allocator/src/partition_alloc/shim/malloc_zone_functions_apple_unittest.cc', #pylint: disable=line-too-long |
| 208 | '../../base/allocator/partition_allocator/src/partition_alloc/shim/winheap_stubs_win.cc', #pylint: disable=line-too-long |
| 209 | '../../base/allocator/partition_allocator/src/partition_alloc/shim/winheap_stubs_win_unittest.cc', #pylint: disable=line-too-long |
| 210 | '../../base/allocator/partition_allocator/src/partition_alloc/slot_start_unittest.cc', #pylint: disable=line-too-long |
| 211 | '../../base/allocator/partition_allocator/src/partition_alloc/spinning_mutex.cc', #pylint: disable=line-too-long |
| 212 | '../../base/allocator/partition_allocator/src/partition_alloc/stack/asm/arm64/push_registers_asm.cc', #pylint: disable=line-too-long |
| 213 | '../../base/allocator/partition_allocator/src/partition_alloc/stack/asm/arm/push_registers_asm.cc', #pylint: disable=line-too-long |
| 214 | '../../base/allocator/partition_allocator/src/partition_alloc/stack/asm/riscv64/push_registers_asm.cc', #pylint: disable=line-too-long |
| 215 | '../../base/allocator/partition_allocator/src/partition_alloc/stack/asm/x64/push_registers_asm.cc', #pylint: disable=line-too-long |
| 216 | '../../base/allocator/partition_allocator/src/partition_alloc/stack/asm/x86/push_registers_asm.cc', #pylint: disable=line-too-long |
| 217 | '../../base/allocator/partition_allocator/src/partition_alloc/stack/stack.cc', #pylint: disable=line-too-long |
| 218 | '../../base/allocator/partition_allocator/src/partition_alloc/stack/stack_unittest.cc', #pylint: disable=line-too-long |
| 219 | '../../base/allocator/partition_allocator/src/partition_alloc/tagging.cc', #pylint: disable=line-too-long |
| 220 | '../../base/allocator/partition_allocator/src/partition_alloc/tagging_unittest.cc', #pylint: disable=line-too-long |
| 221 | '../../base/allocator/partition_allocator/src/partition_alloc/thread_cache.cc', #pylint: disable=line-too-long |
| 222 | '../../base/allocator/partition_allocator/src/partition_alloc/thread_cache_unittest.cc', #pylint: disable=line-too-long |
| 223 | '../../base/allocator/partition_allocator/src/partition_alloc/thread_isolation/pkey.cc', #pylint: disable=line-too-long |
| 224 | '../../base/allocator/partition_allocator/src/partition_alloc/thread_isolation/pkey_unittest.cc', #pylint: disable=line-too-long |
| 225 | '../../base/allocator/partition_allocator/src/partition_alloc/thread_isolation/thread_isolation.cc', #pylint: disable=line-too-long |
| 226 | ] |
Sajjad Mirza | 750bd0b | 2019-10-16 23:39:51 | [diff] [blame] | 227 | |
Sajjad Mirza | bf9e66a | 2019-03-07 21:49:06 | [diff] [blame] | 228 | # Map of exclusion lists indexed by target OS. |
| 229 | # If no target OS is defined, or one is defined that doesn't have a specific |
Sajjad Mirza | 750bd0b | 2019-10-16 23:39:51 | [diff] [blame] | 230 | # entry, use _DEFAULT_COVERAGE_EXCLUSION_LIST. |
Sajjad Mirza | bf9e66a | 2019-03-07 21:49:06 | [diff] [blame] | 231 | _COVERAGE_EXCLUSION_LIST_MAP = { |
Yun Liu | e643df75 | 2019-10-25 19:11:33 | [diff] [blame] | 232 | 'android': [ |
| 233 | # This file caused webview native library failed on arm64. |
| 234 | '../../device/gamepad/dualshock4_controller.cc', |
mikt | d60ced3 | 2024-09-18 03:17:22 | [diff] [blame] | 235 | ] + _DEFAULT_COVERAGE_EXCLUSION_LIST, |
Chong Gu | 1809f31 | 2021-02-17 18:12:40 | [diff] [blame] | 236 | 'fuchsia': [ |
Alison Gale | d965ba0 | 2024-04-26 21:50:54 | [diff] [blame] | 237 | # TODO(crbug.com/40167659): These files caused clang to crash while |
Chong Gu | 1809f31 | 2021-02-17 18:12:40 | [diff] [blame] | 238 | # compiling them. |
Chong Gu | 1809f31 | 2021-02-17 18:12:40 | [diff] [blame] | 239 | '../../third_party/skia/src/core/SkOpts.cpp', |
| 240 | '../../third_party/skia/src/opts/SkOpts_hsw.cpp', |
| 241 | '../../third_party/skia/third_party/skcms/skcms.cc', |
mikt | d60ced3 | 2024-09-18 03:17:22 | [diff] [blame] | 242 | ] + _DEFAULT_COVERAGE_EXCLUSION_LIST, |
Yuke Liao | 8098d70 | 2019-08-05 23:57:41 | [diff] [blame] | 243 | 'linux': [ |
| 244 | # These files caused a static initializer to be generated, which |
| 245 | # shouldn't. |
Alison Gale | 3a395916 | 2024-04-29 18:52:44 | [diff] [blame] | 246 | # TODO(crbug.com/41474559): Remove when the bug is fixed. |
Sajjad Mirza | 750bd0b | 2019-10-16 23:39:51 | [diff] [blame] | 247 | '../../chrome/browser/media/router/providers/cast/cast_internal_message_util.cc', #pylint: disable=line-too-long |
mark a. foltz | 5cb6068 | 2022-10-05 17:43:12 | [diff] [blame] | 248 | '../../components/media_router/common/providers/cast/channel/cast_channel_enum.cc', #pylint: disable=line-too-long |
| 249 | '../../components/media_router/common/providers/cast/channel/cast_message_util.cc', #pylint: disable=line-too-long |
Zhaoyang Li | 7540893 | 2020-10-13 19:06:34 | [diff] [blame] | 250 | '../../components/media_router/common/providers/cast/cast_media_source.cc', #pylint: disable=line-too-long |
Yuke Liao | 40543c9f7 | 2020-01-07 18:27:04 | [diff] [blame] | 251 | '../../ui/events/keycodes/dom/keycode_converter.cc', |
mikt | d60ced3 | 2024-09-18 03:17:22 | [diff] [blame] | 252 | ] + _DEFAULT_COVERAGE_EXCLUSION_LIST, |
Sajjad Mirza | bf9e66a | 2019-03-07 21:49:06 | [diff] [blame] | 253 | 'chromeos': [ |
| 254 | # These files caused clang to crash while compiling them. They are |
| 255 | # excluded pending an investigation into the underlying compiler bug. |
| 256 | '../../third_party/webrtc/p2p/base/p2p_transport_channel.cc', |
| 257 | '../../third_party/icu/source/common/uts46.cpp', |
| 258 | '../../third_party/icu/source/common/ucnvmbcs.cpp', |
| 259 | '../../base/android/android_image_reader_compat.cc', |
mikt | d60ced3 | 2024-09-18 03:17:22 | [diff] [blame] | 260 | ] + _DEFAULT_COVERAGE_EXCLUSION_LIST, |
Sajjad Mirza | bf9e66a | 2019-03-07 21:49:06 | [diff] [blame] | 261 | } |
| 262 | |
Sajjad Mirza | 18f89f2 | 2019-12-20 21:18:12 | [diff] [blame] | 263 | # Map of force lists indexed by target OS. |
| 264 | _COVERAGE_FORCE_LIST_MAP = { |
Sebastien Marchand | bd02bc29e | 2020-03-11 15:53:36 | [diff] [blame] | 265 | # clang_profiling.cc refers to the symbol `__llvm_profile_dump` from the |
Sajjad Mirza | 18f89f2 | 2019-12-20 21:18:12 | [diff] [blame] | 266 | # profiling runtime. In a partial coverage build, it is possible for a |
Sebastien Marchand | bd02bc29e | 2020-03-11 15:53:36 | [diff] [blame] | 267 | # binary to include clang_profiling.cc but have no instrumented files, thus |
Sajjad Mirza | 18f89f2 | 2019-12-20 21:18:12 | [diff] [blame] | 268 | # causing an unresolved symbol error because the profiling runtime will not |
| 269 | # be linked in. Therefore we force coverage for this file to ensure that |
| 270 | # any target that includes it will also get the profiling runtime. |
Sebastien Marchand | bd02bc29e | 2020-03-11 15:53:36 | [diff] [blame] | 271 | 'win': [r'..\..\base\test\clang_profiling.cc'], |
Alison Gale | d965ba0 | 2024-04-26 21:50:54 | [diff] [blame] | 272 | # TODO(crbug.com/40154378) We're seeing runtime LLVM errors in mac-rel when |
Sajjad Mirza | 72b3140d | 2020-11-25 16:45:03 | [diff] [blame] | 273 | # no files are changed, so we suspect that this is similar to the other |
| 274 | # problem with clang_profiling.cc on Windows. The TODO here is to force |
| 275 | # coverage for this specific file on ALL platforms, if it turns out to fix |
| 276 | # this issue on Mac as well. It's the only file that directly calls |
| 277 | # `__llvm_profile_dump` so it warrants some special treatment. |
| 278 | 'mac': ['../../base/test/clang_profiling.cc'], |
Sajjad Mirza | 18f89f2 | 2019-12-20 21:18:12 | [diff] [blame] | 279 | } |
Sajjad Mirza | bf9e66a | 2019-03-07 21:49:06 | [diff] [blame] | 280 | |
Sajjad Mirza | 750bd0b | 2019-10-16 23:39:51 | [diff] [blame] | 281 | |
Sajjad Mirza | bf9e66a | 2019-03-07 21:49:06 | [diff] [blame] | 282 | def _remove_flags_from_command(command): |
| 283 | # We need to remove the coverage flags for this file, but we only want to |
| 284 | # remove them if we see the exact sequence defined in _COVERAGE_FLAGS. |
| 285 | # That ensures that we only remove the flags added by GN when |
| 286 | # "use_clang_coverage" is true. Otherwise, we would remove flags set by |
| 287 | # other parts of the build system. |
| 288 | start_flag = _COVERAGE_FLAGS[0] |
| 289 | num_flags = len(_COVERAGE_FLAGS) |
| 290 | start_idx = 0 |
| 291 | try: |
| 292 | while True: |
| 293 | idx = command.index(start_flag, start_idx) |
Sajjad Mirza | 18f89f2 | 2019-12-20 21:18:12 | [diff] [blame] | 294 | if command[idx:idx + num_flags] == _COVERAGE_FLAGS: |
| 295 | del command[idx:idx + num_flags] |
Zhaoyang Li | 7540893 | 2020-10-13 19:06:34 | [diff] [blame] | 296 | # There can be multiple sets of _COVERAGE_FLAGS. All of these need to be |
| 297 | # removed. |
| 298 | start_idx = idx |
| 299 | else: |
| 300 | start_idx = idx + 1 |
Sajjad Mirza | bf9e66a | 2019-03-07 21:49:06 | [diff] [blame] | 301 | except ValueError: |
| 302 | pass |
Yuke Liao | bb571bd6 | 2018-10-31 21:51:52 | [diff] [blame] | 303 | |
Sajjad Mirza | 18f89f2 | 2019-12-20 21:18:12 | [diff] [blame] | 304 | |
Yuke Liao | bb571bd6 | 2018-10-31 21:51:52 | [diff] [blame] | 305 | def main(): |
Yuke Liao | bb571bd6 | 2018-10-31 21:51:52 | [diff] [blame] | 306 | arg_parser = argparse.ArgumentParser() |
| 307 | arg_parser.usage = __doc__ |
| 308 | arg_parser.add_argument( |
| 309 | '--files-to-instrument', |
| 310 | type=str, |
Yuke Liao | bb571bd6 | 2018-10-31 21:51:52 | [diff] [blame] | 311 | help='Path to a file that contains a list of file names to instrument.') |
Sajjad Mirza | bf9e66a | 2019-03-07 21:49:06 | [diff] [blame] | 312 | arg_parser.add_argument( |
Sajjad Mirza | 18f89f2 | 2019-12-20 21:18:12 | [diff] [blame] | 313 | '--target-os', required=False, help='The OS to compile for.') |
Yuke Liao | bb571bd6 | 2018-10-31 21:51:52 | [diff] [blame] | 314 | arg_parser.add_argument('args', nargs=argparse.REMAINDER) |
| 315 | parsed_args = arg_parser.parse_args() |
| 316 | |
Sajjad Mirza | bf9e66a | 2019-03-07 21:49:06 | [diff] [blame] | 317 | if (parsed_args.files_to_instrument and |
| 318 | not os.path.isfile(parsed_args.files_to_instrument)): |
Yuke Liao | bb571bd6 | 2018-10-31 21:51:52 | [diff] [blame] | 319 | raise Exception('Path to the coverage instrumentation file: "%s" doesn\'t ' |
| 320 | 'exist.' % parsed_args.files_to_instrument) |
| 321 | |
| 322 | compile_command = parsed_args.args |
Sajjad Mirza | bf9e66a | 2019-03-07 21:49:06 | [diff] [blame] | 323 | if not any('clang' in s for s in compile_command): |
| 324 | return subprocess.call(compile_command) |
| 325 | |
Sajjad Mirza | 750bd0b | 2019-10-16 23:39:51 | [diff] [blame] | 326 | target_os = parsed_args.target_os |
| 327 | |
Yuke Liao | bb571bd6 | 2018-10-31 21:51:52 | [diff] [blame] | 328 | try: |
| 329 | # The command is assumed to use Clang as the compiler, and the path to the |
| 330 | # source file is behind the -c argument, and the path to the source path is |
| 331 | # relative to the root build directory. For example: |
| 332 | # clang++ -fvisibility=hidden -c ../../base/files/file_path.cc -o \ |
| 333 | # obj/base/base/file_path.o |
Sajjad Mirza | 750bd0b | 2019-10-16 23:39:51 | [diff] [blame] | 334 | # On Windows, clang-cl.exe uses /c instead of -c. |
| 335 | source_flag = '/c' if target_os == 'win' else '-c' |
| 336 | source_flag_index = compile_command.index(source_flag) |
Yuke Liao | bb571bd6 | 2018-10-31 21:51:52 | [diff] [blame] | 337 | except ValueError: |
Sajjad Mirza | 750bd0b | 2019-10-16 23:39:51 | [diff] [blame] | 338 | print('%s argument is not found in the compile command.' % source_flag) |
Yuke Liao | bb571bd6 | 2018-10-31 21:51:52 | [diff] [blame] | 339 | raise |
| 340 | |
Sajjad Mirza | 750bd0b | 2019-10-16 23:39:51 | [diff] [blame] | 341 | if source_flag_index + 1 >= len(compile_command): |
Yuke Liao | bb571bd6 | 2018-10-31 21:51:52 | [diff] [blame] | 342 | raise Exception('Source file to be compiled is missing from the command.') |
| 343 | |
Sajjad Mirza | e677802c | 2019-12-18 21:51:59 | [diff] [blame] | 344 | # On Windows, filesystem paths should use '\', but GN creates build commands |
| 345 | # that use '/'. We invoke os.path.normpath to ensure that the path uses the |
| 346 | # correct separator for the current platform (i.e. '\' on Windows and '/' |
| 347 | # otherwise). |
| 348 | compile_source_file = os.path.normpath(compile_command[source_flag_index + 1]) |
Bruce Dawson | 09c1bd0 | 2021-06-26 00:06:11 | [diff] [blame] | 349 | extension = os.path.splitext(compile_source_file)[1] |
| 350 | if not extension in ['.c', '.cc', '.cpp', '.cxx', '.m', '.mm', '.S']: |
| 351 | raise Exception('Invalid source file %s found' % compile_source_file) |
Sajjad Mirza | 750bd0b | 2019-10-16 23:39:51 | [diff] [blame] | 352 | exclusion_list = _COVERAGE_EXCLUSION_LIST_MAP.get( |
| 353 | target_os, _DEFAULT_COVERAGE_EXCLUSION_LIST) |
Sajjad Mirza | 18f89f2 | 2019-12-20 21:18:12 | [diff] [blame] | 354 | force_list = _COVERAGE_FORCE_LIST_MAP.get(target_os, []) |
Sajjad Mirza | bf9e66a | 2019-03-07 21:49:06 | [diff] [blame] | 355 | |
Sajjad Mirza | 18f89f2 | 2019-12-20 21:18:12 | [diff] [blame] | 356 | should_remove_flags = False |
| 357 | if compile_source_file not in force_list: |
| 358 | if compile_source_file in exclusion_list: |
| 359 | should_remove_flags = True |
| 360 | elif parsed_args.files_to_instrument: |
| 361 | with open(parsed_args.files_to_instrument) as f: |
| 362 | if compile_source_file not in f.read(): |
| 363 | should_remove_flags = True |
| 364 | |
| 365 | if should_remove_flags: |
Sajjad Mirza | bf9e66a | 2019-03-07 21:49:06 | [diff] [blame] | 366 | _remove_flags_from_command(compile_command) |
Yuke Liao | bb571bd6 | 2018-10-31 21:51:52 | [diff] [blame] | 367 | |
| 368 | return subprocess.call(compile_command) |
| 369 | |
Sajjad Mirza | 18f89f2 | 2019-12-20 21:18:12 | [diff] [blame] | 370 | |
Yuke Liao | bb571bd6 | 2018-10-31 21:51:52 | [diff] [blame] | 371 | if __name__ == '__main__': |
| 372 | sys.exit(main()) |
Richard Wang | 91cc90f | 2023-07-25 16:49:12 | [diff] [blame] | 373 | |
| 374 | # LINT.ThenChange(/build/config/siso/clang_code_coverage_wrapper.star) |