diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 78292f20ac2e..ecf6702c4382 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -2283,13 +2283,12 @@ def get_all_link_deps(self): return [] def is_internal(self) -> bool: - if not self.should_install(): - return True - for out in self.get_outputs(): - # Can't check if this is a static library, so try to guess - if not out.endswith(('.a', '.lib')): - return False - return True + ''' + Returns True iif this is a not installed static library. + ''' + if len(self.outputs) != 1: + return False + return CustomTargetIndex(self, self.outputs[0]).is_internal() def extract_all_objects_recurse(self): return self.get_outputs() @@ -2443,7 +2442,11 @@ def should_install(self) -> bool: return self.target.should_install() def is_internal(self) -> bool: - return self.target.is_internal() + ''' + Returns True iif this is a not installed static library + ''' + suf = os.path.splitext(self.output)[-1] + return (suf == '.a' or suf == '.lib') and not self.should_install() def extract_all_objects_recurse(self): return self.target.extract_all_objects_recurse() diff --git a/mesonbuild/modules/pkgconfig.py b/mesonbuild/modules/pkgconfig.py index 62e1c1595cae..c1f31cd72932 100644 --- a/mesonbuild/modules/pkgconfig.py +++ b/mesonbuild/modules/pkgconfig.py @@ -186,7 +186,8 @@ def _add_link_whole(self, t, public): # lists in case a library is link_with and link_whole at the same time. # See remove_dups() below. self.link_whole_targets.append(t) - self._add_lib_dependencies(t.link_targets, t.link_whole_targets, t.external_deps, public) + if isinstance(t, build.BuildTarget): + self._add_lib_dependencies(t.link_targets, t.link_whole_targets, t.external_deps, public) def add_version_reqs(self, name, version_reqs): if version_reqs: diff --git a/test cases/common/45 pkgconfig-gen/meson.build b/test cases/common/45 pkgconfig-gen/meson.build index 4638123cf1e8..1cb55e9061ee 100644 --- a/test cases/common/45 pkgconfig-gen/meson.build +++ b/test cases/common/45 pkgconfig-gen/meson.build @@ -18,6 +18,8 @@ if v.version_compare('<0.29') error('MESON_SKIP_TEST: pkg-config version \'' + v + '\' too old') endif +python = import('python').find_installation() +fs = import('fs') pkgg = import('pkgconfig') lib = shared_library('simple', 'simple.c') @@ -96,3 +98,17 @@ stat2 = static_library('stat2', 'simple.c', install: true) simple4 = library('simple4', 'simple.c', link_with: stat2) simple5 = library('simple5', 'simple5.c', link_with: simple4, link_whole: stat2) pkgg.generate(simple5) + +# Regression test: A library linking to an uninstalled custom_target static +# library used to crash when generating its pkgconfig file. +# Copy libstat2.a to libstat3.a to have a static library as custom target. +infile = stat2.full_path() +outfile = meson.current_build_dir() / 'libstat3.a' +script = 'import shutil ; shutil.copyfile("@0@", "@1@")'.format(infile, outfile) +ct = custom_target('stat3', + input: stat2, + output: fs.name(outfile), + command: [python, '-c', script], +) +simple6 = library('simple6', link_with: ct) +pkgg.generate(simple6)