Fix the options to analyze the dependencies of C++ files
@@ -7,7 +7,6 @@ import shlex
import shutil
import subprocess
import sys
-import tempfile
from logging import getLogger
from typing import *
@@ -44,19 +43,14 @@ class CPlusPlusLanguageEnvironment(LanguageEnvironment):
@functools.lru_cache(maxsize=None)
def _cplusplus_list_depending_files(path: pathlib.Path, *, CXX: pathlib.Path, joined_CXXFLAGS: str) -> List[pathlib.Path]:
- # Using /dev/stdout is acceptable because Library Chcker doesn't work on Windows.
is_windows = (platform.uname().system == 'Windows')
- with tempfile.TemporaryDirectory() as temp_dir:
- temp_file = pathlib.Path(temp_dir) / 'dependencies.txt'
- command = [str(CXX), *shlex.split(joined_CXXFLAGS), '-MD', '-MF', str(temp_file), '-MM', str(path)]
+ command = [str(CXX), *shlex.split(joined_CXXFLAGS), '-MM', str(path)]
try:
- subprocess.check_call(command)
+ data = subprocess.check_output(command)
except subprocess.CalledProcessError:
logger.error("failed to analyze dependencies with %s: %s (hint: Please check #include directives of the file and its dependencies. The paths must exist, must not contain '\\', and must be case-sensitive.)", CXX, str(path))
print(f'::warning file={str(path)}::failed to analyze dependencies', file=sys.stderr)
raise
- with open(temp_file, 'rb') as fp:
- data = fp.read()
logger.debug('dependencies of %s: %s', str(path), repr(data))
makefile_rule = shlex.split(data.decode().strip().replace('\\\n', '').replace('\\\r\n', ''), posix=not is_windows)
return [pathlib.Path(path).resolve() for path in makefile_rule[1:]]
