Exemplo n.º 1
0
def _ConfigureLLVMCoverageTools(args):
    """Configures llvm coverage tools."""
    if args.coverage_tools_dir:
        llvm_bin_dir = coverage_utils.GetFullPath(args.coverage_tools_dir)
        global LLVM_COV_PATH
        global LLVM_PROFDATA_PATH
        LLVM_COV_PATH = os.path.join(llvm_bin_dir, 'llvm-cov')
        LLVM_PROFDATA_PATH = os.path.join(llvm_bin_dir, 'llvm-profdata')
    else:
        update_clang_coverage_tools.DownloadCoverageToolsIfNeeded()

    coverage_tools_exist = (os.path.exists(LLVM_COV_PATH)
                            and os.path.exists(LLVM_PROFDATA_PATH))
    assert coverage_tools_exist, (
        'Cannot find coverage tools, please make sure '
        'both \'%s\' and \'%s\' exist.') % (LLVM_COV_PATH, LLVM_PROFDATA_PATH)
Exemplo n.º 2
0
def Main():
    """Execute tool commands."""
    # Setup coverage binaries even when script is called with empty params. This
    # is used by coverage bot for initial setup.
    if len(sys.argv) == 1:
        update_clang_coverage_tools.DownloadCoverageToolsIfNeeded()
        print(__doc__)
        return

    # Change directory to source root to aid in relative paths calculations.
    global SRC_ROOT_PATH
    SRC_ROOT_PATH = coverage_utils.GetFullPath(
        os.path.join(os.path.dirname(__file__), os.path.pardir,
                     os.path.pardir))
    os.chdir(SRC_ROOT_PATH)

    args = _ParseCommandArguments()
    coverage_utils.ConfigureLogging(verbose=args.verbose,
                                    log_file=args.log_file)
    _ConfigureLLVMCoverageTools(args)

    global BUILD_DIR
    BUILD_DIR = coverage_utils.GetFullPath(args.build_dir)

    global OUTPUT_DIR
    OUTPUT_DIR = coverage_utils.GetFullPath(args.output_dir)

    assert args.web_tests or args.command or args.profdata_file, (
        'Need to either provide commands to run using -c/--command option OR '
        'provide prof-data file as input using -p/--profdata-file option OR '
        'run web tests using -wt/--run-web-tests.')

    assert not args.command or (len(args.targets) == len(args.command)), (
        'Number of targets must be equal to the number of test commands.')

    assert os.path.exists(BUILD_DIR), ('Build directory: "%s" doesn\'t exist. '
                                       'Please run "gn gen" to generate.' %
                                       BUILD_DIR)

    _ValidateCurrentPlatformIsSupported()
    _ValidateBuildingWithClangCoverage()

    absolute_filter_paths = []
    if args.filters:
        absolute_filter_paths = _VerifyPathsAndReturnAbsolutes(args.filters)

    _SetupOutputDir()

    # Get .profdata file and list of binary paths.
    if args.web_tests:
        commands = [_GetCommandForWebTests(args.web_tests)]
        profdata_file_path = _CreateCoverageProfileDataForTargets(
            args.targets, commands, args.jobs)
        binary_paths = [_GetBinaryPathForWebTests()]
    elif args.command:
        for i in range(len(args.command)):
            assert not 'run_web_tests.py' in args.command[i], (
                'run_web_tests.py is not supported via --command argument. '
                'Please use --run-web-tests argument instead.')

        # A list of commands are provided. Run them to generate profdata file, and
        # create a list of binary paths from parsing commands.
        _VerifyTargetExecutablesAreInBuildDirectory(args.command)
        profdata_file_path = _CreateCoverageProfileDataForTargets(
            args.targets, args.command, args.jobs)
        binary_paths = [_GetBinaryPath(command) for command in args.command]
    else:
        # An input prof-data file is already provided. Just calculate binary paths.
        profdata_file_path = args.profdata_file
        binary_paths = _GetBinaryPathsFromTargets(args.targets, args.build_dir)

    # If the checkout uses the hermetic xcode binaries, then otool must be
    # directly invoked. The indirection via /usr/bin/otool won't work unless
    # there's an actual system install of Xcode.
    otool_path = None
    if sys.platform == 'darwin':
        hermetic_otool_path = os.path.join(SRC_ROOT_PATH, 'build', 'mac_files',
                                           'xcode_binaries', 'Contents',
                                           'Developer', 'Toolchains',
                                           'XcodeDefault.xctoolchain', 'usr',
                                           'bin', 'otool')
        if os.path.exists(hermetic_otool_path):
            otool_path = hermetic_otool_path
    binary_paths.extend(
        coverage_utils.GetSharedLibraries(binary_paths, BUILD_DIR, otool_path))

    logging.info(
        'Generating code coverage report in html (this can take a while '
        'depending on size of target!).')
    per_file_summary_data = _GeneratePerFileCoverageSummary(
        binary_paths, profdata_file_path, absolute_filter_paths,
        args.ignore_filename_regex)
    _GeneratePerFileLineByLineCoverageInHtml(binary_paths, profdata_file_path,
                                             absolute_filter_paths,
                                             args.ignore_filename_regex)
    component_mappings = None
    if not args.no_component_view:
        component_mappings = json.load(urllib2.urlopen(COMPONENT_MAPPING_URL))

    # Call prepare here.
    processor = coverage_utils.CoverageReportPostProcessor(
        OUTPUT_DIR,
        SRC_ROOT_PATH,
        per_file_summary_data,
        no_component_view=args.no_component_view,
        no_file_view=args.no_file_view,
        component_mappings=component_mappings)

    processor.PrepareHtmlReport()