Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

dvdhrm
Copy link

@dvdhrm dvdhrm commented Sep 10, 2025

run_command() already treats all file paths in argv as build-def dependencies. Unfortunately, it does not allow the user to specify such dependencies manually. Add depend_files to allow manually adding build-def dependencies, rather than requiring users to stash them into the argument array, even if unused, just to get the same behavior.

run_command() already treats all file paths in argv as build-def
dependencies. Unfortunately, it does not allow the user to specify such
dependencies manually. Add `depend_files` to allow manually adding
build-def dependencies, rather than requiring users to stash them into
the argument array, even if unused, just to get the same behavior.
@dvdhrm dvdhrm requested a review from jpakkane as a code owner September 10, 2025 11:39
eli-schwartz

This comment was marked as duplicate.

Copy link
Member

@eli-schwartz eli-schwartz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

configure_file() provides a depfile kwarg instead, and expects the command being run to output the files it ends up using.

@@ -833,6 +834,9 @@ def run_command_impl(self,
else:
raise InterpreterException(overridden_msg.format(a.name, cmd.description()))

for f in kwargs['depend_files']:
self.add_build_def_file(f)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the kwarg is part of func_run_command I don't know why it's being read+used in the totally different run_command_impl, but it is the cause of the CI failures.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

func_run_command() just forwards to run_command_impl(), and the latter shares the type-definition of the kwargs argument.

I think the CI failure is because this should read:

for f in kwargs.get('depend_files', []):
            self.add_build_def_file(f)

I wonder, though, why this didn't trigger errors in my local tests. I used:

./run_project_tests.py --only "common/33 run program"

And this worked fine. Hmm. But maybe I am missing something here. How exactly would you adjust func_run_command() to support the option?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I got this right, then func_run_command() properly fills in the default value in kwargs, and as such I get an empty depend_files when called via run_command() in meson build files. However, there are 2 other users of the actual implementation of func_run_command(), which is run_command_impl(), and those do not fill in defaults but pass kwargs manually (and explicitly specify all kwargs).

Do you prefer to update explicit users to specify all options, or should I use the kwargs.get(..., []) style?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I already told you what I want, but I can explain the distinction between the two and why your analysis doesn't apply in this case. Sorry for not elucidating earlier.

We have two functions:

  • a DSL entry-point with functionality relevant to the DSL
  • a backend refactoring function so that we can share the logic for "spawn a command" in various places where this is relevant

Most of the logic for the former (technically before this PR, all of it) needs to be forwarded regardless, because it tunes the details of the command spawning itself. It isn't work that occurs independently beforehand. Even though other uses don't necessarily need to control these details, run_command_impl must somehow accept knobs for e.g. env, and it could be done via a dict kwarg or via separate arguments but we happened to use this.

depend_files is unnecessary to expose to run_command_impl, it can live wholly inside of func_run_command which means avoiding unnecessary complexity inside other internal callers of run_command_impl.

@dvdhrm
Copy link
Author

dvdhrm commented Sep 10, 2025

configure_file() provides a depfile kwarg instead, and expects the command being run to output the files it ends up using.

Does that mean you prefer the depfile style? I copied depend_files from custom_target(). I did not investigate which one was added later, or which one is considered the better option.

depend_files is certainly very easy to use, but splits authority between the script and the build system, which can be confusing. But the design of depfile kinda means you create an intermediate script as part of the build system, anyway (unless your target script exactly supports the semantics of depfile, and all the semantics of run_command()).

I don't care too much. Would you prefer if it was depfile?

@eli-schwartz
Copy link
Member

There are advantages and disadvantages to each. But don't you already need a script if you're doing globbing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants