From 0065df3a69e897e2863f5f8818fcd94492557fa7 Mon Sep 17 00:00:00 2001 From: Jade Abraham Date: Thu, 26 Sep 2024 16:07:37 -0700 Subject: [PATCH] tighten warning for libs.private Signed-off-by: Jade Abraham --- util/chplenv/third_party_utils.py | 34 +++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/util/chplenv/third_party_utils.py b/util/chplenv/third_party_utils.py index 8006b3dfda47..0f0a2b332b60 100644 --- a/util/chplenv/third_party_utils.py +++ b/util/chplenv/third_party_utils.py @@ -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. @@ -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 = [ ] @@ -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))