Skip to content

Commit 3addf08

Browse files
authored
Merge pull request #381 from online-judge-tools/mac-clang-depfile
Fix the options to analyze the dependencies of C++ files
2 parents 28f6bb9 + b77d5de commit 3addf08

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

onlinejudge_verify/languages/cplusplus.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import shutil
88
import subprocess
99
import sys
10-
import tempfile
1110
from logging import getLogger
1211
from typing import *
1312

@@ -44,22 +43,17 @@ def _is_gcc(self) -> bool:
4443

4544
@functools.lru_cache(maxsize=None)
4645
def _cplusplus_list_depending_files(path: pathlib.Path, *, CXX: pathlib.Path, joined_CXXFLAGS: str) -> List[pathlib.Path]:
47-
# Using /dev/stdout is acceptable because Library Chcker doesn't work on Windows.
4846
is_windows = (platform.uname().system == 'Windows')
49-
with tempfile.TemporaryDirectory() as temp_dir:
50-
temp_file = pathlib.Path(temp_dir) / 'dependencies.txt'
51-
command = [str(CXX), *shlex.split(joined_CXXFLAGS), '-MD', '-MF', str(temp_file), '-MM', str(path)]
52-
try:
53-
subprocess.check_call(command)
54-
except subprocess.CalledProcessError:
55-
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))
56-
print(f'::warning file={str(path)}::failed to analyze dependencies', file=sys.stderr)
57-
raise
58-
with open(temp_file, 'rb') as fp:
59-
data = fp.read()
60-
logger.debug('dependencies of %s: %s', str(path), repr(data))
61-
makefile_rule = shlex.split(data.decode().strip().replace('\\\n', '').replace('\\\r\n', ''), posix=not is_windows)
62-
return [pathlib.Path(path).resolve() for path in makefile_rule[1:]]
47+
command = [str(CXX), *shlex.split(joined_CXXFLAGS), '-MM', str(path)]
48+
try:
49+
data = subprocess.check_output(command)
50+
except subprocess.CalledProcessError:
51+
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))
52+
print(f'::warning file={str(path)}::failed to analyze dependencies', file=sys.stderr)
53+
raise
54+
logger.debug('dependencies of %s: %s', str(path), repr(data))
55+
makefile_rule = shlex.split(data.decode().strip().replace('\\\n', '').replace('\\\r\n', ''), posix=not is_windows)
56+
return [pathlib.Path(path).resolve() for path in makefile_rule[1:]]
6357

6458

6559
@functools.lru_cache(maxsize=None)

0 commit comments

Comments
 (0)