14
14
import logging
15
15
import os
16
16
import pipes
17
- import subprocess
17
+ import sys
18
18
19
19
from multiprocessing import Process
20
20
21
21
22
+ # hack to import SwiftBuildSupport and swift_build_support
23
+ parent_dir = os .path .join (os .path .dirname (os .path .abspath (__file__ )), '..' )
24
+ sys .path .append (parent_dir )
25
+ support_dir = os .path .join (parent_dir , 'swift_build_support' )
26
+ sys .path .append (support_dir )
27
+ from swift_build_support import xcrun # noqa (E402)
28
+ from SwiftBuildSupport import check_output , check_call # noqa (E402)
29
+
30
+ # FIXME: This doesn't work on non-Darwin platforms.
31
+ LLVM_PROFDATA_PATH = xcrun .find ('default' , 'llvm-profdata' )
32
+ _profdata_help = check_output ([LLVM_PROFDATA_PATH , 'merge' , '-help' ])
33
+ LLVM_PROFDATA_SUPPORTS_SPARSE = 'sparse' in _profdata_help
34
+
35
+
22
36
class ProfdataMergerProcess (Process ):
23
37
def __init__ (self , config , file_queue ):
24
38
super (ProfdataMergerProcess , self ).__init__ ()
@@ -45,13 +59,13 @@ def merge_file_buffer(self):
45
59
if os .path .exists (self .profdata_path ):
46
60
os .rename (self .profdata_path , self .profdata_tmp_path )
47
61
self .filename_buffer .append (self .profdata_tmp_path )
48
- cleaned_files = ' ' . join ( pipes .quote (f ) for f in self .filename_buffer )
49
- # FIXME: This doesn't necessarily always line up with the version
50
- # of clang++ used to build the binaries.
51
- llvm_cmd = ( "xcrun llvm-profdata merge -o %s %s"
52
- % ( self . profdata_path , cleaned_files ))
62
+ cleaned_files = [ pipes .quote (f ) for f in self .filename_buffer ]
63
+ llvm_cmd = [ LLVM_PROFDATA_PATH , "merge" , "-o" , self . profdata_path ]
64
+ if LLVM_PROFDATA_SUPPORTS_SPARSE :
65
+ llvm_cmd . append ( "-sparse" )
66
+ llvm_cmd += cleaned_files
53
67
self .report (llvm_cmd )
54
- ret = subprocess . call (llvm_cmd , shell = True )
68
+ ret = check_call (llvm_cmd )
55
69
if ret != 0 :
56
70
self .report ("llvm profdata command failed -- Exited with code %d"
57
71
% ret , level = logging .ERROR )
0 commit comments