Fix possible crash in ctx.cmd_and_log() when verbose mode is on

- When waf is run with -v, and it runs a call to context.cmd_and_log() with an argument list,
  argument[0] is a relative path, and a cwd **kwarg is passed so that the argument[0] resolves
  correctly, then the call will crash saying the program could not be found. For example, the
  caller may be wrapping calls using a nodejs environment like:

  ctx.cmd_and_log("./node_modules/bin/webpack", cwd="webui")

  and this will fail with "Program ./node_modules/.bin/webpack not found!"
  if waf is run with -v. The user friendly check for usable programs still
  stays in place for shell calls and absolute paths, but allows the caller
  to use this pattern even when verbose mode is on. This same fix was
  previously made for context.exec_command().
This commit is contained in:
Wynn Wilkes 2024-01-10 08:40:07 -07:00
parent a739525f3e
commit 6730d9b140
1 changed files with 4 additions and 1 deletions

View File

@ -426,7 +426,10 @@ class Context(ctx):
to_ret = kw.pop('output', STDOUT)
if Logs.verbose and not kw['shell'] and not Utils.check_exe(cmd[0], env=kw.get('env', os.environ)):
raise Errors.WafError('Program %r not found!' % cmd[0])
# This call isn't a shell command, and if the specified exe doesn't exist, check for a relative path being set
# with cwd and if so assume the caller knows what they're doing and don't pre-emptively fail
if not (cmd[0][0] == '.' and 'cwd' in kw):
raise Errors.WafError('Program %s not found!' % cmd[0])
kw['stdout'] = kw['stderr'] = subprocess.PIPE
if quiet is None: