blob: e233c2c6efec0f0a9afe77e0b6fd91103958820b [file] [log] [blame]
Vedant Kumard9aed822016-06-13 23:33:48 +00001#!/usr/bin/env python
2
3'''Prepare a code coverage artifact.
4
5- Collate raw profiles into one indexed profile.
6- Delete the raw profiles.
7- Copy the coverage mappings in the binaries directory.
8'''
9
10import argparse
11import glob
12import os
13import subprocess
14import sys
15
16def merge_raw_profiles(host_llvm_profdata, profile_data_dir):
17 print ':: Merging raw profiles...',
18 sys.stdout.flush()
19 raw_profiles = glob.glob(os.path.join(profile_data_dir, '*.profraw'))
20 manifest_path = os.path.join(profile_data_dir, 'profiles.manifest')
21 profdata_path = os.path.join(profile_data_dir, 'Coverage.profdata')
22 with open(manifest_path, 'w') as manifest:
23 manifest.write('\n'.join(raw_profiles))
24 subprocess.check_call([host_llvm_profdata, 'merge', '-sparse', '-f',
25 manifest_path, '-o', profdata_path])
26 for raw_profile in raw_profiles:
27 os.remove(raw_profile)
28 print 'Done!'
29
30def extract_covmappings(host_llvm_cov, profile_data_dir, llvm_bin_dir):
31 print ':: Extracting covmappings...',
32 sys.stdout.flush()
33 for prog in os.listdir(llvm_bin_dir):
34 if prog == 'llvm-lit':
35 continue
36 covmapping_path = os.path.join(profile_data_dir,
37 os.path.basename(prog) + '.covmapping')
38 subprocess.check_call([host_llvm_cov, 'convert-for-testing',
39 os.path.join(llvm_bin_dir, prog), '-o',
40 covmapping_path])
41 print 'Done!'
42
43if __name__ == '__main__':
44 parser = argparse.ArgumentParser(description=__doc__)
45 parser.add_argument('host_llvm_profdata', help='Path to llvm-profdata')
46 parser.add_argument('host_llvm_cov', help='Path to llvm-cov')
47 parser.add_argument('profile_data_dir',
48 help='Path to the directory containing the raw profiles')
49 parser.add_argument('llvm_bin_dir',
50 help='Path to the directory containing llvm binaries')
51 args = parser.parse_args()
52
53 merge_raw_profiles(args.host_llvm_profdata, args.profile_data_dir)
54 extract_covmappings(args.host_llvm_cov, args.profile_data_dir,
55 args.llvm_bin_dir)