Skip to content

Commit f3a3fc5

Browse files
committed
gtest: remove recursive make, add python driver + Xcode error hook-up.
This change does the following: * Removes the gtest/Makefile recursive-make-based calling strategy for gtest execution. * Adds the gtest/do-gtest.py call script. - This handles finding and calling the Makefiles that really run tests. - This script also transforms the test output into something that Xcode can place a failure marker on when a test fails. * Modifies the Xcode external build command target for gtest. It now calls the gtest/do-gtest.py script. There is still room for improvement on Xcode integration of do-gtest.py. Essentially the next several lines of error reporting from the gtest output should be coalesced into a single line so that Xcode can tell more about the error directly in the editor. Right now it just puts a red mark and says "failure" but doesn't give any details. llvm-svn: 218470
1 parent 129c44c commit f3a3fc5

File tree

4 files changed

+84
-14
lines changed

4 files changed

+84
-14
lines changed

lldb/gtest/Makefile

Lines changed: 0 additions & 5 deletions
This file was deleted.

lldb/gtest/do-gtest.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/usr/bin/env python
2+
3+
from __future__ import print_function
4+
5+
import os
6+
import re
7+
import select
8+
import subprocess
9+
import sys
10+
11+
def find_makefile_dirs():
12+
makefile_dirs = []
13+
for root, dirs, files in os.walk("."):
14+
for file in files:
15+
if file == "Makefile":
16+
makefile_dirs.append(root)
17+
return makefile_dirs
18+
19+
_TESTDIR_RELATIVE_REGEX = re.compile(r"^([^/:]+:\d+:)")
20+
21+
def filter_run_line(sub_expr, line):
22+
return _TESTDIR_RELATIVE_REGEX.sub(sub_expr, line)
23+
24+
def call_make(makefile_dir, extra_args=None):
25+
command = ["make", "-C", makefile_dir]
26+
if extra_args:
27+
command.extend(extra_args)
28+
29+
# Replace the matched no-directory filename with one where the makefile directory is prepended.
30+
sub_expr = makefile_dir + r"/\1";
31+
32+
proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
33+
34+
while True:
35+
reads = [proc.stdout.fileno(), proc.stderr.fileno()]
36+
select_result = select.select(reads, [], [])
37+
38+
for fd in select_result[0]:
39+
if fd == proc.stdout.fileno():
40+
line = proc.stdout.readline()
41+
print(filter_run_line(sub_expr, line.rstrip()))
42+
elif fd == proc.stderr.fileno():
43+
line = proc.stderr.readline()
44+
print(filter_run_line(sub_expr, line.rstrip()), file=sys.stderr)
45+
46+
proc_retval = proc.poll()
47+
if proc_retval != None:
48+
# Process stopped. Drain output before finishing up.
49+
50+
# Drain stdout.
51+
while True:
52+
line = proc.stdout.readline()
53+
if line:
54+
print(filter_run_line(sub_expr, line.rstrip()))
55+
else:
56+
break
57+
58+
# Drain stderr.
59+
while True:
60+
line = proc.stderr.readline()
61+
if line:
62+
print(filter_run_line(sub_expr, line.rstrip()), file=sys.stderr)
63+
else:
64+
break
65+
66+
return proc_retval
67+
68+
69+
global_retval = 0
70+
extra_args = None
71+
72+
if len(sys.argv) > 1:
73+
if sys.argv[1] == 'clean':
74+
extra_args = ['clean']
75+
76+
for makefile_dir in find_makefile_dirs():
77+
print("found makefile dir: {}".format(makefile_dir))
78+
retval = call_make(makefile_dir, extra_args)
79+
if retval != 0:
80+
global_retval = retval
81+
82+
sys.exit(global_retval)

lldb/gtest/gtest.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@
6767
/* Begin PBXLegacyTarget section */
6868
23CDD8F319D4790700461DDC /* gtest */ = {
6969
isa = PBXLegacyTarget;
70-
buildArgumentsString = "$(ACTION)";
70+
buildArgumentsString = "do-gtest.py $(ACTION)";
7171
buildConfigurationList = 23CDD8F619D4790700461DDC /* Build configuration list for PBXLegacyTarget "gtest" */;
7272
buildPhases = (
7373
);
74-
buildToolPath = /usr/bin/make;
74+
buildToolPath = /usr/bin/python;
7575
buildWorkingDirectory = .;
7676
dependencies = (
7777
);

lldb/gtest/unittest/Makefile

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)