Compare commits

...

226 Commits

Author SHA1 Message Date
Ariadne Conill 0226cdda6d Merge pull request 'meson: use a feature option for tests instead of boolean' (#244) from dcbaker/pkgconf:tests-feature into master
Reviewed-on: ariadne/pkgconf#244
2022-08-20 13:27:45 +00:00
Dylan Baker fa803c7ecd meson: use a feature option for tests instead of boolean
This allows tests to be autodetected gracefully, which is particularly
convenient for kyua and atf_sh which are fairly painful to build and
install by hand. Those who want to ensure tests are enabled or disabled
may pass `-Dtests=enabled` or `-Dtests=disabled` respectively.

This does require a modest bump in the required meson version to 0.49,
which was released at the end of 2018, so roughly 4 years ago.
2022-08-17 11:07:44 -07:00
Ariadne Conill bddf1641f8 bomtool: fix ASan issues 2022-08-16 20:41:10 +00:00
Ariadne Conill 8754bdfe09 pkgconf 1.9.3. 2022-08-16 19:50:26 +00:00
Ariadne Conill 6a66b312b4 libpkgconf: increase API level to 10903 2022-08-16 19:49:42 +00:00
Ariadne Conill 4c38d3f60c update NEWS for pkgconf 1.9.3 2022-08-16 19:49:02 +00:00
Ariadne Conill b7593aea27 build: automake: use top_srcdir as needed 2022-08-16 19:48:44 +00:00
Ariadne Conill dbd78db67f tests: add regression test for github #259 2022-08-16 19:42:13 +00:00
Ariadne Conill 80bc5ac3b9 tuple: if a global tuple is explicitly defined with --define-variable, prefer it
fixes github #259
2022-08-16 19:39:05 +00:00
Ariadne Conill 5044491f43 queue: add function to free a compiled solution 2022-08-16 19:27:35 +00:00
Ariadne Conill c6d14e6fa1 cli: renderer-msvc: remove pointless buf_remaining store 2022-08-16 18:53:29 +00:00
Ariadne Conill ced9bee613 pkg: remove dead store in pkgconf_compare_version 2022-08-16 18:51:11 +00:00
Ariadne Conill 2c89541101 bomtool: return EXIT_FAILURE if solver fails to solve 2022-08-16 18:50:35 +00:00
Ariadne Conill 5500a15133 fragment: avoid trying to merge fragments where data == NULL 2022-08-16 18:46:43 +00:00
Ariadne Conill 74faf8d0e2 queue: do not enqueue unsolved nodes as part of a solution 2022-08-16 18:38:46 +00:00
Ariadne Conill c918b6e225 bomtool: enable PKGCONF_PKG_PKGF_SEARCH_PRIVATE to collect dev dependencies 2022-08-13 06:44:40 +00:00
Ariadne Conill 12f3a30980 bomtool: write dependency relationships in both directions 2022-08-13 06:44:19 +00:00
Ariadne Conill 01c1d9f4cc bomtool: remove empty creation date field 2022-08-12 13:07:58 +00:00
Ariadne Conill 9e8052b699 bomtool: add enough to generate a basic SBOM 2022-08-12 12:57:53 +00:00
Ariadne Conill 696124b608 pkg: add support for parsing the URL from pc files 2022-08-12 12:36:21 +00:00
Ariadne Conill 79327b8967 add bomtool skeleton 2022-08-12 12:07:56 +00:00
Ariadne Conill f3021a82c5 libpkgconf.pc: add license 2022-08-12 11:59:11 +00:00
Ariadne Conill 194ad3e656 man: pc.5: document copyright/maintainer fields 2022-08-11 16:01:30 +00:00
Ariadne Conill aa99ddf789 pkg: add Copyright and Maintainer fields
These are helpful pieces of information for BOM documents
generated by pkgconf.
2022-08-11 15:52:33 +00:00
Ariadne Conill 68b5cab72d cli: remove redundant SEARCH_PRIVATE block
It turns out there was already a check for PKG_CFLAGS being requested,
but the check was busted because PKG_CFLAGS is a combined-or of all of
the various --cflags flags.

Check that PKG_CFLAGS bits are set at all on want_flags instead.
2022-08-11 15:06:08 +00:00
Ariadne Conill 78f00da130 Merge pull request 'cli: use Requires.private when cflags are requested' (#243) from psykose/pkgconf:cflags-i into master
Reviewed-on: ariadne/pkgconf#243
2022-08-11 13:49:44 +00:00
psykose 746005582f
cli: use Requires.private when cflags are requested 2022-08-11 15:47:32 +02:00
Ariadne Conill 28b5d57b98 pkg: free SPDX license tags when a package is destroyed 2022-08-08 10:25:24 +00:00
Ariadne Conill af9b26c15c pkgconf 1.9.2. 2022-08-08 10:03:15 +00:00
Ariadne Conill c0d2d65347 NEWS for pkgconf 1.9.2. 2022-08-08 10:02:56 +00:00
Ariadne Conill 69a3d458ef libpkgconf: revise API revision to 10902 2022-08-08 09:59:50 +00:00
Ariadne Conill 7e9aa7e1fc pkg: do not break cycles across dependency lists 2022-08-08 09:56:28 +00:00
Ariadne Conill 4e449bd45f cli: do not search requires.private for --libs unless --static 2022-08-08 09:42:01 +00:00
Ariadne Conill 69f630aadc pkg: only advance serial if we are actually traversing from a root 2022-08-08 09:34:45 +00:00
Ariadne Conill 760d1eea10 cli: use pkgconf_queue_solve instead of pkgconf_queue_apply 2022-08-08 09:27:39 +00:00
Ariadne Conill 8764578719 tests: ignore stdout on regress:missing test 2022-08-08 09:26:22 +00:00
Ariadne Conill 5b10a85a82 queue: add pkgconf_queue_solve API 2022-08-08 09:08:27 +00:00
Ariadne Conill 884a88583b tests: add testcase for requires.private debounce 2022-08-08 08:56:53 +00:00
Ariadne Conill 4e8f376c5d tests: add fixtures for github #258 2022-08-08 05:26:00 +00:00
Ariadne Conill 79d25f979d queue: ensure private deps get flattened when --static is requested 2022-08-08 00:58:55 +00:00
Ariadne Conill 03ba00d30b Merge pull request 'bsdstubs: include errno.h' (#242) from dcbaker/pkgconf:bsdstubs-errno into master
Reviewed-on: ariadne/pkgconf#242
2022-08-08 00:51:32 +00:00
Ariadne Conill 1a66d963cf pkgconf 1.9.1. 2022-08-08 00:44:23 +00:00
Ariadne Conill 8271ea1952 NEWS: update for pkgconf 1.9.1. 2022-08-08 00:43:20 +00:00
Ariadne Conill b29f9d8713 cli: do not flatten or traverse the graph when asking for module-specific values 2022-08-08 00:40:52 +00:00
Ariadne Conill 94b3f118cc tests: add regression test to catch --modversion regression introduced by new solver 2022-08-08 00:37:07 +00:00
Dylan Baker 7976daab9a bsdstubs: include errno.h
Needed for ENOMEM, and fixes the build on MacOS.
2022-08-06 22:30:25 -07:00
Ariadne Conill d8d669f637 pkgconf 1.9.0. 2022-08-07 04:47:04 +00:00
Ariadne Conill 23556ff818 Bump libpkgconf SOVERSION for 1.9.0 changes. 2022-08-07 04:46:35 +00:00
Ariadne Conill da9b2cfbc1 NEWS: note the SPDX license branch has been merged 2022-08-07 04:45:33 +00:00
Ariadne Conill b2579a661b man: pc(5): document the License field 2022-08-07 04:42:55 +00:00
Ariadne Conill 666b520273 tests: add tests for SPDX license assertions 2022-08-07 04:40:31 +00:00
Ariadne Conill d5f9bdae57 cli: add support for dumping SPDX expressions from modules 2022-08-07 04:40:19 +00:00
Ariadne Conill 0e05308f9c pkg: add SPDX license assertion to pkgconf builtin 2022-08-07 04:35:29 +00:00
Ariadne Conill 1389aa05ba pkg: add pkgconf_pkg_t.license field
The pkgconf_pkg_t.license field maps to the new License keyword, and
should be an SPDX license expression.
2022-08-07 04:21:22 +00:00
Ariadne Conill dce34e9afd Update NEWS for pending 1.9.0 release 2022-08-07 04:13:43 +00:00
Ariadne Conill 9aa0006c27 tests: improve circular reference tests to make use of the circular reference diagnostic 2022-08-07 01:35:12 +00:00
Ariadne Conill 7edfdbff0b pkg: upgrade circular reference trace to a warning 2022-08-07 01:29:21 +00:00
Ariadne Conill 662668d082 pkg: add trace log when breaking a circular reference 2022-08-07 01:09:07 +00:00
Eli Schwartz 59a56dfa64 trivial sync of pkg.m4 from freedesktop
This contains 3 changes, mostly inconsequential:

- fix some spelling issues in the comments

  eb866ade77

- bump the serial number; upstream rationale is very 🤷 but it is
  what it is:
  > There aren't any significant changes here, but this will cause aclocal
  > to get the latest version.

  677e924875

- make the status log for PKG_CHECK_MODULES say "checking for <mod>..."
  instead of "checking for <VAR>..."

  3b96e7434c

There are additional whitespace-only changes that could be synced, and
were explicitly synced in commit 95b683c864
but then undone in commit 360a818f2f so
rather than fighting over it, are simply ignored. Diffing against the
freedesktop version of pkg.m4 will therefore show additional
inconsistencies.
2022-08-07 00:40:17 +00:00
Ariadne Conill 56881f64f0 cli: resolve uninitialized pointer warnings reported by GCC 12 2022-08-07 00:38:38 +00:00
Ariadne Conill b310728111 Merge pull request 'Do a better job cleaning up memory' (#239) from dcbaker/pkgconf:free-memory into master
Reviewed-on: ariadne/pkgconf#239
2022-08-04 23:36:15 +00:00
Dylan Baker 179a0560a6 ci: run meson test with the address sanitizer enabled
Set the ASAN_OPTION so that the exitcode is not 1, this avoids asan
returning the exitcode that the tests already expect from a normal
pkgconf error
2022-08-04 15:52:10 -07:00
Dylan Baker 1cfa2d1e20 pkg: prevent circular ownership
Otherwise in a case where A references B, and B references A, A and B
will have mutual ownership of each other and prevent each other from
being free'd.
2022-08-04 15:52:10 -07:00
Dylan Baker 301d8fa0c6 queue: free unused dependencies when flattening 2022-08-04 15:52:10 -07:00
Dylan Baker 34b110200a dependency: zero list after freeing 2022-08-04 15:52:10 -07:00
Dylan Baker e71a5a3370 dependency: add debug information for dependency refcounting 2022-08-04 15:52:10 -07:00
Dylan Baker 4934205737 pkg: add name of pkg being refed/unrefed to debug outpu 2022-08-04 15:52:10 -07:00
Dylan Baker a46ce3672f queue: when collecting dependents don't iterate private twice
Currently, the private field is iterated collecting private deps and
normal deps. It should only be iterated when collecting private deps.
2022-08-04 15:52:10 -07:00
Dylan Baker 4493a322f6 main: do cleanup when checking required version 2022-08-04 15:52:10 -07:00
Dylan Baker a391f9b650 pkg: use goto cleanup idiom 2022-08-04 15:52:10 -07:00
Dylan Baker 38103134a5 main: goto cleanup in validate case too
This fixes leaks in two tests
2022-08-04 15:52:10 -07:00
Dylan Baker 171738024e cache: clear the cache with pkgconf_cache_remove
Which results in more code re-use.
2022-08-04 15:52:10 -07:00
Dylan Baker e4d1c8ffa5 queue: when flattening do nothing if the flattened deps are empty 2022-08-04 15:52:10 -07:00
Dylan Baker 6609001114 queue: unref dependency in all cases 2022-08-04 15:52:10 -07:00
Dylan Baker e275594ba6 queue: ensure cleanup happens when applying 2022-08-04 15:52:10 -07:00
Dylan Baker 4a1119aa2a dependency: Fix reference counting of dependency_addraw
We only want a reference to be added for the value inserted into the
list, not the one returned. The returned one is unowned until it reaches
the public dependency_add function, which returns an owned pointer
instead. This makes things semantically more correct.

Unfortunately, this means in a few cases we have to write some ugly
code like:
```c
pkgconf_dependency_t *dep = pkgcond_dependency_add("args");
pkgconf_dependency_unref(dep->owner, dep);
```
2022-08-04 15:52:10 -07:00
Dylan Baker a4de6235c2 cache: when removing a package from the cache unset the cached flag 2022-08-04 15:52:10 -07:00
Dylan Baker ebe74fd253 cache: free the cache table when it is empty and set to NULL
We do the latter for the benefit of libpkgconf. This cleans up a
significant number of memory leaks in the cache handling.
2022-08-04 15:52:10 -07:00
Ariadne Conill d240afe7d9 Merge pull request 'Fix macro definition interfering with -Wmisleading-indentation' (#241) from dcbaker/pkgconf:submit/misleading-indentation into master
Reviewed-on: ariadne/pkgconf#241
2022-08-04 04:33:11 +00:00
Dylan Baker 125a13d3b9 meson: add -Wmisleading-indentation
A useful warning when loop and conditional statements are allowed
without braces.
2022-08-03 12:03:15 -07:00
Dylan Baker 96c61cbab0 libpkgconf: remove trailing ; from macro definition
GCC has a lovely bug (which I will report as soon as I have an account),
which causes -Wmisleading-indentation to miss cases of misleading
indentation after a `;;`, since the macro adds `;`, and in call cases
the caller also adds `;`, we end up with a double macro and gcc fails to
warn.
2022-08-03 12:03:15 -07:00
Ariadne Conill a042827951 Merge pull request 'meson cleanups and fixes' (#240) from dcbaker/pkgconf:submit/meson-cleanups into master
Reviewed-on: ariadne/pkgconf#240
2022-08-02 23:09:24 +00:00
Dylan Baker dd779ad9f8 meson: add check to run_command
Because we really should be checking that it succeeds, and because not
setting it is deprecated.
2022-08-01 09:40:08 -07:00
Dylan Baker c04097e491 meson: pass configured files idiomatically
Instead of attempting to figure out what the paths will be, take the
returned file object and pass that around, meson will then automatically
figure out the correct paths.
2022-08-01 09:40:08 -07:00
Dylan Baker 06fe2e23b0 meson: use current_source_dir and current_build_dir instead of *_root
The latter doesn't work correctly when being used as a subproject, as it
returns the *absolute* root. So if pkgconf is being built as part of
muon, then it will return muon's source root. current_source_dir, on the
other hand returns the directory correctly whether being built as a
subproject or superproject.
2022-08-01 09:40:08 -07:00
Dylan Baker 1f993bc095 meson: use string methods to avoid repeating data
Instead of writing `['HAVE_FOO_H', 'foo.h']`, use meson's string methods
to just write `['foo.h']`, and let meson create `HAVE_FOO_H` for us.
2022-08-01 09:40:08 -07:00
Dylan Baker f947af057f meson: use str.format for improved readability 2022-08-01 09:40:08 -07:00
Dylan Baker 5ba74dec93 meson: use straight indexing instead of array.get()
It's more terse, and we don't need the support of a fallback value.
2022-08-01 09:40:08 -07:00
Dylan Baker bf307c1d95 ci: set meson to build with -Werror
This will help catch any new warnings added in CI.
2022-08-01 09:40:08 -07:00
Dylan Baker 4a2c9c285f meson: use C99 as the standard
autoconf uses either C99 or Gnu99. Meson does not provide a graceful way
to select gnu99 if possible or c99 (though there are several proposals
currently happening to get there), so I've selected c99 as the
conservative default. Without this, the compiler uses whatever it's
default happens to be, which may or may not work out correctly, and
hides bugs from CI that are present with c99 as the default.
2022-07-29 10:23:18 -07:00
Dylan Baker 40ec08594e meson: add warning for implicit-function-declarations
This would be triggered without the previous addition of -D_BSD_SOURCE
for strdup, among others
2022-07-29 10:23:18 -07:00
Dylan Baker 71974d8c54 meson: Add _BSD_SOURCE and _DEFAULT_SOURCE
To avoid warnings about string functions like strdup which are otherwise
undefined, but succeed at linking anyway when the C standard is c99.
2022-07-29 10:23:02 -07:00
Ariadne Conill 918b660992 woodpecker: track debian testing for autoconf 2.71 2022-07-26 18:15:50 +00:00
Ariadne Conill f93870efd9 tests: add testcase for legacy FDO rules plus pc_sysrootdir 2022-07-26 18:05:31 +00:00
Ariadne Conill 18e2406002 tests: add omg-sysroot-uninstalled fixture 2022-07-26 18:03:15 +00:00
Ariadne Conill 6c70781aad introduce PKG_CONFIG_PKGCONF1_SYSROOT_RULES for legacy pkgconf behavior 2022-07-26 18:00:22 +00:00
Ariadne Conill f8aefea7ec pkg: add flags argument to pkgconf_pkg_new_from_file 2022-07-26 17:13:15 +00:00
Ariadne Conill 297e18f2c8 tuple: add flags parameter to pkgconf_tuple_parse 2022-07-26 17:08:48 +00:00
Ariadne Conill d9ec3ee642 tests: add testcases for confirming desired sysroot behavior regarding -uninstalled packages 2022-07-26 16:46:39 +00:00
Ariadne Conill b0802cb3d1 Revert "pkgconf_pkg_parser_value_set(): fix code-path ordering bug."
This reverts commit 13fe4c8c58.
2022-06-26 19:41:31 +00:00
Ariadne Conill b602e33141 github actions: use debian testing 2022-06-26 19:39:09 +00:00
Ariadne Conill 72e429ae70 tuple: use ${pc_sysrootdir} instead of client->sysroot_dir where relevant 2022-06-26 19:35:19 +00:00
Ariadne Conill 7fa632a658 tests: sysroot: add additional tests 2022-06-26 19:34:54 +00:00
Ariadne Conill 9950312fde tests: add additional test fixtures 2022-06-26 19:34:39 +00:00
Ariadne Conill 19b1befb5d add additional sysroot testcase fixtures 2022-06-26 19:21:52 +00:00
Ariadne Conill a61193c723 pkg: fix sysroot_dir logic for github 213 2022-06-26 19:16:00 +00:00
Ariadne Conill d68a867dc0 tuple: fall back to using globals rather than preferring them 2022-06-26 19:15:07 +00:00
Ariadne Conill bc272e4e9f autoconf: run autoupdate 2022-06-26 18:58:08 +00:00
Ariadne Conill 623b8f7851 tests: further fixups 2022-06-26 18:56:36 +00:00
Ariadne Conill fdd7d192e0 queue: fix ISO C conformance for fallthrough label 2022-06-26 18:39:00 +00:00
Ariadne Conill 11164376f7 main: handle --personality load failure 2022-06-26 18:34:22 +00:00
Ariadne Conill ab352222a2 tests: fix up some test changes from the solver optimizations
the output of pkgconf is basically functionally equivalent in both cases
2022-06-26 18:22:04 +00:00
Ariadne Conill 04a6dda79f main: refactor apply_variable 2022-06-26 18:17:30 +00:00
Ariadne Conill a1a415111f queue: handle pkgconf_pkg_verify_dependency failure while flattening 2022-06-26 18:09:22 +00:00
Ariadne Conill 9bc6d80e61 queue: push new unresolved dependencies to the front of the queue, rather than the tail 2022-06-26 18:06:04 +00:00
Ariadne Conill fe4db3aad9 queue: skip dependency collection for root node 2022-06-26 18:04:42 +00:00
Ariadne Conill 5a82a259ac queue: use maxdepth after flattening 2022-06-26 15:17:08 +00:00
Ariadne Conill a416dc1fd6 queue: advance client serial when walking requires.private for flattening 2022-06-26 15:16:36 +00:00
Ariadne Conill 197fcadd4c queue: add flattening code 2022-06-26 15:02:37 +00:00
Ariadne Conill 5817e8848f pkg: track the number of hits a package has gotten while solving for dependencies 2022-06-26 07:22:56 +00:00
Ariadne Conill 6ae17bd0ef pkg: split pkgconf_pkg_traverse into a serial-modifying version 2022-06-26 06:05:40 +00:00
Ariadne Conill ffa0805d58 cache: use pkgconf_reallocarray stub 2022-06-26 04:38:02 +00:00
Ariadne Conill c1579d381c bsdstubs: add pkgconf_reallocarray 2022-06-26 04:37:18 +00:00
Ariadne Conill 4c76f6bf01 meson: check for reallocarray
it is needed for the new cache code
2022-06-26 04:33:47 +00:00
Ariadne Conill 664f741f26 autoconf: check for reallocarray
it is needed for the new cache code
2022-06-26 04:33:25 +00:00
Ariadne Conill 464672404e cache: refactor to use a continguous table and bsearch
cache functions are the hottest part of the pkgconf code when
profiled, by removing the linked list for lookups, we can turn
lookups into an O(k) operation
2022-06-26 04:30:35 +00:00
Dylan Baker c0fa7879b2 libpkgconf: zero path lists after freeing
This is required to make the pointer safely re-usable after being freed,
otherwise the list still says that it has nodes, but they point nowhere.
This is particularly important for libpkgconf, if a caller needs to
re-enter the library after freeing a path in a static path (such as the
default personality)
2022-06-26 03:12:34 +00:00
Dylan Baker 2d201af326 libpkgconf: Add a helper to zero `pkgconf_list_t`s 2022-06-26 03:12:34 +00:00
Ariadne Conill 21ffd343e1 CI: woodpecker: use matrix builds 2022-06-26 03:11:36 +00:00
Ariadne Conill a441455bf4 CI: add woodpecker config 2022-06-26 03:11:36 +00:00
Ariadne Conill cf48b61a59 stdinc: include strings.h on POSIX 2022-02-21 04:42:26 -06:00
Ariadne Conill 40131312ec meson: check for strdup, strcasecmp, strncasecmp 2022-02-21 04:41:08 -06:00
Ariadne Conill cc4ccc1429 meson: use _BSD_SOURCE for checking for symbols 2022-02-21 04:39:49 -06:00
Ariadne Conill ac964d13f3
Merge pull request #240 from Tachi107/readme-meson
docs: mention Meson instead of CMake for Win build
2022-02-21 04:27:20 -06:00
Ariadne Conill 0995e49977
Merge branch 'master' into readme-meson 2022-02-21 04:27:11 -06:00
Ariadne Conill 820af53a2d
Merge pull request #241 from Olf0/patch-1
Re-do MR #235, i.e. the vanished commit fe98e1b
2022-02-21 04:25:48 -06:00
Ariadne Conill a45dbccc01
Merge pull request #242 from data-man/dirent_latest
Update dirent.h to latest
2022-02-21 04:25:36 -06:00
Ariadne Conill c6cfca6730
Merge pull request #245 from dcbaker/submit/remove-const
libpkgconf: remove const modifier from error_handler data pointer
2022-02-21 04:25:26 -06:00
Ariadne Conill aaabc2cb15
Merge pull request #246 from dcbaker/submit/personality-deinit
personality: use an unsigned to track initializations instead of a bool.
2022-02-21 04:25:14 -06:00
Dylan Baker c581e24a67 personality: use an unsigned to track initializations
Instead of a bool. The latter will result in de-initing leaving the
library unable to init again, which works out for the cli, but is
problematic for other consumers (meson++ and muon).

v2: - Add docs that the functions are not thread safe
2022-02-14 21:22:05 -08:00
Dylan Baker f5d6bb71f8 libpkgconf: remove const modifier from error_handler data pointer
Currently, the data pointer is `const void *`, which means that the
handler can't modify the data without casting away the constness.
2022-02-07 09:34:09 -08:00
data-man b132ce8317 Update dirent.h to latest 2022-01-08 10:55:28 +05:00
olf ae3a9c5440
Re-do MR #235, i.e. the vanished commit fe98e1b 2021-12-11 22:56:31 +01:00
Andrea Pappacoda 6109e06089
docs: mention Meson instead of CMake for Win build
Fixes #233
2021-12-11 14:49:19 +01:00
Dylan Baker 1044bb57ca meson: make use of override_dependency() if possible
This allows simplifying the subproject override to simply

```meson
dependency('libpkgconf')
```
2021-12-01 09:17:07 -06:00
Dylan Baker 72c59b89c6 meson: Add dependency for for libpkgconf
This allows others using libpkgconf as a dependency to do use this as a
subproject. They can write something like:

```meson
dependency('libpkgconf', fallback : ['libpkgconf', 'dep_libpkgconf'])
```

Then install a wrap file for libpkgconf and build it as part of their
project.
2021-12-01 09:17:07 -06:00
Mattias Hansson 8d9d3de6eb pkg.m4: PKG_CHECK_MODULES provides modversion
Projects using PKG_CHECK_MODULES wants to add dependency versions to
their binaries. Currently, the projects have to resolve dependency
versions themselves when using pkgconf.

With this patch PKG_CHECK_MODULES now defines a $PKG_VERSION variable
that represents `--modversion`.
2021-10-27 06:41:28 -05:00
Mattias Hansson 360a818f2f pkg.m4: Unified indentation in PKG_CHECK_MODULES
Currently the indentation in PKG_CHECK_MODULES is a mix och tabs and
spaces which makes it hard to read. This patch unifies the indentation
in the function to spaces.
2021-10-27 06:41:28 -05:00
Ariadne Conill f3049d634d README: note that --debug output should not be considered stable 2021-10-25 21:52:52 -06:00
Ariadne Conill bf933903aa hackfix a couple of flaky tests 2021-10-07 01:29:29 -06:00
Ariadne Conill 2b82a4f63e use a serial instead of PKGCONF_PKG_PROPF_SEEN 2021-10-07 00:27:32 -06:00
Ariadne Conill 7d8cc1e4ce dependency: add pkgconf_dependency_copy() 2021-10-06 13:13:34 -06:00
Ariadne Conill c547edd07f deconst the client on pkgconf_dependency_add() 2021-10-06 11:52:18 -06:00
Ariadne Conill 4144d506bb implement dependency refcounting 2021-10-06 11:48:37 -06:00
olf d87114068f Fix typo
verses -> versus
2021-10-06 12:30:49 -05:00
Ariadne Conill 8130dd159e dependency: add pkgconf_dependency_free_one 2021-10-06 11:29:18 -06:00
Ariadne Conill 2b390ea9cf add memory leak fix info to NEWS 2021-08-17 15:32:30 -06:00
Ariadne Conill 4b87e256d3 cache: clear package cache without using the refcounts 2021-08-17 15:29:55 -06:00
Ariadne Conill df1b671c83 dependency: use dependency match owner with pkgconf_pkg_unref() 2021-08-17 15:18:47 -06:00
Ariadne Conill 41bff10998 cli: ensure the client and cross-personality are cleaned up in all cases 2021-08-17 14:54:36 -06:00
Ariadne Conill f411e7e55b cli: free package resolution queue unconditionally 2021-08-17 14:47:10 -06:00
Ariadne Conill ce82e36c14 cli: fix memory leak when packages are not provided on the command line 2021-08-17 14:39:44 -06:00
Ariadne Conill cef30268e1 pkgconf 1.8.0. 2021-07-24 20:40:52 -06:00
Ariadne Conill a10a88ef64 tests: regress: disable sysroot_munge test for now, not working with distcheck 2021-07-24 20:39:29 -06:00
Ariadne Conill 2ed2b98e64 workflows: more distcheck fixes 2021-07-24 20:28:04 -06:00
Ariadne Conill 9b49eb2280 workflows: install xz package 2021-07-24 20:26:44 -06:00
Ariadne Conill 4d5b378f9e workflows: use distcheck instead of check for autotools tests 2021-07-24 20:25:15 -06:00
Ariadne Conill f3f7145963 NEWS: add updates for pkgconf 1.8.0 2021-07-24 20:19:46 -06:00
Ariadne Conill 78bcb17116 personality: do not perform path filtering on default SYSTEM_INCLUDE_PATHS and SYSTEM_LIBRARY_PATHS
This is not consistent with the way the personality files or environment variables
are handled.

Fixes #224.
2021-07-24 20:06:55 -06:00
Ariadne Conill 4e73e37d29 meson: fix non-static build 2021-07-24 19:56:46 -06:00
Ariadne Conill ceece2c195 pkg: fix up comment about issue #213 workaround 2021-07-24 19:47:33 -06:00
Ariadne Conill 76968a4f8d fix static builds on Windows with Meson
Fixes #222
2021-07-24 19:45:43 -06:00
Sandro Mani ed86f2dda3 Don't prepend sysroot_dir if pkg-config file lies outside of sysroot_dir 2021-07-24 20:43:58 -05:00
Ariadne Conill 9ea26eb913 README: expand on the pkg-config compatibility promise
A bunch of CMake developers, who apparently did not comprehend the previous
compatibility promise statement, decided to passive-aggressively demand we fix
their non-bug anyway.

Clarify in more detail what level of pkg-config compatibility we provide, and
mention that such passive-aggressive behaviour is considered a CoC violation.

Fixes #228.
2021-07-24 19:41:48 -06:00
Stone Tickle fa859bb045 close error_msgout if opened 2021-07-24 06:08:25 -05:00
Stone Tickle dba2600014 deinit personality in cli 2021-07-24 06:08:25 -05:00
Stone Tickle d688a7bd03 implement pkgconf_cross_personality_deinit 2021-07-24 06:08:25 -05:00
midipix 13fe4c8c58 pkgconf_pkg_parser_value_set(): fix code-path ordering bug.
Prior to this commit, the code path responsible for prefix redefinition
(motivated by --define-prefix or otherwise) was visited more than
once, specifically since the check ignored pkg->owner->prefix_varname.
2021-06-18 14:42:41 -05:00
Ariadne Conill 1f319c2608 we are moving to OFTC 2021-05-19 05:52:27 -05:00
orbea 2fdc5f0081 man: Document the --validate option. 2021-03-29 09:50:41 -08:00
Christoph Reiter 4f73f6a1d6 Rework path handling on native Windows
The current approach was to parse the .pc and, detect the prefix, throw
everything together and at the end replace all \ with / to not produce invalid
escape sequences.

This has the problem that escaping in .pc files is ignored and no longer
possible. Also in case the prefix path has a space in it the result would be
invalid because of missing escaping.

This changes the following things:

* We no longer normalize values at the end. Instead we assume .pc files use "/"
  as a directory separator or "\\", same format as under Unix. "\" alone no
  longer works. This shouldn't be a problem since most build tools produce .pc
  files with "/" like meson, cmake, autotools.

* When injecting the prefix at runtime we convert the prefix to use "/" and
  escape spaces so that in combination with the .pc content the result is a
  valid escaped path value again.

This patch has been used in MSYS2 for some months now.

See #212
2021-03-20 06:59:38 -08:00
Christoph Reiter 4be39c59fb Remove usage of cygwin_conv_path() under cygwin/msys
This converted Unix paths to Windows paths, but all cygwin tools
work with Unix paths so this shouldn't be needed.

There is one use case if you use a cygwin pkgconf with a non-cygwin toolchain,
but pkgconf works reasonable well natively now so this shouldn't be needed
anymore and more likely leads to problems and confusion.

Both cygwin and msys have patched this out already:
* https://cygwin.com/git-cygwin-packages/?p=git/cygwin-packages/pkgconf.git;a=blob;f=pkgconf.cygport;h=e5d003f3f3dfc9e374b916974018022ad8d68852;hb=HEAD#l55
* a4bce0c294/pkgconf/PKGBUILD (L26)
2021-03-20 06:58:53 -08:00
Ariadne Conill 458101e787 pkgconf 1.7.4. 2021-03-18 07:05:03 -06:00
Ariadne Conill dbb6a232e5 path: don't use PATH_MAX, use PKGCONF_ITEM_SIZE * 4 for realpath buffer 2021-03-18 06:56:55 -06:00
Ariadne Conill a4e8cf87ad remove sourcehut CI config 2021-03-18 06:52:55 -06:00
Ariadne Conill 9f6b2ced47 README: use github CI badge 2021-03-18 06:52:31 -06:00
Ariadne Conill 37b596ccda CI: fix alpine autotools CI 2021-03-18 06:49:16 -06:00
Ariadne Conill caaf4861cf CI: fix alpine CI 2021-03-18 06:48:07 -06:00
Ariadne Conill 00cc9a8caf CI: add alpine CI alongside debian CI 2021-03-18 06:46:09 -06:00
Ariadne Conill 599dfcb264 main: extend copyright notice to 2021 2021-03-18 06:42:57 -06:00
Ariadne Conill 402fd9fe1f add funding.yml 2021-03-18 06:38:24 -06:00
Ariadne Conill fd1b8ccca6 main: if PKG_CONFIG_FDO_SYSROOT_RULES is set, or DESTDIR matches PKG_CONFIG_SYSROOT_DIRS, disable the automatic sysroot rewriting
Closes #205.
2021-03-18 06:22:11 -06:00
Ariadne Conill b6c8f6fb0a NEWS: document --static --pure default on Windows (closes #207) 2021-03-18 06:05:48 -06:00
Ariadne Conill 008d706958 libpkgconf: personality: default: set want_default_static and want_default_pure to true on windows 2021-03-18 06:03:47 -06:00
Ariadne Conill f9531ce9fe add support for pkgconf_cross_personality_t.want_default_pure 2021-03-18 06:02:00 -06:00
Ariadne Conill 52d19e1b9e libpkgconf: fileio: pkgconf_fgetline(): handle quoted=true when a comment introduction is encountered
Fixes #215.
2021-03-18 05:45:41 -06:00
Ariadne Conill 347281ebfe tests: add fragment-comment testcase (ref #215) 2021-03-18 05:39:45 -06:00
Jeff Moguillansky dcf529b83d cli: add environment variable PKG_CONFIG_DONT_DEFINE_PREFIX
On Windows, pkgconf redefines the prefix by default.
This gives the user the option to disable this behavior via an environment variable.
The benefit of an environment variable is the user can change this behavior when
using a build system such as cmake or meson, which may not expose this
parameter to the user.
2021-02-06 14:06:04 -07:00
Ryan Scott ab404bc25b Fix #209
This commit fixes #209 by applying the suggestion from
https://github.com/pkgconf/pkgconf/issues/209#issuecomment-771609136.
2021-02-05 23:57:10 -07:00
Fabian Groffen 13a5d9a5f0 libpkgconf: path: supply buffer to realpath
To avoid a crash on some platforms (like Darwin 9) provide a buffer to
realpath(3).

Darwin 9 (last PPC target) documents realpath needs to be given a buffer
to the resolved_path argument large enough to hold PATH_MAX bytes.
With NULL argument it crashes.  Solaris makes no mention of
resolved_path to be allowed NULL, yet recent versions accept it and
malloc(3) accordingly.

Because the documentation explicitly mentions PATH_MAX being the limit
to what realpath(3) would write in resolved_path, switching to a static
buffer here doesn't limit resolution compared to dynamically allocating
a buffer by realpath(3).

While this change requires a bit more space on the stack, it avoids a
malloc/free sequence, and allows successful operation on (older)
platforms that lack support for dynamically allocating a return buffer
in realpath(3).

Signed-off-by: Fabian Groffen <grobian@gentoo.org>
2021-01-08 18:44:40 -05:00
Christoph Reiter 78a77dd497 meson: install README.md/AUTHORS to share/doc/pkgconf
To mirror what the autotools build does.
2020-11-28 19:42:00 -07:00
Christoph Reiter 0526364b85 meson: allow building a static version of libpkgconf
when using library() instead of shared_library() the user can decide
to build a shared or static version, or both. The default is still shared
as before.

This mirrors what the autotools based build sysstem can do.
2020-11-28 19:42:00 -07:00
Christoph Reiter a69bdfa28e meson: generate a .pc file for libpkgconf 2020-11-28 19:42:00 -07:00
Christoph Reiter de8fc9e438 meson: install headers into pkgconf/libpkgconf instead of just libpkgconf
To mirror what the autotools build does
2020-11-28 19:42:00 -07:00
Christoph Reiter 869f2a84d6 pkgconf_pkg_parser_version_func: fix whitespace detection
In case the version string has no whitespace then strcspn() returns
strlen() of the input, so whitespace is only found if len != strlen.

This fixes invalid warnings when parsing version fields.
2020-11-28 19:17:03 -07:00
Christoph Reiter b218cae5a9 Add CI for debian+meson/autotools
Builds and runs tests. Using Debian testing since the test framework
is only in testing right now.
2020-11-23 10:31:52 -07:00
Christoph Reiter 24589cddb0 Add basic CI for mingw-w64 32/64 bit
This only builds things with meson and no tests are run.
2020-11-23 04:13:05 -07:00
Ariadne Conill f418b997e5 configure: shift issue tracking back to github 2020-11-21 10:00:41 -07:00
orbea bd960e9d05 man: Silence pkgconf-personality.5 warning.
man: ./pkgconf-personality.5:97:2: WARNING: unusual Xr order: pc(5) after pkg.m4(7)
2020-08-09 20:22:14 -06:00
Ariadne Conill 1eeb4ee5c2 start NEWS for 1.7.4 2020-06-11 18:03:42 -06:00
Ariadne Conill 2a8bebf289 libpkgconf: path: rewrite DOS paths in non-cygwin case too 2020-06-11 18:00:56 -06:00
Tobias Stoeckmann 262a0c964f man: pkgconf: fixed typo
Fixed typo in it's vs its.
2020-06-10 00:20:36 -06:00
Tobias Stoeckmann f818a69b3d libpkgconf: pkg: fix out ouf boundary access
If a file with a matching "uninstalled" name exists but cannot be
parsed, an invalid memory area is accessed.

How to reproduce:
$ touch poc-uninstalled.pc
$ PKG_CONFIG_PATH=. pkgconf poc
2020-06-10 00:20:36 -06:00
Ariadne Conill ef135d819c meson: remove some autotools cruft 2020-06-02 18:58:00 -06:00
Ariadne Conill aca0674837 pkgconf 1.7.3. 2020-05-30 19:20:25 -06:00
Ariadne Conill 40726b14ac update NEWS 2020-05-30 19:20:25 -06:00
Ariadne Conill 354c87279b libpkgconf: tuple: fix truncation when no overflow occurs 2020-05-30 19:20:25 -06:00
Tobias Stoeckmann 5eb9cae009 libpkgconf: tuple: fix out of boundary write
This is the same issue which has been fixed in dependency code.

If a line contains a variable which is longer than PKGCONF_ITEM_SIZE,
then the varname buffer overflows.

The code itself still does not check if a closing } exists and
truncates variable names which are too long. Since these would
be functional changes and this commit is about a protection against
undefined behaviour on a language level, these changes are not
included.

Proof of concept:
$ echo "Description: poc" > poc.pc
$ echo "Version: 1" >> poc.pc
$ echo -n 'Name: ${'
$ dd if=/dev/zero bs=1 count=66535 | tr '\0' 'x' >> poc.pc
$ echo >> poc.pc
$ pkgconf poc.pc

On my Linux system, when compiled with gcc, the varname buffer overflows
directly into buf, which means that no crash can be notified.

It's easiest to figure out when adding strlen() and sizeof() output
as debug lines.
2020-05-30 19:09:24 -06:00
Tobias Stoeckmann 100bc605de libpkgconf: fragment: fix out of boundary write
fragment_quote adds quotation to fragments if needed. It allocates a
buffer and grows it as needed.

Unfortunately the dst pointer is not updated after a realloc, which
means that dst still points into the old memory area. Further writing
characters into that area leads to out of boundy writes.

Proof of concept:

$ cat > poc.pc << EOF
Name: poc
Description: poc
Version: 1
CFlags: -Ia
CFlags: -I%%%%%%%%%%%%%%%%%%%%b
CFlags: -I%%%%%%%%%%%%%%%%%%%%c
CFlags: -Id
EOF
$ pkgconf --cflags poc.pc

Most reliable attempt is to compile pkgconf with address sanitizer,
but this file should lead to an abort on a glibc system due to modified
chunk pointers (tested with Linux on amd64).

But since this is undefined behaviour, it depends on system details.
2020-05-30 19:05:53 -06:00
Ariadne Conill 7bd08a51bf update NEWS 2020-05-30 12:43:08 -06:00
Tobias Stoeckmann dc04193c48 libpkgconf: fragment: fix out of boundary read
Parsing a fragment which consists only of a single dash leads to
an out of boundary read. It duplicates the following entry which
is not expected behaviour if another fragment follows.

Proof of concept:

$ cat > poc.pc << "EOF"
Name: poc
Description: poc
Version: 1
Cflags: - -I/somewhere
EOF
$ PKG_CONFIG_PATH=. pkgconf --cflags poc
-I/somewhere -I/somewhere

If - is the last entry, it leads to an out of boundary read, which is
easy to see if pkgconf is compiled with address sanitizer.
2020-05-30 12:43:08 -06:00
Vincent Torri 42b355310f fix missing backslashes in paths on Windows
According to

https://docs.microsoft.com/fr-fr/windows/win32/fileio/naming-a-file

backslashes (with slashes) are a path separator, hence must no be
considered as an escape code.

The first fix, in argvsplit.c, disables this. But because of fragment_quote(),
the backslashes are doubled. Hence the second fix in fragment.c

With this pc file :

prefix=C:/Documents/msys2/opt/efl_64
libdir=${prefix}/lib
includedir=${prefix}/include

Name: eina
Description: efl: eina
Version: 1.24.99
Requires.private: iconv
Libs: -L${libdir} -leina -pthread -levil
Libs.private: -lpsapi -lole32 -lws2_32 -lsecur32 -luuid -lregex -lm
Cflags:-I${includedir}/eina-1 -I${includedir}/efl-1
-I${includedir}/eina-1/eina -pthread

pkgconf.exe --cflags eina

returns :

-IC:\Documents\msys2\opt\efl_64/include/eina-1
-IC:\Documents\msys2\opt\efl_64/include/efl-1
-IC:\Documents\msys2\opt\efl_64/include/eina-1/eina -pthread
-DWINICONV_CONST= -IC:\Documents\msys2\opt\ewpi_64/include
2020-05-30 12:39:43 -06:00
Ariadne Conill e3e89926b5 start NEWS for 1.7.3 2020-05-26 14:04:34 -06:00
Tobias Stoeckmann fb9acedcad libpkgconf: dependency: fix out of boundary write
It is possible to trigger an out of boundary write in function
pkgconf_dependency_parse_str if a dependency line contains a very
long comparator. The comparator is stored in a temporary buffer which
has a size of PKGCONF_ITEM_SIZE.

The line which is parsed can be up to PKGCONF_BUFSIZE characters long,
which is larger than PKGCONF_ITEM_SIZE (although it depends on PATH_MAX).

Having a comparator which is longer than PKGCONF_ITEM_SIZE therefore
leads to an out of boundary write. Although it is undefined behaviour,
this can lead to an overridden compare variable, which in turn can lead
to an invalid instruction pointer, i.e. most likely a crash or code
execution (very unlikely).

Proof of concept:

$ echo "Requires: x " > poc.pc
$ dd if=/dev/zero bs=1 count=65535 | tr '\0' '<' >> poc.pc
$ pkgconf poc.pc

Eiter compile pkgconf with address sanitizer or run pkgconf multiple
times, eventually it might crash (assuming that ASLR is in place).

In order to fix this, I decided to use an end pointer to avoid OOB write.
Alternative would be to increase the buffer size, but I try to avoid that
since this would be additional ~60 KB stack space for a very unlikely
situation.
2020-05-26 14:03:55 -06:00
Ariadne Conill c6b93941a0 pkgconf 1.7.2. 2020-05-26 13:46:20 -06:00
Ariadne Conill c613eb5cce libpkgconf: pkg: use a second pointer for demunging windows paths 2020-05-26 13:42:39 -06:00
61 changed files with 2875 additions and 1237 deletions

View File

@ -1,23 +0,0 @@
image: alpine/edge
packages:
- build-base
- autoconf
- automake
- libtool
- kyua
- atf
- xz
- gzip
sources:
- https://git.sr.ht/~kaniini/pkgconf
tasks:
- autogen: |
cd ~/pkgconf
sh autogen.sh
- configure: |
cd ~/pkgconf
./configure
- distcheck: |
cd ~/pkgconf
make distcheck

View File

@ -1,25 +0,0 @@
image: fedora/rawhide
packages:
- make
- kernel-devel
- gcc
- gcc-c++
- autoconf
- automake
- libtool
- kyua
- libatf-sh
- xz
- gzip
sources:
- https://git.sr.ht/~kaniini/pkgconf
tasks:
- autogen: |
cd ~/pkgconf
sh autogen.sh
- configure: |
cd ~/pkgconf
./configure
- distcheck: |
cd ~/pkgconf
make distcheck

View File

@ -1,19 +0,0 @@
image: freebsd/latest
packages:
- autoconf
- automake
- libtool
- kyua
- atf
sources:
- https://git.sr.ht/~kaniini/pkgconf
tasks:
- autogen: |
cd ~/pkgconf
sh autogen.sh
- configure: |
cd ~/pkgconf
./configure
- distcheck: |
cd ~/pkgconf
make distcheck

View File

@ -1,17 +0,0 @@
image: alpine/edge
packages:
- build-base
- meson
- ninja
- kyua
- atf
sources:
- https://git.sr.ht/~kaniini/pkgconf
tasks:
- configure: |
cd ~/pkgconf
meson build
- distcheck: |
cd ~/pkgconf
ninja -C build
ninja -C build test

View File

@ -1,16 +0,0 @@
image: fedora/rawhide
packages:
- meson
- ninja-build
- kyua
- libatf-sh
sources:
- https://git.sr.ht/~kaniini/pkgconf
tasks:
- configure: |
cd ~/pkgconf
meson build
- distcheck: |
cd ~/pkgconf
ninja -C build
ninja -C build test

View File

@ -1,16 +0,0 @@
image: freebsd/latest
packages:
- meson
- ninja
- kyua
- atf
sources:
- https://git.sr.ht/~kaniini/pkgconf
tasks:
- configure: |
cd ~/pkgconf
meson build
- distcheck: |
cd ~/pkgconf
ninja -C build
ninja -C build test

3
.github/FUNDING.yml vendored Normal file
View File

@ -0,0 +1,3 @@
github: kaniini
patreon: kaniini
liberapay: kaniini

153
.github/workflows/test.yml vendored Normal file
View File

@ -0,0 +1,153 @@
name: test
on:
push:
pull_request:
jobs:
msys2:
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
include: [
{ msystem: MINGW64, arch: x86_64},
{ msystem: MINGW32, arch: i686}
]
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: setup-msys2
uses: msys2/setup-msys2@v2
with:
msystem: ${{ matrix.msystem }}
update: true
install: >-
mingw-w64-${{ matrix.arch }}-meson
mingw-w64-${{ matrix.arch }}-ninja
mingw-w64-${{ matrix.arch }}-gcc
- name: Build
shell: msys2 {0}
run: |
# the code assumes msvc style printf atm
export CFLAGS=-D__USE_MINGW_ANSI_STDIO=0
meson -Dtests=false _build
meson compile -C _build
debian-meson:
runs-on: ubuntu-latest
container:
image: debian:testing
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Update system and add dependencies
run: |
apt-get update
apt-get install -y kyua atf-sh build-essential meson
- name: Build
run: |
meson _build -Dwerror=true
meson compile -C _build
- name: Run tests
run: |
meson test -v -C _build
debian-meson-asan:
runs-on: ubuntu-latest
container:
image: debian:testing
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Update system and add dependencies
run: |
apt-get update
apt-get install -y kyua atf-sh build-essential meson
- name: Build
run: |
meson _build -Db_sanitize=address
meson compile -C _build
- name: Run tests
run: |
meson test -v -C _build
env:
ASAN_OPTIONS: "exitcode=7"
debian-autotools:
runs-on: ubuntu-latest
container:
image: debian:testing
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Update system and add dependencies
run: |
apt-get update
apt-get install -y kyua atf-sh build-essential autoconf libtool
- name: Build
run: |
./autogen.sh
./configure
make -j9
- name: Run tests
run: |
make distcheck
alpine-meson:
runs-on: ubuntu-latest
container:
image: alpine
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Update system and add dependencies
run: |
apk update
apk add kyua atf build-base meson
- name: Build
run: |
meson _build -Dwerror=true
meson compile -C _build
- name: Run tests
run: |
meson test -v -C _build
alpine-autotools:
runs-on: ubuntu-latest
container:
image: alpine
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Update system and add dependencies
run: |
apk update
apk add kyua atf build-base autoconf automake libtool xz gzip
- name: Build
run: |
./autogen.sh
./configure
make -j9
- name: Run tests
run: |
make distcheck

75
.woodpecker.yml Normal file
View File

@ -0,0 +1,75 @@
pipeline:
debian-meson:
image: debian:testing
commands:
- apt-get update
- apt-get install -y kyua atf-sh build-essential meson
- meson _build -Dwerror=true
- meson compile -C _build
- meson test -v -C _build
when:
matrix:
IMAGE: debian
BUILD: meson
debian-meson-asan:
image: debian:testing
environment:
- ASAN_OPTIONS="exitcode=7"
commands:
- apt-get update
- apt-get install -y kyua atf-sh build-essential meson
- meson _build -Db_sanitize=address
- meson compile -C _build
- meson test -v -C _build
when:
matrix:
IMAGE: debian
BUILD: meson
debian-autotools:
image: debian:testing
commands:
- apt-get update
- apt-get install -y kyua atf-sh build-essential autoconf libtool
- ./autogen.sh
- ./configure
- make -j
- make distcheck
when:
matrix:
IMAGE: debian
BUILD: autotools
alpine-meson:
image: alpine
commands:
- apk add -U --no-cache kyua atf build-base meson
- meson _build -Dwerror=true
- meson compile -C _build
- meson test -v -C _build
when:
matrix:
IMAGE: alpine
BUILD: meson
alpine-autotools:
image: alpine
commands:
- apk add -U --no-cache kyua atf build-base autoconf automake libtool xz gzip
- ./autogen.sh
- ./configure
- make -j
- make distcheck
when:
matrix:
IMAGE: alpine
BUILD: autotools
matrix:
IMAGE:
- debian
- alpine
BUILD:
- meson
- autotools

View File

@ -11,7 +11,7 @@ nodist_pkgconfig_DATA = libpkgconf.pc
AM_CFLAGS = -DPERSONALITY_PATH=\"$(personality_dir)\" -DPKG_DEFAULT_PATH=\"$(pkg_default_dir)\" -DSYSTEM_INCLUDEDIR=\"$(system_includedir)\" -DSYSTEM_LIBDIR=\"$(system_libdir)\"
bin_PROGRAMS = pkgconf
bin_PROGRAMS = pkgconf bomtool
lib_LTLIBRARIES = libpkgconf.la
EXTRA_DIST = pkg.m4 \
@ -61,6 +61,7 @@ EXTRA_DIST = pkg.m4 \
tests/lib3/bar.pc \
tests/lib1/conflicts.pc \
tests/lib1/omg-uninstalled.pc \
tests/lib1/omg-sysroot-uninstalled.pc \
tests/lib1/isystem.pc \
tests/lib1/idirafter.pc \
tests/lib1/idirafter-ordering.pc \
@ -76,6 +77,7 @@ EXTRA_DIST = pkg.m4 \
tests/lib1/fragment-collision-intermediary.pc \
tests/lib1/fragment-collision-1.pc \
tests/lib1/fragment-collision-2.pc \
tests/lib1/fragment-comment.pc \
tests/lib1/fragment-escaping-1.pc \
tests/lib1/fragment-escaping-2.pc \
tests/lib1/fragment-escaping-3.pc \
@ -87,6 +89,9 @@ EXTRA_DIST = pkg.m4 \
tests/lib1/malformed-1.pc \
tests/lib1/malformed-quoting.pc \
tests/lib1/malformed-version.pc \
tests/lib1/metapackage.pc \
tests/lib1/metapackage-1.pc \
tests/lib1/metapackage-2.pc \
tests/lib1/explicit-sysroot.pc \
tests/lib1/escaped-backslash.pc \
tests/lib1/cflags-internal.pc \
@ -97,6 +102,10 @@ EXTRA_DIST = pkg.m4 \
tests/lib1/tuple-quoting.pc \
tests/lib1/empty-tuple.pc \
tests/lib1/orphaned-requires-private.pc \
tests/lib1/sysroot-dir-2.pc \
tests/lib1/sysroot-dir-3.pc \
tests/lib1/sysroot-dir-4.pc \
tests/lib1/sysroot-dir-5.pc \
$(test_scripts) \
doc/conf.py \
doc/extract.py \
@ -145,7 +154,7 @@ libpkgconf_la_SOURCES = \
libpkgconf/path.c \
libpkgconf/personality.c \
libpkgconf/parser.c
libpkgconf_la_LDFLAGS = -no-undefined -version-info 3:0:0 -export-symbols-regex '^pkgconf_'
libpkgconf_la_LDFLAGS = -no-undefined -version-info 4:0:0 -export-symbols-regex '^pkgconf_'
dist_man_MANS = \
man/pkgconf.1 \
@ -158,11 +167,17 @@ pkgconf_SOURCES = \
cli/main.c \
cli/getopt_long.c \
cli/renderer-msvc.c
pkgconf_CPPFLAGS = -Ilibpkgconf -Icli
pkgconf_CPPFLAGS = -I$(top_srcdir)/libpkgconf -I$(top_srcdir)/cli
noinst_HEADERS = \
cli/getopt_long.h \
cli/renderer-msvc.h
bomtool_LDADD = libpkgconf.la
bomtool_SOURCES = \
cli/bomtool/main.c \
cli/getopt_long.c
bomtool_CPPFLAGS = -I$(top_srcdir)/libpkgconf -I$(top_srcdir)/cli -I$(top_srcdir)/cli/bomtool
dist_doc_DATA = README.md AUTHORS
m4datadir = $(datadir)/aclocal

136
NEWS
View File

@ -1,6 +1,142 @@
Changes from previous version of pkgconf
========================================
Changes from 1.9.2 to 1.9.3:
----------------------------
* Fix a bunch of minor code issues pointed out using Clang static analyzer.
* New API: pkgconf_solution_free(), which frees a compiled solution graph.
* Fix behavior when overriding global variables with `--define-variable`.
Changes from 1.9.1 to 1.9.2:
----------------------------
* Do not try to break dependency cycles across dependency lists. This causes
the solved graph to sometimes miss required dependency nodes because the
solver detected an incorrect dependency cycle.
* New API: pkgconf_queue_solve(), which replaces pkgconf_queue_apply().
pkgconf_queue_apply is now deprecated and should not be used in new code.
Changes from 1.9.0 to 1.9.1:
----------------------------
* Skip graph flattening and traversal for query types which only make sense
for a single pkg-config module.
The old solver walked these graphs with --maximum-traverse-depth=1 in
these cases, but this is no longer helpful because the graph is flattened
by the new solver.
Changes from 1.8.0 to 1.9.0:
----------------------------
* pkgconf 1.9.0 is the first testing release in the pkgconf 2.0 development
series. While it is believed to be suitable for production, there may be
bugs due to the overall redesign of the solver and other initiatives.
Additionally, a future release of pkgconf plans will have additional ABI
breaks for the libpkgconf library before the pkgconf 2.0 release is cut.
* There is now a new solver that is designed to provide higher performance
with complicated graphs, which works by flattening the dependency graph
into a smaller set of dependencies. This graph can then be evaluated
instead of the original dependency graph without having to visit every
edge in the graph.
NOTE: This solver, while providing significant performance improvements,
does so, at the cost of changed behavior for some edge cases (such as
circular dependencies).
* Bug fixes:
- Resolved several memory leaks with edge cases when using libpkgconf
directly.
- pkgconf CLI now consistently frees libpkgconf resources under all
circumstances.
- SYSROOT rules are no longer applied to `-uninstalled` packages by
default. Use `PKG_CONFIG_PKGCONF1_SYSROOT_RULES` for legacy behavior.
* A new `--license` selector has been added to the pkgconf CLI. This uses
SPDX expressions which can be set as the `License` field in `.pc` files.
See the `pc(5)` manpage for more information.
* The canonical location for pkgconf maintenance going forward is
<https://gitea.treehouse.systems/ariadne/pkgconf>. This is presently
mirrored to GitHub for user convenience, but that mirroring will
be terminated at some point (due to GitHub Copilot).
Changes from 1.7.4 to 1.8.0:
----------------------------
* This is the last planned maintenance branch. I see pkgconf as basically
a finished tool at this point, and very few people were ultimately interested
in libpkgconf. So, from here on out, it will just be bug fixes only and
very minor enhancements.
* Bug fixes:
- Improved path handling on Windows to conform to what the MSYS2
and Cygwin teams were already modifying pkgconf to do.
Patches by Christoph Reiter.
- Fix a minor memory leak relating to cross-personalities.
Patch by Stone Tickle.
- Fix static builds for Windows on Meson.
Patch by Alexander Neumann.
- Fix some edge cases with --redefine-prefix.
Patch by midipix.
- Do not prepend sysroot_dir if the .pc file does not exist in the
sysroot.
Patch by Sandro Mani.
- Do not perform path filtering on default system include and library
path lists. This fixes consistency with other mechanisms that modify
these path lists.
* Enhancements:
- Document the --validate option in the manpage.
Patch by orbea.
Changes from 1.7.3 to 1.7.4:
----------------------------
* Bug fixes:
- Fix null-dereference crash when pulling a malformed 'uninstalled'
.pc file into a dependency tree. Patch by Tobias Stöckmann.
- Fix truncation of comment characters when quoted.
- Fix handling of .pc module names in --list-all on Windows.
Patch by Ryan Scott.
- Handle platforms where realpath(3) requires a pre-allocated buffer.
Patch by Fabian Groffen.
- Fix version whitespace warning.
Patch by Christoph Reiter.
* Enhancements:
- Rewrite DOS paths on native Windows builds that don't use
Cygwin/MSYS.
- Add WantDefaultPure cross-compiler personality option.
- Prefer --static --pure linking on Windows.
- Add PKG_CONFIG_DONT_DEFINE_PREFIX environment variable.
Patch by Jeff Moguillansky.
- Many improvements when building pkgconf with Meson.
Patches by Christoph Reiter.
Changes from 1.7.2 to 1.7.3:
----------------------------
* Bug fixes:
- Fix a possible out of boundary write when evaluating dependencies.
Patch by Tobias Stöckmann.
- Fix escaping logic on Windows. Patch by Vincent Torri.
- Fix out of boundary reads and writes with a malformed fragment.
Patches by Tobias Stöckmann.
- Fix a possible out of boundary write when evaluating tuples.
Patch by Tobias Stöckmann.
Changes from 1.7.1 to 1.7.2:
----------------------------
* Bug fixes:
- Fix a windows-specific crash relating to path fixups.
Changes from 1.7.0 to 1.7.1:
----------------------------

View File

@ -1,11 +1,11 @@
# pkgconf [![builds.sr.ht status](https://builds.sr.ht/~kaniini/pkgconf.svg)](https://builds.sr.ht/~kaniini/pkgconf?)
# pkgconf [![test](https://github.com/pkgconf/pkgconf/actions/workflows/test.yml/badge.svg)](https://github.com/pkgconf/pkgconf/actions/workflows/test.yml)
`pkgconf` is a program which helps to configure compiler and linker flags for
development libraries. It is similar to pkg-config from freedesktop.org.
`libpkgconf` is a library which provides access to most of `pkgconf`'s functionality, to allow
other tooling such as compilers and IDEs to discover and use libraries configured by
pkgconf.
`libpkgconf` is a library which provides access to most of `pkgconf`'s functionality,
to allow other tooling such as compilers and IDEs to discover and use libraries
configured by pkgconf.
## using `pkgconf` with autotools
@ -41,7 +41,7 @@ to improve this behaviour.
As of the 1.1 series, pkgconf also fully implements support for `Provides` rules,
while pkg-config does not. pkg-config only provides the `--print-provides` functionality
as a stub. There are other intentional implementation differences in pkgconf's dependency
resolver verses pkg-config's dependency resolver in terms of completeness and correctness,
resolver versus pkg-config's dependency resolver in terms of completeness and correctness,
such as, for example, how `Conflicts` rules are processed.
## linker flags optimization
@ -60,6 +60,10 @@ Doing so is discouraged by the [freedesktop tutorial][fd-tut] anyway.
## compatibility with pkg-config
I really hate that I have to have this section, I like being a nice person, but we
unfortunately have to say this because otherwise we get passive-aggressive people who
try to argue with us about what pkg-config compatibility means.
We do not provide bug-level compatibility with pkg-config.
What that means is, if you feel that there is a legitimate regression versus pkg-config,
@ -67,6 +71,26 @@ do let us know, but also make sure that the .pc files are valid and follow the r
the [pkg-config tutorial][fd-tut], as most likely fixing them to follow the specified
rules will solve the problem.
Additionally, **we do not consider pkgconf doing what you tell it to do, in cases for
which pkg-config fails to do so, to be a bug**.
If, for example, you use environment variables such as `PKG_CONFIG_SYSTEM_[INCLUDE|LIBRARY]_PATH`
and then find yourself surprised that `pkgconf` is stripping `-I` and `-L` flags relating
to those paths, it is not a `pkgconf` problem -- `pkgconf` is doing exactly what you told
it to do.
We will reject bugs like this, and if someone insists on fixing such a non-bug, this
constitutes a violation of our [Code of Conduct](CODE_OF_CONDUCT.md), which may be
addressed by banning from this repository.
## debug output
Please use only the stable interfaces to query pkg-config. Do not screen-scrape the
output from `--debug`: this is sent to `stderr` for a reason, it is not intended to be
scraped. The `--debug` output is **not** a stable interface, and should **never** be
depended on as a source of information. If you need a stable interface to query pkg-config
which is not covered, please get in touch.
## compiling `pkgconf` and `libpkgconf` on UNIX
pkgconf is basically compiled the same way any other autotools-based project is
@ -88,17 +112,16 @@ flags like so:
$ make
$ sudo make install
## compiling `pkgconf` and `libpkgconf` with CMake (usually for Windows)
## compiling `pkgconf` and `libpkgconf` with Meson (usually for Windows)
pkgconf is compiled using CMake on Windows. In theory, you could also use CMake to build
on UNIX, but this is not recommended at this time as it pkgconf is typically built much earlier
than CMake.
$ mkdir build
$ cd build
$ cmake ..
$ make
$ sudo make install
pkgconf is compiled using [Meson](https://mesonbuild.com) on Windows. In theory, you could also use
Meson to build on UNIX, but this is not recommended at this time as it pkgconf is typically built
much earlier than Meson.
$ meson setup build -Dtests=false
$ meson compile -C build
$ meson install -C build
There are a few defines such as SYSTEM_LIBDIR, PKGCONFIGDIR and SYSTEM_INCLUDEDIR.
However, on Windows, the default PKGCONFIGDIR value is usually overridden at runtime based
@ -119,8 +142,8 @@ Please only use the tarballs from distfiles.dereferenced.org.
## contacts
You can report bugs at <https://todo.sr.ht/~kaniini/pkgconf>.
You can report bugs at <https://github.com/pkgconf/pkgconf/issues>.
There is a mailing list at <https://lists.sr.ht/~kaniini/pkgconf>.
You can contact us via IRC at `#pkgconf` at `irc.freenode.net`.
You can contact us via IRC at `#pkgconf` at `irc.oftc.net`.

365
cli/bomtool/main.c Normal file
View File

@ -0,0 +1,365 @@
/*
* bomtool/main.c
* main() routine, printer functions
*
* Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019
* pkgconf authors (see AUTHORS).
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* This software is provided 'as is' and without any warranty, express or
* implied. In no event shall the authors be liable for any damages arising
* from the use of this software.
*/
#include "libpkgconf/config.h"
#include <libpkgconf/stdinc.h>
#include <libpkgconf/libpkgconf.h>
#include "getopt_long.h"
#define PKG_VERSION (((uint64_t) 1) << 1)
#define PKG_ABOUT (((uint64_t) 1) << 2)
#define PKG_HELP (((uint64_t) 1) << 3)
static const char *spdx_version = "SPDX-2.2";
static const char *bom_license = "CC0-1.0";
static const char *document_ref = "SPDXRef-DOCUMENT";
static pkgconf_client_t pkg_client;
static uint64_t want_flags;
static size_t maximum_package_count = 0;
static int maximum_traverse_depth = 2000;
FILE *error_msgout = NULL;
static bool
error_handler(const char *msg, const pkgconf_client_t *client, void *data)
{
(void) client;
(void) data;
fprintf(error_msgout, "%s", msg);
return true;
}
static const char *
sbom_spdx_identity(pkgconf_pkg_t *pkg)
{
static char buf[PKGCONF_ITEM_SIZE];
snprintf(buf, sizeof buf, "%sC64%s", pkg->id, pkg->version);
return buf;
}
static const char *
sbom_name(pkgconf_pkg_t *world)
{
static char buf[PKGCONF_BUFSIZE];
pkgconf_node_t *node;
pkgconf_strlcpy(buf, "SBOM-SPDX", sizeof buf);
PKGCONF_FOREACH_LIST_ENTRY(world->required.head, node)
{
pkgconf_dependency_t *dep = node->data;
pkgconf_pkg_t *match = dep->match;
if (!dep->match)
continue;
pkgconf_strlcat(buf, "-", sizeof buf);
pkgconf_strlcat(buf, sbom_spdx_identity(match), sizeof buf);
}
return buf;
}
static void
write_sbom_header(pkgconf_client_t *client, pkgconf_pkg_t *world)
{
(void) client;
(void) world;
printf("SPDXVersion: %s\n", spdx_version);
printf("DataLicense: %s\n", bom_license);
printf("SPDXID: %s\n", document_ref);
printf("DocumentName: %s\n", sbom_name(world));
printf("DocumentNamespace: https://spdx.org/spdxdocs/bomtool-%s\n", PACKAGE_VERSION);
printf("Creator: Tool: bomtool %s\n", PACKAGE_VERSION);
printf("\n\n");
}
static const char *
sbom_identity(pkgconf_pkg_t *pkg)
{
static char buf[PKGCONF_ITEM_SIZE];
snprintf(buf, sizeof buf, "%s@%s", pkg->id, pkg->version);
return buf;
}
static void
write_sbom_package(pkgconf_client_t *client, pkgconf_pkg_t *pkg, void *unused)
{
(void) client;
(void) unused;
if (pkg->flags & PKGCONF_PKG_PROPF_VIRTUAL)
return;
printf("##### Package: %s\n\n", sbom_identity(pkg));
printf("PackageName: %s\n", sbom_identity(pkg));
printf("SPDXID: SPDXRef-Package-%s\n", sbom_spdx_identity(pkg));
printf("PackageVersion: %s\n", pkg->version);
printf("PackageDownloadLocation: NOASSERTION\n");
printf("PackageVerificationCode: NOASSERTION\n");
/* XXX: What about projects? */
if (pkg->maintainer != NULL)
printf("PackageSupplier: Person: %s\n", pkg->maintainer);
if (pkg->url != NULL)
printf("PackageHomePage: %s\n", pkg->url);
printf("PackageLicenseDeclared: %s\n", pkg->license != NULL ? pkg->license : "NOASSERTION");
if (pkg->copyright != NULL)
printf("PackageCopyrightText: <text>%s</text>\n", pkg->copyright);
if (pkg->description != NULL)
printf("PackageSummary: <text>%s</text>\n", pkg->description);
printf("\n\n");
}
static void
write_sbom_relationships(pkgconf_client_t *client, pkgconf_pkg_t *pkg, void *unused)
{
(void) client;
(void) unused;
char baseref[PKGCONF_ITEM_SIZE];
pkgconf_node_t *node;
if (pkg->flags & PKGCONF_PKG_PROPF_VIRTUAL)
return;
snprintf(baseref, sizeof baseref, "SPDXRef-Package-%sC64%s", pkg->id, pkg->version);
PKGCONF_FOREACH_LIST_ENTRY(pkg->required.head, node)
{
pkgconf_dependency_t *dep = node->data;
pkgconf_pkg_t *match = dep->match;
if (!dep->match)
continue;
printf("Relationship: %s DEPENDS_ON SPDXRef-Package-%s\n", baseref, sbom_spdx_identity(match));
printf("Relationship: SPDXRef-Package-%s DEPENDENCY_OF %s\n", sbom_spdx_identity(match), baseref);
}
PKGCONF_FOREACH_LIST_ENTRY(pkg->requires_private.head, node)
{
pkgconf_dependency_t *dep = node->data;
pkgconf_pkg_t *match = dep->match;
if (!dep->match)
continue;
printf("Relationship: %s DEPENDS_ON SPDXRef-Package-%s\n", baseref, sbom_spdx_identity(match));
printf("Relationship: SPDXRef-Package-%s DEV_DEPENDENCY_OF %s\n", sbom_spdx_identity(match), baseref);
}
if (pkg->required.head != NULL || pkg->requires_private.head != NULL)
printf("\n\n");
}
static bool
generate_sbom_from_world(pkgconf_client_t *client, pkgconf_pkg_t *world)
{
int eflag;
pkgconf_node_t *node;
write_sbom_header(client, world);
eflag = pkgconf_pkg_traverse(client, world, write_sbom_package, NULL, maximum_traverse_depth, 0);
if (eflag != PKGCONF_PKG_ERRF_OK)
return false;
eflag = pkgconf_pkg_traverse(client, world, write_sbom_relationships, NULL, maximum_traverse_depth, 0);
if (eflag != PKGCONF_PKG_ERRF_OK)
return false;
PKGCONF_FOREACH_LIST_ENTRY(world->required.head, node)
{
pkgconf_dependency_t *dep = node->data;
pkgconf_pkg_t *match = dep->match;
if (!dep->match)
continue;
printf("Relationship: %s DESCRIBES SPDXRef-Package-%s\n", document_ref, sbom_spdx_identity(match));
}
return true;
}
static int
version(void)
{
printf("bomtool %s\n", PACKAGE_VERSION);
return EXIT_SUCCESS;
}
static int
about(void)
{
printf("bomtool (%s %s)\n", PACKAGE_NAME, PACKAGE_VERSION);
printf("Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021\n");
printf(" pkgconf authors (see AUTHORS in documentation directory).\n\n");
printf("Permission to use, copy, modify, and/or distribute this software for any\n");
printf("purpose with or without fee is hereby granted, provided that the above\n");
printf("copyright notice and this permission notice appear in all copies.\n\n");
printf("This software is provided 'as is' and without any warranty, express or\n");
printf("implied. In no event shall the authors be liable for any damages arising\n");
printf("from the use of this software.\n\n");
printf("Report bugs at <%s>.\n", PACKAGE_BUGREPORT);
return EXIT_SUCCESS;
}
static int
usage(void)
{
printf("usage: bomtool [--flags] [modules]\n");
printf("\nbasic options:\n\n");
printf(" --help this message\n");
printf(" --about print bomtool version and license to stdout\n");
printf(" --version print bomtool version to stdout\n");
return EXIT_SUCCESS;
}
int
main(int argc, char *argv[])
{
int ret = EXIT_SUCCESS;
pkgconf_list_t pkgq = PKGCONF_LIST_INITIALIZER;
unsigned int want_client_flags = PKGCONF_PKG_PKGF_SEARCH_PRIVATE;
pkgconf_cross_personality_t *personality = pkgconf_cross_personality_default();
pkgconf_pkg_t world = {
.id = "virtual:world",
.realname = "virtual world package",
.flags = PKGCONF_PKG_PROPF_STATIC | PKGCONF_PKG_PROPF_VIRTUAL,
};
error_msgout = stderr;
struct pkg_option options[] = {
{ "version", no_argument, &want_flags, PKG_VERSION, },
{ "about", no_argument, &want_flags, PKG_ABOUT, },
{ "help", no_argument, &want_flags, PKG_HELP, },
{ NULL, 0, NULL, 0 }
};
while ((ret = pkg_getopt_long_only(argc, argv, "", options, NULL)) != -1)
{
switch (ret)
{
case '?':
case ':':
return EXIT_FAILURE;
default:
break;
}
}
pkgconf_client_init(&pkg_client, error_handler, NULL, personality);
/* we have determined what features we want most likely. in some cases, we override later. */
pkgconf_client_set_flags(&pkg_client, want_client_flags);
/* at this point, want_client_flags should be set, so build the dir list */
pkgconf_client_dir_list_build(&pkg_client, personality);
if ((want_flags & PKG_ABOUT) == PKG_ABOUT)
return about();
if ((want_flags & PKG_VERSION) == PKG_VERSION)
return version();
if ((want_flags & PKG_HELP) == PKG_HELP)
return usage();
while (1)
{
const char *package = argv[pkg_optind];
if (package == NULL)
break;
/* check if there is a limit to the number of packages allowed to be included, if so and we have hit
* the limit, stop adding packages to the queue.
*/
if (maximum_package_count > 0 && pkgq.length > maximum_package_count)
break;
while (isspace((unsigned int)package[0]))
package++;
/* skip empty packages */
if (package[0] == '\0') {
pkg_optind++;
continue;
}
if (argv[pkg_optind + 1] == NULL || !PKGCONF_IS_OPERATOR_CHAR(*(argv[pkg_optind + 1])))
{
pkgconf_queue_push(&pkgq, package);
pkg_optind++;
}
else
{
char packagebuf[PKGCONF_BUFSIZE];
snprintf(packagebuf, sizeof packagebuf, "%s %s %s", package, argv[pkg_optind + 1], argv[pkg_optind + 2]);
pkg_optind += 3;
pkgconf_queue_push(&pkgq, packagebuf);
}
}
if (pkgq.head == NULL)
{
fprintf(stderr, "Please specify at least one package name on the command line.\n");
ret = EXIT_FAILURE;
goto out;
}
ret = EXIT_SUCCESS;
if (!pkgconf_queue_solve(&pkg_client, &pkgq, &world, maximum_traverse_depth))
{
ret = EXIT_FAILURE;
goto out;
}
if (!generate_sbom_from_world(&pkg_client, &world))
{
ret = EXIT_FAILURE;
goto out;
}
out:
pkgconf_solution_free(&pkg_client, &world);
pkgconf_queue_free(&pkgq);
pkgconf_cross_personality_deinit(personality);
pkgconf_client_deinit(&pkg_client);
return ret;
}

View File

@ -70,6 +70,7 @@
#define PKG_INTERNAL_CFLAGS (((uint64_t) 1) << 42)
#define PKG_DUMP_PERSONALITY (((uint64_t) 1) << 43)
#define PKG_SHARED (((uint64_t) 1) << 44)
#define PKG_DUMP_LICENSE (((uint64_t) 1) << 45)
static pkgconf_client_t pkg_client;
static const pkgconf_fragment_render_ops_t *want_render_ops = NULL;
@ -85,7 +86,7 @@ FILE *error_msgout = NULL;
FILE *logfile_out = NULL;
static bool
error_handler(const char *msg, const pkgconf_client_t *client, const void *data)
error_handler(const char *msg, const pkgconf_client_t *client, void *data)
{
(void) client;
(void) data;
@ -346,16 +347,6 @@ apply_path(pkgconf_client_t *client, pkgconf_pkg_t *world, void *unused, int max
return true;
}
static void
print_variable(pkgconf_client_t *client, pkgconf_pkg_t *pkg, const char *variable)
{
const char *var;
var = pkgconf_tuple_find(client, &pkg->vars, variable);
if (var != NULL)
printf("%s", var);
}
static bool
apply_variable(pkgconf_client_t *client, pkgconf_pkg_t *world, void *variable, int maxdepth)
{
@ -366,11 +357,12 @@ apply_variable(pkgconf_client_t *client, pkgconf_pkg_t *world, void *variable, i
{
pkgconf_dependency_t *dep = iter->data;
pkgconf_pkg_t *pkg = dep->match;
const char *var;
if (iter->prev != NULL)
printf(" ");
var = pkgconf_tuple_find(client, &pkg->vars, variable);
print_variable(client, pkg, variable);
if (var != NULL)
printf("%s%s", iter->prev != NULL ? " " : "", var);
}
printf("\n");
@ -593,6 +585,32 @@ apply_simulate(pkgconf_client_t *client, pkgconf_pkg_t *world, void *data, int m
}
#endif
static void
print_license(pkgconf_client_t *client, pkgconf_pkg_t *pkg, void *data)
{
(void) client;
(void) data;
if (pkg->flags & PKGCONF_PKG_PROPF_VIRTUAL)
return;
/* NOASSERTION is the default when the license is unknown, per SPDX spec § 3.15 */
printf("%s: %s\n", pkg->id, pkg->license != NULL ? pkg->license : "NOASSERTION");
}
static bool
apply_license(pkgconf_client_t *client, pkgconf_pkg_t *world, void *data, int maxdepth)
{
int eflag;
eflag = pkgconf_pkg_traverse(client, world, print_license, data, maxdepth, 0);
if (eflag != PKGCONF_PKG_ERRF_OK)
return false;
return true;
}
static void
version(void)
{
@ -603,7 +621,7 @@ static void
about(void)
{
printf("%s %s\n", PACKAGE_NAME, PACKAGE_VERSION);
printf("Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020\n");
printf("Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021\n");
printf(" pkgconf authors (see AUTHORS in documentation directory).\n\n");
printf("Permission to use, copy, modify, and/or distribute this software for any\n");
printf("purpose with or without fee is hereby granted, provided that the above\n");
@ -696,6 +714,7 @@ usage(void)
printf(" --path show the exact filenames for any matching .pc files\n");
printf(" --modversion print the specified module's version to stdout\n");
printf(" --internal-cflags do not filter 'internal' cflags from output\n");
printf(" --license print the specified module's license to stdout if known\n");
printf("\nfiltering output:\n\n");
#ifndef PKGCONF_LITE
@ -801,7 +820,13 @@ main(int argc, char *argv[])
char *logfile_arg = NULL;
char *want_env_prefix = NULL;
unsigned int want_client_flags = PKGCONF_PKG_PKGF_NONE;
pkgconf_cross_personality_t *personality;
pkgconf_cross_personality_t *personality = NULL;
bool opened_error_msgout = false;
pkgconf_pkg_t world = {
.id = "virtual:world",
.realname = "virtual world package",
.flags = PKGCONF_PKG_PROPF_STATIC | PKGCONF_PKG_PROPF_VIRTUAL,
};
want_flags = 0;
@ -882,6 +907,7 @@ main(int argc, char *argv[])
{ "dump-personality", no_argument, &want_flags, PKG_DUMP_PERSONALITY },
{ "personality", required_argument, NULL, 53 },
#endif
{ "license", no_argument, &want_flags, PKG_DUMP_LICENSE },
{ NULL, 0, NULL, 0 }
};
@ -893,12 +919,6 @@ main(int argc, char *argv[])
}
#endif
#ifndef PKGCONF_LITE
personality = deduce_personality(argv);
#else
personality = pkgconf_cross_personality_default();
#endif
while ((ret = pkg_getopt_long_only(argc, argv, "", options, NULL)) != -1)
{
switch (ret)
@ -949,13 +969,21 @@ main(int argc, char *argv[])
#endif
case '?':
case ':':
return EXIT_FAILURE;
break;
ret = EXIT_FAILURE;
goto out;
default:
break;
}
}
if (personality == NULL) {
#ifndef PKGCONF_LITE
personality = deduce_personality(argv);
#else
personality = pkgconf_cross_personality_default();
#endif
}
pkgconf_path_copy_list(&personality->dir_list, &dir_list);
pkgconf_path_free(&dir_list);
@ -1000,21 +1028,33 @@ main(int argc, char *argv[])
if ((want_flags & PKG_ABOUT) == PKG_ABOUT)
{
about();
return EXIT_SUCCESS;
ret = EXIT_SUCCESS;
goto out;
}
if ((want_flags & PKG_VERSION) == PKG_VERSION)
{
version();
return EXIT_SUCCESS;
ret = EXIT_SUCCESS;
goto out;
}
if ((want_flags & PKG_HELP) == PKG_HELP)
{
usage();
return EXIT_SUCCESS;
ret = EXIT_SUCCESS;
goto out;
}
if (getenv("PKG_CONFIG_FDO_SYSROOT_RULES"))
want_client_flags |= PKGCONF_PKG_PKGF_FDO_SYSROOT_RULES;
if (getenv("PKG_CONFIG_PKGCONF1_SYSROOT_RULES"))
want_client_flags |= PKGCONF_PKG_PKGF_PKGCONF1_SYSROOT_RULES;
if ((want_flags & PKG_SHORT_ERRORS) == PKG_SHORT_ERRORS)
want_client_flags |= PKGCONF_PKG_PKGF_SIMPLIFY_ERRORS;
@ -1024,8 +1064,10 @@ main(int argc, char *argv[])
error_msgout = stderr;
if ((want_flags & PKG_ERRORS_ON_STDOUT) == PKG_ERRORS_ON_STDOUT)
error_msgout = stdout;
if ((want_flags & PKG_SILENCE_ERRORS) == PKG_SILENCE_ERRORS)
if ((want_flags & PKG_SILENCE_ERRORS) == PKG_SILENCE_ERRORS) {
error_msgout = fopen(PATH_DEV_NULL, "w");
opened_error_msgout = true;
}
if ((want_flags & PKG_IGNORE_CONFLICTS) == PKG_IGNORE_CONFLICTS || getenv("PKG_CONFIG_IGNORE_CONFLICTS") != NULL)
want_client_flags |= PKGCONF_PKG_PKGF_SKIP_CONFLICTS;
@ -1040,7 +1082,7 @@ main(int argc, char *argv[])
* this allows for a --static which searches private modules, but has the same fragment behaviour as if
* --static were disabled. see <https://github.com/pkgconf/pkgconf/issues/83> for rationale.
*/
if ((want_flags & PKG_PURE) == PKG_PURE || getenv("PKG_CONFIG_PURE_DEPGRAPH") != NULL)
if ((want_flags & PKG_PURE) == PKG_PURE || getenv("PKG_CONFIG_PURE_DEPGRAPH") != NULL || personality->want_default_pure)
want_client_flags &= ~PKGCONF_PKG_PKGF_MERGE_PRIVATE_FRAGMENTS;
if ((want_flags & PKG_ENV_ONLY) == PKG_ENV_ONLY)
@ -1062,23 +1104,17 @@ main(int argc, char *argv[])
if ((want_flags & PKG_NO_PROVIDES) == PKG_NO_PROVIDES)
want_client_flags |= PKGCONF_PKG_PKGF_SKIP_PROVIDES;
if ((want_flags & PKG_DONT_DEFINE_PREFIX) == PKG_DONT_DEFINE_PREFIX)
if ((want_flags & PKG_DONT_DEFINE_PREFIX) == PKG_DONT_DEFINE_PREFIX || getenv("PKG_CONFIG_DONT_DEFINE_PREFIX") != NULL)
want_client_flags &= ~PKGCONF_PKG_PKGF_REDEFINE_PREFIX;
if ((want_flags & PKG_INTERNAL_CFLAGS) == PKG_INTERNAL_CFLAGS)
want_client_flags |= PKGCONF_PKG_PKGF_DONT_FILTER_INTERNAL_CFLAGS;
#ifdef XXX_NOTYET
/* if these selectors are used, it means that we are inquiring about a single package.
* so signal to libpkgconf that we do not want to use the dependency resolver for more than one level,
* and also limit the SAT problem to a single package.
*
* i disabled this because too many upstream maintainers are still invoking pkg-config correctly to have
* the more sane behaviour as default. use --maximum-traverse-depth=1 or PKG_CONFIG_MAXIMUM_TRAVERSE_DEPTH
* environment variable to get the same results in meantime.
*/
if ((want_flags & PKG_EXISTS) == 0 &&
((want_flags & PKG_REQUIRES) == PKG_REQUIRES ||
if (((want_flags & PKG_REQUIRES) == PKG_REQUIRES ||
(want_flags & PKG_REQUIRES_PRIVATE) == PKG_REQUIRES_PRIVATE ||
(want_flags & PKG_PROVIDES) == PKG_PROVIDES ||
(want_flags & PKG_VARIABLES) == PKG_VARIABLES ||
@ -1089,7 +1125,6 @@ main(int argc, char *argv[])
maximum_package_count = 1;
maximum_traverse_depth = 1;
}
#endif
if (getenv("PKG_CONFIG_ALLOW_SYSTEM_CFLAGS") != NULL)
want_flags |= PKG_KEEP_SYSTEM_CFLAGS;
@ -1100,9 +1135,25 @@ main(int argc, char *argv[])
if ((builddir = getenv("PKG_CONFIG_TOP_BUILD_DIR")) != NULL)
pkgconf_client_set_buildroot_dir(&pkg_client, builddir);
if ((want_flags & PKG_REQUIRES_PRIVATE) == PKG_REQUIRES_PRIVATE ||
(want_flags & PKG_CFLAGS))
{
want_client_flags |= PKGCONF_PKG_PKGF_SEARCH_PRIVATE;
}
if ((sysroot_dir = getenv("PKG_CONFIG_SYSROOT_DIR")) != NULL)
{
const char *destdir;
pkgconf_client_set_sysroot_dir(&pkg_client, sysroot_dir);
if ((destdir = getenv("DESTDIR")) != NULL)
{
if (!strcmp(destdir, sysroot_dir))
want_client_flags |= PKGCONF_PKG_PKGF_FDO_SYSROOT_RULES;
}
}
/* we have determined what features we want most likely. in some cases, we override later. */
pkgconf_client_set_flags(&pkg_client, want_client_flags);
@ -1112,21 +1163,25 @@ main(int argc, char *argv[])
if (required_pkgconfig_version != NULL)
{
if (pkgconf_compare_version(PACKAGE_VERSION, required_pkgconfig_version) >= 0)
return EXIT_SUCCESS;
ret = EXIT_SUCCESS;
else
ret = EXIT_FAILURE;
return EXIT_FAILURE;
goto out;
}
if ((want_flags & PKG_LIST) == PKG_LIST)
{
pkgconf_scan_all(&pkg_client, NULL, print_list_entry);
return EXIT_SUCCESS;
ret = EXIT_SUCCESS;
goto out;
}
if ((want_flags & PKG_LIST_PACKAGE_NAMES) == PKG_LIST_PACKAGE_NAMES)
{
pkgconf_scan_all(&pkg_client, NULL, print_package_entry);
return EXIT_SUCCESS;
ret = EXIT_SUCCESS;
goto out;
}
if (logfile_arg == NULL)
@ -1140,7 +1195,7 @@ main(int argc, char *argv[])
if (required_module_version != NULL)
{
pkgconf_pkg_t *pkg;
pkgconf_pkg_t *pkg = NULL;
pkgconf_node_t *node;
pkgconf_list_t deplist = PKGCONF_LIST_INITIALIZER;
@ -1159,18 +1214,28 @@ main(int argc, char *argv[])
{
if (want_flags & PKG_PRINT_ERRORS)
pkgconf_error(&pkg_client, "Package '%s' was not found\n", pkgiter->package);
return EXIT_FAILURE;
ret = EXIT_FAILURE;
goto cleanup;
}
if (pkgconf_compare_version(pkg->version, required_module_version) >= 0)
return EXIT_SUCCESS;
{
ret = EXIT_SUCCESS;
goto cleanup;
}
}
return EXIT_FAILURE;
ret = EXIT_FAILURE;
cleanup:
if (pkg != NULL)
pkgconf_pkg_unref(&pkg_client, pkg);
pkgconf_dependency_free(&deplist);
goto out;
}
else if (required_exact_module_version != NULL)
{
pkgconf_pkg_t *pkg;
pkgconf_pkg_t *pkg = NULL;
pkgconf_node_t *node;
pkgconf_list_t deplist = PKGCONF_LIST_INITIALIZER;
@ -1189,18 +1254,28 @@ main(int argc, char *argv[])
{
if (want_flags & PKG_PRINT_ERRORS)
pkgconf_error(&pkg_client, "Package '%s' was not found\n", pkgiter->package);
return EXIT_FAILURE;
ret = EXIT_FAILURE;
goto cleanup2;
}
if (pkgconf_compare_version(pkg->version, required_exact_module_version) == 0)
return EXIT_SUCCESS;
{
ret = EXIT_SUCCESS;
goto cleanup2;
}
}
return EXIT_FAILURE;
ret = EXIT_FAILURE;
cleanup2:
if (pkg != NULL)
pkgconf_pkg_unref(&pkg_client, pkg);
pkgconf_dependency_free(&deplist);
goto out;
}
else if (required_max_module_version != NULL)
{
pkgconf_pkg_t *pkg;
pkgconf_pkg_t *pkg = NULL;
pkgconf_node_t *node;
pkgconf_list_t deplist = PKGCONF_LIST_INITIALIZER;
@ -1219,14 +1294,24 @@ main(int argc, char *argv[])
{
if (want_flags & PKG_PRINT_ERRORS)
pkgconf_error(&pkg_client, "Package '%s' was not found\n", pkgiter->package);
return EXIT_FAILURE;
ret = EXIT_FAILURE;
goto cleanup3;
}
if (pkgconf_compare_version(pkg->version, required_max_module_version) <= 0)
return EXIT_SUCCESS;
{
ret = EXIT_SUCCESS;
goto cleanup3;
}
}
return EXIT_FAILURE;
ret = EXIT_FAILURE;
cleanup3:
if (pkg != NULL)
pkgconf_pkg_unref(&pkg_client, pkg);
pkgconf_dependency_free(&deplist);
goto out;
}
while (1)
@ -1270,85 +1355,68 @@ main(int argc, char *argv[])
if (pkgq.head == NULL)
{
fprintf(stderr, "Please specify at least one package name on the command line.\n");
return EXIT_FAILURE;
ret = EXIT_FAILURE;
goto out;
}
ret = EXIT_SUCCESS;
if (!pkgconf_queue_solve(&pkg_client, &pkgq, &world, maximum_traverse_depth))
{
ret = EXIT_FAILURE;
goto out;
}
#ifndef PKGCONF_LITE
if ((want_flags & PKG_SIMULATE) == PKG_SIMULATE)
{
want_flags &= ~(PKG_CFLAGS|PKG_LIBS);
pkgconf_client_set_flags(&pkg_client, want_client_flags | PKGCONF_PKG_PKGF_SKIP_ERRORS);
if (!pkgconf_queue_apply(&pkg_client, &pkgq, apply_simulate, -1, NULL))
{
ret = EXIT_FAILURE;
goto out;
}
apply_simulate(&pkg_client, &world, NULL, -1);
}
#endif
if (!pkgconf_queue_validate(&pkg_client, &pkgq, maximum_traverse_depth))
if ((want_flags & PKG_VALIDATE) == PKG_VALIDATE)
goto out;
if ((want_flags & PKG_DUMP_LICENSE) == PKG_DUMP_LICENSE)
{
ret = EXIT_FAILURE;
apply_license(&pkg_client, &world, &ret, maximum_traverse_depth);
goto out;
}
if ((want_flags & PKG_VALIDATE) == PKG_VALIDATE)
return 0;
if ((want_flags & PKG_UNINSTALLED) == PKG_UNINSTALLED)
{
ret = EXIT_FAILURE;
pkgconf_queue_apply(&pkg_client, &pkgq, apply_uninstalled, maximum_traverse_depth, &ret);
apply_uninstalled(&pkg_client, &world, &ret, maximum_traverse_depth);
goto out;
}
if (want_env_prefix != NULL)
{
if (!pkgconf_queue_apply(&pkg_client, &pkgq, apply_env, maximum_traverse_depth, want_env_prefix))
{
ret = EXIT_FAILURE;
goto out;
}
apply_env(&pkg_client, &world, want_env_prefix, maximum_traverse_depth);
want_flags = 0;
}
if ((want_flags & PKG_PROVIDES) == PKG_PROVIDES)
{
want_flags &= ~(PKG_CFLAGS|PKG_LIBS);
if (!pkgconf_queue_apply(&pkg_client, &pkgq, apply_provides, maximum_traverse_depth, NULL))
{
ret = EXIT_FAILURE;
goto out;
}
apply_provides(&pkg_client, &world, NULL, maximum_traverse_depth);
}
#ifndef PKGCONF_LITE
if ((want_flags & PKG_DIGRAPH) == PKG_DIGRAPH)
{
want_flags &= ~(PKG_CFLAGS|PKG_LIBS);
if (!pkgconf_queue_apply(&pkg_client, &pkgq, apply_digraph, maximum_traverse_depth, NULL))
{
ret = EXIT_FAILURE;
goto out;
}
apply_digraph(&pkg_client, &world, NULL, maximum_traverse_depth);
}
#endif
if ((want_flags & PKG_MODVERSION) == PKG_MODVERSION)
{
want_flags &= ~(PKG_CFLAGS|PKG_LIBS);
if (!pkgconf_queue_apply(&pkg_client, &pkgq, apply_modversion, maximum_traverse_depth, NULL))
{
ret = EXIT_FAILURE;
goto out;
}
apply_modversion(&pkg_client, &world, NULL, maximum_traverse_depth);
}
if ((want_flags & PKG_PATH) == PKG_PATH)
@ -1356,22 +1424,13 @@ main(int argc, char *argv[])
want_flags &= ~(PKG_CFLAGS|PKG_LIBS);
pkgconf_client_set_flags(&pkg_client, want_client_flags | PKGCONF_PKG_PKGF_SKIP_ROOT_VIRTUAL);
if (!pkgconf_queue_apply(&pkg_client, &pkgq, apply_path, maximum_traverse_depth, NULL))
{
ret = EXIT_FAILURE;
goto out;
}
apply_path(&pkg_client, &world, NULL, maximum_traverse_depth);
}
if ((want_flags & PKG_VARIABLES) == PKG_VARIABLES)
{
want_flags &= ~(PKG_CFLAGS|PKG_LIBS);
if (!pkgconf_queue_apply(&pkg_client, &pkgq, apply_variables, maximum_traverse_depth, NULL))
{
ret = EXIT_FAILURE;
goto out;
}
apply_variables(&pkg_client, &world, NULL, maximum_traverse_depth);
}
if (want_variable)
@ -1379,72 +1438,48 @@ main(int argc, char *argv[])
want_flags &= ~(PKG_CFLAGS|PKG_LIBS);
pkgconf_client_set_flags(&pkg_client, want_client_flags | PKGCONF_PKG_PKGF_SKIP_ROOT_VIRTUAL);
if (!pkgconf_queue_apply(&pkg_client, &pkgq, apply_variable, maximum_traverse_depth, want_variable))
{
ret = EXIT_FAILURE;
goto out;
}
apply_variable(&pkg_client, &world, want_variable, maximum_traverse_depth);
}
if ((want_flags & PKG_REQUIRES) == PKG_REQUIRES)
{
want_flags &= ~(PKG_CFLAGS|PKG_LIBS);
if (!pkgconf_queue_apply(&pkg_client, &pkgq, apply_requires, maximum_traverse_depth, NULL))
{
ret = EXIT_FAILURE;
goto out;
}
apply_requires(&pkg_client, &world, NULL, maximum_traverse_depth);
}
if ((want_flags & PKG_REQUIRES_PRIVATE) == PKG_REQUIRES_PRIVATE)
{
want_flags &= ~(PKG_CFLAGS|PKG_LIBS);
pkgconf_client_set_flags(&pkg_client, want_client_flags | PKGCONF_PKG_PKGF_SEARCH_PRIVATE);
if (!pkgconf_queue_apply(&pkg_client, &pkgq, apply_requires_private, maximum_traverse_depth, NULL))
{
ret = EXIT_FAILURE;
goto out;
}
pkgconf_client_set_flags(&pkg_client, want_client_flags);
apply_requires_private(&pkg_client, &world, NULL, maximum_traverse_depth);
}
if ((want_flags & PKG_CFLAGS))
{
pkgconf_client_set_flags(&pkg_client, want_client_flags | PKGCONF_PKG_PKGF_SEARCH_PRIVATE);
if (!pkgconf_queue_apply(&pkg_client, &pkgq, apply_cflags, maximum_traverse_depth, NULL))
{
ret = EXIT_FAILURE;
goto out_println;
}
pkgconf_client_set_flags(&pkg_client, want_client_flags);
apply_cflags(&pkg_client, &world, NULL, maximum_traverse_depth);
}
if ((want_flags & PKG_LIBS))
{
if (!pkgconf_queue_apply(&pkg_client, &pkgq, apply_libs, maximum_traverse_depth, NULL))
{
ret = EXIT_FAILURE;
goto out_println;
}
if (!(want_flags & PKG_STATIC))
pkgconf_client_set_flags(&pkg_client, pkg_client.flags & ~PKGCONF_PKG_PKGF_SEARCH_PRIVATE);
apply_libs(&pkg_client, &world, NULL, maximum_traverse_depth);
}
pkgconf_queue_free(&pkgq);
out_println:
if (want_flags & (PKG_CFLAGS|PKG_LIBS))
printf("\n");
out:
pkgconf_solution_free(&pkg_client, &world);
pkgconf_queue_free(&pkgq);
pkgconf_cross_personality_deinit(personality);
pkgconf_client_deinit(&pkg_client);
if (logfile_out != NULL)
fclose(logfile_out);
if (opened_error_msgout)
fclose(error_msgout);
return ret;
}

View File

@ -149,7 +149,6 @@ msvc_renderer_render_buf(const pkgconf_list_t *list, char *buf, size_t buflen, b
{
cnt = pkgconf_strlcpy(bptr, ".lib", buf_remaining);
bptr += cnt;
buf_remaining -= cnt;
}
if (escape)

View File

@ -11,8 +11,8 @@ dnl This software is provided 'as is' and without any warranty, express or
dnl implied. In no event shall the authors be liable for any damages arising
dnl from the use of this software.
AC_PREREQ([2.68])
AC_INIT([pkgconf], [1.7.1], [https://todo.sr.ht/~kaniini/pkgconf])
AC_PREREQ([2.71])
AC_INIT([pkgconf],[1.9.3],[https://github.com/pkgconf/pkgconf/issues/new])
AC_CONFIG_SRCDIR([cli/main.c])
AC_CONFIG_MACRO_DIR([m4])
AX_CHECK_COMPILE_FLAG([-Wall], [CFLAGS="$CFLAGS -Wall"])
@ -22,7 +22,7 @@ AX_CHECK_COMPILE_FLAG([-std=gnu99], [CFLAGS="$CFLAGS -std=gnu99"], [
AX_CHECK_COMPILE_FLAG([-std=c99], [CFLAGS="$CFLAGS -std=c99"])
])
AC_CONFIG_HEADERS([libpkgconf/config.h])
AC_CHECK_FUNCS([strlcpy strlcat strndup cygwin_conv_path])
AC_CHECK_FUNCS([strlcpy strlcat strndup reallocarray])
AC_CHECK_HEADERS([sys/stat.h])
AM_INIT_AUTOMAKE([foreign dist-xz subdir-objects])
AM_SILENT_RULES([yes])
@ -30,26 +30,26 @@ LT_INIT
AC_SYS_LARGEFILE
AC_ARG_WITH([personality-dir],[AC_HELP_STRING([--with-personality-dir],[specify
AC_ARG_WITH([personality-dir],[AS_HELP_STRING([--with-personality-dir],[specify
the place where cross-compile personality files will be found])],
PERSONALITY_PATH="$withval",
PERSONALITY_PATH="${datadir}/pkgconfig/personality.d:${sysconfdir}/pkgconfig/personality.d")
AC_SUBST([PERSONALITY_PATH])
AC_ARG_WITH([pkg-config-dir],[AC_HELP_STRING([--with-pkg-config-dir],[specify
AC_ARG_WITH([pkg-config-dir],[AS_HELP_STRING([--with-pkg-config-dir],[specify
the place where pc files will be found])],PKG_DEFAULT_PATH="$withval",
PKG_DEFAULT_PATH="${libdir}/pkgconfig:${datadir}/pkgconfig")
AC_SUBST([PKG_DEFAULT_PATH])
AC_ARG_WITH([system-libdir],[AC_HELP_STRING([--with-system-libdir],[specify the
AC_ARG_WITH([system-libdir],[AS_HELP_STRING([--with-system-libdir],[specify the
system library directory (default LIBDIR)])],
SYSTEM_LIBDIR="$withval", SYSTEM_LIBDIR="${libdir}")
AC_SUBST([SYSTEM_LIBDIR])
AC_ARG_WITH([system-includedir],[AC_HELP_STRING([--with-system-includedir],[specify the
AC_ARG_WITH([system-includedir],[AS_HELP_STRING([--with-system-includedir],[specify the
system include directory (default INCLUDEDIR)])],
SYSTEM_INCLUDEDIR="$withval", SYSTEM_INCLUDEDIR="${includedir}")

View File

@ -55,7 +55,7 @@ variables.
.. c:function:: bool pkgconf_path_relocate(char *buf, size_t buflen)
Relocates a path, possibly calling normpath() or cygwin_conv_path() on it.
Relocates a path, possibly calling normpath() on it.
:param char* buf: The path to relocate.
:param size_t buflen: The buffer length the path is contained in.

View File

@ -5,7 +5,8 @@ libdir=@libdir@
Name: libpkgconf
Description: a library for accessing and manipulating development framework configuration
URL: http://github.com/pkgconf/pkgconf
URL: https://gitea.treehouse.systems/ariadne/pkgconf
License: ISC
Version: @PACKAGE_VERSION@
CFlags: -I${includedir}/pkgconf
Libs: -L${libdir} -lpkgconf

View File

@ -118,9 +118,11 @@ pkgconf_argv_split(const char *src, int *argc, char ***argv)
}
else switch(*src_iter)
{
#ifndef _WIN32
case '\\':
escaped = true;
break;
#endif
case '\"':
case '\'':

View File

@ -20,6 +20,7 @@
#include <stdlib.h>
#include <sys/types.h>
#include <string.h>
#include <errno.h>
#include <libpkgconf/bsdstubs.h>
#include <libpkgconf/config.h>
@ -137,3 +138,23 @@ pkgconf_strndup(const char *src, size_t len)
{
return strndup(src, len);
}
#ifndef HAVE_REALLOCARRAY
void *
reallocarray(void *ptr, size_t m, size_t n)
{
if (n && m > -1 / n)
{
errno = ENOMEM;
return 0;
}
return realloc(ptr, m * n);
}
#endif
void *
pkgconf_reallocarray(void *ptr, size_t m, size_t n)
{
return reallocarray(ptr, m, n);
}

View File

@ -25,6 +25,7 @@ extern "C" {
PKGCONF_API extern size_t pkgconf_strlcpy(char *dst, const char *src, size_t siz);
PKGCONF_API extern size_t pkgconf_strlcat(char *dst, const char *src, size_t siz);
PKGCONF_API extern char *pkgconf_strndup(const char *src, size_t len);
PKGCONF_API extern void *pkgconf_reallocarray(void *ptr, size_t m, size_t n);
#ifdef __cplusplus
}

View File

@ -16,6 +16,8 @@
#include <libpkgconf/stdinc.h>
#include <libpkgconf/libpkgconf.h>
#include <assert.h>
/*
* !doc
*
@ -29,6 +31,46 @@
* be shared across threads.
*/
static int
cache_member_cmp(const void *a, const void *b)
{
const char *key = a;
const pkgconf_pkg_t *pkg = *(void **) b;
return strcmp(key, pkg->id);
}
static int
cache_member_sort_cmp(const void *a, const void *b)
{
const pkgconf_pkg_t *pkgA = *(void **) a;
const pkgconf_pkg_t *pkgB = *(void **) b;
if (pkgA == NULL)
return 1;
if (pkgB == NULL)
return -1;
return strcmp(pkgA->id, pkgB->id);
}
static void
cache_dump(const pkgconf_client_t *client)
{
size_t i;
PKGCONF_TRACE(client, "dumping package cache contents");
for (i = 0; i < client->cache_count; i++)
{
const pkgconf_pkg_t *pkg = client->cache_table[i];
PKGCONF_TRACE(client, "%zu: %p(%s)",
i, pkg, pkg == NULL ? "NULL" : pkg->id);
}
}
/*
* !doc
*
@ -46,17 +88,19 @@
pkgconf_pkg_t *
pkgconf_cache_lookup(pkgconf_client_t *client, const char *id)
{
pkgconf_node_t *node;
if (client->cache_table == NULL)
return NULL;
PKGCONF_FOREACH_LIST_ENTRY(client->pkg_cache.head, node)
pkgconf_pkg_t **pkg;
pkg = bsearch(id, client->cache_table,
client->cache_count, sizeof (void *),
cache_member_cmp);
if (pkg != NULL)
{
pkgconf_pkg_t *pkg = node->data;
if (!strcmp(pkg->id, id))
{
PKGCONF_TRACE(client, "found: %s @%p", id, pkg);
return pkgconf_pkg_ref(client, pkg);
}
PKGCONF_TRACE(client, "found: %s @%p", id, *pkg);
return pkgconf_pkg_ref(client, *pkg);
}
PKGCONF_TRACE(client, "miss: %s", id);
@ -82,12 +126,19 @@ pkgconf_cache_add(pkgconf_client_t *client, pkgconf_pkg_t *pkg)
return;
pkgconf_pkg_ref(client, pkg);
pkgconf_node_insert(&pkg->cache_iter, pkg, &client->pkg_cache);
PKGCONF_TRACE(client, "added @%p to cache", pkg);
/* mark package as cached */
pkg->flags |= PKGCONF_PKG_PROPF_CACHED;
++client->cache_count;
client->cache_table = pkgconf_reallocarray(client->cache_table,
client->cache_count, sizeof (void *));
client->cache_table[client->cache_count - 1] = pkg;
qsort(client->cache_table, client->cache_count,
sizeof(void *), cache_member_sort_cmp);
}
/*
@ -104,6 +155,9 @@ pkgconf_cache_add(pkgconf_client_t *client, pkgconf_pkg_t *pkg)
void
pkgconf_cache_remove(pkgconf_client_t *client, pkgconf_pkg_t *pkg)
{
if (client->cache_table == NULL)
return;
if (pkg == NULL)
return;
@ -112,7 +166,41 @@ pkgconf_cache_remove(pkgconf_client_t *client, pkgconf_pkg_t *pkg)
PKGCONF_TRACE(client, "removed @%p from cache", pkg);
pkgconf_node_delete(&pkg->cache_iter, &client->pkg_cache);
pkgconf_pkg_t **slot;
slot = bsearch(pkg->id, client->cache_table,
client->cache_count, sizeof (void *),
cache_member_cmp);
if (slot == NULL)
return;
(*slot)->flags &= ~PKGCONF_PKG_PROPF_CACHED;
pkgconf_pkg_unref(client, *slot);
*slot = NULL;
qsort(client->cache_table, client->cache_count,
sizeof(void *), cache_member_sort_cmp);
if (client->cache_table[client->cache_count - 1] != NULL)
{
PKGCONF_TRACE(client, "end of cache table refers to %p, not NULL",
client->cache_table[client->cache_count - 1]);
cache_dump(client);
abort();
}
client->cache_count--;
if (client->cache_count > 0)
{
client->cache_table = pkgconf_reallocarray(client->cache_table,
client->cache_count, sizeof(void *));
}
else
{
free(client->cache_table);
client->cache_table = NULL;
}
}
/*
@ -129,15 +217,15 @@ pkgconf_cache_remove(pkgconf_client_t *client, pkgconf_pkg_t *pkg)
void
pkgconf_cache_free(pkgconf_client_t *client)
{
pkgconf_node_t *iter, *iter2;
if (client->cache_table == NULL)
return;
PKGCONF_FOREACH_LIST_ENTRY_SAFE(client->pkg_cache.head, iter2, iter)
{
pkgconf_pkg_t *pkg = iter->data;
pkgconf_pkg_unref(client, pkg);
}
while (client->cache_count > 0)
pkgconf_cache_remove(client, client->cache_table[0]);
memset(&client->pkg_cache, 0, sizeof client->pkg_cache);
free(client->cache_table);
client->cache_table = NULL;
client->cache_count = 0;
PKGCONF_TRACE(client, "cleared package cache");
}

View File

@ -98,6 +98,8 @@ pkgconf_client_init(pkgconf_client_t *client, pkgconf_error_handler_func_t error
client->error_handler_data = error_handler_data;
client->error_handler = error_handler;
client->auditf = NULL;
client->cache_table = NULL;
client->cache_count = 0;
#ifndef PKGCONF_LITE
if (client->trace_handler == NULL)
@ -401,7 +403,7 @@ pkgconf_trace(const pkgconf_client_t *client, const char *filename, size_t linen
* :rtype: bool
*/
bool
pkgconf_default_error_handler(const char *msg, const pkgconf_client_t *client, const void *data)
pkgconf_default_error_handler(const char *msg, const pkgconf_client_t *client, void *data)
{
(void) msg;
(void) client;

View File

@ -1,29 +1,5 @@
/* libpkgconf/config.h.in. Generated from configure.ac by autoheader. */
/* Define to 1 if you have the `cygwin_conv_path' function. */
#mesondefine HAVE_CYGWIN_CONV_PATH
/* Define to 1 if you have the <dlfcn.h> header file. */
#mesondefine HAVE_DLFCN_H
/* Define to 1 if you have the <inttypes.h> header file. */
#mesondefine HAVE_INTTYPES_H
/* Define to 1 if you have the <memory.h> header file. */
#mesondefine HAVE_MEMORY_H
/* Define to 1 if you have the <stdint.h> header file. */
#mesondefine HAVE_STDINT_H
/* Define to 1 if you have the <stdlib.h> header file. */
#mesondefine HAVE_STDLIB_H
/* Define to 1 if you have the <strings.h> header file. */
#mesondefine HAVE_STRINGS_H
/* Define to 1 if you have the <string.h> header file. */
#mesondefine HAVE_STRING_H
/* Define to 1 if you have the `strlcat' function. */
#mesondefine HAVE_STRLCAT
@ -33,17 +9,8 @@
/* Define to 1 if you have the `strndup' function. */
#mesondefine HAVE_STRNDUP
/* Define to 1 if you have the <sys/stat.h> header file. */
#mesondefine HAVE_SYS_STAT_H
/* Define to 1 if you have the <sys/types.h> header file. */
#mesondefine HAVE_SYS_TYPES_H
/* Define to 1 if you have the <unistd.h> header file. */
#mesondefine HAVE_UNISTD_H
/* Define to the sub-directory where libtool stores uninstalled libraries. */
#mesondefine LT_OBJDIR
/* Define to 1 if you have the `reallocarray' function. */
#mesondefine HAVE_REALLOCARRAY
/* Name of package */
#mesondefine PACKAGE

View File

@ -73,7 +73,7 @@ find_colliding_dependency(const pkgconf_dependency_t *dep, const pkgconf_list_t
}
static inline pkgconf_dependency_t *
add_or_replace_dependency_node(const pkgconf_client_t *client, pkgconf_dependency_t *dep, pkgconf_list_t *list)
add_or_replace_dependency_node(pkgconf_client_t *client, pkgconf_dependency_t *dep, pkgconf_list_t *list)
{
char depbuf[PKGCONF_ITEM_SIZE];
pkgconf_dependency_t *dep2 = find_colliding_dependency(dep, list);
@ -92,7 +92,7 @@ add_or_replace_dependency_node(const pkgconf_client_t *client, pkgconf_dependenc
{
PKGCONF_TRACE(client, "dropping dependency [%s]@%p because of collision", depbuf, dep);
free(dep);
pkgconf_dependency_unref(dep->owner, dep);
return NULL;
}
else if (dep2->flags && dep->flags == 0)
@ -100,7 +100,7 @@ add_or_replace_dependency_node(const pkgconf_client_t *client, pkgconf_dependenc
PKGCONF_TRACE(client, "dropping dependency [%s]@%p because of collision", depbuf2, dep2);
pkgconf_node_delete(&dep2->iter, list);
free(dep2);
pkgconf_dependency_unref(dep2->owner, dep2);
}
else
/* If both dependencies have equal strength, we keep both, because of situations like:
@ -113,13 +113,20 @@ add_or_replace_dependency_node(const pkgconf_client_t *client, pkgconf_dependenc
}
PKGCONF_TRACE(client, "added dependency [%s] to list @%p; flags=%x", dependency_to_str(dep, depbuf, sizeof depbuf), list, dep->flags);
pkgconf_node_insert_tail(&dep->iter, dep, list);
pkgconf_node_insert_tail(&dep->iter, pkgconf_dependency_ref(dep->owner, dep), list);
/* This dependency is intentionally unowned.
*
* Internally we have no use for the returned type, and usually just
* discard it. However, there is a publig pkgconf_dependency_add
* function, which references this return value before returning it,
* giving ownership at that point.
*/
return dep;
}
static inline pkgconf_dependency_t *
pkgconf_dependency_addraw(const pkgconf_client_t *client, pkgconf_list_t *list, const char *package, size_t package_sz, const char *version, size_t version_sz, pkgconf_pkg_comparator_t compare, unsigned int flags)
pkgconf_dependency_addraw(pkgconf_client_t *client, pkgconf_list_t *list, const char *package, size_t package_sz, const char *version, size_t version_sz, pkgconf_pkg_comparator_t compare, unsigned int flags)
{
pkgconf_dependency_t *dep;
@ -131,6 +138,8 @@ pkgconf_dependency_addraw(const pkgconf_client_t *client, pkgconf_list_t *list,
dep->compare = compare;
dep->flags = flags;
dep->owner = client;
dep->refcount = 0;
return add_or_replace_dependency_node(client, dep, list);
}
@ -152,12 +161,12 @@ pkgconf_dependency_addraw(const pkgconf_client_t *client, pkgconf_list_t *list,
* :rtype: pkgconf_dependency_t *
*/
pkgconf_dependency_t *
pkgconf_dependency_add(const pkgconf_client_t *client, pkgconf_list_t *list, const char *package, const char *version, pkgconf_pkg_comparator_t compare, unsigned int flags)
pkgconf_dependency_add(pkgconf_client_t *client, pkgconf_list_t *list, const char *package, const char *version, pkgconf_pkg_comparator_t compare, unsigned int flags)
{
if (version != NULL)
return pkgconf_dependency_addraw(client, list, package, strlen(package), version, strlen(version), compare, flags);
return pkgconf_dependency_addraw(client, list, package, strlen(package), NULL, 0, compare, flags);
pkgconf_dependency_t *dep;
dep = pkgconf_dependency_addraw(client, list, package, strlen(package), version,
version != NULL ? strlen(version) : 0, compare, flags);
return pkgconf_dependency_ref(dep->owner, dep);
}
/*
@ -177,6 +186,77 @@ pkgconf_dependency_append(pkgconf_list_t *list, pkgconf_dependency_t *tail)
pkgconf_node_insert_tail(&tail->iter, tail, list);
}
/*
* !doc
*
* .. c:function:: void pkgconf_dependency_free_one(pkgconf_dependency_t *dep)
*
* Frees a dependency node.
*
* :param pkgconf_dependency_t* dep: The dependency node to free.
* :return: nothing
*/
void
pkgconf_dependency_free_one(pkgconf_dependency_t *dep)
{
if (dep->match != NULL)
pkgconf_pkg_unref(dep->match->owner, dep->match);
if (dep->package != NULL)
free(dep->package);
if (dep->version != NULL)
free(dep->version);
free(dep);
}
/*
* !doc
*
* .. c:function:: pkgconf_dependency_t *pkgconf_dependency_ref(pkgconf_client_t *owner, pkgconf_dependency_t *dep)
*
* Increases a dependency node's refcount.
*
* :param pkgconf_client_t* owner: The client object which owns the memory of this dependency node.
* :param pkgconf_dependency_t* dep: The dependency to increase the refcount of.
* :return: the dependency node on success, else NULL
*/
pkgconf_dependency_t *
pkgconf_dependency_ref(pkgconf_client_t *client, pkgconf_dependency_t *dep)
{
if (client != dep->owner)
return NULL;
dep->refcount++;
PKGCONF_TRACE(client, "%s refcount@%p: %d", dep->package, dep, dep->refcount);
return dep;
}
/*
* !doc
*
* .. c:function:: void pkgconf_dependency_unref(pkgconf_client_t *owner, pkgconf_dependency_t *dep)
*
* Decreases a dependency node's refcount and frees it if necessary.
*
* :param pkgconf_client_t* owner: The client object which owns the memory of this dependency node.
* :param pkgconf_dependency_t* dep: The dependency to decrease the refcount of.
* :return: nothing
*/
void
pkgconf_dependency_unref(pkgconf_client_t *client, pkgconf_dependency_t *dep)
{
if (client != dep->owner)
return;
--dep->refcount;
PKGCONF_TRACE(client, "%s refcount@%p: %d", dep->package, dep, dep->refcount);
if (dep->refcount <= 0)
pkgconf_dependency_free_one(dep);
}
/*
* !doc
*
@ -196,17 +276,11 @@ pkgconf_dependency_free(pkgconf_list_t *list)
{
pkgconf_dependency_t *dep = node->data;
if (dep->match != NULL)
pkgconf_pkg_unref(NULL, dep->match);
if (dep->package != NULL)
free(dep->package);
if (dep->version != NULL)
free(dep->version);
free(dep);
pkgconf_node_delete(&dep->iter, list);
pkgconf_dependency_unref(dep->owner, dep);
}
pkgconf_list_zero(list);
}
/*
@ -225,7 +299,7 @@ pkgconf_dependency_free(pkgconf_list_t *list)
* :return: nothing
*/
void
pkgconf_dependency_parse_str(const pkgconf_client_t *client, pkgconf_list_t *deplist_head, const char *depends, unsigned int flags)
pkgconf_dependency_parse_str(pkgconf_client_t *client, pkgconf_list_t *deplist_head, const char *depends, unsigned int flags)
{
parse_state_t state = OUTSIDE_MODULE;
pkgconf_pkg_comparator_t compare = PKGCONF_CMP_ANY;
@ -237,6 +311,7 @@ pkgconf_dependency_parse_str(const pkgconf_client_t *client, pkgconf_list_t *dep
char *vstart = NULL;
char *package = NULL, *version = NULL;
char *cnameptr = cmpname;
char *cnameend = cmpname + PKGCONF_ITEM_SIZE - 1;
memset(cmpname, '\0', sizeof cmpname);
@ -304,7 +379,8 @@ pkgconf_dependency_parse_str(const pkgconf_client_t *client, pkgconf_list_t *dep
if (PKGCONF_IS_OPERATOR_CHAR(*ptr))
{
state = INSIDE_OPERATOR;
*cnameptr++ = *ptr;
if (cnameptr < cnameend)
*cnameptr++ = *ptr;
}
break;
@ -315,7 +391,7 @@ pkgconf_dependency_parse_str(const pkgconf_client_t *client, pkgconf_list_t *dep
state = AFTER_OPERATOR;
compare = pkgconf_pkg_comparator_lookup_by_name(cmpname);
}
else
else if (cnameptr < cnameend)
*cnameptr++ = *ptr;
break;
@ -369,10 +445,43 @@ pkgconf_dependency_parse_str(const pkgconf_client_t *client, pkgconf_list_t *dep
* :return: nothing
*/
void
pkgconf_dependency_parse(const pkgconf_client_t *client, pkgconf_pkg_t *pkg, pkgconf_list_t *deplist, const char *depends, unsigned int flags)
pkgconf_dependency_parse(pkgconf_client_t *client, pkgconf_pkg_t *pkg, pkgconf_list_t *deplist, const char *depends, unsigned int flags)
{
char *kvdepends = pkgconf_tuple_parse(client, &pkg->vars, depends);
char *kvdepends = pkgconf_tuple_parse(client, &pkg->vars, depends, pkg->flags);
pkgconf_dependency_parse_str(client, deplist, kvdepends, flags);
free(kvdepends);
}
/*
* !doc
*
* .. c:function:: pkgconf_dependency_t *pkgconf_dependency_copy(pkgconf_client_t *client, const pkgconf_dependency_t *dep)
*
* Copies a dependency node to a new one.
*
* :param pkgconf_client_t* client: The client object that will own this dependency.
* :param pkgconf_dependency_t* dep: The dependency node to copy.
* :return: a pointer to a new dependency node, else NULL
*/
pkgconf_dependency_t *
pkgconf_dependency_copy(pkgconf_client_t *client, const pkgconf_dependency_t *dep)
{
pkgconf_dependency_t *new_dep;
new_dep = calloc(sizeof(pkgconf_dependency_t), 1);
new_dep->package = strdup(dep->package);
if (dep->version != NULL)
new_dep->version = strdup(dep->version);
new_dep->compare = dep->compare;
new_dep->flags = dep->flags;
new_dep->owner = client;
new_dep->refcount = 0;
if (dep->match != NULL)
new_dep->match = pkgconf_pkg_ref(client, dep->match);
return pkgconf_dependency_ref(client, new_dep);
}

View File

@ -44,6 +44,9 @@ pkgconf_fgetline(char *line, size_t size, FILE *stream)
*s++ = c;
break;
}
else
*s++ = c;
quoted = false;
continue;
}

View File

@ -93,15 +93,18 @@ pkgconf_fragment_is_special(const char *string)
}
static inline void
pkgconf_fragment_munge(const pkgconf_client_t *client, char *buf, size_t buflen, const char *source, const char *sysroot_dir)
pkgconf_fragment_munge(const pkgconf_client_t *client, char *buf, size_t buflen, const char *source, const char *sysroot_dir, unsigned int flags)
{
*buf = '\0';
if (sysroot_dir == NULL)
sysroot_dir = pkgconf_tuple_find_global(client, "pc_sysrootdir");
if (!(flags & PKGCONF_PKG_PROPF_UNINSTALLED) || (client->flags & PKGCONF_PKG_PKGF_PKGCONF1_SYSROOT_RULES))
{
if (sysroot_dir == NULL)
sysroot_dir = pkgconf_tuple_find_global(client, "pc_sysrootdir");
if (sysroot_dir != NULL && pkgconf_fragment_should_munge(source, sysroot_dir))
pkgconf_strlcat(buf, sysroot_dir, buflen);
if (sysroot_dir != NULL && pkgconf_fragment_should_munge(source, sysroot_dir))
pkgconf_strlcat(buf, sysroot_dir, buflen);
}
pkgconf_strlcat(buf, source, buflen);
@ -110,39 +113,40 @@ pkgconf_fragment_munge(const pkgconf_client_t *client, char *buf, size_t buflen,
}
static inline char *
pkgconf_fragment_copy_munged(const pkgconf_client_t *client, const char *source)
pkgconf_fragment_copy_munged(const pkgconf_client_t *client, const char *source, unsigned int flags)
{
char mungebuf[PKGCONF_ITEM_SIZE];
pkgconf_fragment_munge(client, mungebuf, sizeof mungebuf, source, client->sysroot_dir);
pkgconf_fragment_munge(client, mungebuf, sizeof mungebuf, source, client->sysroot_dir, flags);
return strdup(mungebuf);
}
/*
* !doc
*
* .. c:function:: void pkgconf_fragment_add(const pkgconf_client_t *client, pkgconf_list_t *list, const char *string)
* .. c:function:: void pkgconf_fragment_add(const pkgconf_client_t *client, pkgconf_list_t *list, const char *string, unsigned int flags)
*
* Adds a `fragment` of text to a `fragment list`, possibly modifying the fragment if a sysroot is set.
*
* :param pkgconf_client_t* client: The pkgconf client being accessed.
* :param pkgconf_list_t* list: The fragment list.
* :param char* string: The string of text to add as a fragment to the fragment list.
* :param uint flags: Parsing-related flags for the package.
* :return: nothing
*/
void
pkgconf_fragment_add(const pkgconf_client_t *client, pkgconf_list_t *list, const char *string)
pkgconf_fragment_add(const pkgconf_client_t *client, pkgconf_list_t *list, const char *string, unsigned int flags)
{
pkgconf_fragment_t *frag;
if (*string == '\0')
return;
if (!pkgconf_fragment_is_special(string))
if (strlen(string) > 1 && !pkgconf_fragment_is_special(string))
{
frag = calloc(sizeof(pkgconf_fragment_t), 1);
frag->type = *(string + 1);
frag->data = pkgconf_fragment_copy_munged(client, string + 2);
frag->data = pkgconf_fragment_copy_munged(client, string + 2, flags);
PKGCONF_TRACE(client, "added fragment {%c, '%s'} to list @%p", frag->type, frag->data, list);
}
@ -156,12 +160,12 @@ pkgconf_fragment_add(const pkgconf_client_t *client, pkgconf_list_t *list, const
pkgconf_fragment_t *parent = list->tail->data;
/* only attempt to merge 'special' fragments together */
if (!parent->type && pkgconf_fragment_is_unmergeable(parent->data))
if (!parent->type && parent->data != NULL && pkgconf_fragment_is_unmergeable(parent->data))
{
size_t len;
char *newdata;
pkgconf_fragment_munge(client, mungebuf, sizeof mungebuf, string, NULL);
pkgconf_fragment_munge(client, mungebuf, sizeof mungebuf, string, NULL, flags);
len = strlen(parent->data) + strlen(mungebuf) + 2;
newdata = malloc(len);
@ -433,7 +437,11 @@ fragment_quote(const pkgconf_fragment_t *frag)
(*src > ')' && *src < '+') ||
(*src > ':' && *src < '=') ||
(*src > '=' && *src < '@') ||
(*src > 'Z' && *src < '^') ||
(*src > 'Z' && *src < '\\') ||
#ifndef _WIN32
(*src == '\\') ||
#endif
(*src > '\\' && *src < '^') ||
(*src == '`') ||
(*src > 'z' && *src < '~') ||
(*src > '~')))
@ -443,8 +451,10 @@ fragment_quote(const pkgconf_fragment_t *frag)
if ((ptrdiff_t)(dst - out) + 2 > outlen)
{
ptrdiff_t offset = dst - out;
outlen *= 2;
out = realloc(out, outlen);
dst = out + offset;
}
}
@ -657,15 +667,16 @@ pkgconf_fragment_free(pkgconf_list_t *list)
* :param pkgconf_client_t* client: The pkgconf client being accessed.
* :param pkgconf_list_t* list: The `fragment list` to add the fragment entries to.
* :param pkgconf_list_t* vars: A list of variables to use for variable substitution.
* :param uint flags: Any parsing flags to be aware of.
* :param char* value: The string to parse into fragments.
* :return: true on success, false on parse error
*/
bool
pkgconf_fragment_parse(const pkgconf_client_t *client, pkgconf_list_t *list, pkgconf_list_t *vars, const char *value)
pkgconf_fragment_parse(const pkgconf_client_t *client, pkgconf_list_t *list, pkgconf_list_t *vars, const char *value, unsigned int flags)
{
int i, ret, argc;
char **argv;
char *repstr = pkgconf_tuple_parse(client, vars, value);
char *repstr = pkgconf_tuple_parse(client, vars, value, flags);
PKGCONF_TRACE(client, "post-subst: [%s] -> [%s]", value, repstr);
@ -679,6 +690,8 @@ pkgconf_fragment_parse(const pkgconf_client_t *client, pkgconf_list_t *list, pkg
for (i = 0; i < argc; i++)
{
PKGCONF_TRACE(client, "processing %s", argv[i]);
if (argv[i] == NULL)
{
PKGCONF_TRACE(client, "parsed fragment string is inconsistent: argc = %d while argv[%d] == NULL", argc, i);
@ -687,7 +700,7 @@ pkgconf_fragment_parse(const pkgconf_client_t *client, pkgconf_list_t *list, pkg
return false;
}
pkgconf_fragment_add(client, list, argv[i]);
pkgconf_fragment_add(client, list, argv[i], flags);
}
pkgconf_argv_free(argv);

View File

@ -34,6 +34,14 @@ typedef struct {
#define PKGCONF_LIST_INITIALIZER { NULL, NULL, 0 }
static inline void
pkgconf_list_zero(pkgconf_list_t *list)
{
list->head = NULL;
list->tail = NULL;
list->length = 0;
}
static inline void
pkgconf_node_insert(pkgconf_node_t *node, void *data, pkgconf_list_t *list)
{

View File

@ -2,8 +2,7 @@
#define LIBPKGCONF_LIBPKGCONF_API_H
/* Makefile.am specifies visibility using the libtool option -export-symbols-regex '^pkgconf_'
* Unfortunately, that is not available when building with cmake, so use attributes instead,
* in a way that doesn't depend on any cmake magic.
* Unfortunately, that is not available when building with meson, so use attributes instead.
*/
#if defined(PKGCONFIG_IS_STATIC)
# define PKGCONF_API

View File

@ -20,6 +20,7 @@
#include <stdarg.h>
#include <stddef.h>
#include <stdbool.h>
#include <stdint.h>
#include <libpkgconf/libpkgconf-api.h>
#include <libpkgconf/iter.h>
#include <libpkgconf/bsdstubs.h>
@ -78,8 +79,8 @@ typedef struct pkgconf_cross_personality_ pkgconf_cross_personality_t;
#define PKGCONF_FOREACH_LIST_ENTRY_REVERSE(tail, value) \
for ((value) = (tail); (value) != NULL; (value) = (value)->prev)
#define LIBPKGCONF_VERSION 10700
#define LIBPKGCONF_VERSION_STR "1.7.0"
#define LIBPKGCONF_VERSION 10903
#define LIBPKGCONF_VERSION_STR "1.9.3"
struct pkgconf_fragment_ {
pkgconf_node_t iter;
@ -100,6 +101,9 @@ struct pkgconf_dependency_ {
pkgconf_pkg_t *match;
unsigned int flags;
int refcount;
pkgconf_client_t *owner;
};
struct pkgconf_tuple_ {
@ -107,8 +111,12 @@ struct pkgconf_tuple_ {
char *key;
char *value;
unsigned int flags;
};
#define PKGCONF_PKG_TUPLEF_OVERRIDE 0x1
struct pkgconf_path_ {
pkgconf_node_t lnode;
@ -120,13 +128,10 @@ struct pkgconf_path_ {
#define PKGCONF_PKG_PROPF_NONE 0x00
#define PKGCONF_PKG_PROPF_STATIC 0x01
#define PKGCONF_PKG_PROPF_CACHED 0x02
#define PKGCONF_PKG_PROPF_SEEN 0x04
#define PKGCONF_PKG_PROPF_UNINSTALLED 0x08
#define PKGCONF_PKG_PROPF_VIRTUAL 0x10
struct pkgconf_pkg_ {
pkgconf_node_t cache_iter;
int refcount;
char *id;
char *filename;
@ -135,6 +140,9 @@ struct pkgconf_pkg_ {
char *description;
char *url;
char *pc_filedir;
char *license;
char *maintainer;
char *copyright;
pkgconf_list_t libs;
pkgconf_list_t libs_private;
@ -157,16 +165,19 @@ struct pkgconf_pkg_ {
*/
pkgconf_tuple_t *orig_prefix;
pkgconf_tuple_t *prefix;
uint64_t serial;
size_t hits;
};
typedef bool (*pkgconf_pkg_iteration_func_t)(const pkgconf_pkg_t *pkg, void *data);
typedef void (*pkgconf_pkg_traverse_func_t)(pkgconf_client_t *client, pkgconf_pkg_t *pkg, void *data);
typedef bool (*pkgconf_queue_apply_func_t)(pkgconf_client_t *client, pkgconf_pkg_t *world, void *data, int maxdepth);
typedef bool (*pkgconf_error_handler_func_t)(const char *msg, const pkgconf_client_t *client, const void *data);
typedef bool (*pkgconf_error_handler_func_t)(const char *msg, const pkgconf_client_t *client, void *data);
struct pkgconf_client_ {
pkgconf_list_t dir_list;
pkgconf_list_t pkg_cache;
pkgconf_list_t filter_libdirs;
pkgconf_list_t filter_includedirs;
@ -191,6 +202,11 @@ struct pkgconf_client_ {
char *prefix_varname;
bool already_sent_notice;
uint64_t serial;
pkgconf_pkg_t **cache_table;
size_t cache_count;
};
struct pkgconf_cross_personality_ {
@ -204,6 +220,7 @@ struct pkgconf_cross_personality_ {
char *sysroot_dir;
bool want_default_static;
bool want_default_pure;
};
/* client.c */
@ -230,6 +247,7 @@ PKGCONF_API void pkgconf_client_dir_list_build(pkgconf_client_t *client, const p
/* personality.c */
PKGCONF_API pkgconf_cross_personality_t *pkgconf_cross_personality_default(void);
PKGCONF_API pkgconf_cross_personality_t *pkgconf_cross_personality_find(const char *triplet);
PKGCONF_API void pkgconf_cross_personality_deinit(pkgconf_cross_personality_t *personality);
#define PKGCONF_IS_MODULE_SEPARATOR(c) ((c) == ',' || isspace ((unsigned int)(c)))
#define PKGCONF_IS_OPERATOR_CHAR(c) ((c) == '<' || (c) == '>' || (c) == '!' || (c) == '=')
@ -250,8 +268,11 @@ PKGCONF_API pkgconf_cross_personality_t *pkgconf_cross_personality_find(const ch
#define PKGCONF_PKG_PKGF_SIMPLIFY_ERRORS 0x1000
#define PKGCONF_PKG_PKGF_DONT_FILTER_INTERNAL_CFLAGS 0x2000
#define PKGCONF_PKG_PKGF_DONT_MERGE_SPECIAL_FRAGMENTS 0x4000
#define PKGCONF_PKG_PKGF_FDO_SYSROOT_RULES 0x8000
#define PKGCONF_PKG_PKGF_PKGCONF1_SYSROOT_RULES 0x10000
#define PKGCONF_PKG_DEPF_INTERNAL 0x1
#define PKGCONF_PKG_DEPF_PRIVATE 0x2
#define PKGCONF_PKG_ERRF_OK 0x0
#define PKGCONF_PKG_ERRF_PACKAGE_NOT_FOUND 0x1
@ -279,17 +300,17 @@ PKGCONF_API void pkgconf_parser_parse(FILE *f, void *data, const pkgconf_parser_
PKGCONF_API bool pkgconf_error(const pkgconf_client_t *client, const char *format, ...) PRINTFLIKE(2, 3);
PKGCONF_API bool pkgconf_warn(const pkgconf_client_t *client, const char *format, ...) PRINTFLIKE(2, 3);
PKGCONF_API bool pkgconf_trace(const pkgconf_client_t *client, const char *filename, size_t lineno, const char *funcname, const char *format, ...) PRINTFLIKE(5, 6);
PKGCONF_API bool pkgconf_default_error_handler(const char *msg, const pkgconf_client_t *client, const void *data);
PKGCONF_API bool pkgconf_default_error_handler(const char *msg, const pkgconf_client_t *client, void *data);
#ifndef PKGCONF_LITE
#if defined(__GNUC__) || defined(__INTEL_COMPILER)
#define PKGCONF_TRACE(client, ...) do { \
pkgconf_trace(client, __FILE__, __LINE__, __PRETTY_FUNCTION__, __VA_ARGS__); \
} while (0);
} while (0)
#else
#define PKGCONF_TRACE(client, ...) do { \
pkgconf_trace(client, __FILE__, __LINE__, __func__, __VA_ARGS__); \
} while (0);
} while (0)
#endif
#else
#define PKGCONF_TRACE(client, ...)
@ -312,12 +333,16 @@ PKGCONF_API int pkgconf_compare_version(const char *a, const char *b);
PKGCONF_API pkgconf_pkg_t *pkgconf_scan_all(pkgconf_client_t *client, void *ptr, pkgconf_pkg_iteration_func_t func);
/* parse.c */
PKGCONF_API pkgconf_pkg_t *pkgconf_pkg_new_from_file(pkgconf_client_t *client, const char *path, FILE *f);
PKGCONF_API void pkgconf_dependency_parse_str(const pkgconf_client_t *client, pkgconf_list_t *deplist_head, const char *depends, unsigned int flags);
PKGCONF_API void pkgconf_dependency_parse(const pkgconf_client_t *client, pkgconf_pkg_t *pkg, pkgconf_list_t *deplist_head, const char *depends, unsigned int flags);
PKGCONF_API pkgconf_pkg_t *pkgconf_pkg_new_from_file(pkgconf_client_t *client, const char *path, FILE *f, unsigned int flags);
PKGCONF_API void pkgconf_dependency_parse_str(pkgconf_client_t *client, pkgconf_list_t *deplist_head, const char *depends, unsigned int flags);
PKGCONF_API void pkgconf_dependency_parse(pkgconf_client_t *client, pkgconf_pkg_t *pkg, pkgconf_list_t *deplist_head, const char *depends, unsigned int flags);
PKGCONF_API void pkgconf_dependency_append(pkgconf_list_t *list, pkgconf_dependency_t *tail);
PKGCONF_API void pkgconf_dependency_free(pkgconf_list_t *list);
PKGCONF_API pkgconf_dependency_t *pkgconf_dependency_add(const pkgconf_client_t *client, pkgconf_list_t *list, const char *package, const char *version, pkgconf_pkg_comparator_t compare, unsigned int flags);
PKGCONF_API void pkgconf_dependency_free_one(pkgconf_dependency_t *dep);
PKGCONF_API pkgconf_dependency_t *pkgconf_dependency_add(pkgconf_client_t *client, pkgconf_list_t *list, const char *package, const char *version, pkgconf_pkg_comparator_t compare, unsigned int flags);
PKGCONF_API pkgconf_dependency_t *pkgconf_dependency_ref(pkgconf_client_t *client, pkgconf_dependency_t *dep);
PKGCONF_API void pkgconf_dependency_unref(pkgconf_client_t *client, pkgconf_dependency_t *dep);
PKGCONF_API pkgconf_dependency_t *pkgconf_dependency_copy(pkgconf_client_t *client, const pkgconf_dependency_t *dep);
/* argvsplit.c */
PKGCONF_API int pkgconf_argv_split(const char *src, int *argc, char ***argv);
@ -330,8 +355,8 @@ typedef struct pkgconf_fragment_render_ops_ {
} pkgconf_fragment_render_ops_t;
typedef bool (*pkgconf_fragment_filter_func_t)(const pkgconf_client_t *client, const pkgconf_fragment_t *frag, void *data);
PKGCONF_API bool pkgconf_fragment_parse(const pkgconf_client_t *client, pkgconf_list_t *list, pkgconf_list_t *vars, const char *value);
PKGCONF_API void pkgconf_fragment_add(const pkgconf_client_t *client, pkgconf_list_t *list, const char *string);
PKGCONF_API bool pkgconf_fragment_parse(const pkgconf_client_t *client, pkgconf_list_t *list, pkgconf_list_t *vars, const char *value, unsigned int flags);
PKGCONF_API void pkgconf_fragment_add(const pkgconf_client_t *client, pkgconf_list_t *list, const char *string, unsigned int flags);
PKGCONF_API void pkgconf_fragment_copy(const pkgconf_client_t *client, pkgconf_list_t *list, const pkgconf_fragment_t *base, bool is_private);
PKGCONF_API void pkgconf_fragment_copy_list(const pkgconf_client_t *client, pkgconf_list_t *list, const pkgconf_list_t *base);
PKGCONF_API void pkgconf_fragment_delete(pkgconf_list_t *list, pkgconf_fragment_t *node);
@ -346,9 +371,9 @@ PKGCONF_API bool pkgconf_fragment_has_system_dir(const pkgconf_client_t *client,
PKGCONF_API char *pkgconf_fgetline(char *line, size_t size, FILE *stream);
/* tuple.c */
PKGCONF_API pkgconf_tuple_t *pkgconf_tuple_add(const pkgconf_client_t *client, pkgconf_list_t *parent, const char *key, const char *value, bool parse);
PKGCONF_API pkgconf_tuple_t *pkgconf_tuple_add(const pkgconf_client_t *client, pkgconf_list_t *parent, const char *key, const char *value, bool parse, unsigned int flags);
PKGCONF_API char *pkgconf_tuple_find(const pkgconf_client_t *client, pkgconf_list_t *list, const char *key);
PKGCONF_API char *pkgconf_tuple_parse(const pkgconf_client_t *client, pkgconf_list_t *list, const char *value);
PKGCONF_API char *pkgconf_tuple_parse(const pkgconf_client_t *client, pkgconf_list_t *list, const char *value, unsigned int flags);
PKGCONF_API void pkgconf_tuple_free(pkgconf_list_t *list);
PKGCONF_API void pkgconf_tuple_free_entry(pkgconf_tuple_t *tuple, pkgconf_list_t *list);
PKGCONF_API void pkgconf_tuple_add_global(pkgconf_client_t *client, const char *key, const char *value);
@ -359,9 +384,11 @@ PKGCONF_API void pkgconf_tuple_define_global(pkgconf_client_t *client, const cha
/* queue.c */
PKGCONF_API void pkgconf_queue_push(pkgconf_list_t *list, const char *package);
PKGCONF_API bool pkgconf_queue_compile(pkgconf_client_t *client, pkgconf_pkg_t *world, pkgconf_list_t *list);
PKGCONF_API bool pkgconf_queue_solve(pkgconf_client_t *client, pkgconf_list_t *list, pkgconf_pkg_t *world, int maxdepth);
PKGCONF_API void pkgconf_queue_free(pkgconf_list_t *list);
PKGCONF_API bool pkgconf_queue_apply(pkgconf_client_t *client, pkgconf_list_t *list, pkgconf_queue_apply_func_t func, int maxdepth, void *data);
PKGCONF_API bool pkgconf_queue_validate(pkgconf_client_t *client, pkgconf_list_t *list, int maxdepth);
PKGCONF_API void pkgconf_solution_free(pkgconf_client_t *client, pkgconf_pkg_t *world);
/* cache.c */
PKGCONF_API pkgconf_pkg_t *pkgconf_cache_lookup(pkgconf_client_t *client, const char *id);

View File

@ -8,5 +8,5 @@ install_headers('libpkgconf.h',
'iter.h',
'bsdstubs.h',
'libpkgconf-api.h',
subdir : 'libpkgconf')
subdir : 'pkgconf/libpkgconf')

View File

@ -17,10 +17,6 @@
#include <libpkgconf/stdinc.h>
#include <libpkgconf/libpkgconf.h>
#if defined(HAVE_CYGWIN_CONV_PATH) && defined(__MSYS__)
# include <sys/cygwin.h>
#endif
#if defined(HAVE_SYS_STAT_H) && ! defined(_WIN32)
# include <sys/stat.h>
# define PKGCONF_CACHE_INODES
@ -92,15 +88,11 @@ pkgconf_path_add(const char *text, pkgconf_list_t *dirlist, bool filter)
return;
if (S_ISLNK(st.st_mode))
{
char *linkdest = realpath(path, NULL);
char pathbuf[PKGCONF_ITEM_SIZE * 4];
char *linkdest = realpath(path, pathbuf);
if (linkdest != NULL && stat(linkdest, &st) == -1)
{
free(linkdest);
return;
}
free(linkdest);
}
if (path_list_contains_entry(path, dirlist, &st))
return;
@ -276,6 +268,8 @@ pkgconf_path_free(pkgconf_list_t *dirlist)
free(pnode->path);
free(pnode);
}
pkgconf_list_zero(dirlist);
}
static char *
@ -310,7 +304,7 @@ normpath(const char *path)
*
* .. c:function:: bool pkgconf_path_relocate(char *buf, size_t buflen)
*
* Relocates a path, possibly calling normpath() or cygwin_conv_path() on it.
* Relocates a path, possibly calling normpath() on it.
*
* :param char* buf: The path to relocate.
* :param size_t buflen: The buffer length the path is contained in.
@ -320,28 +314,10 @@ normpath(const char *path)
bool
pkgconf_path_relocate(char *buf, size_t buflen)
{
#if defined(HAVE_CYGWIN_CONV_PATH) && defined(__MSYS__)
ssize_t size;
char *tmpbuf, *ti;
#ifdef _WIN32
char *ti;
#endif
size = cygwin_conv_path(CCP_POSIX_TO_WIN_A, buf, NULL, 0);
if (size < 0 || (size_t) size > buflen)
return false;
tmpbuf = malloc(size);
if (cygwin_conv_path(CCP_POSIX_TO_WIN_A, buf, tmpbuf, size))
return false;
pkgconf_strlcpy(buf, tmpbuf, buflen);
free(tmpbuf);
/* rewrite any backslash arguments for best compatibility */
for (ti = buf; *ti != '\0'; ti++)
{
if (*ti == '\\')
*ti = '/';
}
#else
char *tmpbuf;
if ((tmpbuf = normpath(buf)) != NULL)
@ -356,7 +332,6 @@ pkgconf_path_relocate(char *buf, size_t buflen)
pkgconf_strlcpy(buf, tmpbuf, buflen);
free(tmpbuf);
}
#endif
return true;
}

View File

@ -21,9 +21,19 @@
# define strcasecmp _stricmp
#endif
static bool default_personality_init = false;
/*
* Increment each time the default personality is inited, decrement each time
* it's deinited. Whenever it is 0, then the deinit frees the personality. In
* that case an additional call to init will create it anew.
*/
static unsigned default_personality_init = 0;
static pkgconf_cross_personality_t default_personality = {
.name = "default",
#ifdef _WIN32
.want_default_static = true,
.want_default_pure = true,
#endif
};
static inline void
@ -81,24 +91,49 @@ build_default_search_path(pkgconf_list_t* dirlist)
*
* Returns the default cross-compile personality.
*
* Not thread safe.
*
* :rtype: pkgconf_cross_personality_t*
* :return: the default cross-compile personality
*/
pkgconf_cross_personality_t *
pkgconf_cross_personality_default(void)
{
if (default_personality_init)
if (default_personality_init) {
++default_personality_init;
return &default_personality;
}
build_default_search_path(&default_personality.dir_list);
pkgconf_path_split(SYSTEM_LIBDIR, &default_personality.filter_libdirs, true);
pkgconf_path_split(SYSTEM_INCLUDEDIR, &default_personality.filter_includedirs, true);
pkgconf_path_split(SYSTEM_LIBDIR, &default_personality.filter_libdirs, false);
pkgconf_path_split(SYSTEM_INCLUDEDIR, &default_personality.filter_includedirs, false);
default_personality_init = true;
++default_personality_init;
return &default_personality;
}
/*
* !doc
*
* .. c:function:: void pkgconf_cross_personality_deinit(pkgconf_cross_personality_t *)
*
* Decrements the count of default cross personality instances.
*
* Not thread safe.
*
* :rtype: void
*/
void
pkgconf_cross_personality_deinit(pkgconf_cross_personality_t *personality)
{
if (--default_personality_init == 0) {
pkgconf_path_free(&personality->dir_list);
pkgconf_path_free(&personality->filter_libdirs);
pkgconf_path_free(&personality->filter_includedirs);
}
}
#ifndef PKGCONF_LITE
static bool
valid_triplet(const char *triplet)
@ -156,6 +191,7 @@ static const personality_keyword_pair_t personality_keyword_pairs[] = {
{"SystemIncludePaths", personality_fragment_func, offsetof(pkgconf_cross_personality_t, filter_includedirs)},
{"SystemLibraryPaths", personality_fragment_func, offsetof(pkgconf_cross_personality_t, filter_libdirs)},
{"Triplet", personality_copy_func, offsetof(pkgconf_cross_personality_t, name)},
{"WantDefaultPure", personality_bool_func, offsetof(pkgconf_cross_personality_t, want_default_pure)},
{"WantDefaultStatic", personality_bool_func, offsetof(pkgconf_cross_personality_t, want_default_static)},
};

View File

@ -37,6 +37,14 @@
#define PKG_CONFIG_EXT ".pc"
static unsigned int
pkgconf_pkg_traverse_main(pkgconf_client_t *client,
pkgconf_pkg_t *root,
pkgconf_pkg_traverse_func_t func,
void *data,
int maxdepth,
unsigned int skip_flags);
static inline bool
str_has_suffix(const char *str, const char *suffix)
{
@ -64,7 +72,7 @@ pkg_get_parent_dir(pkgconf_pkg_t *pkg)
return strdup(buf);
}
typedef void (*pkgconf_pkg_parser_keyword_func_t)(const pkgconf_client_t *client, pkgconf_pkg_t *pkg, const char *keyword, const size_t lineno, const ptrdiff_t offset, const char *value);
typedef void (*pkgconf_pkg_parser_keyword_func_t)(pkgconf_client_t *client, pkgconf_pkg_t *pkg, const char *keyword, const size_t lineno, const ptrdiff_t offset, const char *value);
typedef struct {
const char *keyword;
const pkgconf_pkg_parser_keyword_func_t func;
@ -78,17 +86,17 @@ static int pkgconf_pkg_parser_keyword_pair_cmp(const void *key, const void *ptr)
}
static void
pkgconf_pkg_parser_tuple_func(const pkgconf_client_t *client, pkgconf_pkg_t *pkg, const char *keyword, const size_t lineno, const ptrdiff_t offset, const char *value)
pkgconf_pkg_parser_tuple_func(pkgconf_client_t *client, pkgconf_pkg_t *pkg, const char *keyword, const size_t lineno, const ptrdiff_t offset, const char *value)
{
(void) keyword;
(void) lineno;
char **dest = (char **)((char *) pkg + offset);
*dest = pkgconf_tuple_parse(client, &pkg->vars, value);
*dest = pkgconf_tuple_parse(client, &pkg->vars, value, pkg->flags);
}
static void
pkgconf_pkg_parser_version_func(const pkgconf_client_t *client, pkgconf_pkg_t *pkg, const char *keyword, const size_t lineno, const ptrdiff_t offset, const char *value)
pkgconf_pkg_parser_version_func(pkgconf_client_t *client, pkgconf_pkg_t *pkg, const char *keyword, const size_t lineno, const ptrdiff_t offset, const char *value)
{
(void) keyword;
(void) lineno;
@ -97,10 +105,10 @@ pkgconf_pkg_parser_version_func(const pkgconf_client_t *client, pkgconf_pkg_t *p
char **dest = (char **)((char *) pkg + offset);
/* cut at any detected whitespace */
p = pkgconf_tuple_parse(client, &pkg->vars, value);
p = pkgconf_tuple_parse(client, &pkg->vars, value, pkg->flags);
len = strcspn(p, " \t");
if (len)
if (len != strlen(p))
{
i = p + (ptrdiff_t) len;
*i = '\0';
@ -113,10 +121,10 @@ pkgconf_pkg_parser_version_func(const pkgconf_client_t *client, pkgconf_pkg_t *p
}
static void
pkgconf_pkg_parser_fragment_func(const pkgconf_client_t *client, pkgconf_pkg_t *pkg, const char *keyword, const size_t lineno, const ptrdiff_t offset, const char *value)
pkgconf_pkg_parser_fragment_func(pkgconf_client_t *client, pkgconf_pkg_t *pkg, const char *keyword, const size_t lineno, const ptrdiff_t offset, const char *value)
{
pkgconf_list_t *dest = (pkgconf_list_t *)((char *) pkg + offset);
bool ret = pkgconf_fragment_parse(client, dest, &pkg->vars, value);
bool ret = pkgconf_fragment_parse(client, dest, &pkg->vars, value, pkg->flags);
if (!ret)
{
@ -126,7 +134,7 @@ pkgconf_pkg_parser_fragment_func(const pkgconf_client_t *client, pkgconf_pkg_t *
}
static void
pkgconf_pkg_parser_dependency_func(const pkgconf_client_t *client, pkgconf_pkg_t *pkg, const char *keyword, const size_t lineno, const ptrdiff_t offset, const char *value)
pkgconf_pkg_parser_dependency_func(pkgconf_client_t *client, pkgconf_pkg_t *pkg, const char *keyword, const size_t lineno, const ptrdiff_t offset, const char *value)
{
(void) keyword;
(void) lineno;
@ -137,7 +145,7 @@ pkgconf_pkg_parser_dependency_func(const pkgconf_client_t *client, pkgconf_pkg_t
/* a variant of pkgconf_pkg_parser_dependency_func which colors the dependency node as an "internal" dependency. */
static void
pkgconf_pkg_parser_internal_dependency_func(const pkgconf_client_t *client, pkgconf_pkg_t *pkg, const char *keyword, const size_t lineno, const ptrdiff_t offset, const char *value)
pkgconf_pkg_parser_internal_dependency_func(pkgconf_client_t *client, pkgconf_pkg_t *pkg, const char *keyword, const size_t lineno, const ptrdiff_t offset, const char *value)
{
(void) keyword;
(void) lineno;
@ -146,19 +154,34 @@ pkgconf_pkg_parser_internal_dependency_func(const pkgconf_client_t *client, pkgc
pkgconf_dependency_parse(client, pkg, dest, value, PKGCONF_PKG_DEPF_INTERNAL);
}
/* a variant of pkgconf_pkg_parser_dependency_func which colors the dependency node as an "internal" dependency. */
static void
pkgconf_pkg_parser_private_dependency_func(pkgconf_client_t *client, pkgconf_pkg_t *pkg, const char *keyword, const size_t lineno, const ptrdiff_t offset, const char *value)
{
(void) keyword;
(void) lineno;
pkgconf_list_t *dest = (pkgconf_list_t *)((char *) pkg + offset);
pkgconf_dependency_parse(client, pkg, dest, value, PKGCONF_PKG_DEPF_PRIVATE);
}
/* keep this in alphabetical order */
static const pkgconf_pkg_parser_keyword_pair_t pkgconf_pkg_parser_keyword_funcs[] = {
{"CFLAGS", pkgconf_pkg_parser_fragment_func, offsetof(pkgconf_pkg_t, cflags)},
{"CFLAGS.private", pkgconf_pkg_parser_fragment_func, offsetof(pkgconf_pkg_t, cflags_private)},
{"Conflicts", pkgconf_pkg_parser_dependency_func, offsetof(pkgconf_pkg_t, conflicts)},
{"Copyright", pkgconf_pkg_parser_tuple_func, offsetof(pkgconf_pkg_t, copyright)},
{"Description", pkgconf_pkg_parser_tuple_func, offsetof(pkgconf_pkg_t, description)},
{"LIBS", pkgconf_pkg_parser_fragment_func, offsetof(pkgconf_pkg_t, libs)},
{"LIBS.private", pkgconf_pkg_parser_fragment_func, offsetof(pkgconf_pkg_t, libs_private)},
{"License", pkgconf_pkg_parser_tuple_func, offsetof(pkgconf_pkg_t, license)},
{"Maintainer", pkgconf_pkg_parser_tuple_func, offsetof(pkgconf_pkg_t, maintainer)},
{"Name", pkgconf_pkg_parser_tuple_func, offsetof(pkgconf_pkg_t, realname)},
{"Provides", pkgconf_pkg_parser_dependency_func, offsetof(pkgconf_pkg_t, provides)},
{"Requires", pkgconf_pkg_parser_dependency_func, offsetof(pkgconf_pkg_t, required)},
{"Requires.internal", pkgconf_pkg_parser_internal_dependency_func, offsetof(pkgconf_pkg_t, requires_private)},
{"Requires.private", pkgconf_pkg_parser_dependency_func, offsetof(pkgconf_pkg_t, requires_private)},
{"Requires.private", pkgconf_pkg_parser_private_dependency_func, offsetof(pkgconf_pkg_t, requires_private)},
{"URL", pkgconf_pkg_parser_tuple_func, offsetof(pkgconf_pkg_t, url)},
{"Version", pkgconf_pkg_parser_version_func, offsetof(pkgconf_pkg_t, version)},
};
@ -214,6 +237,37 @@ determine_prefix(const pkgconf_pkg_t *pkg, char *buf, size_t buflen)
return buf;
}
/*
* Takes a real path and converts it to a pkgconf value. This means normalizing
* directory separators and escaping things (only spaces covered atm).
*
* This is useful for things like prefix/pcfiledir which might get injected
* at runtime and are not sourced from the .pc file.
*
* "C:\foo bar\baz" -> "C:/foo\ bar/baz"
* "/foo bar/baz" -> "/foo\ bar/baz"
*/
static char *
convert_path_to_value(const char *path)
{
char *buf = calloc((strlen(path) + 1) * 2, 1);
char *bptr = buf;
const char *i;
for (i = path; *i != '\0'; i++)
{
if (*i == PKG_DIR_SEP_S)
*bptr++ = '/';
else if (*i == ' ') {
*bptr++ = '\\';
*bptr++ = *i;
} else
*bptr++ = *i;
}
return buf;
}
static void
remove_additional_separators(char *buf)
{
@ -238,16 +292,6 @@ remove_additional_separators(char *buf)
static void
canonicalize_path(char *buf)
{
#ifdef _WIN32
char *p = buf;
while (*p) {
if (*p == '\\')
*p = '/';
p++;
}
#endif
remove_additional_separators(buf);
}
@ -283,10 +327,10 @@ pkgconf_pkg_parser_value_set(void *opaque, const size_t lineno, const char *keyw
pkgconf_strlcpy(newvalue, pkg->prefix->value, sizeof newvalue);
pkgconf_strlcat(newvalue, canonicalized_value + strlen(pkg->orig_prefix->value), sizeof newvalue);
pkgconf_tuple_add(pkg->owner, &pkg->vars, keyword, newvalue, false);
pkgconf_tuple_add(pkg->owner, &pkg->vars, keyword, newvalue, false, pkg->flags);
}
else if (strcmp(keyword, pkg->owner->prefix_varname) || !(pkg->owner->flags & PKGCONF_PKG_PKGF_REDEFINE_PREFIX))
pkgconf_tuple_add(pkg->owner, &pkg->vars, keyword, value, true);
pkgconf_tuple_add(pkg->owner, &pkg->vars, keyword, value, true, pkg->flags);
else
{
char pathbuf[PKGCONF_ITEM_SIZE];
@ -294,11 +338,13 @@ pkgconf_pkg_parser_value_set(void *opaque, const size_t lineno, const char *keyw
if (relvalue != NULL)
{
pkg->orig_prefix = pkgconf_tuple_add(pkg->owner, &pkg->vars, "orig_prefix", canonicalized_value, true);
pkg->prefix = pkgconf_tuple_add(pkg->owner, &pkg->vars, keyword, relvalue, false);
char *prefix_value = convert_path_to_value(relvalue);
pkg->orig_prefix = pkgconf_tuple_add(pkg->owner, &pkg->vars, "orig_prefix", canonicalized_value, true, pkg->flags);
pkg->prefix = pkgconf_tuple_add(pkg->owner, &pkg->vars, keyword, prefix_value, false, pkg->flags);
free(prefix_value);
}
else
pkgconf_tuple_add(pkg->owner, &pkg->vars, keyword, value, true);
pkgconf_tuple_add(pkg->owner, &pkg->vars, keyword, value, true, pkg->flags);
}
}
@ -356,18 +402,19 @@ pkgconf_pkg_validate(const pkgconf_client_t *client, const pkgconf_pkg_t *pkg)
/*
* !doc
*
* .. c:function:: pkgconf_pkg_t *pkgconf_pkg_new_from_file(const pkgconf_client_t *client, const char *filename, FILE *f)
* .. c:function:: pkgconf_pkg_t *pkgconf_pkg_new_from_file(const pkgconf_client_t *client, const char *filename, FILE *f, unsigned int flags)
*
* Parse a .pc file into a pkgconf_pkg_t object structure.
*
* :param pkgconf_client_t* client: The pkgconf client object to use for dependency resolution.
* :param char* filename: The filename of the package file (including full path).
* :param FILE* f: The file object to read from.
* :param uint flags: The flags to use when parsing.
* :returns: A ``pkgconf_pkg_t`` object which contains the package data.
* :rtype: pkgconf_pkg_t *
*/
pkgconf_pkg_t *
pkgconf_pkg_new_from_file(pkgconf_client_t *client, const char *filename, FILE *f)
pkgconf_pkg_new_from_file(pkgconf_client_t *client, const char *filename, FILE *f, unsigned int flags)
{
pkgconf_pkg_t *pkg;
char *idptr;
@ -376,7 +423,18 @@ pkgconf_pkg_new_from_file(pkgconf_client_t *client, const char *filename, FILE *
pkg->owner = client;
pkg->filename = strdup(filename);
pkg->pc_filedir = pkg_get_parent_dir(pkg);
pkgconf_tuple_add(client, &pkg->vars, "pcfiledir", pkg->pc_filedir, true);
pkg->flags = flags;
char *pc_filedir_value = convert_path_to_value(pkg->pc_filedir);
pkgconf_tuple_add(client, &pkg->vars, "pcfiledir", pc_filedir_value, true, pkg->flags);
free(pc_filedir_value);
/* If pc_filedir is outside of sysroot_dir, override sysroot_dir for this
* package.
* See https://github.com/pkgconf/pkgconf/issues/213
*/
if (client->sysroot_dir && strncmp(pkg->pc_filedir, client->sysroot_dir, strlen(client->sysroot_dir)))
pkgconf_tuple_add(client, &pkg->vars, "pc_sysrootdir", "", false, pkg->flags);
/* make module id */
if ((idptr = strrchr(pkg->filename, PKG_DIR_SEP_S)) != NULL)
@ -389,8 +447,9 @@ pkgconf_pkg_new_from_file(pkgconf_client_t *client, const char *filename, FILE *
* strrchr() took us to the last \ in that case, so we just have to see if
* it is followed by a /. If so, lop it off.
*/
if ((idptr = strrchr(idptr, '/')) != NULL)
idptr++;
char *mungeptr;
if ((mungeptr = strrchr(idptr, '/')) != NULL)
idptr = ++mungeptr;
#endif
pkg->id = strdup(idptr);
@ -407,7 +466,8 @@ pkgconf_pkg_new_from_file(pkgconf_client_t *client, const char *filename, FILE *
return NULL;
}
pkgconf_dependency_add(client, &pkg->provides, pkg->id, pkg->version, PKGCONF_CMP_EQUAL, 0);
pkgconf_dependency_t *dep = pkgconf_dependency_add(client, &pkg->provides, pkg->id, pkg->version, PKGCONF_CMP_EQUAL, 0);
pkgconf_dependency_unref(dep->owner, dep);
return pkgconf_pkg_ref(client, pkg);
}
@ -470,6 +530,15 @@ pkgconf_pkg_free(pkgconf_client_t *client, pkgconf_pkg_t *pkg)
if (pkg->pc_filedir != NULL)
free(pkg->pc_filedir);
if (pkg->license != NULL)
free(pkg->license);
if (pkg->maintainer != NULL)
free(pkg->maintainer);
if (pkg->copyright != NULL)
free(pkg->copyright);
free(pkg);
}
@ -492,7 +561,7 @@ pkgconf_pkg_ref(pkgconf_client_t *client, pkgconf_pkg_t *pkg)
PKGCONF_TRACE(client, "WTF: client %p refers to package %p owned by other client %p", client, pkg, pkg->owner);
pkg->refcount++;
PKGCONF_TRACE(client, "refcount@%p: %d", pkg, pkg->refcount);
PKGCONF_TRACE(client, "%s refcount@%p: %d", pkg->id, pkg, pkg->refcount);
return pkg;
}
@ -515,7 +584,7 @@ pkgconf_pkg_unref(pkgconf_client_t *client, pkgconf_pkg_t *pkg)
PKGCONF_TRACE(client, "WTF: client %p unrefs package %p owned by other client %p", client, pkg, pkg->owner);
pkg->refcount--;
PKGCONF_TRACE(pkg->owner, "refcount@%p: %d", pkg, pkg->refcount);
PKGCONF_TRACE(pkg->owner, "%s refcount@%p: %d", pkg->id, pkg, pkg->refcount);
if (pkg->refcount <= 0)
pkgconf_pkg_free(pkg->owner, pkg);
@ -537,13 +606,12 @@ pkgconf_pkg_try_specific_path(pkgconf_client_t *client, const char *path, const
if (!(client->flags & PKGCONF_PKG_PKGF_NO_UNINSTALLED) && (f = fopen(uninst_locbuf, "r")) != NULL)
{
PKGCONF_TRACE(client, "found (uninstalled): %s", uninst_locbuf);
pkg = pkgconf_pkg_new_from_file(client, uninst_locbuf, f);
pkg->flags |= PKGCONF_PKG_PROPF_UNINSTALLED;
pkg = pkgconf_pkg_new_from_file(client, uninst_locbuf, f, PKGCONF_PKG_PROPF_UNINSTALLED);
}
else if ((f = fopen(locbuf, "r")) != NULL)
{
PKGCONF_TRACE(client, "found: %s", locbuf);
pkg = pkgconf_pkg_new_from_file(client, locbuf, f);
pkg = pkgconf_pkg_new_from_file(client, locbuf, f, 0);
}
return pkg;
@ -581,7 +649,7 @@ pkgconf_pkg_scan_dir(pkgconf_client_t *client, const char *path, void *data, pkg
if (f == NULL)
continue;
pkg = pkgconf_pkg_new_from_file(client, filebuf, f);
pkg = pkgconf_pkg_new_from_file(client, filebuf, f, 0);
if (pkg != NULL)
{
if (func(pkg, data))
@ -701,7 +769,7 @@ pkgconf_pkg_find(pkgconf_client_t *client, const char *name)
PKGCONF_TRACE(client, "%s is a file", name);
pkg = pkgconf_pkg_new_from_file(client, name, f);
pkg = pkgconf_pkg_new_from_file(client, name, f, 0);
if (pkg != NULL)
{
pkgconf_path_add(pkg->pc_filedir, &client->dir_list, true);
@ -784,8 +852,8 @@ pkgconf_compare_version(const char *a, const char *b)
pkgconf_strlcpy(buf1, a, sizeof buf1);
pkgconf_strlcpy(buf2, b, sizeof buf2);
one = str1 = buf1;
two = str2 = buf2;
one = buf1;
two = buf2;
while (*one || *two)
{
@ -920,6 +988,7 @@ static pkgconf_pkg_t pkgconf_virtual = {
.description = "virtual package defining pkgconf API version supported",
.url = PACKAGE_BUGREPORT,
.version = PACKAGE_VERSION,
.license = "ISC",
.flags = PKGCONF_PKG_PROPF_STATIC,
.vars = {
.head = &(pkgconf_node_t){
@ -1401,9 +1470,9 @@ pkgconf_pkg_walk_list(pkgconf_client_t *client,
unsigned int skip_flags)
{
unsigned int eflags = PKGCONF_PKG_ERRF_OK;
pkgconf_node_t *node;
pkgconf_node_t *node, *next;
PKGCONF_FOREACH_LIST_ENTRY(deplist->head, node)
PKGCONF_FOREACH_LIST_ENTRY_SAFE(deplist->head, next, node)
{
unsigned int eflags_local = PKGCONF_PKG_ERRF_OK;
pkgconf_dependency_t *depnode = node->data;
@ -1423,23 +1492,41 @@ pkgconf_pkg_walk_list(pkgconf_client_t *client,
if (pkgdep == NULL)
continue;
if (pkgdep->flags & PKGCONF_PKG_PROPF_SEEN)
if (pkgdep->serial == client->serial)
{
pkgconf_pkg_unref(client, pkgdep);
continue;
pkgdep->hits++;
/* In this case we have a circular reference.
* We break that by deleteing the circular node from the
* the list, so that we dont create a situation where
* memory is leaked due to circular ownership.
* i.e: A owns B owns A
*
* TODO(ariadne): Breaking circular references between Requires and Requires.private
* lists causes problems. Find a way to refactor the Requires.private list out.
*/
if (!(depnode->flags & PKGCONF_PKG_DEPF_PRIVATE) &&
!(parent->flags & PKGCONF_PKG_PROPF_VIRTUAL))
{
pkgconf_warn(client, "%s: breaking circular reference (%s -> %s -> %s)\n",
parent->id, parent->id, pkgdep->id, parent->id);
pkgconf_node_delete(node, deplist);
pkgconf_dependency_unref(client, depnode);
}
goto next;
}
if (skip_flags && (depnode->flags & skip_flags) == skip_flags)
{
pkgconf_pkg_unref(client, pkgdep);
continue;
}
goto next;
pkgconf_audit_log_dependency(client, pkgdep, depnode);
pkgdep->flags |= PKGCONF_PKG_PROPF_SEEN;
eflags |= pkgconf_pkg_traverse(client, pkgdep, func, data, depth - 1, skip_flags);
pkgdep->flags &= ~PKGCONF_PKG_PROPF_SEEN;
pkgdep->hits++;
pkgdep->serial = client->serial;
eflags |= pkgconf_pkg_traverse_main(client, pkgdep, func, data, depth - 1, skip_flags);
next:
pkgconf_pkg_unref(client, pkgdep);
}
@ -1509,8 +1596,8 @@ pkgconf_pkg_walk_conflicts_list(pkgconf_client_t *client,
* :return: ``PKGCONF_PKG_ERRF_OK`` on success, else an error code.
* :rtype: unsigned int
*/
unsigned int
pkgconf_pkg_traverse(pkgconf_client_t *client,
static unsigned int
pkgconf_pkg_traverse_main(pkgconf_client_t *client,
pkgconf_pkg_t *root,
pkgconf_pkg_traverse_func_t func,
void *data,
@ -1522,7 +1609,7 @@ pkgconf_pkg_traverse(pkgconf_client_t *client,
if (maxdepth == 0)
return eflags;
PKGCONF_TRACE(client, "%s: level %d", root->id, maxdepth);
PKGCONF_TRACE(client, "%s: level %d, serial %lu", root->id, maxdepth, client->serial);
if ((root->flags & PKGCONF_PKG_PROPF_VIRTUAL) != PKGCONF_PKG_PROPF_VIRTUAL || (client->flags & PKGCONF_PKG_PKGF_SKIP_ROOT_VIRTUAL) != PKGCONF_PKG_PKGF_SKIP_ROOT_VIRTUAL)
{
@ -1558,6 +1645,20 @@ pkgconf_pkg_traverse(pkgconf_client_t *client,
return eflags;
}
unsigned int
pkgconf_pkg_traverse(pkgconf_client_t *client,
pkgconf_pkg_t *root,
pkgconf_pkg_traverse_func_t func,
void *data,
int maxdepth,
unsigned int skip_flags)
{
if (root->flags & PKGCONF_PKG_PROPF_VIRTUAL)
client->serial++;
return pkgconf_pkg_traverse_main(client, root, func, data, maxdepth, skip_flags);
}
static void
pkgconf_pkg_cflags_collect(pkgconf_client_t *client, pkgconf_pkg_t *pkg, void *data)
{

View File

@ -51,7 +51,7 @@ pkgconf_queue_push(pkgconf_list_t *list, const char *package)
pkgconf_queue_t *pkgq = calloc(sizeof(pkgconf_queue_t), 1);
pkgq->package = strdup(package);
pkgconf_node_insert_tail(&pkgq->iter, pkgq, list);
pkgconf_node_insert(&pkgq->iter, pkgq, list);
}
/*
@ -107,13 +107,199 @@ pkgconf_queue_free(pkgconf_list_t *list)
}
}
static void
pkgconf_queue_collect_dependents(pkgconf_client_t *client, pkgconf_pkg_t *pkg, void *data)
{
pkgconf_node_t *node;
pkgconf_pkg_t *world = data;
if (pkg == world)
return;
PKGCONF_FOREACH_LIST_ENTRY(pkg->required.head, node)
{
pkgconf_dependency_t *flattened_dep;
flattened_dep = pkgconf_dependency_copy(client, node->data);
pkgconf_node_insert(&flattened_dep->iter, flattened_dep, &world->required);
}
if (client->flags & PKGCONF_PKG_PKGF_SEARCH_PRIVATE)
{
PKGCONF_FOREACH_LIST_ENTRY(pkg->requires_private.head, node)
{
pkgconf_dependency_t *flattened_dep;
flattened_dep = pkgconf_dependency_copy(client, node->data);
pkgconf_node_insert(&flattened_dep->iter, flattened_dep, &world->requires_private);
}
}
}
static int
dep_sort_cmp(const void *a, const void *b)
{
const pkgconf_dependency_t *depA = *(void **) a;
const pkgconf_dependency_t *depB = *(void **) b;
return depB->match->hits - depA->match->hits;
}
static inline void
flatten_dependency_set(pkgconf_client_t *client, pkgconf_list_t *list)
{
pkgconf_node_t *node, *next;
pkgconf_dependency_t **deps = NULL;
size_t dep_count = 0, i;
PKGCONF_FOREACH_LIST_ENTRY_SAFE(list->head, next, node)
{
pkgconf_dependency_t *dep = node->data;
pkgconf_pkg_t *pkg = pkgconf_pkg_verify_dependency(client, dep, NULL);
if (pkg == NULL)
continue;
if (pkg->serial == client->serial)
{
pkgconf_node_delete(node, list);
pkgconf_dependency_unref(client, dep);
goto next;
}
if (dep->match == NULL)
{
PKGCONF_TRACE(client, "WTF: unmatched dependency %p <%s>", dep, dep->package);
abort();
}
/* for virtuals, we need to check to see if there are dupes */
for (i = 0; i < dep_count; i++)
{
pkgconf_dependency_t *other_dep = deps[i];
PKGCONF_TRACE(client, "dedup %s = %s?", dep->package, other_dep->package);
if (!strcmp(dep->package, other_dep->package))
{
PKGCONF_TRACE(client, "skipping, %zu deps", dep_count);
goto next;
}
}
pkg->serial = client->serial;
/* copy to the deps table */
dep_count++;
deps = pkgconf_reallocarray(deps, dep_count, sizeof (void *));
deps[dep_count - 1] = dep;
PKGCONF_TRACE(client, "added %s to dep table", dep->package);
next:
pkgconf_pkg_unref(client, pkg);
}
if (deps == NULL)
return;
qsort(deps, dep_count, sizeof (void *), dep_sort_cmp);
/* zero the list and start readding */
pkgconf_list_zero(list);
for (i = 0; i < dep_count; i++)
{
pkgconf_dependency_t *dep = deps[i];
if (dep->match == NULL)
continue;
memset(&dep->iter, '\0', sizeof (dep->iter));
pkgconf_node_insert(&dep->iter, dep, list);
PKGCONF_TRACE(client, "slot %zu: dep %s matched to %p<%s> hits %lu", i, dep->package, dep->match, dep->match->id, dep->match->hits);
}
free(deps);
}
static inline unsigned int
pkgconf_queue_verify(pkgconf_client_t *client, pkgconf_pkg_t *world, pkgconf_list_t *list, int maxdepth)
{
unsigned int result;
if (!pkgconf_queue_compile(client, world, list))
return PKGCONF_PKG_ERRF_DEPGRAPH_BREAK;
return pkgconf_pkg_verify_graph(client, world, maxdepth);
/* collect all the dependencies */
result = pkgconf_pkg_traverse(client, world, pkgconf_queue_collect_dependents, world, maxdepth, 0);
if (result != PKGCONF_PKG_ERRF_OK)
return result;
/* flatten the dependency set using serials.
* we copy the dependencies to a vector, and then erase the list.
* then we copy them back to the list.
*/
++client->serial;
PKGCONF_TRACE(client, "flattening requires deps");
flatten_dependency_set(client, &world->required);
++client->serial;
PKGCONF_TRACE(client, "flattening requires.private deps");
flatten_dependency_set(client, &world->requires_private);
return PKGCONF_PKG_ERRF_OK;
}
/*
* !doc
*
* .. c:function:: void pkgconf_solution_free(pkgconf_client_t *client, pkgconf_pkg_t *world, int maxdepth)
*
* Removes references to package nodes contained in a solution.
*
* :param pkgconf_client_t* client: The pkgconf client object to use for dependency resolution.
* :param pkgconf_pkg_t* world: The root for the generated dependency graph. Should have PKGCONF_PKG_PROPF_VIRTUAL flag.
* :returns: nothing
*/
void
pkgconf_solution_free(pkgconf_client_t *client, pkgconf_pkg_t *world)
{
(void) client;
if (world->flags & PKGCONF_PKG_PROPF_VIRTUAL)
{
pkgconf_dependency_free(&world->required);
pkgconf_dependency_free(&world->requires_private);
}
}
/*
* !doc
*
* .. c:function:: bool pkgconf_queue_solve(pkgconf_client_t *client, pkgconf_list_t *list, pkgconf_pkg_t *world, int maxdepth)
*
* Solves and flattens the dependency graph for the supplied dependency list.
*
* :param pkgconf_client_t* client: The pkgconf client object to use for dependency resolution.
* :param pkgconf_list_t* list: The list of dependency requests to consider.
* :param pkgconf_pkg_t* world: The root for the generated dependency graph, provided by the caller. Should have PKGCONF_PKG_PROPF_VIRTUAL flag.
* :param int maxdepth: The maximum allowed depth for the dependency resolver. A depth of -1 means unlimited.
* :returns: true if the dependency resolver found a solution, otherwise false.
* :rtype: bool
*/
bool
pkgconf_queue_solve(pkgconf_client_t *client, pkgconf_list_t *list, pkgconf_pkg_t *world, int maxdepth)
{
/* if maxdepth is one, then we will not traverse deeper than our virtual package. */
if (!maxdepth)
maxdepth = -1;
return pkgconf_queue_verify(client, world, list, maxdepth) == PKGCONF_PKG_ERRF_OK;
}
/*
@ -124,6 +310,8 @@ pkgconf_queue_verify(pkgconf_client_t *client, pkgconf_pkg_t *world, pkgconf_lis
* Attempt to compile a dependency resolution queue into a dependency resolution problem, then attempt to solve the problem and
* feed the solution to a callback function if a complete dependency graph is found.
*
* This function should not be used in new code. Use pkgconf_queue_solve instead.
*
* :param pkgconf_client_t* client: The pkgconf client object to use for dependency resolution.
* :param pkgconf_list_t* list: The list of dependency requests to consider.
* :param pkgconf_queue_apply_func_t func: The callback function to call if a solution is found by the dependency resolver.
@ -135,6 +323,7 @@ pkgconf_queue_verify(pkgconf_client_t *client, pkgconf_pkg_t *world, pkgconf_lis
bool
pkgconf_queue_apply(pkgconf_client_t *client, pkgconf_list_t *list, pkgconf_queue_apply_func_t func, int maxdepth, void *data)
{
bool ret = false;
pkgconf_pkg_t world = {
.id = "virtual:world",
.realname = "virtual world package",
@ -145,18 +334,18 @@ pkgconf_queue_apply(pkgconf_client_t *client, pkgconf_list_t *list, pkgconf_queu
if (!maxdepth)
maxdepth = -1;
if (pkgconf_queue_verify(client, &world, list, maxdepth) != PKGCONF_PKG_ERRF_OK)
return false;
if (!pkgconf_queue_solve(client, list, &world, maxdepth))
goto cleanup;
/* the world dependency set is flattened after it is returned from pkgconf_queue_verify */
if (!func(client, &world, data, maxdepth))
{
pkgconf_pkg_free(client, &world);
return false;
}
goto cleanup;
ret = true;
cleanup:
pkgconf_pkg_free(client, &world);
return true;
return ret;
}
/*

View File

@ -59,6 +59,7 @@
# include <dirent.h>
# include <unistd.h>
# include <limits.h>
# include <strings.h>
# ifdef PATH_MAX
# define PKGCONF_ITEM_SIZE (PATH_MAX + 1024)
# else

View File

@ -45,7 +45,23 @@
void
pkgconf_tuple_add_global(pkgconf_client_t *client, const char *key, const char *value)
{
pkgconf_tuple_add(client, &client->global_vars, key, value, false);
pkgconf_tuple_add(client, &client->global_vars, key, value, false, 0);
}
static pkgconf_tuple_t *
lookup_global_tuple(const pkgconf_client_t *client, const char *key)
{
pkgconf_node_t *node;
PKGCONF_FOREACH_LIST_ENTRY(client->global_vars.head, node)
{
pkgconf_tuple_t *tuple = node->data;
if (!strcmp(tuple->key, key))
return tuple;
}
return NULL;
}
/*
@ -63,17 +79,13 @@ pkgconf_tuple_add_global(pkgconf_client_t *client, const char *key, const char *
char *
pkgconf_tuple_find_global(const pkgconf_client_t *client, const char *key)
{
pkgconf_node_t *node;
pkgconf_tuple_t *tuple;
PKGCONF_FOREACH_LIST_ENTRY(client->global_vars.head, node)
{
pkgconf_tuple_t *tuple = node->data;
tuple = lookup_global_tuple(client, key);
if (tuple == NULL)
return NULL;
if (!strcmp(tuple->key, key))
return tuple->value;
}
return NULL;
return tuple->value;
}
/*
@ -108,13 +120,18 @@ pkgconf_tuple_define_global(pkgconf_client_t *client, const char *kv)
{
char *workbuf = strdup(kv);
char *value;
pkgconf_tuple_t *tuple;
value = strchr(workbuf, '=');
if (value == NULL)
goto out;
*value++ = '\0';
pkgconf_tuple_add_global(client, workbuf, value);
tuple = pkgconf_tuple_add(client, &client->global_vars, workbuf, value, false, 0);
if (tuple != NULL)
tuple->flags = PKGCONF_PKG_TUPLEF_OVERRIDE;
out:
free(workbuf);
}
@ -161,6 +178,45 @@ dequote(const char *value)
return buf;
}
static const char *
find_sysroot(const pkgconf_client_t *client, pkgconf_list_t *vars)
{
const char *sysroot_dir;
sysroot_dir = pkgconf_tuple_find(client, vars, "pc_sysrootdir");
if (sysroot_dir == NULL)
sysroot_dir = client->sysroot_dir;
return sysroot_dir;
}
static bool
should_rewrite_sysroot(const pkgconf_client_t *client, pkgconf_list_t *vars, const char *buf, unsigned int flags)
{
const char *sysroot_dir;
if (flags & PKGCONF_PKG_PROPF_UNINSTALLED && !(client->flags & PKGCONF_PKG_PKGF_FDO_SYSROOT_RULES))
return false;
sysroot_dir = find_sysroot(client, vars);
if (sysroot_dir == NULL)
return false;
if (*buf != '/')
return false;
if (!strcmp(sysroot_dir, "/"))
return false;
if (strlen(buf) <= strlen(sysroot_dir))
return false;
if (strstr(buf + strlen(sysroot_dir), sysroot_dir) == NULL)
return false;
return true;
}
/*
* !doc
*
@ -177,7 +233,7 @@ dequote(const char *value)
* :rtype: pkgconf_tuple_t *
*/
pkgconf_tuple_t *
pkgconf_tuple_add(const pkgconf_client_t *client, pkgconf_list_t *list, const char *key, const char *value, bool parse)
pkgconf_tuple_add(const pkgconf_client_t *client, pkgconf_list_t *list, const char *key, const char *value, bool parse, unsigned int flags)
{
char *dequote_value;
pkgconf_tuple_t *tuple = calloc(sizeof(pkgconf_tuple_t), 1);
@ -186,14 +242,14 @@ pkgconf_tuple_add(const pkgconf_client_t *client, pkgconf_list_t *list, const ch
dequote_value = dequote(value);
PKGCONF_TRACE(client, "adding tuple to @%p: %s => %s (parsed? %d)", list, key, dequote_value, parse);
tuple->key = strdup(key);
if (parse)
tuple->value = pkgconf_tuple_parse(client, list, dequote_value);
tuple->value = pkgconf_tuple_parse(client, list, dequote_value, flags);
else
tuple->value = strdup(dequote_value);
PKGCONF_TRACE(client, "adding tuple to @%p: %s => %s (parsed? %d)", list, key, tuple->value, parse);
pkgconf_node_insert(&tuple->iter, tuple, list);
free(dequote_value);
@ -218,10 +274,11 @@ char *
pkgconf_tuple_find(const pkgconf_client_t *client, pkgconf_list_t *list, const char *key)
{
pkgconf_node_t *node;
char *res;
pkgconf_tuple_t *global_tuple;
if ((res = pkgconf_tuple_find_global(client, key)) != NULL)
return res;
global_tuple = lookup_global_tuple(client, key);
if (global_tuple != NULL && global_tuple->flags & PKGCONF_PKG_TUPLEF_OVERRIDE)
return global_tuple->value;
PKGCONF_FOREACH_LIST_ENTRY(list->head, node)
{
@ -231,31 +288,39 @@ pkgconf_tuple_find(const pkgconf_client_t *client, pkgconf_list_t *list, const c
return tuple->value;
}
if (global_tuple != NULL)
return global_tuple->value;
return NULL;
}
/*
* !doc
*
* .. c:function:: char *pkgconf_tuple_parse(const pkgconf_client_t *client, pkgconf_list_t *vars, const char *value)
* .. c:function:: char *pkgconf_tuple_parse(const pkgconf_client_t *client, pkgconf_list_t *vars, const char *value, unsigned int flags)
*
* Parse an expression for variable substitution.
*
* :param pkgconf_client_t* client: The pkgconf client object to access.
* :param pkgconf_list_t* list: The variable list to search for variables (along side the global variable list).
* :param char* value: The ``key=value`` string to parse.
* :param uint flags: Any flags to consider while parsing.
* :return: the variable data with any variables substituted
* :rtype: char *
*/
char *
pkgconf_tuple_parse(const pkgconf_client_t *client, pkgconf_list_t *vars, const char *value)
pkgconf_tuple_parse(const pkgconf_client_t *client, pkgconf_list_t *vars, const char *value, unsigned int flags)
{
char buf[PKGCONF_BUFSIZE];
const char *ptr;
char *bptr = buf;
if (*value == '/' && client->sysroot_dir != NULL && strncmp(value, client->sysroot_dir, strlen(client->sysroot_dir)))
bptr += pkgconf_strlcpy(buf, client->sysroot_dir, sizeof buf);
if (!(client->flags & PKGCONF_PKG_PKGF_FDO_SYSROOT_RULES) &&
(!(flags & PKGCONF_PKG_PROPF_UNINSTALLED) || (client->flags & PKGCONF_PKG_PKGF_PKGCONF1_SYSROOT_RULES)))
{
if (*value == '/' && client->sysroot_dir != NULL && strncmp(value, client->sysroot_dir, strlen(client->sysroot_dir)))
bptr += pkgconf_strlcpy(buf, client->sysroot_dir, sizeof buf);
}
for (ptr = value; *ptr != '\0' && bptr - buf < PKGCONF_BUFSIZE; ptr++)
{
@ -264,6 +329,7 @@ pkgconf_tuple_parse(const pkgconf_client_t *client, pkgconf_list_t *vars, const
else if (*(ptr + 1) == '{')
{
char varname[PKGCONF_ITEM_SIZE];
char *vend = varname + PKGCONF_ITEM_SIZE - 1;
char *vptr = varname;
const char *pptr;
char *kv, *parsekv;
@ -273,7 +339,15 @@ pkgconf_tuple_parse(const pkgconf_client_t *client, pkgconf_list_t *vars, const
for (pptr = ptr + 2; *pptr != '\0'; pptr++)
{
if (*pptr != '}')
*vptr++ = *pptr;
{
if (vptr < vend)
*vptr++ = *pptr;
else
{
*vptr = '\0';
break;
}
}
else
{
*vptr = '\0';
@ -281,6 +355,8 @@ pkgconf_tuple_parse(const pkgconf_client_t *client, pkgconf_list_t *vars, const
}
}
PKGCONF_TRACE(client, "lookup tuple %s", varname);
ptr += (pptr - ptr);
kv = pkgconf_tuple_find_global(client, varname);
if (kv != NULL)
@ -294,7 +370,7 @@ pkgconf_tuple_parse(const pkgconf_client_t *client, pkgconf_list_t *vars, const
if (kv != NULL)
{
parsekv = pkgconf_tuple_parse(client, vars, kv);
parsekv = pkgconf_tuple_parse(client, vars, kv, flags);
strncpy(bptr, parsekv, PKGCONF_BUFSIZE - (bptr - buf));
bptr += strlen(parsekv);
@ -321,16 +397,15 @@ pkgconf_tuple_parse(const pkgconf_client_t *client, pkgconf_list_t *vars, const
* safe to skip ahead in the string to scan for our sysroot dir.
*
* Finally, we call pkgconf_path_relocate() to clean the path of spurious elements.
*
* New in 1.9: Only attempt to rewrite the sysroot if we are not processing an uninstalled package.
*/
if (*buf == '/' &&
client->sysroot_dir != NULL &&
strcmp(client->sysroot_dir, "/") != 0 &&
strlen(buf) > strlen(client->sysroot_dir) &&
strstr(buf + strlen(client->sysroot_dir), client->sysroot_dir) != NULL)
if (should_rewrite_sysroot(client, vars, buf, flags))
{
char cleanpath[PKGCONF_ITEM_SIZE];
const char *sysroot_dir = find_sysroot(client, vars);
pkgconf_strlcpy(cleanpath, buf + strlen(client->sysroot_dir), sizeof cleanpath);
pkgconf_strlcpy(cleanpath, buf + strlen(sysroot_dir), sizeof cleanpath);
pkgconf_path_relocate(cleanpath, sizeof cleanpath);
return strdup(cleanpath);
@ -378,4 +453,6 @@ pkgconf_tuple_free(pkgconf_list_t *list)
PKGCONF_FOREACH_LIST_ENTRY_SAFE(list->head, next, node)
pkgconf_tuple_free_entry(node->data, list);
pkgconf_list_zero(list);
}

File diff suppressed because it is too large Load Diff

View File

@ -99,6 +99,9 @@ These flags are always used, regardless of whether static compilation is request
.It Cflags.private
Required compiler flags for static compilation.
(optional; fragment list; pkgconf extension)
.It Copyright
A copyright attestation statement.
(optional; literal; pkgconf extension)
.It Libs
Required linking flags for this package.
Libraries this package depends on for linking against it, which are not
@ -110,6 +113,13 @@ statically.
Libraries this package depends on for linking against it statically, which are
not described as dependencies should be specified here.
(optional; fragment list)
.It License
The asserted SPDX license tag that should be applied to the given package.
(optional; literal; pkgconf extension)
.It Maintainer
The preferred contact for the maintainer. This should be in the format of a
name followed by an e-mail address or website.
(optional; literal; pkgconf extension)
.It Requires
Required dependencies that must be met for the package to be usable.
All dependencies must be satisfied or the pkg-config implementation must not use
@ -151,6 +161,9 @@ includedir=${prefix}/include
Name: libfoo # human-readable name
Description: an example library called libfoo # human-readable description
Copyright: Copyright (c) 2022 pkgconf project authors
License: Apache-2.0
Maintainer: the pkgconf project <http://www.pkgconf.org>
Version: 1.0
URL: http://www.pkgconf.org
Requires: libbar > 2.0.0

View File

@ -76,6 +76,9 @@ include files.
A list of directories that are included by default in the search path for
libraries.
(mandatory; fragment list)
.It WantDefaultPure
If true, pkgconf will default to preferring a pure dependency graph.
(optional; boolean; default is false)
.It WantDefaultStatic
If true, pkgconf will default to operating in static linking mode.
(optional; boolean; default is false)
@ -93,5 +96,5 @@ SystemLibraryPaths: /home/kaniini/sysroot/x86_64-pc-linux-gnu/lib
.Ed
.Sh SEE ALSO
.Xr pkgconf 1 ,
.Xr pkg.m4 7 ,
.Xr pc 5
.Xr pc 5 ,
.Xr pkg.m4 7

View File

@ -51,6 +51,10 @@ Ignore
rules in modules.
.It Fl -env-only
Learn about pkgconf's configuration strictly from environmental variables.
.It Fl -validate Ar package ...
Validate specific
.Sq .pc
files for correctness.
.It Fl -maximum-traverse-depth Ns = Ns Ar DEPTH
Impose a limit on the allowed depth in the dependency graph.
For example, a depth of 2 will restrict the resolver from acting on child
@ -106,7 +110,7 @@ the requested modules.
.It Fl -uninstalled
Exit with a non-zero result if the dependency resolver uses an
.Sq uninstalled
module as part of it's solution.
module as part of its solution.
.It Fl -no-uninstalled
Forbids the dependency resolver from considering 'uninstalled' modules as part
of a solution.
@ -213,6 +217,10 @@ The format of the debug log messages is implementation-specific.
If set, disables the path relocation feature.
.It Va PKG_CONFIG_MSVC_SYNTAX
If set, uses MSVC syntax for fragments.
.It Va PKG_CONFIG_FDO_SYSROOT_RULES
If set, follow the sysroot prefixing rules that freedesktop.org pkg-config uses.
.It Va DESTDIR
If set to PKG_CONFIG_SYSROOT_DIR, assume that PKG_CONFIG_FDO_SYSROOT_RULES is set.
.El
.Sh EXAMPLES
Displaying the CFLAGS of a package:

View File

@ -1,42 +1,37 @@
project('pkgconf', 'c',
version : '1.7.1',
version : '1.9.3',
license : 'ISC',
meson_version : '>=0.47')
meson_version : '>=0.49',
default_options : ['c_std=c99'],
)
cc = meson.get_compiler('c')
add_project_arguments(
'-D_BSD_SOURCE',
'-D_DEFAULT_SOURCE',
cc.get_supported_arguments(
'-Wimplicit-function-declaration',
'-Wmisleading-indentation',
),
language : 'c',
)
cdata = configuration_data()
check_headers = [
['HAVE_DLFCN_H', 'dlfcn.h'],
['HAVE_INTTYPES_H', 'inttypes.h'],
['HAVE_MEMORY_H', 'memory.h'],
['HAVE_STDINT_H', 'stdint.h'],
['HAVE_STDLIB_H', 'stdlib.h'],
['HAVE_STRINGS_H', 'strings.h'],
['HAVE_STRING_H', 'string.h'],
['HAVE_SYS_STAT_H', 'sys/stat.h'],
['HAVE_SYS_TYPES_H', 'sys/types.h'],
['HAVE_UNISTD_H', 'unistd.h'],
]
foreach h : check_headers
if cc.has_header(h.get(1))
cdata.set(h.get(0), 1)
endif
endforeach
check_functions = [
['HAVE_CYGWIN_CONV_PATH', 'cygwin_conv_path', 'sys/cygwin.h'],
['HAVE_STRLCAT', 'strlcat', 'string.h'],
['HAVE_STRLCPY', 'strlcpy', 'string.h'],
['HAVE_STRNDUP', 'strndup', 'string.h'],
['strlcat', 'string.h'],
['strlcpy', 'string.h'],
['strndup', 'string.h'],
['strdup', 'string.h'],
['strncasecmp', 'strings.h'],
['strcasecmp', 'strings.h'],
['reallocarray', 'stdlib.h'],
]
foreach f : check_functions
if cc.has_function(f.get(1), prefix : '#include <' + f.get(2) + '>') and cc.has_header_symbol(f.get(2), f.get(1))
cdata.set(f.get(0), 1)
if cc.has_function(f[0], prefix : '#define _BSD_SOURCE\n#include <@0@>'.format(f[1])) and cc.has_header_symbol(f[1], f[0], prefix : '#define _BSD_SOURCE')
cdata.set('HAVE_@0@'.format(f[0].to_upper().underscorify()), 1)
endif
endforeach
@ -57,13 +52,20 @@ cdata.set_quoted('PERSONALITY_PATH', ':'.join(personality_path))
cdata.set_quoted('PACKAGE_NAME', meson.project_name())
cdata.set_quoted('PACKAGE_VERSION', meson.project_version())
cdata.set_quoted('PACKAGE_BUGREPORT', 'https://todo.sr.ht/~kaniini/pkgconf')
cdata.set('abs_top_srcdir', meson.source_root())
cdata.set('abs_top_builddir', meson.build_root())
cdata.set('abs_top_srcdir', meson.current_source_dir())
cdata.set('abs_top_builddir', meson.current_build_dir())
subdir('libpkgconf')
libpkgconf = shared_library('pkgconf',
libtype = get_option('default_library')
if libtype == 'static'
build_static = '-DPKGCONFIG_IS_STATIC'
else
build_static = '-DPKGCONFIG_IS_NOT_STATIC'
endif
libpkgconf = library('pkgconf',
'libpkgconf/argvsplit.c',
'libpkgconf/audit.c',
'libpkgconf/bsdstubs.c',
@ -78,10 +80,32 @@ libpkgconf = shared_library('pkgconf',
'libpkgconf/pkg.c',
'libpkgconf/queue.c',
'libpkgconf/tuple.c',
c_args: '-DLIBPKGCONF_EXPORT',
c_args: ['-DLIBPKGCONF_EXPORT', build_static],
install : true,
version : '3.0.0',
soversion : '3',
version : '4.0.0',
soversion : '4',
)
# For other projects using libpkgconfig as a subproject
dep_libpkgconf = declare_dependency(
link_with : libpkgconf,
include_directories : include_directories('.'),
)
# If we have a new enough meson override the dependency so that only
# `dependency('libpkgconf')` is required from the consumer
if meson.version().version_compare('>= 0.54.0')
meson.override_dependency('libpkgconf', dep_libpkgconf)
endif
pkg = import('pkgconfig')
pkg.generate(libpkgconf,
name : 'libpkgconf',
description : 'a library for accessing and manipulating development framework configuration',
url: 'http://github.com/pkgconf/pkgconf',
filebase : 'libpkgconf',
subdirs: ['pkgconf'],
extra_cflags : build_static
)
@ -90,20 +114,20 @@ pkgconf_exe = executable('pkgconf',
'cli/getopt_long.c',
'cli/renderer-msvc.c',
link_with : libpkgconf,
c_args: build_static,
install : true)
if get_option('tests')
kyua_exe = find_program('kyua')
atf_sh_exe = find_program('atf-sh')
test('kyua', kyua_exe, args : ['--config=none', 'test', '--kyuafile=' + join_paths(meson.build_root(), 'Kyuafile'), '--build-root=' + meson.build_root()])
configure_file(input : 'Kyuafile.in', output : 'Kyuafile', configuration : cdata)
subdir('tests')
endif
with_tests = get_option('tests')
kyua_exe = find_program('kyua', required : with_tests, disabler : true)
atf_sh_exe = find_program('atf-sh', required : with_tests, disabler : true)
kyuafile = configure_file(input : 'Kyuafile.in', output : 'Kyuafile', configuration : cdata)
test('kyua', kyua_exe, args : ['--config=none', 'test', '--kyuafile', kyuafile, '--build-root', meson.current_build_dir()])
subdir('tests')
install_man('man/pkgconf.1')
install_man('man/pkg.m4.7')
install_man('man/pc.5')
install_man('man/pkgconf-personality.5')
install_data('pkg.m4', install_dir: 'share/aclocal')
install_data('AUTHORS', install_dir: 'share/doc/pkgconf')
install_data('README.md', install_dir: 'share/doc/pkgconf')

View File

@ -1,3 +1,5 @@
option('tests', type: 'boolean', value: true,
description: 'Build tests which depends upon the kyua framework'
)
option(
'tests',
type: 'feature',
description: 'Build tests which depends upon the kyua framework',
)

36
pkg.m4
View File

@ -1,5 +1,5 @@
# pkg.m4 - Macros to locate and utilise pkg-config. -*- Autoconf -*-
# serial 11 (pkg-config-0.29.1)
# pkg.m4 - Macros to locate and use pkg-config. -*- Autoconf -*-
# serial 12 (pkg-config-0.29.2)
dnl Copyright © 2004 Scott James Remnant <scott@netsplit.com>.
dnl Copyright © 2012-2015 Dan Nicholson <dbn.lists@gmail.com>
@ -41,7 +41,7 @@ dnl
dnl See the "Since" comment for each macro you use to see what version
dnl of the macros you require.
m4_defun([PKG_PREREQ],
[m4_define([PKG_MACROS_VERSION], [0.29.1])
[m4_define([PKG_MACROS_VERSION], [0.29.2])
m4_if(m4_version_compare(PKG_MACROS_VERSION, [$1]), -1,
[m4_fatal([pkg.m4 version $1 or higher is required but ]PKG_MACROS_VERSION[ found])])
])dnl PKG_PREREQ
@ -86,7 +86,7 @@ dnl Check to see whether a particular set of modules exists. Similar to
dnl PKG_CHECK_MODULES(), but does not set variables or print errors.
dnl
dnl Please remember that m4 expands AC_REQUIRE([PKG_PROG_PKG_CONFIG])
dnl only at the first occurence in configure.ac, so if the first place
dnl only at the first occurrence in configure.ac, so if the first place
dnl it's called might be skipped (such as if it is within an "if", you
dnl have to call PKG_CHECK_EXISTS manually
AC_DEFUN([PKG_CHECK_EXISTS],
@ -142,27 +142,28 @@ AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $1, overriding pkg-config])dnl
AC_ARG_VAR([$1][_LIBS], [linker flags for $1, overriding pkg-config])dnl
pkg_failed=no
AC_MSG_CHECKING([for $1])
AC_MSG_CHECKING([for $2])
_PKG_CONFIG([$1][_CFLAGS], [cflags], [$2])
_PKG_CONFIG([$1][_LIBS], [libs], [$2])
_PKG_CONFIG([$1][_VERSION], [modversion], [$2])
m4_define([_PKG_TEXT], [Alternatively, you may set the environment variables $1[]_CFLAGS
and $1[]_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.])
if test $pkg_failed = yes; then
AC_MSG_RESULT([no])
AC_MSG_RESULT([no])
_PKG_SHORT_ERRORS_SUPPORTED
if test $_pkg_short_errors_supported = yes; then
$1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "$2" 2>&1`
else
$1[]_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "$2" 2>&1`
$1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "$2" 2>&1`
else
$1[]_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "$2" 2>&1`
fi
# Put the nasty error message in config.log where it belongs
echo "$$1[]_PKG_ERRORS" >&AS_MESSAGE_LOG_FD
# Put the nasty error message in config.log where it belongs
echo "$$1[]_PKG_ERRORS" >&AS_MESSAGE_LOG_FD
m4_default([$4], [AC_MSG_ERROR(
m4_default([$4], [AC_MSG_ERROR(
[Package requirements ($2) were not met:
$$1_PKG_ERRORS
@ -173,8 +174,8 @@ installed software in a non-standard prefix.
_PKG_TEXT])[]dnl
])
elif test $pkg_failed = untried; then
AC_MSG_RESULT([no])
m4_default([$4], [AC_MSG_FAILURE(
AC_MSG_RESULT([no])
m4_default([$4], [AC_MSG_FAILURE(
[The pkg-config script could not be found or is too old. Make sure it
is in your PATH or set the PKG_CONFIG environment variable to the full
path to pkg-config.
@ -184,10 +185,11 @@ _PKG_TEXT
To get pkg-config, see <http://pkg-config.freedesktop.org/>.])[]dnl
])
else
$1[]_CFLAGS=$pkg_cv_[]$1[]_CFLAGS
$1[]_LIBS=$pkg_cv_[]$1[]_LIBS
$1[]_CFLAGS=$pkg_cv_[]$1[]_CFLAGS
$1[]_LIBS=$pkg_cv_[]$1[]_LIBS
$1[]_VERSION=$pkg_cv_[]$1[]_VERSION
AC_MSG_RESULT([yes])
$3
$3
fi[]dnl
])dnl PKG_CHECK_MODULES

View File

@ -29,6 +29,9 @@ tests_init \
libs_circular_directpc \
libs_static \
libs_static_ordering \
license_isc \
license_noassertion \
modversion_noflatten \
pkg_config_path \
nolibs \
nocflags \
@ -72,7 +75,7 @@ libs_cflags_version_multiple_body()
{
export PKG_CONFIG_PATH="${selfdir}/lib1"
atf_check \
-o inline:"-I/test/include/foo -fPIC -L/test/lib -lbar -lfoo \n" \
-o inline:"-fPIC -I/test/include/foo -L/test/lib -lbar -lfoo \n" \
pkgconf --cflags --libs 'foo > 1.2 bar >= 1.3'
}
@ -80,7 +83,7 @@ libs_cflags_version_multiple_coma_body()
{
export PKG_CONFIG_PATH="${selfdir}/lib1"
atf_check \
-o inline:"-I/test/include/foo -fPIC -L/test/lib -lbar -lfoo \n" \
-o inline:"-fPIC -I/test/include/foo -L/test/lib -lbar -lfoo \n" \
pkgconf --cflags --libs 'foo > 1.2,bar >= 1.3'
}
@ -208,20 +211,20 @@ libs_intermediary_body()
pkgconf --libs intermediary-1 intermediary-2
}
libs_circular1_body()
{
export PKG_CONFIG_PATH="${selfdir}/lib1"
atf_check \
-o inline:"-lcircular-1 -lcircular-2 -lcircular-3 \n" \
pkgconf --libs circular-1
}
libs_circular2_body()
{
export PKG_CONFIG_PATH="${selfdir}/lib1"
atf_check \
-o inline:"-lcircular-3 -lcircular-1 -lcircular-2 \n" \
pkgconf --libs circular-3
-o inline:"circular-1: breaking circular reference (circular-1 -> circular-2 -> circular-1)\n" \
pkgconf circular-2 --validate
}
libs_circular1_body()
{
export PKG_CONFIG_PATH="${selfdir}/lib1"
atf_check \
-o inline:"circular-3: breaking circular reference (circular-3 -> circular-1 -> circular-3)\n" \
pkgconf circular-1 --validate
}
libs_circular_directpc_body()
@ -307,3 +310,24 @@ single_depth_selectors_body()
-o inline:"foo\n" \
pkgconf --with-path=${selfdir}/lib3 --print-requires bar
}
license_isc_body()
{
atf_check \
-o inline:"foo: ISC\n" \
pkgconf --with-path=${selfdir}/lib1 --license foo
}
license_noassertion_body()
{
atf_check \
-o inline:"bar: NOASSERTION\nfoo: ISC\n" \
pkgconf --with-path=${selfdir}/lib1 --license bar
}
modversion_noflatten_body()
{
atf_check \
-o inline:"1.3\n" \
pkgconf --with-path=${selfdir}/lib1 --modversion bar
}

View File

@ -9,3 +9,4 @@ Version: 1.2.3
Libs: -L${libdir} -lfoo
Cflags: -fPIC -I${includedir}/foo
Cflags.private: -DFOO_STATIC
License: ISC

View File

@ -0,0 +1,4 @@
Name: fragment-comment
Description: Test case for issue #215
Version: 1.0
Cflags: kuku=\#ttt

View File

@ -0,0 +1,6 @@
Name: metapackage-1
Version: 0.1
Description: metapackage for testing purposes
Requires.private: metapackage-2
Libs: -lmetapackage-1
Cflags: -I/metapackage-1

View File

@ -0,0 +1,5 @@
Name: metapackage-2
Version: 0.1
Description: metapackage for testing purposes
Libs: -lmetapackage-2
Cflags: -I/metapackage-2

View File

@ -0,0 +1,4 @@
Name: metapackage
Version: 0.1
Description: metapackage for testing purposes
Requires: metapackage-1, metapackage-2

View File

@ -0,0 +1,10 @@
prefix=${pc_sysrootdir}/test
exec_prefix=${prefix}
libdir=${prefix}/lib
includedir=${prefix}/include
Name: omg-sysroot
Description: A testing pkg-config file
Version: 1.2.3
Libs: -L${libdir} -lomg
Cflags: -fPIC -I${includedir}/omg

View File

@ -0,0 +1,7 @@
prefix=${pc_sysrootdir}/usr
Name: sysroot-dir
Description: Package for testing whether sysroot dirs are repeated or not
Version: 1
CFlags: -I${prefix}/include
Libs: -L${prefix}/lib -lfoo

View File

@ -0,0 +1,9 @@
prefix=/sysroot/usr
includedir=${prefix}/include
libdir=${prefix}/lib
Name: sysroot-dir
Description: Package for testing whether sysroot dirs are repeated or not
Version: 1
CFlags: -I${includedir}
Libs: -L${libdir} -lfoo

View File

@ -0,0 +1,9 @@
prefix=${pc_sysrootdir}/usr
includedir=${prefix}/include
libdir=${prefix}/lib
Name: sysroot-dir
Description: Package for testing whether sysroot dirs are repeated or not
Version: 1
CFlags: -I${includedir}
Libs: -L${libdir} -lfoo

View File

@ -0,0 +1,9 @@
prefix=/sysroot/usr
includedir=${prefix}/include
libdir=${prefix}/lib
Name: sysroot-dir
Description: Package for testing whether sysroot dirs are repeated or not
Version: 1
CFlags: -I${includedir}
Libs: -L${libdir} -lfoo

View File

@ -18,6 +18,6 @@ tests = [
# yuck
foreach test : tests
configure_file(input: test + '.sh', output: test, copy: true)
run_command('chmod', '755', join_paths(meson.build_root(), 'tests', test))
test_file = configure_file(input: test + '.sh', output: test, copy: true)
run_command('chmod', '755', test_file, check : true)
endforeach

View File

@ -29,6 +29,7 @@ tests_init \
fragment_quoting_3 \
fragment_quoting_5 \
fragment_quoting_7 \
fragment_comment \
msvc_fragment_quoting \
msvc_fragment_render_cflags \
tuple_dequote \
@ -264,6 +265,14 @@ fragment_quoting_7a_body()
set +x
}
fragment_comment_body()
{
atf_check \
-o inline:'kuku=\#ttt \n' \
pkgconf --with-path="${selfdir}/lib1" --cflags fragment-comment
}
msvc_fragment_quoting_body()
{
export PKG_CONFIG_PATH="${selfdir}/lib1"

View File

@ -8,6 +8,7 @@ tests_init \
depgraph_break_2 \
depgraph_break_3 \
define_variable \
define_variable_override \
variable \
keep_system_libs \
libs \
@ -23,13 +24,15 @@ tests_init \
idirafter_munge_sysroot \
idirafter_ordering \
pcpath \
sysroot_munge \
virtual_variable \
fragment_collision \
malformed_1 \
malformed_quoting \
explicit_sysroot \
empty_tuple
empty_tuple \
solver_requires_private_debounce
# sysroot_munge \
case_sensitivity_body()
{
@ -70,6 +73,13 @@ define_variable_body()
pkgconf --variable=typelibdir --define-variable='libdir=\${libdir}' typelibdir
}
define_variable_override_body()
{
export PKG_CONFIG_PATH="${selfdir}/lib1"
atf_check -o inline:"/test\n" \
pkgconf --variable=prefix --define-variable='prefix=/test' typelibdir
}
variable_body()
{
export PKG_CONFIG_PATH="${selfdir}/lib1"
@ -112,7 +122,7 @@ libs_never_mergeback_body()
export PKG_CONFIG_PATH="${selfdir}/lib1"
atf_check \
-o inline:"-L/test/bar/lib -lfoo1 \n" \
pkgconf --libs prefix-foo1
pkgconf --libs prefix-foo1
atf_check \
-o inline:"-L/test/bar/lib -lfoo1 -lfoo2 \n" \
pkgconf --libs prefix-foo1 prefix-foo2
@ -160,9 +170,9 @@ isystem_munge_order_body()
isystem_munge_sysroot_body()
{
export PKG_CONFIG_PATH="${selfdir}/lib1" PKG_CONFIG_SYSROOT_DIR='/test'
export PKG_CONFIG_PATH="${selfdir}/lib1" PKG_CONFIG_SYSROOT_DIR="${selfdir}"
atf_check \
-o match:"-isystem /test/opt/bad/include" \
-o match:"-isystem ${selfdir}/opt/bad/include" \
pkgconf --cflags isystem
}
@ -176,9 +186,9 @@ idirafter_munge_order_body()
idirafter_munge_sysroot_body()
{
export PKG_CONFIG_PATH="${selfdir}/lib1" PKG_CONFIG_SYSROOT_DIR='/test'
export PKG_CONFIG_PATH="${selfdir}/lib1" PKG_CONFIG_SYSROOT_DIR="${selfdir}"
atf_check \
-o match:"-idirafter /test/opt/bad/include" \
-o match:"-idirafter ${selfdir}/opt/bad/include" \
pkgconf --cflags idirafter
}
@ -195,20 +205,16 @@ pcpath_body()
export PKG_CONFIG_PATH="${selfdir}/lib2"
atf_check \
-o inline:"-fPIC -I/test/include/foo \n" \
pkgconf --cflags ${selfdir}/lib3/bar.pc
pkgconf --cflags ${selfdir}/lib3/bar.pc
}
sysroot_munge_body()
{
export PKG_CONFIG_PATH="${selfdir}/lib1" PKG_CONFIG_SYSROOT_DIR="/sysroot"
sed "s|/sysroot/|${selfdir}/|g" ${selfdir}/lib1/sysroot-dir.pc > ${selfdir}/lib1/sysroot-dir-selfdir.pc
export PKG_CONFIG_PATH="${selfdir}/lib1" PKG_CONFIG_SYSROOT_DIR="${selfdir}"
atf_check \
-o inline:"-L/sysroot/lib -lfoo \n" \
pkgconf --libs sysroot-dir
export PKG_CONFIG_SYSROOT_DIR="/sysroot2"
atf_check \
-o inline:"-L/sysroot2/sysroot/lib -lfoo \n" \
pkgconf --libs sysroot-dir
-o inline:"-L${selfdir}/lib -lfoo \n" \
pkgconf --libs sysroot-dir-selfdir
}
virtual_variable_body()
@ -226,7 +232,7 @@ virtual_variable_body()
fragment_collision_body()
{
atf_check -o inline:"-D_BAZ -D_BAR -D_FOO -D_THREAD_SAFE -pthread \n" \
atf_check -o inline:"-D_BAZ -D_FOO -D_BAR -D_THREAD_SAFE -pthread \n" \
pkgconf --with-path="${selfdir}/lib1" --cflags fragment-collision
}
@ -244,8 +250,8 @@ malformed_quoting_body()
explicit_sysroot_body()
{
export PKG_CONFIG_SYSROOT_DIR=/sysroot
atf_check -o inline:"/sysroot/usr/share/test\n" \
export PKG_CONFIG_SYSROOT_DIR=${selfdir}
atf_check -o inline:"${selfdir}/usr/share/test\n" \
pkgconf --with-path="${selfdir}/lib1" --variable=pkgdatadir explicit-sysroot
}
@ -254,3 +260,9 @@ empty_tuple_body()
atf_check -o inline:"\n" \
pkgconf --with-path="${selfdir}/lib1" --cflags empty-tuple
}
solver_requires_private_debounce_body()
{
atf_check -o inline:"-I/metapackage-1 -I/metapackage-2 -lmetapackage-1 -lmetapackage-2 \n" \
pkgconf --with-path="${selfdir}/lib1" --cflags --libs metapackage
}

View File

@ -69,7 +69,7 @@ private_duplication_body()
{
export PKG_CONFIG_PATH="${selfdir}/lib1"
atf_check \
-o inline:"-lprivate -lfoo -lbaz -lzee -lbar -lfoo \n" \
-o inline:"-lprivate -lfoo -lbaz -lzee -lfoo -lbar \n" \
pkgconf --static --libs-only-l private-libs-duplication
}
@ -87,7 +87,7 @@ missing_body()
atf_check \
-s exit:1 \
-e ignore \
-o inline:"\n" \
-o ignore \
pkgconf --cflags missing-require
}

View File

@ -6,6 +6,11 @@ tests_init \
cflags \
variable \
do_not_eat_slash \
do_not_duplicate_sysroot_dir \
uninstalled \
uninstalled_pkgconf1 \
uninstalled_fdo \
uninstalled_fdo_pc_sysrootdir
do_not_eat_slash_body()
{
@ -36,3 +41,70 @@ variable_body()
-o inline:"${SYSROOT_DIR}/test/include\n" \
pkgconf --variable=includedir foo
}
do_not_duplicate_sysroot_dir_body()
{
export PKG_CONFIG_PATH="${selfdir}/lib1"
export PKG_CONFIG_SYSROOT_DIR="/sysroot"
atf_check \
-o inline:"-I/sysroot/usr/include \n" \
pkgconf --cflags sysroot-dir-2
atf_check \
-o inline:"-I/sysroot/usr/include \n" \
pkgconf --cflags sysroot-dir-3
atf_check \
-o inline:"-I/sysroot/usr/include \n" \
pkgconf --cflags sysroot-dir-5
export PKG_CONFIG_SYSROOT_DIR="${SYSROOT_DIR}"
atf_check \
-o inline:"-I${SYSROOT_DIR}/usr/include \n" \
pkgconf --cflags sysroot-dir-4
}
uninstalled_body()
{
export PKG_CONFIG_PATH="${selfdir}/lib1"
export PKG_CONFIG_SYSROOT_DIR="/sysroot"
atf_check \
-o inline:"-L/test/lib -lomg \n" \
pkgconf --libs omg
}
uninstalled_pkgconf1_body()
{
export PKG_CONFIG_PATH="${selfdir}/lib1"
export PKG_CONFIG_SYSROOT_DIR="/sysroot"
export PKG_CONFIG_PKGCONF1_SYSROOT_RULES="1"
atf_check \
-o inline:"-L/sysroot/test/lib -lomg \n" \
pkgconf --libs omg
}
uninstalled_fdo_body()
{
export PKG_CONFIG_PATH="${selfdir}/lib1"
export PKG_CONFIG_SYSROOT_DIR="/sysroot"
export PKG_CONFIG_FDO_SYSROOT_RULES="1"
atf_check \
-o inline:"-L/test/lib -lomg \n" \
pkgconf --libs omg
}
uninstalled_fdo_pc_sysrootdir_body()
{
export PKG_CONFIG_PATH="${selfdir}/lib1"
export PKG_CONFIG_SYSROOT_DIR="/sysroot"
export PKG_CONFIG_FDO_SYSROOT_RULES="1"
atf_check \
-o inline:"-L/sysroot/test/lib -lomg \n" \
pkgconf --libs omg-sysroot
}

View File

@ -24,9 +24,8 @@ done
selfdir="@abs_top_srcdir@/tests"
LIBRARY_PATH_ENV="LIBRARY_PATH"
PATH_SEP=":"
SYSROOT_DIR="${selfdir}/test"
SYSROOT_DIR="${selfdir}"
case "$(uname -s)" in
Msys|CYGWIN*) PATH_SEP=";";;
Haiku) LIBRARY_PATH_ENV="BELIBRARIES";;
esac