Cleanup: quiet warnings & simplify Popen use in project_source_info

This commit is contained in:
Campbell Barton
2025-02-11 13:42:09 +11:00
parent ad4eb66fdf
commit c0b9814c07

View File

@@ -103,8 +103,6 @@ def do_ignore(filepath: str, ignore_prefix_list: Sequence[str] | None) -> bool:
def makefile_log() -> list[str]: def makefile_log() -> list[str]:
import subprocess
import time
# support both make and ninja # support both make and ninja
make_exe = cmake_cache_var_or_exit("CMAKE_MAKE_PROGRAM") make_exe = cmake_cache_var_or_exit("CMAKE_MAKE_PROGRAM")
@@ -113,7 +111,7 @@ def makefile_log() -> list[str]:
if make_exe_basename.startswith(("make", "gmake")): if make_exe_basename.startswith(("make", "gmake")):
print("running 'make' with --dry-run ...") print("running 'make' with --dry-run ...")
process = subprocess.Popen( with subprocess.Popen(
( (
make_exe, make_exe,
"-C", CMAKE_DIR, "-C", CMAKE_DIR,
@@ -123,33 +121,27 @@ def makefile_log() -> list[str]:
"VERBOSE=1", "VERBOSE=1",
), ),
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
) ) as proc:
stdout_data, stderr_data = proc.communicate()
elif make_exe_basename.startswith("ninja"): elif make_exe_basename.startswith("ninja"):
print("running 'ninja' with -t commands ...") print("running 'ninja' with -t commands ...")
process = subprocess.Popen( with subprocess.Popen(
( (
make_exe, make_exe,
"-C", CMAKE_DIR, "-C", CMAKE_DIR,
"-t", "commands", "-t", "commands",
), ),
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
) ) as proc:
stdout_data, stderr_data = proc.communicate()
if process is None: else:
print("Can't execute process") print("CMAKE_MAKE_PROGRAM: \"{:s}\" is not known (make/gmake/ninja)")
sys.exit(1) sys.exit(1)
del stderr_data
while process.poll(): print("done!", len(stdout_data), "bytes")
time.sleep(1) return stdout_data.decode("utf-8", errors="ignore").split("\n")
# We know this is always true based on the input arguments to `Popen`.
assert process.stdout is not None
stdout: IO[bytes] = process.stdout
out = stdout.read()
stdout.close()
print("done!", len(out), "bytes")
return out.decode("utf-8", errors="ignore").split("\n")
def build_info( def build_info(
@@ -225,7 +217,6 @@ def build_defines_as_source() -> str:
Returns a string formatted as an include: Returns a string formatted as an include:
'#defines A=B\n#define....' '#defines A=B\n#define....'
""" """
import subprocess
# Works for both GCC and CLANG. # Works for both GCC and CLANG.
cmd = (cmake_cache_var_or_exit("CMAKE_C_COMPILER"), "-dM", "-E", "-") cmd = (cmake_cache_var_or_exit("CMAKE_C_COMPILER"), "-dM", "-E", "-")
process = subprocess.Popen( process = subprocess.Popen(