pick include-what-you-use from same path as iwyu_tool.py

Avoid that iwyu_tool.py relies on finding include-what-you-use from the
PATH, i.e. even if iwyu_tool.py is not in the path and gets executed by
absolute path, it should still succeed in finding the executable binary
include-what-you-use.
This commit is contained in:
Paul Seyfert 2017-08-07 16:56:47 +02:00 committed by Kim Gräsman
parent 94873ba1cb
commit 615507a3cd
1 changed files with 11 additions and 0 deletions

View File

@ -86,10 +86,21 @@ FORMATTERS = {
'clang': clang_formatter
}
def get_output(cwd, command):
""" Run the given command and return its output as a string. """
# Environment dictionary handling from https://stackoverflow.com/a/4453495
# ensures that: The current environment is not altered, instead it is
# copied for the child process, then the directory of iwyu_tool.py is
# prepended to the PATH variable.
env = os.environ.copy()
path_variable = os.path.dirname(__file__)
if 'PATH' in env:
path_variable += os.pathsep + env['PATH']
env['PATH'] = path_variable
process = subprocess.Popen(command,
cwd=cwd,
env=env,
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)