[Minor] log ninja result#584
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces logging for the ninja build process in python/tvm_ffi/cpp/extension.py by checking the TVM_FFI_LOG_BUILD environment variable. Feedback was provided to improve the robustness of the decoding process by using platform-specific encodings (e.g., 'oem' on Windows) and adding error handling to prevent potential UnicodeDecodeError failures during logging.
| if os.environ.get("TVM_FFI_LOG_BUILD") in ("1", "stdout"): | ||
| logger.info("ninja build stdout:\n%s", status.stdout.decode("utf-8")) | ||
|
|
||
| if os.environ.get("TVM_FFI_LOG_BUILD") in ("1", "stderr"): | ||
| logger.info("ninja build stderr:\n%s", status.stderr.decode("utf-8")) |
There was a problem hiding this comment.
Hardcoding utf-8 for decoding process output can lead to UnicodeDecodeError on Windows, where the output typically uses the OEM code page. This would cause the build process to fail even if the compilation was successful. It is recommended to use the same encoding logic as the error path and include errors="replace" for robustness. Additionally, caching the environment variable and checking if the output is non-empty before logging improves efficiency and log clarity.
| if os.environ.get("TVM_FFI_LOG_BUILD") in ("1", "stdout"): | |
| logger.info("ninja build stdout:\n%s", status.stdout.decode("utf-8")) | |
| if os.environ.get("TVM_FFI_LOG_BUILD") in ("1", "stderr"): | |
| logger.info("ninja build stderr:\n%s", status.stderr.decode("utf-8")) | |
| log_build = os.environ.get("TVM_FFI_LOG_BUILD") | |
| encoding = "oem" if IS_WINDOWS else "utf-8" | |
| if log_build in ("1", "stdout") and status.stdout: | |
| logger.info("ninja build stdout:\n%s", status.stdout.decode(encoding, errors="replace")) | |
| if log_build in ("1", "stderr") and status.stderr: | |
| logger.info("ninja build stderr:\n%s", status.stderr.decode(encoding, errors="replace")) |
|
|
||
| raise RuntimeError("\n".join(msg)) | ||
|
|
||
| if os.environ.get("TVM_FFI_LOG_BUILD") in ("1", "stdout"): |
There was a problem hiding this comment.
given it is specific to CPP_EXTENSION, would be useful to do TVM_FFI_CPP_EXTENSION_LOG_BUILD
|
Thanks @DarkSharpness lgtm modulo minor nit on naming |
should fix #565