Skip to content

ninjabackend: bring back historical "include_directories(is_system: true)" ordering#15578

Merged
bonzini merged 1 commit intomesonbuild:masterfrom
bonzini:fix15478
Mar 6, 2026
Merged

ninjabackend: bring back historical "include_directories(is_system: true)" ordering#15578
bonzini merged 1 commit intomesonbuild:masterfrom
bonzini:fix15478

Conversation

@bonzini
Copy link
Contributor

@bonzini bonzini commented Feb 23, 2026

Prior to commit a6ddf2534 ("backend/ninja: Extend IncludeDirs.rel_string_list for backend use"), when include_directories() was called with is_system: true and multiple directories, the resulting -isystem flags appeared on the command line in the opposite order from what was specified: the last-listed directory was searched first by the compiler. This was the opposite convention from non-system -I includes, where the first-listed directory is searched first.

The asymmetry was not intentional; it was a side effect of how CompilerArgs.__iadd__ handles flags that are not in prepend_prefixes:

  • -I is in CLikeCompilerArgs.prepend_prefixes, so __iadd__ prepends it. The ninja backend iterates directories in reversed order and adds them one at a time; the prepend-on-each-add counteracts the reversal, producing the original order.

  • -isystem was not in prepend_prefixes, so __iadd__ appended it. The same reversed one-at-a-time iteration then produced a reversed sequence — the last-listed directory ended up first on the command line.

Commit a6ddf25 changed generate_inc_dir to add all directories in a single bulk commands += call instead of one at a time. This preserved the correct order for -I (the double reversal in __iadd__ still works for a bulk add) but silently broke -isystem, because appending a list at once preserves input order rather than reversing it.

Undo the changes a6ddf25 to preserve the previous behavior. Adding -isystem to prepend_prefixes would also make the ordering consistent, but projects that relied on the old reversed behaviour would silently break.

@bonzini
Copy link
Contributor Author

bonzini commented Feb 23, 2026

See #15577 for another attempt at a fix that didn't work well. Maybe it could be revisited once the "object model for compiler arguments" idea pans out.

@bonzini bonzini added this to the 1.11 milestone Mar 2, 2026
…rue)" ordering

Prior to commit a6ddf2534 ("backend/ninja: Extend IncludeDirs.rel_string_list
for backend use"), when include_directories() was called with
`is_system: true` and multiple directories, the resulting `-isystem`
flags appeared on the command line in the opposite order from what was
specified: the last-listed directory was searched first by the compiler.
This was the opposite convention from non-system -I includes, where the
first-listed directory is searched first.

The asymmetry was not intentional; it was a side effect of how
CompilerArgs.__iadd__ handles flags that are not in prepend_prefixes:

- `-I` is in CLikeCompilerArgs.prepend_prefixes, so `__iadd__`
prepends it.  The ninja backend iterates directories in reversed
order and adds them one at a time; the prepend-on-each-add
counteracts the reversal, producing the original order.

- `-isystem` was not in prepend_prefixes, so __iadd__ appended it.
The same reversed one-at-a-time iteration then produced a reversed
sequence — the last-listed directory ended up first on the command line.

Commit a6ddf25 changed generate_inc_dir to add all directories
in a single bulk commands += call instead of one at a time.  This
preserved the correct order for -I (the double reversal in
__iadd__ still works for a bulk add) but silently broke -isystem,
because appending a list at once preserves input order rather than
reversing it.

Undo the changes a6ddf25 to preserve the previous behavior.
Adding -isystem to prepend_prefixes would also make the ordering
consistent, but projects that relied on the old reversed
behaviour would silently break.
@bonzini bonzini merged commit 44c03a2 into mesonbuild:master Mar 6, 2026
33 of 34 checks passed
@bonzini bonzini deleted the fix15478 branch March 7, 2026 14:51
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.

1 participant