Skip to content

Honor includes in partial_dependency of externals dependencies #14318

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## partial_dependency now honor includes keyword for external dependencies.

Previously, the `includes` keyword of [[@dep]]`.partial_dependency` had no effects
if the dependency was an external dependency (e.g. from [[dependency]]).

Since 1.8.0, specifying `includes: true` will now extract the include directories
from the compile args, when `compile_args` is `false`.
However, to preserve backward compatibility, `includes: false` will not remove the
include dirs from the compile args when `compile_args` is `true`.
3 changes: 3 additions & 0 deletions docs/yaml/objects/dep.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ methods:
- includes: any include_directories
- sources: any compiled or static sources the dependency has

*(since 1.8.0)* If `includes` is `true`, `-I` compile args will be preserved
for external dependencies, even if `compile_args` is `false`.

warnings:
- A bug present until 0.50.1 results in the above behavior
not working correctly.
Expand Down
7 changes: 4 additions & 3 deletions mesonbuild/dependencies/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,13 +420,14 @@ def get_partial_dependency(self, *, compile_args: bool = False,
new = copy.copy(self)
new._id = uuid.uuid4().int
if not compile_args:
new.compile_args = []
if includes:
new.compile_args = [c for c in self.compile_args if c.startswith('-I')]
Copy link
Member

Choose a reason for hiding this comment

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

That's not sufficient, at the very least this needs to be c.startswith(('-I', '/I', '-isystem', '-idir-after')), but even that probably isn't sufficient.

I'm also really, really, hesitant to do this in general, since the only valid case where a we could get a raw include is from pkg-config (or maybe CMake?). I'd tried to fix this previously and ran into pkgconf bugs on mingw: #10122

At the very least I think this should be limited to pkg-config dependencies.

Copy link
Member

Choose a reason for hiding this comment

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

I was actually thinking about that PR this weekend

Copy link
Member Author

Choose a reason for hiding this comment

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

I see... But OTOH, it will not change the behavior if compile_args is true. The only thing it changes is when you request includes but not compile_args.

Not sure about -isystem and -idirafter. Should includes from a dependency include system dirs? For /I, I though it was already replaced by -I by meson, but I may be wrong... The only thing I know is that pkgconf --cflags-only-I will only keep arguments beginning with -I.

Copy link
Member Author

Choose a reason for hiding this comment

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

I proposed this because I get caught this morning, trying to use the includes from a dependency. I forgot it was only working for internal dependencies...

Copy link
Member

Choose a reason for hiding this comment

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

My concern is it changes the behavior of a declare_dependency()

x = declare_dependency(compile_args : ['-Dfoo', '-Ibar']).partial_dependency(include_directories : true)

Currently gives an empty declare_dependency. This is what we intend, we don't support putting -I flags in compile_args, you get to keep the pieces if you do that.

Copy link
Member Author

Choose a reason for hiding this comment

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

This wouldn't change, since my changes only apply to external dependencies. Behavior of internal_dependencies remains the same.

Copy link
Member

Choose a reason for hiding this comment

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

hmmm, I'm still not sure. I'll have a look at what ends up here and then go from there.

Either way a test would be good. There might be something in that PR I linked you could steal.

else:
new.compile_args = []
if not link_args:
new.link_args = []
if not sources:
new.sources = []
if not includes:
pass # TODO maybe filter compile_args?
if not sources:
new.sources = []

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright © 2024 Intel Corporation

# TODO: don't use compile whenever we get includes and compile args separated
dep_zlib_sub = dep_zlib.partial_dependency(compile_args : true, includes : true)
dep_zlib_sub = dep_zlib.partial_dependency(includes : true)

executable(
'zlib header only test',
Expand Down
2 changes: 1 addition & 1 deletion test cases/frameworks/1 boost/partial_dep/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

dep_boost = dependency('boost')
dep_boost_headers = dep_boost.partial_dependency(compile_args : true)
dep_boost_headers = dep_boost.partial_dependency(includes : true)

libfoo = static_library(
'foo',
Expand Down
Loading