Skip to content

Commit

Permalink
Tighten warning for 'Requires.private' in simple pkg-config parser (#…
Browse files Browse the repository at this point in the history
…26008)

Tightens up the logic for when we should warn about 'Requires.private'
(and also 'Requires'). We only need to warn when the compiler/linker
flags are not already handled by 'Cflags'/`Libs`.

Details:

`Requires`/`Requires.private` list what other pkg-config libraries are
needed, so that `pkg-config` can pull in the need dependencies/flags.
This ends up being a recursive operation (i.e. 'A' has 'Requires: B', so
we must process 'B.pc'). But if we already have the information needed,
this is unnecessary. So if we have 'Requires: B', but 'B' is already
listed in 'Libs', then for our purposes we have satisfied the
'Requires.'

Our simple pkg-config parser is used only for bundled third-party libs,
and we do not need to ability to recursively search other .pc files to
satisfy the requirements. So this PR uses the above logic to avoid
warning about `Requires`/`Requires.private` not being handled

This should resolve #26002

[Reviewed by @mppf  and @jhh67]
  • Loading branch information
jabraham17 authored Sep 30, 2024
2 parents 32af183 + 0065df3 commit 8f702bf
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions util/chplenv/third_party_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,20 @@ def pkgconfig_get_system_compile_args(pkg):
cflags = cflags_line.split()
return ([ ], cflags)

# helper function to determine if we need to warn about 'Requires'/'Requires.private'
# these fields list other packages that are required to link with this package
# however, this only matters if the required package is not listed in
# 'Libs'/'Libs.private' already
# see https://people.freedesktop.org/~dbn/pkg-config-guide.html
def _pkgconfig_should_warn_for_requires(d, private=False):
libs = d['Libs' if not private else 'Libs.private'].split()
requires = d['Requires' if not private else 'Requires.private'].split()
for req in requires:
lib_name = '-l' + req
if lib_name not in libs:
return True
return False

#
# Return compiler arguments required to use a bundled library
# based on a pkg-config .pc file.
Expand All @@ -154,8 +168,16 @@ def pkgconfig_get_bundled_compile_args(pkg, ucp='', pcfile=''):
return ([ ], [ ])

if 'Requires' in d and d['Requires']:
warning("Simple pkg-config parser does not handle Requires")
warning("in {0}".format(pcpath))
warn = False
if 'Libs' in d:
warn = _pkgconfig_should_warn_for_requires(d)
else:
# no Libs, so no way to check if the required package is already included
warn = True

if warn:
warning("Simple pkg-config parser does not handle Requires")
warning("in {0}".format(pcpath))

cflags = [ ]

Expand Down Expand Up @@ -236,11 +258,15 @@ def pkgconfig_get_bundled_link_args(pkg, ucp='', pcfile='',
if d == None:
return ([ ], [ ])

if 'Requires' in d and d['Requires']:
if d.get('Requires') and _pkgconfig_should_warn_for_requires(d):
warning("Simple pkg-config parser does not handle Requires")
warning("in {0}".format(pcpath))

if static and 'Requires.private' in d and d['Requires.private']:
if (
static
and d.get("Requires.private")
and _pkgconfig_should_warn_for_requires(d, private=True)
):
warning("Simple pkg-config parser does not handle Requires.private")
warning("in {0}".format(pcpath))

Expand Down

0 comments on commit 8f702bf

Please sign in to comment.