Index: lnt/tests/test_suite.py =================================================================== --- lnt/tests/test_suite.py +++ lnt/tests/test_suite.py @@ -580,11 +580,13 @@ def _test_threads(self): return self.opts.threads - def _check_call(self, *args, **kwargs): + def _check_output(self, *args, **kwargs): note('Execute: %s' % ' '.join(args[0])) if 'cwd' in kwargs: note(' (In %s)' % kwargs['cwd']) - return subprocess.check_call(*args, **kwargs) + output = subprocess.check_output(*args, **kwargs) + sys.stdout.write(output) + return output def _clean(self, path): make_cmd = self.opts.make @@ -594,8 +596,8 @@ components = [path] + [self.opts.only_test[0]] subdir = os.path.join(*components) - self._check_call([make_cmd, 'clean'], - cwd=subdir) + self._check_output([make_cmd, 'clean'], + cwd=subdir) def _configure(self, path, extra_cmake_defs=[], execute=True): cmake_cmd = self.opts.cmake @@ -632,11 +634,30 @@ if self.opts.cmake_defines: for item in self.opts.cmake_defines: k, v = item.split('=', 1) + # make sure the overriding of the settings above also works + # when the cmake-define-defined variable has a datatype + # specified. + key_no_datatype = k.split(':', 1)[0] + if key_no_datatype in defs: + del defs[key_no_datatype] defs[k] = v + for item in extra_cmake_defs: k, v = item.split('=', 1) defs[k] = v + # We use 'cmake -LAH -N' later to find out the value of the + # CMAKE_C_COMPILER and CMAKE_CXX_COMPILER variables. + # 'cmake -LAH -N' will only return variables in the cache that have + # a cmake type set. Therefore, explicitly set a 'FILEPATH' type on + # these variables here, if they were untyped so far. + if 'CMAKE_C_COMPILER' in defs: + defs['CMAKE_C_COMPILER:FILEPATH'] = defs['CMAKE_C_COMPILER'] + del defs['CMAKE_C_COMPILER'] + if 'CMAKE_CXX_COMPILER' in defs: + defs['CMAKE_CXX_COMPILER:FILEPATH'] = defs['CMAKE_CXX_COMPILER'] + del defs['CMAKE_CXX_COMPILER'] + lines = ['Configuring with {'] for k, v in sorted(defs.items()): lines.append(" %s: '%s'" % (k, v)) @@ -659,7 +680,7 @@ cmake_cmd = [cmake_cmd] + cmake_flags + [self._test_suite_dir()] + \ ['-D%s=%s' % (k, v) for k, v in defs.items()] if execute: - self._check_call(cmake_cmd, cwd=path) + self._check_output(cmake_cmd, cwd=path) return cmake_cmd @@ -687,7 +708,7 @@ else: args = [target] try: - self._check_call([make_cmd, + self._check_output([make_cmd, '-k', '-j', str(self._build_threads())] + args, cwd=subdir) except subprocess.CalledProcessError: @@ -718,11 +739,11 @@ note('Testing...') try: - self._check_call([lit_cmd, - '-v', - '-j', str(self._test_threads()), - subdir, - '-o', output_json_path.name] + extra_args) + self._check_output([lit_cmd, + '-v', + '-j', str(self._test_threads()), + subdir, + '-o', output_json_path.name] + extra_args) except subprocess.CalledProcessError: # LIT is expected to exit with code 1 if there were test # failures! @@ -745,14 +766,42 @@ name = raw_name.rsplit('.test', 1)[0] return not os.path.exists(os.path.join(path, name)) - def _get_target_flags(self): - assert self.configured is True - return shlex.split(self.opts.cppflags + self.opts.cflags) + def _get_target_flags(self, cmake_vars): + build_type = cmake_vars["build_type"] + cflags = cmake_vars["c_flags"] + if build_type != "": + cflags = \ + " ".join(cflags.split(" ") + + cmake_vars["c_flags_"+build_type.lower()].split(" ")) + return shlex.split(cflags) def _get_cc_info(self): assert self.configured is True - return lnt.testing.util.compilers.get_cc_info(self.opts.cc, - self._get_target_flags()) + cmake_lah_output = self._check_output( + [self.opts.cmake] + ['-LAH', '-N'] + [self._get_path()]) + pattern2var = [ + (re.compile("%s:[^=]*=(.*)$" % cmakevar), var) + for cmakevar, var in ( + ("CMAKE_C_COMPILER", "cc"), + ("CMAKE_BUILD_TYPE", "build_type"), + ("CMAKE_CXX_FLAGS", "cxx_flags"), + ("CMAKE_CXX_FLAGS_DEBUG", "cxx_flags_debug"), + ("CMAKE_CXX_FLAGS_MINSIZEREL", "cxx_flags_minsizerel"), + ("CMAKE_CXX_FLAGS_RELEASE", "cxx_flags_release"), + ("CMAKE_CXX_FLAGS_RELWITHDEBINFO", "cxx_flags_relwithdebinfo"), + ("CMAKE_C_FLAGS", "c_flags"), + ("CMAKE_C_FLAGS_DEBUG", "c_flags_debug"), + ("CMAKE_C_FLAGS_MINSIZEREL", "c_flags_minsizerel"), + ("CMAKE_C_FLAGS_RELEASE", "c_flags_release"), + ("CMAKE_C_FLAGS_RELWITHDEBINFO", "c_flags_relwithdebinfo"),)] + cmake_vars = {} + for line in cmake_lah_output.split("\n"): + for pattern, varname in pattern2var: + m = re.search(pattern, line) + if m: + cmake_vars[varname] = m.group(1) + return lnt.testing.util.compilers.get_cc_info( + cmake_vars["cc"], self._get_target_flags(cmake_vars)) def _parse_lit_output(self, path, data, only_test=False): LIT_METRIC_TO_LNT = { Index: tests/SharedInputs/FakeCompilers/clang++-r154332 =================================================================== --- /dev/null +++ tests/SharedInputs/FakeCompilers/clang++-r154332 @@ -0,0 +1 @@ +fakecompiler.py \ No newline at end of file Index: tests/SharedInputs/FakeCompilers/clang-r154332 =================================================================== --- /dev/null +++ tests/SharedInputs/FakeCompilers/clang-r154332 @@ -0,0 +1 @@ +fakecompiler.py \ No newline at end of file Index: tests/SharedInputs/FakeCompilers/fakecompiler.py =================================================================== --- tests/SharedInputs/FakeCompilers/fakecompiler.py +++ tests/SharedInputs/FakeCompilers/fakecompiler.py @@ -80,6 +80,20 @@ "%s" "-cc1" "-E" ... more boring stuff here ...""" % ( g_program,) +class Clang_r154332(LLVMCompiler): + compiler_name = "clang-r154332" + + def print_verbose_info(self): + print >>sys.stderr, """\ +clang version 3.1 (trunk 154332) (llvm/trunk 154329) +Target: x86_64-apple-darwin11.3.0 +Thread model: posix +InstalledDir: /home/foo/bin +""" + print >>sys.stderr, """\ + "%s" "-cc1" "-E" ... more boring stuff here ...""" % ( + g_program,) + # Clang build from a git repository. class Clang_git(LLVMCompiler): compiler_name = "clang-git" Index: tests/runtest/Inputs/test-suite-cmake/fake-cmake =================================================================== --- tests/runtest/Inputs/test-suite-cmake/fake-cmake +++ tests/runtest/Inputs/test-suite-cmake/fake-cmake @@ -1,17 +1,56 @@ #!/bin/bash -# If we passed a cache, just drop it and look like cmake. -if [[ $1 == "-C" ]]; then +CMAKE_SRC_DIR="notfound" +DUMP_VARS=false +CMAKE_C_COMPILER="" +CMAKE_CXX_COMPILER="" + +while test $# -gt 0 +do + if [[ $1 == "-C" ]]; then + # If we passed a cache, just drop it and look like cmake. echo "Cmake Cache $2" shift - shift -fi -if [[ ! -f $1/CMakeLists.txt ]]; then - exit 1 + shift + elif [[ $1 == -D* ]]; then + # handle -D arguments to cmake. + if [[ $1 == -DCMAKE_C_COMPILER:* ]]; then CMAKE_C_COMPILER=${1#*=}; fi + if [[ $1 == -DCMAKE_CXX_COMPILER:* ]]; then CMAKE_CXX_COMPILER=${1#*=}; fi + shift + elif [[ $1 == -LAH && $2 == -N ]]; then + DUMP_VARS=true + shift + shift + elif [[ ! -f $1/CMakeLists.txt && ! -f $1/CMakeCache.txt ]]; then + # arguments not starting with -D or -C are assumed to point to the cmake + # src or build dir + exit 1 + else + CMAKE_SRC_DIR=$1 + # if CMakeCache.txt exists, read in value for compiler + if [[ -f $1/CMakeCache.txt ]]; then + CMAKE_C_COMPILER=`grep CMAKE_C_COMPILER:FILEPATH= $1/CMakeCache.txt | cut -f2 -d'='` + CMAKE_CXX_COMPILER=`grep CMAKE_CXX_COMPILER:FILEPATH= $1/CMakeCache.txt | cut -f2 -d'='` + fi + shift + fi +done + +if [[ $DUMP_VARS == "true" ]] +then + echo CMAKE_C_COMPILER:FILEPATH=$CMAKE_C_COMPILER + echo CMAKE_CXX_COMPILER:FILEPATH=$CMAKE_CXX_COMPILER + echo CMAKE_BUILD_TYPE:STRING=RelWithDebInfo + echo CMAKE_C_FLAGS:STRING=-O0 + echo CMAKE_CXX_FLAGS:STRING= + echo CMAKE_C_FLAGS_RELWITHDEBINFO:STRING=-O2 -g + echo CMAKE_CXX_FLAGS_RELWITHDEBINFO:STRING=-O2 -g else - cp $1/fake-test $1/fake-results.json $1/fake-results-profile.json . + cp $CMAKE_SRC_DIR/fake-test $CMAKE_SRC_DIR/fake-results.json $CMAKE_SRC_DIR/fake-results-profile.json . echo "Dummy" > CMakeCache.txt + echo CMAKE_C_COMPILER:FILEPATH=$CMAKE_C_COMPILER >> CMakeCache.txt + echo CMAKE_CXX_COMPILER:FILEPATH=$CMAKE_CXX_COMPILER >> CMakeCache.txt mkdir subtest - cp $1/fake-test $1/fake-results.json subtest - exit 0 + cp $CMAKE_SRC_DIR/fake-test $CMAKE_SRC_DIR/fake-results.json subtest fi +exit 0 Index: tests/runtest/test_suite.py =================================================================== --- tests/runtest/test_suite.py +++ tests/runtest/test_suite.py @@ -380,6 +380,22 @@ # RUN: FileCheck --check-prefix CHECK-MISSING-CC < %t.err %s # CHECK-MISSING-CC: error: --cc is required +# Check on conflicting -cc and -cmake-define=CMAKE_C_COMPILER +# options, the right compiler gets stored in the json report +# RUN: lnt runtest test-suite \ +# RUN: --sandbox %t.SANDBOX \ +# RUN: --no-timestamp \ +# RUN: --test-suite %S/Inputs/test-suite-cmake \ +# RUN: --cmake-define=CMAKE_C_COMPILER:STRING=%{shared_inputs}/FakeCompilers/clang-r154332 \ +# RUN: --cc %{shared_inputs}/FakeCompilers/clang-r154331 \ +# RUN: --use-cmake %S/Inputs/test-suite-cmake/fake-cmake \ +# RUN: --use-make %S/Inputs/test-suite-cmake/fake-make \ +# RUN: --use-lit %S/Inputs/test-suite-cmake/fake-lit \ +# RUN: > %t.log 2> %t.err || true +# RUN: FileCheck --check-prefix CHECK-CC-CONFL-CMAKEDEFINE < %t.SANDBOX/build/report.json %s +# CHECK-CC-CONFL-CMAKEDEFINE: "run_order": "154332" + + # Check running with PGO # RUN: lnt runtest test-suite \ # RUN: --sandbox %t.SANDBOX \