cppcheck Popen usage improvements (stderr issues)

pull/353/head
Przemek Wirkus 2014-06-11 17:08:35 +01:00
parent d58d532ebc
commit 74a051e5e6
2 changed files with 46 additions and 47 deletions

View File

@ -276,22 +276,22 @@ def static_analysis_scan(target, toolchain_name, CPPCHECK_CMD, CPPCHECK_MSG_FORM
cpp_sources = " ".join(resources.cpp_sources) cpp_sources = " ".join(resources.cpp_sources)
macros = ['-D%s' % s for s in toolchain.get_symbols() + toolchain.macros] macros = ['-D%s' % s for s in toolchain.get_symbols() + toolchain.macros]
check_cmd = " ".join(CPPCHECK_CMD) + " " includes = map(str.strip, includes)
check_cmd += " ".join(CPPCHECK_MSG_FORMAT) + " " macros = map(str.strip, macros)
check_cmd += " ".join(includes)
check_cmd += " ".join(macros)
# moved to --file-list file
# check_cmd += c_sources
# check_cmd += " " + cpp_sources
# We need to pass some parames via file to avoid "command line too long in some OSs" check_cmd = CPPCHECK_CMD
check_cmd += CPPCHECK_MSG_FORMAT
check_cmd += includes
check_cmd += macros
# We need to pass some params via file to avoid "command line too long in some OSs"
tmp_file = tempfile.NamedTemporaryFile(delete=False) tmp_file = tempfile.NamedTemporaryFile(delete=False)
tmp_file.writelines(line + '\n' for line in c_sources.split()) tmp_file.writelines(line + '\n' for line in c_sources.split())
tmp_file.writelines(line + '\n' for line in cpp_sources.split()) tmp_file.writelines(line + '\n' for line in cpp_sources.split())
tmp_file.close() tmp_file.close()
check_cmd += " --file-list=%s"% tmp_file.name check_cmd += ["--file-list=%s"% tmp_file.name]
_stdout, _stderr, _rc = run_cmd_ext(check_cmd.split() if os.name == 'posix' else check_cmd) _stdout, _stderr, _rc = run_cmd(check_cmd)
if verbose: if verbose:
print _stdout print _stdout
print _stderr print _stderr
@ -332,16 +332,15 @@ def static_analysis_scan(target, toolchain_name, CPPCHECK_CMD, CPPCHECK_MSG_FORM
mbed_c_sources = " ".join(mbed_resources.c_sources) mbed_c_sources = " ".join(mbed_resources.c_sources)
mbed_cpp_sources = " ".join(mbed_resources.cpp_sources) mbed_cpp_sources = " ".join(mbed_resources.cpp_sources)
check_cmd = " ".join(CPPCHECK_CMD) + " " target_includes = map(str.strip, target_includes)
check_cmd += " ".join(CPPCHECK_MSG_FORMAT) + " " mbed_includes = map(str.strip, mbed_includes)
check_cmd += " ".join(target_includes) target_macros = map(str.strip, target_macros)
check_cmd += " ".join(mbed_includes)
check_cmd += " ".join(target_macros) check_cmd = CPPCHECK_CMD
# moved to --file-list file check_cmd += CPPCHECK_MSG_FORMAT
# check_cmd += " " + target_c_sources check_cmd += target_includes
# check_cmd += " " + target_cpp_sources check_cmd += mbed_includes
# check_cmd += " " + mbed_c_sources check_cmd += target_macros
# check_cmd += " " + mbed_cpp_sources
# We need to pass some parames via file to avoid "command line too long in some OSs" # We need to pass some parames via file to avoid "command line too long in some OSs"
tmp_file = tempfile.NamedTemporaryFile(delete=False) tmp_file = tempfile.NamedTemporaryFile(delete=False)
@ -350,9 +349,9 @@ def static_analysis_scan(target, toolchain_name, CPPCHECK_CMD, CPPCHECK_MSG_FORM
tmp_file.writelines(line + '\n' for line in mbed_c_sources.split()) tmp_file.writelines(line + '\n' for line in mbed_c_sources.split())
tmp_file.writelines(line + '\n' for line in mbed_cpp_sources.split()) tmp_file.writelines(line + '\n' for line in mbed_cpp_sources.split())
tmp_file.close() tmp_file.close()
check_cmd += " --file-list=%s"% tmp_file.name check_cmd += ["--file-list=%s"% tmp_file.name]
_stdout, _stderr, _rc = run_cmd_ext(check_cmd.split() if os.name == 'posix' else check_cmd) _stdout, _stderr, _rc = run_cmd_ext(check_cmd)
if verbose: if verbose:
print _stdout print _stdout
print _stderr print _stderr
@ -419,22 +418,22 @@ def static_analysis_scan_library(src_paths, build_path, target, toolchain_name,
dependencies_include_dir.extend(toolchain.scan_resources(build_path).inc_dirs) dependencies_include_dir.extend(toolchain.scan_resources(build_path).inc_dirs)
check_cmd = " ".join(CPPCHECK_CMD) + " " includes = map(str.strip, includes)
check_cmd += " ".join(CPPCHECK_MSG_FORMAT) + " " macros = map(str.strip, macros)
check_cmd += " ".join(includes)
check_cmd += " ".join(macros) check_cmd = CPPCHECK_CMD
# moved to --file-list file check_cmd += CPPCHECK_MSG_FORMAT
# check_cmd += " " + c_sources check_cmd += includes
# check_cmd += " " + cpp_sources check_cmd += macros
# We need to pass some parames via file to avoid "command line too long in some OSs" # We need to pass some parames via file to avoid "command line too long in some OSs"
tmp_file = tempfile.NamedTemporaryFile(delete=False) tmp_file = tempfile.NamedTemporaryFile(delete=False)
tmp_file.writelines(line + '\n' for line in c_sources.split()) tmp_file.writelines(line + '\n' for line in c_sources.split())
tmp_file.writelines(line + '\n' for line in cpp_sources.split()) tmp_file.writelines(line + '\n' for line in cpp_sources.split())
tmp_file.close() tmp_file.close()
check_cmd += " --file-list=%s"% tmp_file.name check_cmd += ["--file-list=%s"% tmp_file.name]
_stdout, _stderr, _rc = run_cmd_ext(check_cmd.split() if os.name == 'posix' else check_cmd) _stdout, _stderr, _rc = run_cmd_ext(check_cmd)
if verbose: if verbose:
print _stdout print _stdout
print _stderr print _stderr

View File

@ -73,7 +73,7 @@ GOANNA_PATH = "c:/Program Files (x86)/RedLizards/Goanna Central 3.1.4/bin"
# cppcheck path (command) and output message format # cppcheck path (command) and output message format
CPPCHECK_CMD = ["cppcheck", "--enable=all"] CPPCHECK_CMD = ["cppcheck", "--enable=all"]
CPPCHECK_MSG_FORMAT = ["--template=\"[{severity}] {file}@{line}: {id}:{message}\""] CPPCHECK_MSG_FORMAT = ["--template=[{severity}] {file}@{line}: {id}:{message}"]
BUILD_OPTIONS = [] BUILD_OPTIONS = []