1#!/usr/bin/env python3 2# Copyright 2020 The Chromium Authors. All rights reserved. 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5"""This script merges code coverage profiles from multiple steps. 6 7This script is taken from the chromium build tools and is synced 8manually on an as-needed basis: 9https://source.chromium.org/chromium/chromium/src/+/master:testing/merge_scripts/code_coverage/merge_steps.py?q=merge_steps.py&ss=chromium 10""" 11 12import argparse 13import os 14import sys 15 16import merge_lib as merger 17 18 19def _merge_steps_argument_parser(*args, **kwargs): 20 parser = argparse.ArgumentParser(*args, **kwargs) 21 parser.add_argument('--input-dir', required=True, help=argparse.SUPPRESS) 22 parser.add_argument( 23 '--output-file', required=True, help='where to store the merged data') 24 parser.add_argument( 25 '--llvm-profdata', required=True, help='path to llvm-profdata executable') 26 parser.add_argument( 27 '--profdata-filename-pattern', 28 default='.*', 29 help='regex pattern of profdata filename to merge for current test type. ' 30 'If not present, all profdata files will be merged.') 31 # TODO(crbug.com/1077304) - migrate this to sparse=False as default, and have 32 # --sparse to set sparse 33 parser.add_argument( 34 '--no-sparse', 35 action='store_false', 36 dest='sparse', 37 help='run llvm-profdata without the sparse flag.') 38 # TODO(crbug.com/1077304) - The intended behaviour is to default sparse to 39 # false. --no-sparse above was added as a workaround, and will be removed. 40 # This is being introduced now in support of the migration to intended 41 # behavior. Ordering of args matters here, as the default is set by the former 42 # (sparse defaults to False because of ordering. See merge_results unit tests 43 # for details) 44 parser.add_argument( 45 '--sparse', 46 action='store_true', 47 dest='sparse', 48 help='run llvm-profdata with the sparse flag.') 49 return parser 50 51 52def main(): 53 desc = "Merge profdata files in <--input-dir> into a single profdata." 54 parser = _merge_steps_argument_parser(description=desc) 55 params = parser.parse_args() 56 merger.merge_profiles(params.input_dir, params.output_file, '.profdata', 57 params.llvm_profdata, params.profdata_filename_pattern, 58 sparse=params.sparse) 59 60 61if __name__ == '__main__': 62 sys.exit(main()) 63