66
77from __future__ import annotations
88
9+ import ast
910import functools
1011import importlib .abc
1112import importlib .machinery
@@ -308,6 +309,21 @@ def find_spec(
308309 tree = self ._rebuild ()
309310 return find_spec (fullname , tree )
310311
312+ def _work_to_do (self , env : dict [str , str ]) -> bool :
313+ if sys .platform == 'win32' :
314+ # On Windows the build command is 'meson compile' eventually with a --ninja-args= option.
315+ if self ._build_cmd [- 1 ].startswith ('--ninja-args=' ):
316+ ninja_args = ast .literal_eval (self ._build_cmd [- 1 ].split ('=' , 1 )[1 ]) + ['-n' ]
317+ dry_run_build_cmd = self ._build_cmd [:- 1 ] + [f'--ninja-args={ ninja_args !r} ' ]
318+ else :
319+ dry_run_build_cmd = self ._build_cmd + ['--ninja-args=-n' ]
320+ else :
321+ dry_run_build_cmd = self ._build_cmd + ['-n' ]
322+ # Check adapted from
323+ # https://github.com/mesonbuild/meson/blob/a35d4d368a21f4b70afa3195da4d6292a649cb4c/mesonbuild/mtest.py#L1635-L1636
324+ p = subprocess .run (dry_run_build_cmd , cwd = self ._build_path , env = env , capture_output = True )
325+ return b'ninja: no work to do.' not in p .stdout and b'samu: nothing to do' not in p .stdout
326+
311327 @functools .lru_cache (maxsize = 1 )
312328 def _rebuild (self ) -> Node :
313329 # skip editable wheel lookup during rebuild: during the build
@@ -317,12 +333,14 @@ def _rebuild(self) -> Node:
317333 env [MARKER ] = os .pathsep .join ((env .get (MARKER , '' ), self ._build_path ))
318334
319335 if self ._verbose or bool (env .get (VERBOSE , '' )):
320- print ('+ ' + ' ' .join (self ._build_cmd ))
321- stdout = None
336+ # We want to show some output only if there is some work to do
337+ if self ._work_to_do (env ):
338+ module_names = ' ' .join (sorted (self ._top_level_modules ))
339+ build_command = ' ' .join (self ._build_cmd )
340+ print (f'meson-python: building { module_names } with { build_command !r} ' , flush = True )
341+ subprocess .run (self ._build_cmd , cwd = self ._build_path , env = env )
322342 else :
323- stdout = subprocess .DEVNULL
324-
325- subprocess .run (self ._build_cmd , cwd = self ._build_path , env = env , stdout = stdout , check = True )
343+ subprocess .run (self ._build_cmd , cwd = self ._build_path , env = env , stdout = subprocess .DEVNULL )
326344
327345 install_plan_path = os .path .join (self ._build_path , 'meson-info' , 'intro-install_plan.json' )
328346 with open (install_plan_path , 'r' , encoding = 'utf8' ) as f :
0 commit comments