[code coverage] Invoke compiler wrapper script on Windows.

Add Windows support into the wrapper and have the toolchain invoke it
when use_clang_coverage = true.

Also clean-up the code for the default exclusion list.

Bug: 989828
Change-Id: Ie4e40721e7b007831c299978b37315dad1c521c8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1863328
Commit-Queue: Sajjad Mirza <sajjadm@chromium.org>
Reviewed-by: Dirk Pranke <dpranke@chromium.org>
Reviewed-by: Nodir Turakulov <nodir@chromium.org>
Reviewed-by: Yuke Liao <liaoyuke@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#706703}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 750bd0b90ea5bf7920e961655a9fe965341bc7a9
This commit is contained in:
Sajjad Mirza 2019-10-16 23:39:51 +00:00 коммит произвёл Commit Bot
Родитель 81342e256c
Коммит 60d20a73e7
2 изменённых файлов: 54 добавлений и 17 удалений

Просмотреть файл

@ -58,21 +58,21 @@ _COVERAGE_FLAGS = [
'-mllvm', '-limited-coverage-experimental=true'
]
# Files that should not be built with coverage flags by default.
_DEFAULT_COVERAGE_EXCLUSION_LIST = []
# Map of exclusion lists indexed by target OS.
# If no target OS is defined, or one is defined that doesn't have a specific
# entry, use the 'default' exclusion_list. Anything added to 'default' will
# apply to all platforms that don't have their own specific list.
# entry, use _DEFAULT_COVERAGE_EXCLUSION_LIST.
_COVERAGE_EXCLUSION_LIST_MAP = {
'default': [],
'linux': [
# These files caused a static initializer to be generated, which
# shouldn't.
# TODO(crbug.com/990948): Remove when the bug is fixed.
'../../chrome/browser/media/router/providers/cast/cast_internal_message_util.cc', #pylint: disable=line-too-long
'../../chrome/browser/media/router/providers/cast/cast_internal_message_util.cc', #pylint: disable=line-too-long
'../../chrome/common/media_router/providers/cast/cast_media_source.cc',
'../../components/cast_channel/cast_channel_enum.cc',
'../../components/cast_channel/cast_message_util.cc'
'../../components/cast_channel/cast_message_util.cc',
],
'chromeos': [
# These files caused clang to crash while compiling them. They are
@ -81,10 +81,12 @@ _COVERAGE_EXCLUSION_LIST_MAP = {
'../../third_party/icu/source/common/uts46.cpp',
'../../third_party/icu/source/common/ucnvmbcs.cpp',
'../../base/android/android_image_reader_compat.cc',
]
],
'win': [],
}
def _remove_flags_from_command(command):
# We need to remove the coverage flags for this file, but we only want to
# remove them if we see the exact sequence defined in _COVERAGE_FLAGS.
@ -128,25 +130,27 @@ def main():
if not any('clang' in s for s in compile_command):
return subprocess.call(compile_command)
target_os = parsed_args.target_os
try:
# The command is assumed to use Clang as the compiler, and the path to the
# source file is behind the -c argument, and the path to the source path is
# relative to the root build directory. For example:
# clang++ -fvisibility=hidden -c ../../base/files/file_path.cc -o \
# obj/base/base/file_path.o
index_dash_c = compile_command.index('-c')
# On Windows, clang-cl.exe uses /c instead of -c.
source_flag = '/c' if target_os == 'win' else '-c'
source_flag_index = compile_command.index(source_flag)
except ValueError:
print('-c argument is not found in the compile command.')
print('%s argument is not found in the compile command.' % source_flag)
raise
if index_dash_c + 1 >= len(compile_command):
if source_flag_index + 1 >= len(compile_command):
raise Exception('Source file to be compiled is missing from the command.')
compile_source_file = compile_command[index_dash_c + 1]
target_os = parsed_args.target_os
if target_os not in _COVERAGE_EXCLUSION_LIST_MAP:
target_os = 'default'
exclusion_list = _COVERAGE_EXCLUSION_LIST_MAP[target_os]
compile_source_file = compile_command[source_flag_index + 1]
exclusion_list = _COVERAGE_EXCLUSION_LIST_MAP.get(
target_os, _DEFAULT_COVERAGE_EXCLUSION_LIST)
if compile_source_file in exclusion_list:
_remove_flags_from_command(compile_command)

Просмотреть файл

@ -147,6 +147,38 @@ template("msvc_toolchain") {
sys_lib_flags = ""
}
if (defined(toolchain_args.use_clang_coverage)) {
toolchain_use_clang_coverage = toolchain_args.use_clang_coverage
} else {
toolchain_use_clang_coverage = use_clang_coverage
}
if (toolchain_use_clang_coverage) {
assert(toolchain_args.is_clang,
"use_clang_coverage should only be used with Clang")
if (defined(toolchain_args.coverage_instrumentation_input_file)) {
toolchain_coverage_instrumentation_input_file =
toolchain_args.coverage_instrumentation_input_file
} else {
toolchain_coverage_instrumentation_input_file =
coverage_instrumentation_input_file
}
coverage_wrapper =
rebase_path("//build/toolchain/clang_code_coverage_wrapper.py",
root_build_dir)
coverage_wrapper = coverage_wrapper + " --target-os=" + target_os
if (toolchain_coverage_instrumentation_input_file != "") {
coverage_wrapper =
coverage_wrapper + " --files-to-instrument=" +
rebase_path(toolchain_coverage_instrumentation_input_file,
root_build_dir)
}
coverage_wrapper = "$python_path " + coverage_wrapper + " "
} else {
coverage_wrapper = ""
}
tool("cc") {
precompiled_header_type = "msvc"
pdbname = "{{target_out_dir}}/{{label_name}}_c.pdb"
@ -160,7 +192,7 @@ template("msvc_toolchain") {
"$object_subdir/{{source_name_part}}.obj",
]
command = "$env_wrapper$cl /nologo /showIncludes $sys_include_flags{{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} /c {{source}} /Fo{{output}} /Fd\"$pdbname\""
command = "$coverage_wrapper$env_wrapper$cl /nologo /showIncludes $sys_include_flags{{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} /c {{source}} /Fo{{output}} /Fd\"$pdbname\""
}
tool("cxx") {
@ -176,7 +208,7 @@ template("msvc_toolchain") {
"$object_subdir/{{source_name_part}}.obj",
]
command = "$env_wrapper$cl /nologo /showIncludes $sys_include_flags{{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} /c {{source}} /Fo{{output}} /Fd\"$pdbname\""
command = "$coverage_wrapper$env_wrapper$cl /nologo /showIncludes $sys_include_flags{{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} /c {{source}} /Fo{{output}} /Fd\"$pdbname\""
}
tool("rc") {
@ -369,6 +401,7 @@ template("win_toolchains") {
forward_variables_from(invoker.toolchain_args, "*")
}
is_clang = false
use_clang_coverage = false
current_os = "win"
current_cpu = toolchain_arch
}