Skip to content

Commit 7688741

Browse files
authored
Invoke build tool via cmake --build in test-suite (#21)
Instead of directly invoking make, this patch teaches test-suite to call `cmake --build ...` instead, which abstracts away the underlying build tool. This fixes building when the CMake generator is overriden, e.g. with `CMAKE_GENERATOR=Ninja lnt runtest test-suite ...` The existing --use-make argument is kept and passed to CMAKE_MAKE_PROGRAM if set for compatibility.
1 parent c13ff67 commit 7688741

File tree

7 files changed

+93
-86
lines changed

7 files changed

+93
-86
lines changed

lnt/tests/test_suite.py

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,6 @@ def run_test(self, opts):
225225
opts.cmake = resolve_command_path(opts.cmake)
226226
if not isexecfile(opts.cmake):
227227
self._fatal("CMake tool not found (looked for %s)" % opts.cmake)
228-
opts.make = resolve_command_path(opts.make)
229-
if not isexecfile(opts.make):
230-
self._fatal("Make tool not found (looked for %s)" % opts.make)
231228
opts.lit = resolve_command_path(opts.lit)
232229
if not isexecfile(opts.lit):
233230
self._fatal("LIT tool not found (looked for %s)" % opts.lit)
@@ -387,7 +384,7 @@ def run(self, cmake_vars, compile=True, test=True, profile=False):
387384
if self.compiled and compile:
388385
self._clean(self._base_path)
389386
if not self.compiled or compile or self.opts.pgo:
390-
self._make(self._base_path)
387+
self._build(self._base_path)
391388
self._install_benchmark(self._base_path)
392389
self.compiled = True
393390

@@ -431,14 +428,14 @@ def _check_output(self, *args, **kwargs):
431428
return output
432429

433430
def _clean(self, path):
434-
make_cmd = self.opts.make
431+
cmake_cmd = self.opts.cmake
435432

436433
subdir = path
437434
if self.opts.only_test:
438435
components = [path] + [self.opts.only_test[0]]
439436
subdir = os.path.join(*components)
440437

441-
self._check_call([make_cmd, 'clean'],
438+
self._check_call([cmake_cmd, '--build', '.', '-t', 'clean'],
442439
cwd=subdir)
443440

444441
def _configure(self, path, extra_cmake_defs=[], execute=True):
@@ -449,6 +446,8 @@ def _configure(self, path, extra_cmake_defs=[], execute=True):
449446
defs['CMAKE_C_COMPILER'] = self.opts.cc
450447
if self.opts.cxx:
451448
defs['CMAKE_CXX_COMPILER'] = self.opts.cxx
449+
if self.opts.make:
450+
defs['CMAKE_MAKE_PROGRAM'] = self.opts.make
452451

453452
cmake_build_types = ('DEBUG', 'MINSIZEREL', 'RELEASE',
454453
'RELWITHDEBINFO')
@@ -560,12 +559,12 @@ def _collect_pgo(self, path):
560559
"TEST_SUITE_RUN_TYPE=train"]
561560
self._configure(path, extra_cmake_defs=extra_defs)
562561
self._clean(self._base_path)
563-
self._make(path)
562+
self._build(path)
564563
self._install_benchmark(path)
565564
self._lit(path, True, False)
566565

567-
def _make(self, path):
568-
make_cmd = self.opts.make
566+
def _build(self, path):
567+
cmake_cmd = self.opts.cmake
569568

570569
subdir = path
571570
target = 'all'
@@ -576,24 +575,23 @@ def _make(self, path):
576575
subdir = os.path.join(*components)
577576

578577
logger.info('Building...')
579-
if not self.opts.succinct:
580-
args = ["VERBOSE=1", target]
581-
else:
582-
args = [target]
583578
try:
584-
self._check_call([make_cmd,
585-
'-k', '-j', str(self._build_threads())] + args,
579+
self._check_call([cmake_cmd,
580+
'--build', '.',
581+
'-t', target,
582+
'-j', str(self._build_threads())] +
583+
([] if self.opts.succinct else ["-v"]),
586584
cwd=subdir)
587585
except subprocess.CalledProcessError:
588-
# make is expected to exit with code 1 if there was any build
586+
# cmake is expected to exit with code 1 if there was any build
589587
# failure. Build failures are not unexpected when testing an
590588
# experimental compiler.
591589
pass
592590

593591
def _install_benchmark(self, path):
594592
if self.remote_run:
595-
make_cmd = self.opts.make
596-
self._check_call([make_cmd, 'rsync'], cwd=path)
593+
cmake_cmd = self.opts.cmake
594+
self._check_call([cmake_cmd, '--build', '.', '-t', 'rsync'], cwd=path)
597595

598596
def _lit(self, path, test, profile):
599597
lit_cmd = self.opts.lit
@@ -898,30 +896,30 @@ def diagnose(self):
898896
logger.info(out)
899897

900898
# Figure out our test's target.
901-
make_cmd = [self.opts.make, "VERBOSE=1", 'help']
899+
cmake_cmd = [self.opts.cmake, '--build', '.', '-t', 'help']
902900

903-
make_targets = subprocess.check_output(make_cmd,
904-
universal_newlines=True)
901+
cmake_targets = subprocess.check_output(cmake_cmd,
902+
universal_newlines=True)
905903
matcher = re.compile(r"^\.\.\.\s{}$".format(short_name),
906904
re.MULTILINE | re.IGNORECASE)
907-
if not matcher.search(make_targets):
905+
if not matcher.search(cmake_targets):
908906
assert False, "did not find benchmark, nestsed? Unimplemented."
909907

910908
local_path = os.path.join(path, bm_path)
911909

912-
make_deps = [self.opts.make, "VERBOSE=1", "timeit-target",
913-
"timeit-host", "fpcmp-host"]
914-
logger.info(" ".join(make_deps))
915-
p = subprocess.Popen(make_deps,
910+
cmake_deps = [self.opts.cmake, "--build", '.', "-t", "timeit-target",
911+
"timeit-host", "fpcmp-host"]
912+
logger.info(" ".join(cmake_deps))
913+
p = subprocess.Popen(cmake_deps,
916914
stdout=subprocess.PIPE,
917915
stderr=subprocess.STDOUT,
918916
universal_newlines=True)
919917
std_out, std_err = p.communicate()
920918
logger.info(std_out)
921919

922-
make_save_temps = [self.opts.make, "VERBOSE=1", short_name]
923-
logger.info(" ".join(make_save_temps))
924-
p = subprocess.Popen(make_save_temps,
920+
cmake_save_temps = [self.opts.cmake, "--build", '.', "-t", short_name]
921+
logger.info(" ".join(cmake_save_temps))
922+
p = subprocess.Popen(cmake_save_temps,
925923
stdout=subprocess.PIPE,
926924
stderr=subprocess.STDOUT,
927925
universal_newlines=True)
@@ -951,8 +949,8 @@ def diagnose(self):
951949
out = subprocess.check_output(cmd_time_report, universal_newlines=True)
952950
logger.info(out)
953951

954-
make_time_report = [self.opts.make, "VERBOSE=1", short_name]
955-
p = subprocess.Popen(make_time_report,
952+
cmake_time_report = [self.opts.cmake, "--build", '.', "-t", short_name]
953+
p = subprocess.Popen(cmake_time_report,
956954
stdout=subprocess.PIPE,
957955
stderr=subprocess.PIPE,
958956
universal_newlines=True)
@@ -971,8 +969,8 @@ def diagnose(self):
971969
universal_newlines=True)
972970
logger.info(out)
973971

974-
make_stats_report = [self.opts.make, "VERBOSE=1", short_name]
975-
p = subprocess.Popen(make_stats_report,
972+
cmake_stats_report = [self.opts.cmake, "--build", '.', "-t", short_name]
973+
p = subprocess.Popen(cmake_stats_report,
976974
stdout=subprocess.PIPE,
977975
stderr=subprocess.PIPE,
978976
universal_newlines=True)
@@ -1002,8 +1000,8 @@ def diagnose(self):
10021000
subprocess.check_output(cmd_iprofiler, universal_newlines=True)
10031001

10041002
os.chdir(local_path)
1005-
make_iprofiler_temps = [self.opts.make, "VERBOSE=1", short_name]
1006-
p = subprocess.Popen(make_iprofiler_temps,
1003+
cmake_iprofiler_temps = [self.opts.cmake, "--build", '.', "-t", short_name]
1004+
p = subprocess.Popen(cmake_iprofiler_temps,
10071005
stdout=subprocess.PIPE,
10081006
stderr=subprocess.PIPE)
10091007
p.communicate()
@@ -1148,7 +1146,7 @@ def diagnose(self):
11481146
help="write raw report data to PATH (or stdout if '-')",
11491147
default=None)
11501148
@click.option("--succinct-compile-output", "succinct",
1151-
help="run Make without VERBOSE=1", is_flag=True)
1149+
help="run CMake without -v", is_flag=True)
11521150
@click.option("-v", "--verbose", "verbose", is_flag=True, default=False,
11531151
help="show verbose test results")
11541152
@click.option("--exclude-stat-from-submission",
@@ -1168,8 +1166,8 @@ def diagnose(self):
11681166
type=click.UNPROCESSED, default="cmake",
11691167
help="Path to CMake [cmake]")
11701168
@click.option("--use-make", "make", metavar="PATH",
1171-
type=click.UNPROCESSED, default="make",
1172-
help="Path to Make [make]")
1169+
type=click.UNPROCESSED,
1170+
help="Path to the build system tool [make/ninja/...]")
11731171
@click.option("--use-lit", "lit", metavar="PATH", type=click.UNPROCESSED,
11741172
default="llvm-lit",
11751173
help="Path to the LIT test runner [llvm-lit]")

tests/runtest/Inputs/test-suite-cmake/fake-cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ do
2323
DUMP_VARS=true
2424
shift
2525
shift
26+
elif [[ $1 == --build ]]; then
27+
source $(dirname "${BASH_SOURCE[0]}")/fake-make
28+
exit $?
2629
elif [[ ! -f $1/CMakeLists.txt && ! -f $1/CMakeCache.txt ]]; then
2730
# arguments not starting with -D or -C are assumed to point to the cmake
2831
# src or build dir
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
3+
if [[ $1 == --build && $2 == . && $3 == -t ]]
4+
then
5+
if [ "$4" == "help" ]
6+
then
7+
echo "The following are some of the valid targets for this Makefile:
8+
... all (the default if no target is provided)
9+
... short_circuit_dtor
10+
... pointer_method2
11+
... pointer_member
12+
... 2003-08-20-EnumSizeProblem
13+
... BuiltinTypeInfo
14+
... ofstream_ctor
15+
... 2003-05-14-expr_stmt
16+
... 2011-03-28-Bitfield
17+
... 2008-01-29-ParamAliasesReturn
18+
... pointer_method
19+
... global_ctor
20+
... 2003-06-08-VirtualFunctions
21+
... Shootout-C++-hash
22+
... Bubblesort
23+
... lists
24+
"
25+
elif [ "$4" == "Bubblesort" ]
26+
then
27+
# Look like we ran the test and made outputs
28+
mkdir -p SingleSource/Benchmarks/Stanford/CMakeFiles/Bubblesort.dir/
29+
mkdir -p SingleSource/Benchmarks/Stanford/Bubblesort.dtps
30+
touch SingleSource/Benchmarks/Stanford/Bubblesort.dtps/data
31+
touch SingleSource/Benchmarks/Stanford/${4}
32+
echo "RUN: Bubblesort | grep test" > SingleSource/Benchmarks/Stanford/${4}.test
33+
echo "output file" > SingleSource/Benchmarks/Stanford/${4}.s
34+
echo "output file" > SingleSource/Benchmarks/Stanford/${4}.i
35+
echo "output file" > SingleSource/Benchmarks/Stanford/${4}.bc
36+
echo "output file" > SingleSource/Benchmarks/Stanford/CMakeFiles/Bubblesort.dir/${4}.o
37+
(>&2 echo "ftime-report data")
38+
else
39+
echo "Unexpected Argument"
40+
exit 1
41+
fi
42+
else
43+
source $(dirname "${BASH_SOURCE[0]}")/fake-cmake "$@"
44+
exit $?
45+
fi

tests/runtest/Inputs/test-suite-cmake/fake-diagnose-make

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

tests/runtest/test_suite-only-test.shtest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
# CHECK-ONLYTEST: Configuring with {
1818
# CHECK-ONLYTEST: one: 'two'
1919
# CHECK-ONLYTEST: three: 'four'
20-
# CHECK-ONLYTEST: Execute: {{.*}}/fake-make -k -j 1 VERBOSE=1 subtest
20+
# CHECK-ONLYTEST: Execute: {{.*}}/fake-cmake --build . -t subtest -j 1 -v

tests/runtest/test_suite-pgo.shtest

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,20 @@
3232
# RUN: > %t.pgo_multi.log 2> %t.pgo_multi.err
3333
# RUN: FileCheck --check-prefix CHECK-PGO-MULTI < %t.pgo_multi.err %s
3434
# CHECK-PGO-MULTI: TEST_SUITE_PROFILE_GENERATE: 'On'
35-
# CHECK-PGO-MULTI: Execute: {{.*}}/Inputs/test-suite-cmake/fake-make{{.*}} all
35+
# CHECK-PGO-MULTI: Execute: {{.*}}/Inputs/test-suite-cmake/fake-cmake --build {{.*}} -t all
3636
# CHECK-PGO-MULTI: fake-lit-profile
3737
# CHECK-PGO-MULTI: TEST_SUITE_PROFILE_GENERATE: 'Off'
3838
# CHECK-PGO-MULTI: TEST_SUITE_PROFILE_USE: 'On'
39-
# CHECK-PGO-MULTI: Execute: {{.*}}/Inputs/test-suite-cmake/fake-make{{.*}} clean
40-
# CHECK-PGO-MULTI: Execute: {{.*}}/Inputs/test-suite-cmake/fake-make{{.*}} all
39+
# CHECK-PGO-MULTI: Execute: {{.*}}/Inputs/test-suite-cmake/fake-cmake --build {{.*}} -t clean
40+
# CHECK-PGO-MULTI: Execute: {{.*}}/Inputs/test-suite-cmake/fake-cmake --build {{.*}} -t all
4141
# CHECK-PGO-MULTI: fake-lit-profile
4242
# CHECK-PGO-MULTI: TEST_SUITE_PROFILE_GENERATE: 'On'
4343
# CHECK-PGO-MULTI: TEST_SUITE_PROFILE_USE: 'Off'
44-
# CHECK-PGO-MULTI: Execute: {{.*}}/Inputs/test-suite-cmake/fake-make{{.*}} clean
45-
# CHECK-PGO-MULTI: Execute: {{.*}}/Inputs/test-suite-cmake/fake-make{{.*}} all
44+
# CHECK-PGO-MULTI: Execute: {{.*}}/Inputs/test-suite-cmake/fake-cmake --build {{.*}} -t clean
45+
# CHECK-PGO-MULTI: Execute: {{.*}}/Inputs/test-suite-cmake/fake-cmake --build {{.*}} -t all
4646
# CHECK-PGO-MULTI: fake-lit-profile
4747
# CHECK-PGO-MULTI: TEST_SUITE_PROFILE_GENERATE: 'Off'
4848
# CHECK-PGO-MULTI: TEST_SUITE_PROFILE_USE: 'On'
49-
# CHECK-PGO-MULTI: Execute: {{.*}}/Inputs/test-suite-cmake/fake-make{{.*}} clean
50-
# CHECK-PGO-MULTI: Execute: {{.*}}/Inputs/test-suite-cmake/fake-make{{.*}} all
49+
# CHECK-PGO-MULTI: Execute: {{.*}}/Inputs/test-suite-cmake/fake-cmake --build {{.*}} -t clean
50+
# CHECK-PGO-MULTI: Execute: {{.*}}/Inputs/test-suite-cmake/fake-cmake --build {{.*}} -t all
5151
# CHECK-PGO-MULTI: fake-lit-profile

tests/runtest/test_suite_diagnose.shtest

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
# RUN: --no-timestamp \
2525
# RUN: --test-suite %S/Inputs/test-suite-cmake \
2626
# RUN: --cc %{shared_inputs}/FakeCompilers/clang-r154331 \
27-
# RUN: --use-cmake %S/Inputs/test-suite-cmake/fake-cmake \
28-
# RUN: --use-make %S/Inputs/test-suite-cmake/fake-diagnose-make \
27+
# RUN: --use-cmake %S/Inputs/test-suite-cmake/fake-diagnose-cmake \
2928
# RUN: --use-lit %S/Inputs/test-suite-cmake/fake-lit \
3029
# RUN: --diagnose --only-test SingleSource/Benchmarks/Stanford/Bubblesort \
3130
# RUN: 2>&1 | tee %t.diagnose.log

0 commit comments

Comments
 (0)