Skip to content

interpreter: Report correct number of targets in subprojects - #16117

Merged
bonzini merged 1 commit into
mesonbuild:masterfrom
dnicolodi:fix/subproject-targets
Aug 24, 2026
Merged

interpreter: Report correct number of targets in subprojects#16117
bonzini merged 1 commit into
mesonbuild:masterfrom
dnicolodi:fix/subproject-targets

Conversation

@dnicolodi

Copy link
Copy Markdown
Member

Fixes #16116

@dnicolodi
dnicolodi requested a review from jpakkane as a code owner August 15, 2026 10:04
@dnicolodi

Copy link
Copy Markdown
Member Author

I'm not so sure this makes the reported number of targets easier to grok. With this, each subprojects reports the number of targers in itself and all of its subprojects, however, the log output is not super clear regarding the tree structure of the subprojects. Maybe this needs some more thinking.

Comment thread mesonbuild/interpreter/interpreter.py Outdated
mlog.log('Build targets in project:', mlog.bold(str(len(self.build.targets))))
# When executing a subproject, only report the targets added by
# the subproject as the number of build targets in the project.
mlog.log('Build targets in project:', mlog.bold(str(len(self.build.targets) - n_existing_targets)))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could we write this as something like len(x for x in self.build.targets if x.subproject == self.subproject and x.for_machine == self.for_machine) (Can't remember exactly which attributes we have here)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Sure, but the interpreter does not have a for_machine attribute for the machine type of the subproject being processed. The only way I see of getting to it is to use the last entry in self.subproject_stack and special handling the root project. Or should I add Interpreter.for_machine?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Given in the future there could be more ways to invoke the subproject (depending on how Meson introduces the possibility to invoke subprojects with different machine maps) that approach seems more complex than the subtraction here. Another possibility is to add a variable with the count and adjust it in add_target; but this PR looks good to me, if it's decided this was a bug and not just a badly worded message.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I am not happy with the count reported with the subtraction approach. This approach still reports the current subproject targets plus all the targets in subprojects called from it. This is a bit less confusing that the cumulative number, but still not great. The approach suggested by @dcbaker would give the least surprising number.

Another possibility is to add a variable with the count and adjust it in add_target

I am not sure this would help. The problem would then become when to reset this new variable to 0. Subprojects are organised as a tree, thus the count would need to be stored as a stack, similarly to Intepreter.subproject_stack (or an entry would need to be added to this stack).

Given in the future there could be more ways to invoke the subproject (depending on how Meson introduces the possibility to invoke subprojects with different machine maps) that approach seems more complex than the subtraction here.

Wouldn't this require to switch from storing the for_machine information to storing the machine_map information in the targets? If so, the count problem would be solved filtering for (subproject, machine_map) instead than for (subproject, for_machine). But I am not familiar with this code at all, thus I may be missing something.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The problem would then become when to reset this new variable to 0.

Each Interpreter would have its own copy, starting at zero.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I eeworked it in this way. PTAL

@dnicolodi
dnicolodi force-pushed the fix/subproject-targets branch from 9500e16 to 4d4b534 Compare August 19, 2026 18:50
@bonzini
bonzini merged commit 817ea9f into mesonbuild:master Aug 24, 2026
28 of 30 checks passed
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.

Meson reports cumulative sum of number of build targets in subprojects

3 participants