Skip to content

Commit 056f4ce

Browse files
author
Harlan
committed
Merge pull request #1775 from harlanhaskins/profdata-sparse
[build_support] Added -sparse option for llvm-profdata if supported
2 parents 54b6aaa + 011ab6f commit 056f4ce

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

utils/profdata_merge/process.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,25 @@
1414
import logging
1515
import os
1616
import pipes
17-
import subprocess
17+
import sys
1818

1919
from multiprocessing import Process
2020

2121

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+
2236
class ProfdataMergerProcess(Process):
2337
def __init__(self, config, file_queue):
2438
super(ProfdataMergerProcess, self).__init__()
@@ -45,13 +59,13 @@ def merge_file_buffer(self):
4559
if os.path.exists(self.profdata_path):
4660
os.rename(self.profdata_path, self.profdata_tmp_path)
4761
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
5367
self.report(llvm_cmd)
54-
ret = subprocess.call(llvm_cmd, shell=True)
68+
ret = check_call(llvm_cmd)
5569
if ret != 0:
5670
self.report("llvm profdata command failed -- Exited with code %d"
5771
% ret, level=logging.ERROR)

0 commit comments

Comments
 (0)