1717__all__ = ["BuildTools" , "CargoTools" , "BazelTools" ]
1818
1919import json
20+ import logging
2021from abc import ABC , abstractmethod
2122from pathlib import Path
2223from subprocess import PIPE , Popen , TimeoutExpired
2324from typing import Any
2425
2526import pytest
2627
28+ logger = logging .getLogger (__package__ )
2729# region common
2830
2931
@@ -47,6 +49,11 @@ def __init__(self, option_prefix: str = "", command_timeout: float = 10.0, build
4749 build_timeout : float
4850 Build command timeout in seconds.
4951 """
52+ logger .debug (
53+ f"Initializing BuildTools: option_prefix={ option_prefix } , "
54+ f"command_timeout={ command_timeout } , "
55+ f"build_timeout={ build_timeout } "
56+ )
5057 if option_prefix :
5158 self ._target_path_flag = f"--{ option_prefix } -target-path"
5259 self ._target_name_flag = f"--{ option_prefix } -target-name"
@@ -177,6 +184,7 @@ def metadata(self) -> dict[str, Any]:
177184 """
178185 # Run command.
179186 command = ["cargo" , "metadata" , "--format-version" , "1" ]
187+ logger .debug (f"Running Cargo metadata command: `{ ' ' .join (command )} `" )
180188 with Popen (command , stdout = PIPE , text = True ) as p :
181189 stdout , _ = p .communicate (timeout = self .command_timeout )
182190 if p .returncode != 0 :
@@ -209,6 +217,7 @@ def find_target_path(self, target_name: str, *, expect_exists: bool = True) -> P
209217 if expect_exists and not target_path .exists ():
210218 raise RuntimeError (f"Executable not found: { target_path } " )
211219
220+ logger .debug (f"Found target path: { target_path } " )
212221 return target_path
213222
214223 def build (self , target_name : str ) -> Path :
@@ -237,6 +246,7 @@ def build(self, target_name: str) -> Path:
237246
238247 # Run build.
239248 command = ["cargo" , "build" , "--manifest-path" , manifest_path ]
249+ logger .debug (f"Running Cargo build command: `{ ' ' .join (command )} `" )
240250 with Popen (command , text = True ) as p :
241251 _ , _ = p .communicate (timeout = self .build_timeout )
242252 if p .returncode != 0 :
@@ -284,6 +294,7 @@ def query(self, query: str = "//...") -> list[str]:
284294 """
285295 # Run command.
286296 command = ["bazel" , "query" , query ]
297+ logger .debug (f"Running Bazel query command: `{ ' ' .join (command )} `" )
287298 with Popen (command , stdout = PIPE , text = True ) as p :
288299 stdout , _ = p .communicate (timeout = self .command_timeout )
289300 if p .returncode != 0 :
@@ -322,6 +333,7 @@ def find_target_path(self, target_name: str, *, expect_exists: bool = True) -> P
322333 "--starlark:expr=target.files_to_run.executable.path" ,
323334 target_name ,
324335 ]
336+ logger .debug (f"Running Bazel cquery command: `{ ' ' .join (command )} `" )
325337 with Popen (command , stdout = PIPE , text = True ) as p :
326338 target_str , _ = p .communicate (timeout = self .command_timeout )
327339 target_str = target_str .strip ()
@@ -333,6 +345,7 @@ def find_target_path(self, target_name: str, *, expect_exists: bool = True) -> P
333345 if expect_exists and not target_path .exists ():
334346 raise RuntimeError (f"Executable not found: { target_path } " )
335347
348+ logger .debug (f"Found target path: { target_path } " )
336349 return target_path
337350
338351 def build (self , target_name : str , * options ) -> Path :
@@ -346,6 +359,7 @@ def build(self, target_name: str, *options) -> Path:
346359 """
347360 # Run build.
348361 command = ["bazel" , "build" , target_name , * options ]
362+ logger .debug (f"Running Bazel build command: `{ ' ' .join (command )} `" )
349363 with Popen (command , text = True ) as p :
350364 _ , _ = p .communicate (timeout = self .build_timeout )
351365 if p .returncode != 0 :
0 commit comments