2011-07-25 02:03:17 +00:00
|
|
|
/*
|
|
|
|
* pkg.c
|
2011-07-25 04:46:10 +00:00
|
|
|
* higher-level dependency graph compilation, management and manipulation
|
2011-07-25 02:03:17 +00:00
|
|
|
*
|
2013-02-24 14:21:36 +00:00
|
|
|
* Copyright (c) 2011, 2012, 2013 pkgconf authors (see AUTHORS).
|
2011-07-25 02:03:17 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2012-07-20 19:29:58 +00:00
|
|
|
* 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.
|
2011-07-25 02:03:17 +00:00
|
|
|
*/
|
|
|
|
|
2016-12-13 18:14:08 +00:00
|
|
|
#include <libpkgconf/config.h>
|
2019-06-07 16:19:28 +00:00
|
|
|
#include <libpkgconf/stdinc.h>
|
2015-09-06 14:35:08 +00:00
|
|
|
#include <libpkgconf/libpkgconf.h>
|
2011-07-25 02:03:17 +00:00
|
|
|
|
2022-07-26 21:06:18 +00:00
|
|
|
#include <assert.h>
|
|
|
|
|
2016-12-16 05:36:59 +00:00
|
|
|
/*
|
|
|
|
* !doc
|
|
|
|
*
|
|
|
|
* libpkgconf `pkg` module
|
|
|
|
* =======================
|
|
|
|
*
|
|
|
|
* The `pkg` module provides dependency resolution services and the overall `.pc` file parsing
|
|
|
|
* routines.
|
|
|
|
*/
|
|
|
|
|
2012-05-07 08:09:59 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
# define PKG_CONFIG_REG_KEY "Software\\pkgconfig\\PKG_CONFIG_PATH"
|
2012-07-02 03:41:08 +00:00
|
|
|
# undef PKG_DEFAULT_PATH
|
2014-08-08 09:19:34 +00:00
|
|
|
# define PKG_DEFAULT_PATH "../lib/pkgconfig;../share/pkgconfig"
|
2017-06-06 03:54:57 +00:00
|
|
|
# define strncasecmp _strnicmp
|
|
|
|
# define strcasecmp _stricmp
|
2012-05-07 08:09:59 +00:00
|
|
|
#endif
|
|
|
|
|
2017-10-16 17:56:19 +00:00
|
|
|
#define PKG_CONFIG_EXT ".pc"
|
2012-02-17 21:35:23 +00:00
|
|
|
|
2022-06-26 06:05:40 +00:00
|
|
|
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);
|
|
|
|
|
2012-05-06 05:12:27 +00:00
|
|
|
static inline bool
|
|
|
|
str_has_suffix(const char *str, const char *suffix)
|
|
|
|
{
|
|
|
|
size_t str_len = strlen(str);
|
|
|
|
size_t suf_len = strlen(suffix);
|
|
|
|
|
|
|
|
if (str_len < suf_len)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return !strncasecmp(str + str_len - suf_len, suffix, suf_len);
|
|
|
|
}
|
|
|
|
|
2018-05-10 00:56:30 +00:00
|
|
|
static char *
|
|
|
|
pkg_get_parent_dir(pkgconf_pkg_t *pkg)
|
2012-07-21 19:49:55 +00:00
|
|
|
{
|
2018-05-10 00:56:30 +00:00
|
|
|
char buf[PKGCONF_ITEM_SIZE], *pathbuf;
|
2012-07-21 19:49:55 +00:00
|
|
|
|
2018-05-10 00:56:30 +00:00
|
|
|
pkgconf_strlcpy(buf, pkg->filename, sizeof buf);
|
2012-09-14 20:42:06 +00:00
|
|
|
pathbuf = strrchr(buf, PKG_DIR_SEP_S);
|
|
|
|
if (pathbuf == NULL)
|
|
|
|
pathbuf = strrchr(buf, '/');
|
|
|
|
if (pathbuf != NULL)
|
2012-08-25 21:34:00 +00:00
|
|
|
pathbuf[0] = '\0';
|
2012-07-21 19:49:55 +00:00
|
|
|
|
2018-05-10 00:56:30 +00:00
|
|
|
return strdup(buf);
|
2012-07-21 19:49:55 +00:00
|
|
|
}
|
|
|
|
|
2021-10-06 17:52:18 +00:00
|
|
|
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);
|
2016-08-26 06:11:50 +00:00
|
|
|
typedef struct {
|
|
|
|
const char *keyword;
|
|
|
|
const pkgconf_pkg_parser_keyword_func_t func;
|
|
|
|
const ptrdiff_t offset;
|
|
|
|
} pkgconf_pkg_parser_keyword_pair_t;
|
|
|
|
|
|
|
|
static int pkgconf_pkg_parser_keyword_pair_cmp(const void *key, const void *ptr)
|
|
|
|
{
|
|
|
|
const pkgconf_pkg_parser_keyword_pair_t *pair = ptr;
|
|
|
|
return strcasecmp(key, pair->keyword);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-10-06 17:52:18 +00:00
|
|
|
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)
|
2016-08-26 06:11:50 +00:00
|
|
|
{
|
2017-09-20 02:58:54 +00:00
|
|
|
(void) keyword;
|
|
|
|
(void) lineno;
|
|
|
|
|
2017-06-05 02:19:55 +00:00
|
|
|
char **dest = (char **)((char *) pkg + offset);
|
2022-07-26 17:08:48 +00:00
|
|
|
*dest = pkgconf_tuple_parse(client, &pkg->vars, value, pkg->flags);
|
2016-08-26 06:11:50 +00:00
|
|
|
}
|
|
|
|
|
2019-07-12 11:35:48 +00:00
|
|
|
static void
|
2021-10-06 17:52:18 +00:00
|
|
|
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)
|
2019-07-12 11:35:48 +00:00
|
|
|
{
|
|
|
|
(void) keyword;
|
|
|
|
(void) lineno;
|
|
|
|
char *p, *i;
|
|
|
|
size_t len;
|
|
|
|
char **dest = (char **)((char *) pkg + offset);
|
|
|
|
|
|
|
|
/* cut at any detected whitespace */
|
2022-07-26 17:08:48 +00:00
|
|
|
p = pkgconf_tuple_parse(client, &pkg->vars, value, pkg->flags);
|
2019-07-12 11:35:48 +00:00
|
|
|
|
2020-04-26 17:28:03 +00:00
|
|
|
len = strcspn(p, " \t");
|
2020-11-28 15:01:16 +00:00
|
|
|
if (len != strlen(p))
|
2019-07-12 11:35:48 +00:00
|
|
|
{
|
|
|
|
i = p + (ptrdiff_t) len;
|
|
|
|
*i = '\0';
|
|
|
|
|
|
|
|
pkgconf_warn(client, "%s:" SIZE_FMT_SPECIFIER ": warning: malformed version field with whitespace, trimming to [%s]\n", pkg->filename,
|
|
|
|
lineno, p);
|
|
|
|
}
|
|
|
|
|
|
|
|
*dest = p;
|
|
|
|
}
|
|
|
|
|
2016-08-26 06:11:50 +00:00
|
|
|
static void
|
2021-10-06 17:52:18 +00:00
|
|
|
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)
|
2016-08-26 06:11:50 +00:00
|
|
|
{
|
2017-06-05 02:19:55 +00:00
|
|
|
pkgconf_list_t *dest = (pkgconf_list_t *)((char *) pkg + offset);
|
2022-07-26 17:08:48 +00:00
|
|
|
bool ret = pkgconf_fragment_parse(client, dest, &pkg->vars, value, pkg->flags);
|
2017-09-20 02:58:54 +00:00
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
{
|
|
|
|
pkgconf_warn(client, "%s:" SIZE_FMT_SPECIFIER ": warning: unable to parse field '%s' into an argument vector, value [%s]\n", pkg->filename,
|
|
|
|
lineno, keyword, value);
|
|
|
|
}
|
2016-08-26 06:11:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-10-06 17:52:18 +00:00
|
|
|
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)
|
2016-08-26 06:11:50 +00:00
|
|
|
{
|
2017-09-20 02:58:54 +00:00
|
|
|
(void) keyword;
|
|
|
|
(void) lineno;
|
|
|
|
|
2017-06-05 02:19:55 +00:00
|
|
|
pkgconf_list_t *dest = (pkgconf_list_t *)((char *) pkg + offset);
|
2018-03-18 23:04:02 +00:00
|
|
|
pkgconf_dependency_parse(client, pkg, dest, value, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* a variant of pkgconf_pkg_parser_dependency_func which colors the dependency node as an "internal" dependency. */
|
|
|
|
static void
|
2021-10-06 17:52:18 +00:00
|
|
|
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)
|
2018-03-18 23:04:02 +00:00
|
|
|
{
|
|
|
|
(void) keyword;
|
|
|
|
(void) lineno;
|
|
|
|
|
|
|
|
pkgconf_list_t *dest = (pkgconf_list_t *)((char *) pkg + offset);
|
|
|
|
pkgconf_dependency_parse(client, pkg, dest, value, PKGCONF_PKG_DEPF_INTERNAL);
|
2016-08-26 06:11:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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)},
|
|
|
|
{"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)},
|
|
|
|
{"Name", pkgconf_pkg_parser_tuple_func, offsetof(pkgconf_pkg_t, realname)},
|
2016-08-26 17:14:32 +00:00
|
|
|
{"Provides", pkgconf_pkg_parser_dependency_func, offsetof(pkgconf_pkg_t, provides)},
|
2017-12-12 06:21:21 +00:00
|
|
|
{"Requires", pkgconf_pkg_parser_dependency_func, offsetof(pkgconf_pkg_t, required)},
|
2018-03-18 23:04:02 +00:00
|
|
|
{"Requires.internal", pkgconf_pkg_parser_internal_dependency_func, offsetof(pkgconf_pkg_t, requires_private)},
|
2016-08-26 06:11:50 +00:00
|
|
|
{"Requires.private", pkgconf_pkg_parser_dependency_func, offsetof(pkgconf_pkg_t, requires_private)},
|
2019-07-12 11:35:48 +00:00
|
|
|
{"Version", pkgconf_pkg_parser_version_func, offsetof(pkgconf_pkg_t, version)},
|
2016-08-26 06:11:50 +00:00
|
|
|
};
|
|
|
|
|
2019-01-14 19:11:59 +00:00
|
|
|
static void
|
|
|
|
pkgconf_pkg_parser_keyword_set(void *opaque, const size_t lineno, const char *keyword, const char *value)
|
2016-08-26 06:11:50 +00:00
|
|
|
{
|
2019-01-14 19:11:59 +00:00
|
|
|
pkgconf_pkg_t *pkg = opaque;
|
|
|
|
|
2016-08-26 06:11:50 +00:00
|
|
|
const pkgconf_pkg_parser_keyword_pair_t *pair = bsearch(keyword,
|
|
|
|
pkgconf_pkg_parser_keyword_funcs, PKGCONF_ARRAY_SIZE(pkgconf_pkg_parser_keyword_funcs),
|
|
|
|
sizeof(pkgconf_pkg_parser_keyword_pair_t), pkgconf_pkg_parser_keyword_pair_cmp);
|
|
|
|
|
|
|
|
if (pair == NULL || pair->func == NULL)
|
2019-01-14 19:11:59 +00:00
|
|
|
return;
|
2016-08-26 06:11:50 +00:00
|
|
|
|
2018-05-10 00:56:30 +00:00
|
|
|
pair->func(pkg->owner, pkg, keyword, lineno, pair->offset, value);
|
2016-08-26 06:11:50 +00:00
|
|
|
}
|
|
|
|
|
2017-01-20 06:58:48 +00:00
|
|
|
static const char *
|
2017-09-09 01:04:49 +00:00
|
|
|
determine_prefix(const pkgconf_pkg_t *pkg, char *buf, size_t buflen)
|
2017-01-20 06:58:48 +00:00
|
|
|
{
|
|
|
|
char *pathiter;
|
|
|
|
|
2017-09-09 01:04:49 +00:00
|
|
|
pkgconf_strlcpy(buf, pkg->filename, buflen);
|
|
|
|
pkgconf_path_relocate(buf, buflen);
|
2017-01-20 06:58:48 +00:00
|
|
|
|
|
|
|
pathiter = strrchr(buf, PKG_DIR_SEP_S);
|
|
|
|
if (pathiter == NULL)
|
|
|
|
pathiter = strrchr(buf, '/');
|
|
|
|
if (pathiter != NULL)
|
|
|
|
pathiter[0] = '\0';
|
|
|
|
|
|
|
|
pathiter = strrchr(buf, PKG_DIR_SEP_S);
|
|
|
|
if (pathiter == NULL)
|
|
|
|
pathiter = strrchr(buf, '/');
|
|
|
|
if (pathiter == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* parent dir is not pkgconfig, can't relocate then */
|
|
|
|
if (strcmp(pathiter + 1, "pkgconfig"))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* okay, work backwards and do it again. */
|
|
|
|
pathiter[0] = '\0';
|
|
|
|
pathiter = strrchr(buf, PKG_DIR_SEP_S);
|
|
|
|
if (pathiter == NULL)
|
|
|
|
pathiter = strrchr(buf, '/');
|
|
|
|
if (pathiter == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
pathiter[0] = '\0';
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2021-03-20 10:01:14 +00:00
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
|
2018-09-17 13:20:28 +00:00
|
|
|
static void
|
|
|
|
remove_additional_separators(char *buf)
|
|
|
|
{
|
|
|
|
char *p = buf;
|
|
|
|
|
|
|
|
while (*p) {
|
|
|
|
if (*p == '/') {
|
|
|
|
char *q;
|
|
|
|
|
|
|
|
q = ++p;
|
|
|
|
while (*q && *q == '/')
|
|
|
|
q++;
|
|
|
|
|
|
|
|
if (p != q)
|
|
|
|
memmove (p, q, strlen (q) + 1);
|
|
|
|
} else {
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
canonicalize_path(char *buf)
|
|
|
|
{
|
|
|
|
remove_additional_separators(buf);
|
|
|
|
}
|
|
|
|
|
2018-09-17 13:20:00 +00:00
|
|
|
static bool
|
|
|
|
is_path_prefix_equal(const char *path1, const char *path2, size_t path2_len)
|
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
|
|
return !_strnicmp(path1, path2, path2_len);
|
|
|
|
#else
|
|
|
|
return !strncmp(path1, path2, path2_len);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2019-01-14 19:11:59 +00:00
|
|
|
static void
|
|
|
|
pkgconf_pkg_parser_value_set(void *opaque, const size_t lineno, const char *keyword, const char *value)
|
2018-05-10 00:56:30 +00:00
|
|
|
{
|
2018-09-17 13:20:28 +00:00
|
|
|
char canonicalized_value[PKGCONF_ITEM_SIZE];
|
2019-01-14 19:11:59 +00:00
|
|
|
pkgconf_pkg_t *pkg = opaque;
|
2018-09-17 13:20:28 +00:00
|
|
|
|
2018-05-10 00:56:30 +00:00
|
|
|
(void) lineno;
|
|
|
|
|
2018-09-17 13:20:28 +00:00
|
|
|
pkgconf_strlcpy(canonicalized_value, value, sizeof canonicalized_value);
|
|
|
|
canonicalize_path(canonicalized_value);
|
|
|
|
|
2018-05-10 00:56:30 +00:00
|
|
|
/* Some pc files will use absolute paths for all of their directories
|
|
|
|
* which is broken when redefining the prefix. We try to outsmart the
|
|
|
|
* file and rewrite any directory that starts with the same prefix.
|
|
|
|
*/
|
2022-06-26 19:41:31 +00:00
|
|
|
if (pkg->owner->flags & PKGCONF_PKG_PKGF_REDEFINE_PREFIX && pkg->orig_prefix
|
2018-09-17 13:20:00 +00:00
|
|
|
&& is_path_prefix_equal(canonicalized_value, pkg->orig_prefix->value, strlen(pkg->orig_prefix->value)))
|
2018-05-10 00:56:30 +00:00
|
|
|
{
|
|
|
|
char newvalue[PKGCONF_ITEM_SIZE];
|
|
|
|
|
|
|
|
pkgconf_strlcpy(newvalue, pkg->prefix->value, sizeof newvalue);
|
2018-09-17 13:20:28 +00:00
|
|
|
pkgconf_strlcat(newvalue, canonicalized_value + strlen(pkg->orig_prefix->value), sizeof newvalue);
|
2022-07-26 17:08:48 +00:00
|
|
|
pkgconf_tuple_add(pkg->owner, &pkg->vars, keyword, newvalue, false, pkg->flags);
|
2018-05-10 00:56:30 +00:00
|
|
|
}
|
2022-06-26 19:41:31 +00:00
|
|
|
else if (strcmp(keyword, pkg->owner->prefix_varname) || !(pkg->owner->flags & PKGCONF_PKG_PKGF_REDEFINE_PREFIX))
|
2022-07-26 17:08:48 +00:00
|
|
|
pkgconf_tuple_add(pkg->owner, &pkg->vars, keyword, value, true, pkg->flags);
|
2018-05-10 00:56:30 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
char pathbuf[PKGCONF_ITEM_SIZE];
|
|
|
|
const char *relvalue = determine_prefix(pkg, pathbuf, sizeof pathbuf);
|
|
|
|
|
|
|
|
if (relvalue != NULL)
|
|
|
|
{
|
2021-03-20 10:01:14 +00:00
|
|
|
char *prefix_value = convert_path_to_value(relvalue);
|
2022-07-26 17:08:48 +00:00
|
|
|
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);
|
2021-03-20 10:01:14 +00:00
|
|
|
free(prefix_value);
|
2018-05-10 00:56:30 +00:00
|
|
|
}
|
|
|
|
else
|
2022-07-26 17:08:48 +00:00
|
|
|
pkgconf_tuple_add(pkg->owner, &pkg->vars, keyword, value, true, pkg->flags);
|
2018-05-10 00:56:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-20 04:37:57 +00:00
|
|
|
typedef struct {
|
|
|
|
const char *field;
|
|
|
|
const ptrdiff_t offset;
|
|
|
|
} pkgconf_pkg_validity_check_t;
|
|
|
|
|
|
|
|
static const pkgconf_pkg_validity_check_t pkgconf_pkg_validations[] = {
|
|
|
|
{"Name", offsetof(pkgconf_pkg_t, realname)},
|
|
|
|
{"Description", offsetof(pkgconf_pkg_t, description)},
|
|
|
|
{"Version", offsetof(pkgconf_pkg_t, version)},
|
|
|
|
};
|
|
|
|
|
2018-06-16 21:35:44 +00:00
|
|
|
static const pkgconf_parser_operand_func_t pkg_parser_funcs[256] = {
|
2019-01-14 19:11:59 +00:00
|
|
|
[':'] = pkgconf_pkg_parser_keyword_set,
|
|
|
|
['='] = pkgconf_pkg_parser_value_set
|
2018-05-10 02:21:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void pkg_warn_func(pkgconf_pkg_t *pkg, const char *fmt, ...) PRINTFLIKE(2, 3);
|
|
|
|
|
|
|
|
static void
|
|
|
|
pkg_warn_func(pkgconf_pkg_t *pkg, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
char buf[PKGCONF_ITEM_SIZE];
|
|
|
|
va_list va;
|
|
|
|
|
|
|
|
va_start(va, fmt);
|
|
|
|
vsnprintf(buf, sizeof buf, fmt, va);
|
|
|
|
va_end(va);
|
|
|
|
|
|
|
|
pkgconf_warn(pkg->owner, "%s", buf);
|
|
|
|
}
|
|
|
|
|
2017-05-20 04:37:57 +00:00
|
|
|
static bool
|
|
|
|
pkgconf_pkg_validate(const pkgconf_client_t *client, const pkgconf_pkg_t *pkg)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
bool valid = true;
|
|
|
|
|
|
|
|
for (i = 0; i < PKGCONF_ARRAY_SIZE(pkgconf_pkg_validations); i++)
|
|
|
|
{
|
2017-06-05 02:19:55 +00:00
|
|
|
char **p = (char **)((char *) pkg + pkgconf_pkg_validations[i].offset);
|
2017-05-20 04:37:57 +00:00
|
|
|
|
|
|
|
if (*p != NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
pkgconf_warn(client, "%s: warning: file does not declare a `%s' field\n", pkg->filename, pkgconf_pkg_validations[i].field);
|
|
|
|
valid = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return valid;
|
|
|
|
}
|
|
|
|
|
2012-05-07 04:00:06 +00:00
|
|
|
/*
|
2016-12-16 05:36:59 +00:00
|
|
|
* !doc
|
2012-05-07 04:00:06 +00:00
|
|
|
*
|
2022-07-26 17:13:15 +00:00
|
|
|
* .. c:function:: pkgconf_pkg_t *pkgconf_pkg_new_from_file(const pkgconf_client_t *client, const char *filename, FILE *f, unsigned int flags)
|
2016-12-16 05:36:59 +00:00
|
|
|
*
|
|
|
|
* 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.
|
2022-07-26 17:13:15 +00:00
|
|
|
* :param uint flags: The flags to use when parsing.
|
2016-12-16 05:36:59 +00:00
|
|
|
* :returns: A ``pkgconf_pkg_t`` object which contains the package data.
|
|
|
|
* :rtype: pkgconf_pkg_t *
|
2012-05-07 04:00:06 +00:00
|
|
|
*/
|
2015-09-06 16:20:48 +00:00
|
|
|
pkgconf_pkg_t *
|
2022-07-26 17:13:15 +00:00
|
|
|
pkgconf_pkg_new_from_file(pkgconf_client_t *client, const char *filename, FILE *f, unsigned int flags)
|
2012-05-07 04:00:06 +00:00
|
|
|
{
|
2015-09-06 16:20:48 +00:00
|
|
|
pkgconf_pkg_t *pkg;
|
2012-07-26 05:12:29 +00:00
|
|
|
char *idptr;
|
2012-05-07 04:00:06 +00:00
|
|
|
|
2015-09-06 16:20:48 +00:00
|
|
|
pkg = calloc(sizeof(pkgconf_pkg_t), 1);
|
2018-05-10 00:33:12 +00:00
|
|
|
pkg->owner = client;
|
2012-05-07 04:00:06 +00:00
|
|
|
pkg->filename = strdup(filename);
|
2018-05-10 00:56:30 +00:00
|
|
|
pkg->pc_filedir = pkg_get_parent_dir(pkg);
|
2022-07-26 17:13:15 +00:00
|
|
|
pkg->flags = flags;
|
2021-03-20 10:01:14 +00:00
|
|
|
|
|
|
|
char *pc_filedir_value = convert_path_to_value(pkg->pc_filedir);
|
2022-07-26 17:08:48 +00:00
|
|
|
pkgconf_tuple_add(client, &pkg->vars, "pcfiledir", pc_filedir_value, true, pkg->flags);
|
2021-03-20 10:01:14 +00:00
|
|
|
free(pc_filedir_value);
|
2018-03-08 05:00:22 +00:00
|
|
|
|
2022-06-26 19:16:00 +00:00
|
|
|
/* If pc_filedir is outside of sysroot_dir, override sysroot_dir for this
|
|
|
|
* package.
|
2021-07-25 01:47:33 +00:00
|
|
|
* See https://github.com/pkgconf/pkgconf/issues/213
|
2021-06-23 12:09:05 +00:00
|
|
|
*/
|
|
|
|
if (client->sysroot_dir && strncmp(pkg->pc_filedir, client->sysroot_dir, strlen(client->sysroot_dir)))
|
2022-07-26 17:08:48 +00:00
|
|
|
pkgconf_tuple_add(client, &pkg->vars, "pc_sysrootdir", "", false, pkg->flags);
|
2021-06-23 12:09:05 +00:00
|
|
|
|
2012-07-26 05:12:29 +00:00
|
|
|
/* make module id */
|
2012-08-25 21:34:00 +00:00
|
|
|
if ((idptr = strrchr(pkg->filename, PKG_DIR_SEP_S)) != NULL)
|
|
|
|
idptr++;
|
2020-05-26 13:41:16 +00:00
|
|
|
else
|
|
|
|
idptr = pkg->filename;
|
|
|
|
|
2017-06-16 20:27:23 +00:00
|
|
|
#ifdef _WIN32
|
2020-05-26 13:41:16 +00:00
|
|
|
/* On Windows, both \ and / are allowed in paths, so we have to chop both.
|
|
|
|
* 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.
|
|
|
|
*/
|
2020-05-26 19:41:39 +00:00
|
|
|
char *mungeptr;
|
|
|
|
if ((mungeptr = strrchr(idptr, '/')) != NULL)
|
2021-02-03 11:54:52 +00:00
|
|
|
idptr = ++mungeptr;
|
2017-06-16 20:27:23 +00:00
|
|
|
#endif
|
2012-08-14 14:04:56 +00:00
|
|
|
|
|
|
|
pkg->id = strdup(idptr);
|
2012-07-26 05:12:29 +00:00
|
|
|
idptr = strrchr(pkg->id, '.');
|
|
|
|
if (idptr)
|
|
|
|
*idptr = '\0';
|
|
|
|
|
2018-05-10 02:21:39 +00:00
|
|
|
pkgconf_parser_parse(f, pkg, pkg_parser_funcs, (pkgconf_parser_warn_func_t) pkg_warn_func, pkg->filename);
|
2016-08-27 04:43:20 +00:00
|
|
|
|
2017-05-20 04:37:57 +00:00
|
|
|
if (!pkgconf_pkg_validate(client, pkg))
|
|
|
|
{
|
|
|
|
pkgconf_warn(client, "%s: warning: skipping invalid file\n", pkg->filename);
|
|
|
|
pkgconf_pkg_free(client, pkg);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2022-07-27 18:46:59 +00:00
|
|
|
pkgconf_dependency_t *dep = pkgconf_dependency_add(client, &pkg->provides, pkg->id, pkg->version, PKGCONF_CMP_EQUAL, 0);
|
|
|
|
pkgconf_dependency_unref(dep->owner, dep);
|
2016-08-27 04:43:20 +00:00
|
|
|
|
2016-12-02 06:29:33 +00:00
|
|
|
return pkgconf_pkg_ref(client, pkg);
|
2012-05-07 04:00:06 +00:00
|
|
|
}
|
|
|
|
|
2016-12-16 05:36:59 +00:00
|
|
|
/*
|
|
|
|
* !doc
|
|
|
|
*
|
|
|
|
* .. c:function:: void pkgconf_pkg_free(pkgconf_client_t *client, pkgconf_pkg_t *pkg)
|
|
|
|
*
|
|
|
|
* Releases all releases for a given ``pkgconf_pkg_t`` object.
|
|
|
|
*
|
|
|
|
* :param pkgconf_client_t* client: The client which owns the ``pkgconf_pkg_t`` object, `pkg`.
|
|
|
|
* :param pkgconf_pkg_t* pkg: The package to free.
|
|
|
|
* :return: nothing
|
|
|
|
*/
|
2012-05-07 01:30:50 +00:00
|
|
|
void
|
2016-12-02 06:29:33 +00:00
|
|
|
pkgconf_pkg_free(pkgconf_client_t *client, pkgconf_pkg_t *pkg)
|
2012-05-07 01:30:50 +00:00
|
|
|
{
|
2017-09-13 19:56:10 +00:00
|
|
|
if (pkg == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (pkg->flags & PKGCONF_PKG_PROPF_STATIC && !(pkg->flags & PKGCONF_PKG_PROPF_VIRTUAL))
|
2012-05-07 02:09:26 +00:00
|
|
|
return;
|
|
|
|
|
2016-12-02 06:29:33 +00:00
|
|
|
pkgconf_cache_remove(client, pkg);
|
2013-02-24 14:14:23 +00:00
|
|
|
|
2017-12-12 06:21:21 +00:00
|
|
|
pkgconf_dependency_free(&pkg->required);
|
2015-09-06 15:38:30 +00:00
|
|
|
pkgconf_dependency_free(&pkg->requires_private);
|
|
|
|
pkgconf_dependency_free(&pkg->conflicts);
|
2016-09-16 14:59:41 +00:00
|
|
|
pkgconf_dependency_free(&pkg->provides);
|
2012-05-07 02:09:26 +00:00
|
|
|
|
2015-09-06 15:44:10 +00:00
|
|
|
pkgconf_fragment_free(&pkg->cflags);
|
|
|
|
pkgconf_fragment_free(&pkg->cflags_private);
|
|
|
|
pkgconf_fragment_free(&pkg->libs);
|
|
|
|
pkgconf_fragment_free(&pkg->libs_private);
|
2012-05-07 02:09:26 +00:00
|
|
|
|
2015-09-06 15:41:40 +00:00
|
|
|
pkgconf_tuple_free(&pkg->vars);
|
2012-05-07 02:09:26 +00:00
|
|
|
|
2017-09-13 19:56:10 +00:00
|
|
|
if (pkg->flags & PKGCONF_PKG_PROPF_VIRTUAL)
|
|
|
|
return;
|
|
|
|
|
2012-05-07 01:30:50 +00:00
|
|
|
if (pkg->id != NULL)
|
|
|
|
free(pkg->id);
|
|
|
|
|
|
|
|
if (pkg->filename != NULL)
|
|
|
|
free(pkg->filename);
|
|
|
|
|
|
|
|
if (pkg->realname != NULL)
|
|
|
|
free(pkg->realname);
|
|
|
|
|
|
|
|
if (pkg->version != NULL)
|
|
|
|
free(pkg->version);
|
|
|
|
|
|
|
|
if (pkg->description != NULL)
|
|
|
|
free(pkg->description);
|
|
|
|
|
|
|
|
if (pkg->url != NULL)
|
|
|
|
free(pkg->url);
|
|
|
|
|
|
|
|
if (pkg->pc_filedir != NULL)
|
|
|
|
free(pkg->pc_filedir);
|
|
|
|
|
2022-07-26 21:06:18 +00:00
|
|
|
/* We shouldn't be trying to free this if someone is still holding a reference to it */
|
|
|
|
assert(pkg->refcount == 0);
|
2012-05-07 01:30:50 +00:00
|
|
|
free(pkg);
|
|
|
|
}
|
|
|
|
|
2016-12-16 05:36:59 +00:00
|
|
|
/*
|
|
|
|
* !doc
|
|
|
|
*
|
|
|
|
* .. c:function:: pkgconf_pkg_t *pkgconf_pkg_ref(const pkgconf_client_t *client, pkgconf_pkg_t *pkg)
|
|
|
|
*
|
|
|
|
* Adds an additional reference to the package object.
|
|
|
|
*
|
|
|
|
* :param pkgconf_client_t* client: The pkgconf client object which owns the package being referenced.
|
|
|
|
* :param pkgconf_pkg_t* pkg: The package object being referenced.
|
|
|
|
* :return: The package itself with an incremented reference count.
|
|
|
|
* :rtype: pkgconf_pkg_t *
|
|
|
|
*/
|
2015-09-06 16:20:48 +00:00
|
|
|
pkgconf_pkg_t *
|
2017-12-05 23:32:00 +00:00
|
|
|
pkgconf_pkg_ref(pkgconf_client_t *client, pkgconf_pkg_t *pkg)
|
2013-02-26 05:29:57 +00:00
|
|
|
{
|
2017-12-05 23:32:00 +00:00
|
|
|
if (pkg->owner != NULL && pkg->owner != client)
|
|
|
|
PKGCONF_TRACE(client, "WTF: client %p refers to package %p owned by other client %p", client, pkg, pkg->owner);
|
2016-12-02 06:29:33 +00:00
|
|
|
|
2013-02-26 05:29:57 +00:00
|
|
|
pkg->refcount++;
|
2022-07-26 20:38:00 +00:00
|
|
|
PKGCONF_TRACE(client, "%s: refcount@%p: %d", pkg->id, pkg, pkg->refcount);
|
2017-12-05 23:24:57 +00:00
|
|
|
|
2013-02-26 05:29:57 +00:00
|
|
|
return pkg;
|
|
|
|
}
|
|
|
|
|
2016-12-16 05:36:59 +00:00
|
|
|
/*
|
|
|
|
* !doc
|
|
|
|
*
|
|
|
|
* .. c:function:: void pkgconf_pkg_unref(pkgconf_client_t *client, pkgconf_pkg_t *pkg)
|
|
|
|
*
|
|
|
|
* Releases a reference on the package object. If the reference count is 0, then also free the package.
|
|
|
|
*
|
|
|
|
* :param pkgconf_client_t* client: The pkgconf client object which owns the package being dereferenced.
|
|
|
|
* :param pkgconf_pkg_t* pkg: The package object being dereferenced.
|
|
|
|
* :return: nothing
|
|
|
|
*/
|
2013-02-26 05:29:57 +00:00
|
|
|
void
|
2016-12-02 06:29:33 +00:00
|
|
|
pkgconf_pkg_unref(pkgconf_client_t *client, pkgconf_pkg_t *pkg)
|
2013-02-26 05:29:57 +00:00
|
|
|
{
|
2017-12-05 23:32:00 +00:00
|
|
|
if (pkg->owner != NULL && pkg->owner != client)
|
|
|
|
PKGCONF_TRACE(client, "WTF: client %p unrefs package %p owned by other client %p", client, pkg, pkg->owner);
|
|
|
|
|
2013-02-26 05:29:57 +00:00
|
|
|
pkg->refcount--;
|
2022-07-26 20:38:00 +00:00
|
|
|
PKGCONF_TRACE(pkg->owner, "%s: refcount@%p: %d", pkg->id, pkg, pkg->refcount);
|
2017-12-05 23:24:57 +00:00
|
|
|
|
2013-02-26 05:29:57 +00:00
|
|
|
if (pkg->refcount <= 0)
|
2017-12-05 23:32:00 +00:00
|
|
|
pkgconf_pkg_free(pkg->owner, pkg);
|
2013-02-26 05:29:57 +00:00
|
|
|
}
|
|
|
|
|
2015-09-06 16:20:48 +00:00
|
|
|
static inline pkgconf_pkg_t *
|
2017-05-20 04:21:58 +00:00
|
|
|
pkgconf_pkg_try_specific_path(pkgconf_client_t *client, const char *path, const char *name)
|
2012-05-07 08:57:28 +00:00
|
|
|
{
|
2015-09-06 16:20:48 +00:00
|
|
|
pkgconf_pkg_t *pkg = NULL;
|
2012-05-07 08:57:28 +00:00
|
|
|
FILE *f;
|
2017-10-16 17:56:19 +00:00
|
|
|
char locbuf[PKGCONF_ITEM_SIZE];
|
|
|
|
char uninst_locbuf[PKGCONF_ITEM_SIZE];
|
2012-05-07 08:57:28 +00:00
|
|
|
|
2017-02-05 02:35:49 +00:00
|
|
|
PKGCONF_TRACE(client, "trying path: %s for %s", path, name);
|
|
|
|
|
2020-05-26 17:01:46 +00:00
|
|
|
snprintf(locbuf, sizeof locbuf, "%s%c%s" PKG_CONFIG_EXT, path, PKG_DIR_SEP_S, name);
|
|
|
|
snprintf(uninst_locbuf, sizeof uninst_locbuf, "%s%c%s-uninstalled" PKG_CONFIG_EXT, path, PKG_DIR_SEP_S, name);
|
2012-05-07 08:57:28 +00:00
|
|
|
|
2017-01-20 00:17:29 +00:00
|
|
|
if (!(client->flags & PKGCONF_PKG_PKGF_NO_UNINSTALLED) && (f = fopen(uninst_locbuf, "r")) != NULL)
|
2012-05-07 08:57:28 +00:00
|
|
|
{
|
2017-02-25 21:53:50 +00:00
|
|
|
PKGCONF_TRACE(client, "found (uninstalled): %s", uninst_locbuf);
|
2022-07-26 17:13:15 +00:00
|
|
|
pkg = pkgconf_pkg_new_from_file(client, uninst_locbuf, f, PKGCONF_PKG_PROPF_UNINSTALLED);
|
2012-05-07 08:57:28 +00:00
|
|
|
}
|
|
|
|
else if ((f = fopen(locbuf, "r")) != NULL)
|
2017-02-05 02:35:49 +00:00
|
|
|
{
|
|
|
|
PKGCONF_TRACE(client, "found: %s", locbuf);
|
2022-07-26 17:13:15 +00:00
|
|
|
pkg = pkgconf_pkg_new_from_file(client, locbuf, f, 0);
|
2017-02-05 02:35:49 +00:00
|
|
|
}
|
2012-05-07 08:57:28 +00:00
|
|
|
|
|
|
|
return pkg;
|
|
|
|
}
|
|
|
|
|
2016-08-27 14:48:53 +00:00
|
|
|
static pkgconf_pkg_t *
|
2016-12-02 06:29:33 +00:00
|
|
|
pkgconf_pkg_scan_dir(pkgconf_client_t *client, const char *path, void *data, pkgconf_pkg_iteration_func_t func)
|
2012-07-26 04:49:07 +00:00
|
|
|
{
|
|
|
|
DIR *dir;
|
|
|
|
struct dirent *dirent;
|
2016-08-27 14:48:53 +00:00
|
|
|
pkgconf_pkg_t *outpkg = NULL;
|
2012-07-26 04:49:07 +00:00
|
|
|
|
|
|
|
dir = opendir(path);
|
|
|
|
if (dir == NULL)
|
2016-08-27 14:48:53 +00:00
|
|
|
return NULL;
|
2012-07-26 04:49:07 +00:00
|
|
|
|
2017-02-05 02:35:49 +00:00
|
|
|
PKGCONF_TRACE(client, "scanning dir [%s]", path);
|
|
|
|
|
2012-07-26 04:49:07 +00:00
|
|
|
for (dirent = readdir(dir); dirent != NULL; dirent = readdir(dir))
|
|
|
|
{
|
2017-10-16 17:56:19 +00:00
|
|
|
char filebuf[PKGCONF_ITEM_SIZE];
|
2015-09-06 16:20:48 +00:00
|
|
|
pkgconf_pkg_t *pkg;
|
2012-07-26 04:49:07 +00:00
|
|
|
FILE *f;
|
|
|
|
|
2016-12-10 22:19:40 +00:00
|
|
|
pkgconf_strlcpy(filebuf, path, sizeof filebuf);
|
|
|
|
pkgconf_strlcat(filebuf, "/", sizeof filebuf);
|
|
|
|
pkgconf_strlcat(filebuf, dirent->d_name, sizeof filebuf);
|
2012-07-26 05:01:40 +00:00
|
|
|
|
2017-01-23 18:42:13 +00:00
|
|
|
if (!str_has_suffix(filebuf, PKG_CONFIG_EXT))
|
2017-01-23 05:07:39 +00:00
|
|
|
continue;
|
|
|
|
|
2017-02-05 02:35:49 +00:00
|
|
|
PKGCONF_TRACE(client, "trying file [%s]", filebuf);
|
|
|
|
|
2012-07-26 05:01:40 +00:00
|
|
|
f = fopen(filebuf, "r");
|
2012-07-26 04:49:07 +00:00
|
|
|
if (f == NULL)
|
|
|
|
continue;
|
|
|
|
|
2022-07-26 17:13:15 +00:00
|
|
|
pkg = pkgconf_pkg_new_from_file(client, filebuf, f, 0);
|
2012-07-26 04:49:07 +00:00
|
|
|
if (pkg != NULL)
|
2012-07-26 05:01:40 +00:00
|
|
|
{
|
2016-08-27 14:48:53 +00:00
|
|
|
if (func(pkg, data))
|
|
|
|
{
|
|
|
|
outpkg = pkg;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2016-12-02 06:29:33 +00:00
|
|
|
pkgconf_pkg_unref(client, pkg);
|
2012-07-26 05:01:40 +00:00
|
|
|
}
|
2012-07-26 04:49:07 +00:00
|
|
|
}
|
|
|
|
|
2016-08-27 14:48:53 +00:00
|
|
|
out:
|
2012-07-26 04:49:07 +00:00
|
|
|
closedir(dir);
|
2016-08-27 14:48:53 +00:00
|
|
|
return outpkg;
|
2012-07-26 04:49:07 +00:00
|
|
|
}
|
|
|
|
|
2016-12-16 05:36:59 +00:00
|
|
|
/*
|
|
|
|
* !doc
|
|
|
|
*
|
|
|
|
* .. c:function:: pkgconf_pkg_t *pkgconf_scan_all(pkgconf_client_t *client, void *data, pkgconf_pkg_iteration_func_t func)
|
|
|
|
*
|
|
|
|
* Iterates over all packages found in the `package directory list`, running ``func`` on them. If ``func`` returns true,
|
|
|
|
* then stop iteration and return the last iterated package.
|
|
|
|
*
|
|
|
|
* :param pkgconf_client_t* client: The pkgconf client object to use for dependency resolution.
|
|
|
|
* :param void* data: An opaque pointer to data to provide the iteration function with.
|
|
|
|
* :param pkgconf_pkg_iteration_func_t func: A function which is called for each package to determine if the package matches,
|
|
|
|
* always return ``false`` to iterate over all packages.
|
|
|
|
* :return: A package object reference if one is found by the scan function, else ``NULL``.
|
|
|
|
* :rtype: pkgconf_pkg_t *
|
|
|
|
*/
|
2016-08-27 14:48:53 +00:00
|
|
|
pkgconf_pkg_t *
|
2016-12-02 06:29:33 +00:00
|
|
|
pkgconf_scan_all(pkgconf_client_t *client, void *data, pkgconf_pkg_iteration_func_t func)
|
2012-07-26 04:49:07 +00:00
|
|
|
{
|
2015-09-06 15:31:21 +00:00
|
|
|
pkgconf_node_t *n;
|
2016-08-27 14:48:53 +00:00
|
|
|
pkgconf_pkg_t *pkg;
|
2012-07-26 04:49:07 +00:00
|
|
|
|
2016-12-01 21:05:03 +00:00
|
|
|
PKGCONF_FOREACH_LIST_ENTRY(client->dir_list.head, n)
|
2013-03-15 22:55:44 +00:00
|
|
|
{
|
2016-12-01 04:15:13 +00:00
|
|
|
pkgconf_path_t *pnode = n->data;
|
2013-03-15 22:55:44 +00:00
|
|
|
|
2017-02-25 21:53:50 +00:00
|
|
|
PKGCONF_TRACE(client, "scanning directory: %s", pnode->path);
|
|
|
|
|
2016-12-01 21:05:03 +00:00
|
|
|
if ((pkg = pkgconf_pkg_scan_dir(client, pnode->path, data, func)) != NULL)
|
2016-08-27 14:48:53 +00:00
|
|
|
return pkg;
|
2013-03-15 22:55:44 +00:00
|
|
|
}
|
2016-08-27 14:48:53 +00:00
|
|
|
|
|
|
|
return NULL;
|
2012-07-26 04:49:07 +00:00
|
|
|
}
|
|
|
|
|
2012-05-07 08:09:59 +00:00
|
|
|
#ifdef _WIN32
|
2016-12-16 04:57:15 +00:00
|
|
|
static pkgconf_pkg_t *
|
2017-06-05 02:19:55 +00:00
|
|
|
pkgconf_pkg_find_in_registry_key(pkgconf_client_t *client, HKEY hkey, const char *name)
|
2012-05-07 08:09:59 +00:00
|
|
|
{
|
2015-09-06 16:20:48 +00:00
|
|
|
pkgconf_pkg_t *pkg = NULL;
|
2012-05-07 08:09:59 +00:00
|
|
|
|
|
|
|
HKEY key;
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
char buf[16384]; /* per registry limits */
|
|
|
|
DWORD bufsize = sizeof buf;
|
|
|
|
if (RegOpenKeyEx(hkey, PKG_CONFIG_REG_KEY,
|
|
|
|
0, KEY_READ, &key) != ERROR_SUCCESS)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
while (RegEnumValue(key, i++, buf, &bufsize, NULL, NULL, NULL, NULL)
|
|
|
|
== ERROR_SUCCESS)
|
|
|
|
{
|
2017-10-16 17:56:19 +00:00
|
|
|
char pathbuf[PKGCONF_ITEM_SIZE];
|
2012-05-07 08:09:59 +00:00
|
|
|
DWORD type;
|
|
|
|
DWORD pathbuflen = sizeof pathbuf;
|
|
|
|
|
2012-07-02 03:41:08 +00:00
|
|
|
if (RegQueryValueEx(key, buf, NULL, &type, (LPBYTE) pathbuf, &pathbuflen)
|
2012-05-07 08:09:59 +00:00
|
|
|
== ERROR_SUCCESS && type == REG_SZ)
|
|
|
|
{
|
2017-01-20 00:17:29 +00:00
|
|
|
pkg = pkgconf_pkg_try_specific_path(client, pathbuf, name);
|
2012-05-07 08:57:28 +00:00
|
|
|
if (pkg != NULL)
|
2012-05-07 08:09:59 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
bufsize = sizeof buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
RegCloseKey(key);
|
|
|
|
return pkg;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-12-16 05:36:59 +00:00
|
|
|
/*
|
|
|
|
* !doc
|
|
|
|
*
|
2017-01-20 00:17:29 +00:00
|
|
|
* .. c:function:: pkgconf_pkg_t *pkgconf_pkg_find(pkgconf_client_t *client, const char *name)
|
2016-12-16 05:36:59 +00:00
|
|
|
*
|
|
|
|
* Search for a package.
|
|
|
|
*
|
|
|
|
* :param pkgconf_client_t* client: The pkgconf client object to use for dependency resolution.
|
|
|
|
* :param char* name: The name of the package `atom` to use for searching.
|
|
|
|
* :return: A package object reference if the package was found, else ``NULL``.
|
|
|
|
* :rtype: pkgconf_pkg_t *
|
|
|
|
*/
|
2015-09-06 16:20:48 +00:00
|
|
|
pkgconf_pkg_t *
|
2017-01-20 00:17:29 +00:00
|
|
|
pkgconf_pkg_find(pkgconf_client_t *client, const char *name)
|
2011-07-25 02:03:17 +00:00
|
|
|
{
|
2015-09-06 16:20:48 +00:00
|
|
|
pkgconf_pkg_t *pkg = NULL;
|
2015-09-06 15:31:21 +00:00
|
|
|
pkgconf_node_t *n;
|
2012-01-16 01:03:54 +00:00
|
|
|
FILE *f;
|
2011-07-25 02:03:17 +00:00
|
|
|
|
2017-02-05 02:35:49 +00:00
|
|
|
PKGCONF_TRACE(client, "looking for: %s", name);
|
|
|
|
|
2012-05-06 05:12:27 +00:00
|
|
|
/* name might actually be a filename. */
|
|
|
|
if (str_has_suffix(name, PKG_CONFIG_EXT))
|
|
|
|
{
|
|
|
|
if ((f = fopen(name, "r")) != NULL)
|
2013-03-15 23:11:43 +00:00
|
|
|
{
|
2015-09-06 16:20:48 +00:00
|
|
|
pkgconf_pkg_t *pkg;
|
2013-03-15 23:11:43 +00:00
|
|
|
|
2017-02-05 02:35:49 +00:00
|
|
|
PKGCONF_TRACE(client, "%s is a file", name);
|
|
|
|
|
2022-07-26 17:13:15 +00:00
|
|
|
pkg = pkgconf_pkg_new_from_file(client, name, f, 0);
|
2017-05-20 04:33:49 +00:00
|
|
|
if (pkg != NULL)
|
|
|
|
{
|
2018-05-10 00:56:30 +00:00
|
|
|
pkgconf_path_add(pkg->pc_filedir, &client->dir_list, true);
|
2017-05-20 04:33:49 +00:00
|
|
|
return pkg;
|
|
|
|
}
|
2013-03-15 23:11:43 +00:00
|
|
|
}
|
2012-05-06 05:12:27 +00:00
|
|
|
}
|
|
|
|
|
2016-08-26 05:26:30 +00:00
|
|
|
/* check builtins */
|
|
|
|
if ((pkg = pkgconf_builtin_pkg_get(name)) != NULL)
|
2017-02-05 02:35:49 +00:00
|
|
|
{
|
|
|
|
PKGCONF_TRACE(client, "%s is a builtin", name);
|
2016-08-26 05:26:30 +00:00
|
|
|
return pkg;
|
2017-02-05 02:35:49 +00:00
|
|
|
}
|
2016-08-26 05:26:30 +00:00
|
|
|
|
2013-02-24 14:14:23 +00:00
|
|
|
/* check cache */
|
2017-01-20 00:17:29 +00:00
|
|
|
if (!(client->flags & PKGCONF_PKG_PKGF_NO_CACHE))
|
2013-02-24 14:14:23 +00:00
|
|
|
{
|
2016-12-02 06:29:33 +00:00
|
|
|
if ((pkg = pkgconf_cache_lookup(client, name)) != NULL)
|
2013-02-26 04:47:32 +00:00
|
|
|
{
|
2017-02-05 02:35:49 +00:00
|
|
|
PKGCONF_TRACE(client, "%s is cached", name);
|
2013-02-26 04:40:30 +00:00
|
|
|
return pkg;
|
2013-02-26 04:47:32 +00:00
|
|
|
}
|
2013-02-24 14:14:23 +00:00
|
|
|
}
|
|
|
|
|
2016-12-01 21:05:03 +00:00
|
|
|
PKGCONF_FOREACH_LIST_ENTRY(client->dir_list.head, n)
|
2012-05-02 23:16:32 +00:00
|
|
|
{
|
2016-12-01 04:15:13 +00:00
|
|
|
pkgconf_path_t *pnode = n->data;
|
2013-03-15 22:55:44 +00:00
|
|
|
|
2017-01-20 00:17:29 +00:00
|
|
|
pkg = pkgconf_pkg_try_specific_path(client, pnode->path, name);
|
2013-03-15 23:11:43 +00:00
|
|
|
if (pkg != NULL)
|
|
|
|
goto out;
|
2012-05-02 23:16:32 +00:00
|
|
|
}
|
2012-05-02 19:06:32 +00:00
|
|
|
|
2012-05-07 08:09:59 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
/* support getting PKG_CONFIG_PATH from registry */
|
2017-01-20 00:17:29 +00:00
|
|
|
pkg = pkgconf_pkg_find_in_registry_key(client, HKEY_CURRENT_USER, name);
|
2012-05-07 08:09:59 +00:00
|
|
|
if (!pkg)
|
2017-01-20 00:17:29 +00:00
|
|
|
pkg = pkgconf_pkg_find_in_registry_key(client, HKEY_LOCAL_MACHINE, name);
|
2012-05-07 08:09:59 +00:00
|
|
|
#endif
|
|
|
|
|
2012-05-07 02:09:26 +00:00
|
|
|
out:
|
2016-12-02 06:29:33 +00:00
|
|
|
pkgconf_cache_add(client, pkg);
|
2013-02-26 04:40:30 +00:00
|
|
|
|
2012-05-07 02:09:26 +00:00
|
|
|
return pkg;
|
2011-07-25 02:03:17 +00:00
|
|
|
}
|
|
|
|
|
2011-07-26 16:56:59 +00:00
|
|
|
/*
|
2016-12-16 05:36:59 +00:00
|
|
|
* !doc
|
|
|
|
*
|
|
|
|
* .. c:function:: int pkgconf_compare_version(const char *a, const char *b)
|
2011-07-26 16:56:59 +00:00
|
|
|
*
|
2016-12-16 05:36:59 +00:00
|
|
|
* Compare versions using RPM version comparison rules as described in the LSB.
|
|
|
|
*
|
|
|
|
* :param char* a: The first version to compare in the pair.
|
|
|
|
* :param char* b: The second version to compare in the pair.
|
|
|
|
* :return: -1 if the first version is greater, 0 if both versions are equal, 1 if the second version is greater.
|
|
|
|
* :rtype: int
|
2011-07-26 16:56:59 +00:00
|
|
|
*/
|
|
|
|
int
|
2015-09-06 16:00:46 +00:00
|
|
|
pkgconf_compare_version(const char *a, const char *b)
|
2011-07-26 16:56:59 +00:00
|
|
|
{
|
|
|
|
char oldch1, oldch2;
|
2017-10-16 17:56:19 +00:00
|
|
|
char buf1[PKGCONF_ITEM_SIZE], buf2[PKGCONF_ITEM_SIZE];
|
2011-07-26 16:56:59 +00:00
|
|
|
char *str1, *str2;
|
|
|
|
char *one, *two;
|
|
|
|
int ret;
|
|
|
|
bool isnum;
|
|
|
|
|
|
|
|
/* optimization: if version matches then it's the same version. */
|
2016-01-21 16:08:36 +00:00
|
|
|
if (a == NULL)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (b == NULL)
|
|
|
|
return -1;
|
|
|
|
|
2011-07-26 16:56:59 +00:00
|
|
|
if (!strcasecmp(a, b))
|
|
|
|
return 0;
|
|
|
|
|
2016-12-10 22:19:40 +00:00
|
|
|
pkgconf_strlcpy(buf1, a, sizeof buf1);
|
|
|
|
pkgconf_strlcpy(buf2, b, sizeof buf2);
|
2011-07-26 16:56:59 +00:00
|
|
|
|
2012-05-11 18:59:18 +00:00
|
|
|
one = str1 = buf1;
|
|
|
|
two = str2 = buf2;
|
2011-07-26 16:56:59 +00:00
|
|
|
|
2012-07-24 02:07:57 +00:00
|
|
|
while (*one || *two)
|
2011-07-26 16:56:59 +00:00
|
|
|
{
|
2015-12-02 11:50:04 +00:00
|
|
|
while (*one && !isalnum((unsigned int)*one) && *one != '~')
|
2011-07-26 16:56:59 +00:00
|
|
|
one++;
|
2015-12-02 11:50:04 +00:00
|
|
|
while (*two && !isalnum((unsigned int)*two) && *two != '~')
|
2011-07-26 17:05:14 +00:00
|
|
|
two++;
|
2011-07-26 16:56:59 +00:00
|
|
|
|
2012-07-24 02:07:57 +00:00
|
|
|
if (*one == '~' || *two == '~')
|
|
|
|
{
|
|
|
|
if (*one != '~')
|
|
|
|
return -1;
|
2012-07-30 10:03:37 +00:00
|
|
|
if (*two != '~')
|
|
|
|
return 1;
|
2012-07-24 02:07:57 +00:00
|
|
|
|
|
|
|
one++;
|
|
|
|
two++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-07-26 16:56:59 +00:00
|
|
|
if (!(*one && *two))
|
|
|
|
break;
|
|
|
|
|
|
|
|
str1 = one;
|
|
|
|
str2 = two;
|
|
|
|
|
2015-12-02 11:50:04 +00:00
|
|
|
if (isdigit((unsigned int)*str1))
|
2011-07-26 16:56:59 +00:00
|
|
|
{
|
2015-12-02 11:50:04 +00:00
|
|
|
while (*str1 && isdigit((unsigned int)*str1))
|
2011-07-26 16:56:59 +00:00
|
|
|
str1++;
|
|
|
|
|
2015-12-02 11:50:04 +00:00
|
|
|
while (*str2 && isdigit((unsigned int)*str2))
|
2011-07-26 16:56:59 +00:00
|
|
|
str2++;
|
|
|
|
|
|
|
|
isnum = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-12-02 11:50:04 +00:00
|
|
|
while (*str1 && isalpha((unsigned int)*str1))
|
2011-07-26 16:56:59 +00:00
|
|
|
str1++;
|
|
|
|
|
2015-12-02 11:50:04 +00:00
|
|
|
while (*str2 && isalpha((unsigned int)*str2))
|
2011-07-26 16:56:59 +00:00
|
|
|
str2++;
|
|
|
|
|
|
|
|
isnum = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
oldch1 = *str1;
|
|
|
|
oldch2 = *str2;
|
|
|
|
|
|
|
|
*str1 = '\0';
|
|
|
|
*str2 = '\0';
|
|
|
|
|
|
|
|
if (one == str1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (two == str2)
|
|
|
|
return (isnum ? 1 : -1);
|
|
|
|
|
|
|
|
if (isnum)
|
|
|
|
{
|
|
|
|
int onelen, twolen;
|
|
|
|
|
|
|
|
while (*one == '0')
|
|
|
|
one++;
|
|
|
|
|
|
|
|
while (*two == '0')
|
|
|
|
two++;
|
|
|
|
|
|
|
|
onelen = strlen(one);
|
|
|
|
twolen = strlen(two);
|
|
|
|
|
2011-07-26 17:05:14 +00:00
|
|
|
if (onelen > twolen)
|
2011-07-26 16:56:59 +00:00
|
|
|
return 1;
|
2011-07-26 17:05:14 +00:00
|
|
|
else if (twolen > onelen)
|
2011-07-26 16:56:59 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = strcmp(one, two);
|
2020-05-24 20:18:16 +00:00
|
|
|
if (ret != 0)
|
|
|
|
return ret < 0 ? -1 : 1;
|
2011-07-26 16:56:59 +00:00
|
|
|
|
|
|
|
*str1 = oldch1;
|
|
|
|
*str2 = oldch2;
|
|
|
|
|
|
|
|
one = str1;
|
|
|
|
two = str2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((!*one) && (!*two))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (!*one)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-09-06 16:20:48 +00:00
|
|
|
static pkgconf_pkg_t pkg_config_virtual = {
|
2013-02-24 13:20:50 +00:00
|
|
|
.id = "pkg-config",
|
|
|
|
.realname = "pkg-config",
|
|
|
|
.description = "virtual package defining pkg-config API version supported",
|
|
|
|
.url = PACKAGE_BUGREPORT,
|
2015-09-03 08:29:35 +00:00
|
|
|
.version = PACKAGE_VERSION,
|
2017-01-23 05:26:01 +00:00
|
|
|
.flags = PKGCONF_PKG_PROPF_STATIC,
|
2013-03-01 16:45:55 +00:00
|
|
|
.vars = {
|
2015-09-06 15:31:21 +00:00
|
|
|
.head = &(pkgconf_node_t){
|
2017-12-21 08:18:50 +00:00
|
|
|
.next = &(pkgconf_node_t){
|
|
|
|
.next = &(pkgconf_node_t){
|
|
|
|
.data = &(pkgconf_tuple_t){
|
|
|
|
.key = "pc_system_libdirs",
|
|
|
|
.value = SYSTEM_LIBDIR,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
.data = &(pkgconf_tuple_t){
|
|
|
|
.key = "pc_system_includedirs",
|
|
|
|
.value = SYSTEM_INCLUDEDIR,
|
|
|
|
}
|
|
|
|
},
|
2015-09-06 15:41:40 +00:00
|
|
|
.data = &(pkgconf_tuple_t){
|
2013-03-01 16:45:55 +00:00
|
|
|
.key = "pc_path",
|
|
|
|
.value = PKG_DEFAULT_PATH,
|
|
|
|
},
|
2018-01-05 17:38:21 +00:00
|
|
|
},
|
|
|
|
.tail = NULL,
|
2017-12-21 08:18:50 +00:00
|
|
|
}
|
2013-02-24 13:20:50 +00:00
|
|
|
};
|
|
|
|
|
2016-08-26 05:26:30 +00:00
|
|
|
static pkgconf_pkg_t pkgconf_virtual = {
|
|
|
|
.id = "pkgconf",
|
|
|
|
.realname = "pkgconf",
|
|
|
|
.description = "virtual package defining pkgconf API version supported",
|
|
|
|
.url = PACKAGE_BUGREPORT,
|
|
|
|
.version = PACKAGE_VERSION,
|
2017-01-23 05:26:01 +00:00
|
|
|
.flags = PKGCONF_PKG_PROPF_STATIC,
|
2016-08-26 05:26:30 +00:00
|
|
|
.vars = {
|
|
|
|
.head = &(pkgconf_node_t){
|
2017-12-21 08:18:50 +00:00
|
|
|
.next = &(pkgconf_node_t){
|
|
|
|
.next = &(pkgconf_node_t){
|
|
|
|
.data = &(pkgconf_tuple_t){
|
|
|
|
.key = "pc_system_libdirs",
|
|
|
|
.value = SYSTEM_LIBDIR,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
.data = &(pkgconf_tuple_t){
|
|
|
|
.key = "pc_system_includedirs",
|
|
|
|
.value = SYSTEM_INCLUDEDIR,
|
|
|
|
}
|
|
|
|
},
|
2016-08-26 05:26:30 +00:00
|
|
|
.data = &(pkgconf_tuple_t){
|
|
|
|
.key = "pc_path",
|
|
|
|
.value = PKG_DEFAULT_PATH,
|
|
|
|
},
|
2018-01-05 17:38:21 +00:00
|
|
|
},
|
|
|
|
.tail = NULL,
|
2016-08-26 05:26:30 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
const char *name;
|
|
|
|
pkgconf_pkg_t *pkg;
|
|
|
|
} pkgconf_builtin_pkg_pair_t;
|
|
|
|
|
|
|
|
/* keep these in alphabetical order */
|
|
|
|
static const pkgconf_builtin_pkg_pair_t pkgconf_builtin_pkg_pair_set[] = {
|
|
|
|
{"pkg-config", &pkg_config_virtual},
|
|
|
|
{"pkgconf", &pkgconf_virtual},
|
|
|
|
};
|
|
|
|
|
|
|
|
static int pkgconf_builtin_pkg_pair_cmp(const void *key, const void *ptr)
|
|
|
|
{
|
|
|
|
const pkgconf_builtin_pkg_pair_t *pair = ptr;
|
|
|
|
return strcasecmp(key, pair->name);
|
|
|
|
}
|
|
|
|
|
2016-12-16 05:36:59 +00:00
|
|
|
/*
|
|
|
|
* !doc
|
|
|
|
*
|
|
|
|
* .. c:function:: pkgconf_pkg_t *pkgconf_builtin_pkg_get(const char *name)
|
|
|
|
*
|
|
|
|
* Looks up a built-in package. The package should not be freed or dereferenced.
|
|
|
|
*
|
|
|
|
* :param char* name: An atom corresponding to a built-in package to search for.
|
|
|
|
* :return: the built-in package if present, else ``NULL``.
|
|
|
|
* :rtype: pkgconf_pkg_t *
|
|
|
|
*/
|
|
|
|
pkgconf_pkg_t *
|
|
|
|
pkgconf_builtin_pkg_get(const char *name)
|
2016-08-26 05:26:30 +00:00
|
|
|
{
|
|
|
|
const pkgconf_builtin_pkg_pair_t *pair = bsearch(name, pkgconf_builtin_pkg_pair_set,
|
|
|
|
PKGCONF_ARRAY_SIZE(pkgconf_builtin_pkg_pair_set), sizeof(pkgconf_builtin_pkg_pair_t),
|
|
|
|
pkgconf_builtin_pkg_pair_cmp);
|
|
|
|
|
|
|
|
return (pair != NULL) ? pair->pkg : NULL;
|
|
|
|
}
|
|
|
|
|
2016-09-09 04:23:15 +00:00
|
|
|
typedef bool (*pkgconf_vercmp_res_func_t)(const char *a, const char *b);
|
2013-02-24 13:20:50 +00:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
const char *name;
|
2015-09-06 15:57:26 +00:00
|
|
|
pkgconf_pkg_comparator_t compare;
|
2016-08-26 15:54:37 +00:00
|
|
|
} pkgconf_pkg_comparator_pair_t;
|
2013-02-24 13:20:50 +00:00
|
|
|
|
2016-08-26 15:54:37 +00:00
|
|
|
static const pkgconf_pkg_comparator_pair_t pkgconf_pkg_comparator_names[] = {
|
|
|
|
{"!=", PKGCONF_CMP_NOT_EQUAL},
|
|
|
|
{"(any)", PKGCONF_CMP_ANY},
|
2015-09-06 16:34:09 +00:00
|
|
|
{"<", PKGCONF_CMP_LESS_THAN},
|
|
|
|
{"<=", PKGCONF_CMP_LESS_THAN_EQUAL},
|
|
|
|
{"=", PKGCONF_CMP_EQUAL},
|
2016-08-26 15:54:37 +00:00
|
|
|
{">", PKGCONF_CMP_GREATER_THAN},
|
|
|
|
{">=", PKGCONF_CMP_GREATER_THAN_EQUAL},
|
2013-02-24 13:20:50 +00:00
|
|
|
};
|
|
|
|
|
2016-08-26 15:54:37 +00:00
|
|
|
static int pkgconf_pkg_comparator_pair_namecmp(const void *key, const void *ptr)
|
|
|
|
{
|
|
|
|
const pkgconf_pkg_comparator_pair_t *pair = ptr;
|
|
|
|
return strcmp(key, pair->name);
|
|
|
|
}
|
|
|
|
|
2016-09-09 04:23:15 +00:00
|
|
|
static bool pkgconf_pkg_comparator_lt(const char *a, const char *b)
|
2013-02-24 13:32:26 +00:00
|
|
|
{
|
2016-09-09 04:23:15 +00:00
|
|
|
return (pkgconf_compare_version(a, b) < 0);
|
2013-02-24 13:32:26 +00:00
|
|
|
}
|
|
|
|
|
2016-09-09 04:23:15 +00:00
|
|
|
static bool pkgconf_pkg_comparator_gt(const char *a, const char *b)
|
2013-02-24 13:32:26 +00:00
|
|
|
{
|
2016-09-09 04:23:15 +00:00
|
|
|
return (pkgconf_compare_version(a, b) > 0);
|
2013-02-24 13:32:26 +00:00
|
|
|
}
|
|
|
|
|
2016-09-09 04:23:15 +00:00
|
|
|
static bool pkgconf_pkg_comparator_lte(const char *a, const char *b)
|
2013-02-24 13:32:26 +00:00
|
|
|
{
|
2016-09-09 04:23:15 +00:00
|
|
|
return (pkgconf_compare_version(a, b) <= 0);
|
2013-02-24 13:32:26 +00:00
|
|
|
}
|
|
|
|
|
2016-09-09 04:23:15 +00:00
|
|
|
static bool pkgconf_pkg_comparator_gte(const char *a, const char *b)
|
2013-02-24 13:32:26 +00:00
|
|
|
{
|
2016-09-09 04:23:15 +00:00
|
|
|
return (pkgconf_compare_version(a, b) >= 0);
|
2013-02-24 13:32:26 +00:00
|
|
|
}
|
|
|
|
|
2016-09-09 04:23:15 +00:00
|
|
|
static bool pkgconf_pkg_comparator_eq(const char *a, const char *b)
|
2013-02-24 13:32:26 +00:00
|
|
|
{
|
2016-09-09 04:23:15 +00:00
|
|
|
return (pkgconf_compare_version(a, b) == 0);
|
2013-02-24 13:32:26 +00:00
|
|
|
}
|
|
|
|
|
2016-09-09 04:23:15 +00:00
|
|
|
static bool pkgconf_pkg_comparator_ne(const char *a, const char *b)
|
2013-02-24 13:32:26 +00:00
|
|
|
{
|
2016-09-09 04:23:15 +00:00
|
|
|
return (pkgconf_compare_version(a, b) != 0);
|
2013-02-24 13:32:26 +00:00
|
|
|
}
|
|
|
|
|
2016-09-09 04:23:15 +00:00
|
|
|
static bool pkgconf_pkg_comparator_any(const char *a, const char *b)
|
2013-02-24 13:32:26 +00:00
|
|
|
{
|
2016-09-09 04:23:15 +00:00
|
|
|
(void) a;
|
|
|
|
(void) b;
|
2013-02-24 13:32:26 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-09-09 05:17:46 +00:00
|
|
|
static bool pkgconf_pkg_comparator_none(const char *a, const char *b)
|
|
|
|
{
|
|
|
|
(void) a;
|
|
|
|
(void) b;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-08-26 15:54:37 +00:00
|
|
|
static const pkgconf_vercmp_res_func_t pkgconf_pkg_comparator_impls[] = {
|
2015-09-06 16:34:09 +00:00
|
|
|
[PKGCONF_CMP_ANY] = pkgconf_pkg_comparator_any,
|
|
|
|
[PKGCONF_CMP_LESS_THAN] = pkgconf_pkg_comparator_lt,
|
|
|
|
[PKGCONF_CMP_GREATER_THAN] = pkgconf_pkg_comparator_gt,
|
|
|
|
[PKGCONF_CMP_LESS_THAN_EQUAL] = pkgconf_pkg_comparator_lte,
|
|
|
|
[PKGCONF_CMP_GREATER_THAN_EQUAL] = pkgconf_pkg_comparator_gte,
|
|
|
|
[PKGCONF_CMP_EQUAL] = pkgconf_pkg_comparator_eq,
|
|
|
|
[PKGCONF_CMP_NOT_EQUAL] = pkgconf_pkg_comparator_ne,
|
2013-02-24 13:32:26 +00:00
|
|
|
};
|
|
|
|
|
2011-07-27 00:59:46 +00:00
|
|
|
/*
|
2016-12-16 05:36:59 +00:00
|
|
|
* !doc
|
|
|
|
*
|
|
|
|
* .. c:function:: const char *pkgconf_pkg_get_comparator(const pkgconf_dependency_t *pkgdep)
|
2011-07-27 00:59:46 +00:00
|
|
|
*
|
2016-12-16 05:36:59 +00:00
|
|
|
* Returns the comparator used in a depgraph dependency node as a string.
|
|
|
|
*
|
|
|
|
* :param pkgconf_dependency_t* pkgdep: The depgraph dependency node to return the comparator for.
|
|
|
|
* :return: A string matching the comparator or ``"???"``.
|
|
|
|
* :rtype: char *
|
2011-07-27 00:59:46 +00:00
|
|
|
*/
|
|
|
|
const char *
|
2016-07-10 20:20:31 +00:00
|
|
|
pkgconf_pkg_get_comparator(const pkgconf_dependency_t *pkgdep)
|
2011-07-27 00:59:46 +00:00
|
|
|
{
|
2017-01-22 19:31:34 +00:00
|
|
|
if (pkgdep->compare >= PKGCONF_ARRAY_SIZE(pkgconf_pkg_comparator_names))
|
2016-08-26 15:54:37 +00:00
|
|
|
return "???";
|
2011-07-27 00:59:46 +00:00
|
|
|
|
2016-08-26 15:54:37 +00:00
|
|
|
return pkgconf_pkg_comparator_names[pkgdep->compare].name;
|
2011-07-27 00:59:46 +00:00
|
|
|
}
|
|
|
|
|
2013-02-24 13:37:20 +00:00
|
|
|
/*
|
2016-12-16 05:36:59 +00:00
|
|
|
* !doc
|
|
|
|
*
|
|
|
|
* .. c:function:: pkgconf_pkg_comparator_t pkgconf_pkg_comparator_lookup_by_name(const char *name)
|
2013-02-24 13:37:20 +00:00
|
|
|
*
|
2016-12-16 05:36:59 +00:00
|
|
|
* Look up the appropriate comparator bytecode in the comparator set (defined
|
|
|
|
* in ``pkg.c``, see ``pkgconf_pkg_comparator_names`` and ``pkgconf_pkg_comparator_impls``).
|
|
|
|
*
|
|
|
|
* :param char* name: The comparator to look up by `name`.
|
|
|
|
* :return: The comparator bytecode if found, else ``PKGCONF_CMP_ANY``.
|
|
|
|
* :rtype: pkgconf_pkg_comparator_t
|
2013-02-24 13:37:20 +00:00
|
|
|
*/
|
2015-09-06 15:57:26 +00:00
|
|
|
pkgconf_pkg_comparator_t
|
|
|
|
pkgconf_pkg_comparator_lookup_by_name(const char *name)
|
2013-02-24 13:37:20 +00:00
|
|
|
{
|
2016-08-26 15:54:37 +00:00
|
|
|
const pkgconf_pkg_comparator_pair_t *p = bsearch(name, pkgconf_pkg_comparator_names,
|
|
|
|
PKGCONF_ARRAY_SIZE(pkgconf_pkg_comparator_names), sizeof(pkgconf_pkg_comparator_pair_t),
|
|
|
|
pkgconf_pkg_comparator_pair_namecmp);
|
2013-02-24 13:37:20 +00:00
|
|
|
|
2016-08-26 15:54:37 +00:00
|
|
|
return (p != NULL) ? p->compare : PKGCONF_CMP_ANY;
|
2013-02-24 13:37:20 +00:00
|
|
|
}
|
|
|
|
|
2016-09-09 03:10:24 +00:00
|
|
|
typedef struct {
|
|
|
|
pkgconf_dependency_t *pkgdep;
|
|
|
|
} pkgconf_pkg_scan_providers_ctx_t;
|
|
|
|
|
2016-09-09 04:54:57 +00:00
|
|
|
typedef struct {
|
|
|
|
const pkgconf_vercmp_res_func_t rulecmp[PKGCONF_CMP_COUNT];
|
2016-09-10 06:51:19 +00:00
|
|
|
const pkgconf_vercmp_res_func_t depcmp[PKGCONF_CMP_COUNT];
|
2016-09-09 04:54:57 +00:00
|
|
|
} pkgconf_pkg_provides_vermatch_rule_t;
|
|
|
|
|
|
|
|
static const pkgconf_pkg_provides_vermatch_rule_t pkgconf_pkg_provides_vermatch_rules[] = {
|
|
|
|
[PKGCONF_CMP_ANY] = {
|
2017-06-05 02:19:55 +00:00
|
|
|
.rulecmp = {
|
|
|
|
[PKGCONF_CMP_ANY] = pkgconf_pkg_comparator_none,
|
|
|
|
},
|
|
|
|
.depcmp = {
|
|
|
|
[PKGCONF_CMP_ANY] = pkgconf_pkg_comparator_none,
|
|
|
|
},
|
2016-09-09 05:17:46 +00:00
|
|
|
},
|
|
|
|
[PKGCONF_CMP_LESS_THAN] = {
|
|
|
|
.rulecmp = {
|
|
|
|
[PKGCONF_CMP_ANY] = pkgconf_pkg_comparator_none,
|
|
|
|
[PKGCONF_CMP_LESS_THAN] = pkgconf_pkg_comparator_lt,
|
|
|
|
[PKGCONF_CMP_GREATER_THAN] = pkgconf_pkg_comparator_gt,
|
|
|
|
[PKGCONF_CMP_LESS_THAN_EQUAL] = pkgconf_pkg_comparator_lte,
|
|
|
|
[PKGCONF_CMP_GREATER_THAN_EQUAL] = pkgconf_pkg_comparator_gte,
|
2016-09-09 06:04:26 +00:00
|
|
|
},
|
2016-09-10 06:51:19 +00:00
|
|
|
.depcmp = {
|
|
|
|
[PKGCONF_CMP_GREATER_THAN] = pkgconf_pkg_comparator_lt,
|
|
|
|
[PKGCONF_CMP_GREATER_THAN_EQUAL] = pkgconf_pkg_comparator_lt,
|
|
|
|
[PKGCONF_CMP_EQUAL] = pkgconf_pkg_comparator_lt,
|
|
|
|
[PKGCONF_CMP_NOT_EQUAL] = pkgconf_pkg_comparator_gte,
|
2016-09-09 06:04:26 +00:00
|
|
|
},
|
2016-09-09 05:17:46 +00:00
|
|
|
},
|
|
|
|
[PKGCONF_CMP_GREATER_THAN] = {
|
|
|
|
.rulecmp = {
|
|
|
|
[PKGCONF_CMP_ANY] = pkgconf_pkg_comparator_none,
|
|
|
|
[PKGCONF_CMP_LESS_THAN] = pkgconf_pkg_comparator_lt,
|
|
|
|
[PKGCONF_CMP_GREATER_THAN] = pkgconf_pkg_comparator_gt,
|
|
|
|
[PKGCONF_CMP_LESS_THAN_EQUAL] = pkgconf_pkg_comparator_lte,
|
|
|
|
[PKGCONF_CMP_GREATER_THAN_EQUAL] = pkgconf_pkg_comparator_gte,
|
2016-09-09 06:04:26 +00:00
|
|
|
},
|
2016-09-10 06:51:19 +00:00
|
|
|
.depcmp = {
|
|
|
|
[PKGCONF_CMP_LESS_THAN] = pkgconf_pkg_comparator_gt,
|
|
|
|
[PKGCONF_CMP_LESS_THAN_EQUAL] = pkgconf_pkg_comparator_gt,
|
|
|
|
[PKGCONF_CMP_EQUAL] = pkgconf_pkg_comparator_gt,
|
|
|
|
[PKGCONF_CMP_NOT_EQUAL] = pkgconf_pkg_comparator_lte,
|
2016-09-09 06:04:26 +00:00
|
|
|
},
|
2016-09-09 05:17:46 +00:00
|
|
|
},
|
|
|
|
[PKGCONF_CMP_LESS_THAN_EQUAL] = {
|
|
|
|
.rulecmp = {
|
|
|
|
[PKGCONF_CMP_ANY] = pkgconf_pkg_comparator_none,
|
|
|
|
[PKGCONF_CMP_LESS_THAN] = pkgconf_pkg_comparator_lt,
|
|
|
|
[PKGCONF_CMP_GREATER_THAN] = pkgconf_pkg_comparator_gt,
|
|
|
|
[PKGCONF_CMP_LESS_THAN_EQUAL] = pkgconf_pkg_comparator_lte,
|
|
|
|
[PKGCONF_CMP_GREATER_THAN_EQUAL] = pkgconf_pkg_comparator_gte,
|
2016-09-09 06:04:26 +00:00
|
|
|
},
|
2016-09-10 06:51:19 +00:00
|
|
|
.depcmp = {
|
|
|
|
[PKGCONF_CMP_GREATER_THAN] = pkgconf_pkg_comparator_lte,
|
|
|
|
[PKGCONF_CMP_GREATER_THAN_EQUAL] = pkgconf_pkg_comparator_lte,
|
|
|
|
[PKGCONF_CMP_EQUAL] = pkgconf_pkg_comparator_lte,
|
|
|
|
[PKGCONF_CMP_NOT_EQUAL] = pkgconf_pkg_comparator_gt,
|
2016-09-09 06:04:26 +00:00
|
|
|
},
|
2016-09-09 05:17:46 +00:00
|
|
|
},
|
|
|
|
[PKGCONF_CMP_GREATER_THAN_EQUAL] = {
|
|
|
|
.rulecmp = {
|
|
|
|
[PKGCONF_CMP_ANY] = pkgconf_pkg_comparator_none,
|
|
|
|
[PKGCONF_CMP_LESS_THAN] = pkgconf_pkg_comparator_lt,
|
|
|
|
[PKGCONF_CMP_GREATER_THAN] = pkgconf_pkg_comparator_gt,
|
|
|
|
[PKGCONF_CMP_LESS_THAN_EQUAL] = pkgconf_pkg_comparator_lte,
|
|
|
|
[PKGCONF_CMP_GREATER_THAN_EQUAL] = pkgconf_pkg_comparator_gte,
|
2016-09-09 06:04:26 +00:00
|
|
|
},
|
2016-09-10 06:51:19 +00:00
|
|
|
.depcmp = {
|
|
|
|
[PKGCONF_CMP_LESS_THAN] = pkgconf_pkg_comparator_gte,
|
|
|
|
[PKGCONF_CMP_LESS_THAN_EQUAL] = pkgconf_pkg_comparator_gte,
|
|
|
|
[PKGCONF_CMP_EQUAL] = pkgconf_pkg_comparator_gte,
|
|
|
|
[PKGCONF_CMP_NOT_EQUAL] = pkgconf_pkg_comparator_lt,
|
2016-09-09 06:04:26 +00:00
|
|
|
},
|
2016-09-09 05:17:46 +00:00
|
|
|
},
|
|
|
|
[PKGCONF_CMP_EQUAL] = {
|
|
|
|
.rulecmp = {
|
|
|
|
[PKGCONF_CMP_ANY] = pkgconf_pkg_comparator_none,
|
|
|
|
[PKGCONF_CMP_LESS_THAN] = pkgconf_pkg_comparator_lt,
|
|
|
|
[PKGCONF_CMP_GREATER_THAN] = pkgconf_pkg_comparator_gt,
|
|
|
|
[PKGCONF_CMP_LESS_THAN_EQUAL] = pkgconf_pkg_comparator_lte,
|
|
|
|
[PKGCONF_CMP_GREATER_THAN_EQUAL] = pkgconf_pkg_comparator_gte,
|
2016-09-10 06:51:19 +00:00
|
|
|
[PKGCONF_CMP_EQUAL] = pkgconf_pkg_comparator_eq,
|
2016-09-09 05:17:46 +00:00
|
|
|
[PKGCONF_CMP_NOT_EQUAL] = pkgconf_pkg_comparator_ne
|
2016-09-10 06:51:19 +00:00
|
|
|
},
|
2017-06-05 02:19:55 +00:00
|
|
|
.depcmp = {
|
|
|
|
[PKGCONF_CMP_ANY] = pkgconf_pkg_comparator_none,
|
|
|
|
},
|
2016-09-09 05:17:46 +00:00
|
|
|
},
|
|
|
|
[PKGCONF_CMP_NOT_EQUAL] = {
|
2016-09-09 04:54:57 +00:00
|
|
|
.rulecmp = {
|
2016-09-09 05:17:46 +00:00
|
|
|
[PKGCONF_CMP_ANY] = pkgconf_pkg_comparator_none,
|
2016-09-09 19:34:38 +00:00
|
|
|
[PKGCONF_CMP_LESS_THAN] = pkgconf_pkg_comparator_gte,
|
|
|
|
[PKGCONF_CMP_GREATER_THAN] = pkgconf_pkg_comparator_lte,
|
|
|
|
[PKGCONF_CMP_LESS_THAN_EQUAL] = pkgconf_pkg_comparator_gt,
|
|
|
|
[PKGCONF_CMP_GREATER_THAN_EQUAL] = pkgconf_pkg_comparator_lt,
|
2016-09-09 06:04:26 +00:00
|
|
|
[PKGCONF_CMP_EQUAL] = pkgconf_pkg_comparator_ne,
|
|
|
|
[PKGCONF_CMP_NOT_EQUAL] = pkgconf_pkg_comparator_eq
|
2016-09-10 06:51:19 +00:00
|
|
|
},
|
2017-06-05 02:19:55 +00:00
|
|
|
.depcmp = {
|
|
|
|
[PKGCONF_CMP_ANY] = pkgconf_pkg_comparator_none,
|
|
|
|
},
|
2016-09-09 04:54:57 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* pkgconf_pkg_scan_provides_vercmp(pkgdep, provider)
|
|
|
|
*
|
|
|
|
* compare a provides node against the requested dependency node.
|
|
|
|
*
|
2016-09-09 05:17:46 +00:00
|
|
|
* XXX: maybe handle PKGCONF_CMP_ANY in a versioned comparison
|
2016-09-09 04:54:57 +00:00
|
|
|
*/
|
|
|
|
static bool
|
|
|
|
pkgconf_pkg_scan_provides_vercmp(const pkgconf_dependency_t *pkgdep, const pkgconf_dependency_t *provider)
|
|
|
|
{
|
|
|
|
const pkgconf_pkg_provides_vermatch_rule_t *rule = &pkgconf_pkg_provides_vermatch_rules[pkgdep->compare];
|
|
|
|
|
2016-09-10 06:51:19 +00:00
|
|
|
if (rule->depcmp[provider->compare] != NULL &&
|
|
|
|
!rule->depcmp[provider->compare](provider->version, pkgdep->version))
|
2016-09-09 04:54:57 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (rule->rulecmp[provider->compare] != NULL &&
|
2016-09-09 05:17:46 +00:00
|
|
|
!rule->rulecmp[provider->compare](pkgdep->version, provider->version))
|
2016-09-09 04:54:57 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-09-09 03:10:24 +00:00
|
|
|
/*
|
|
|
|
* pkgconf_pkg_scan_provides_entry(pkg, ctx)
|
|
|
|
*
|
|
|
|
* attempt to match a single package's Provides rules against the requested dependency node.
|
|
|
|
*/
|
|
|
|
static bool
|
|
|
|
pkgconf_pkg_scan_provides_entry(const pkgconf_pkg_t *pkg, const pkgconf_pkg_scan_providers_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
const pkgconf_dependency_t *pkgdep = ctx->pkgdep;
|
|
|
|
pkgconf_node_t *node;
|
|
|
|
|
2016-09-09 04:54:57 +00:00
|
|
|
PKGCONF_FOREACH_LIST_ENTRY(pkg->provides.head, node)
|
2016-09-09 03:10:24 +00:00
|
|
|
{
|
2016-09-09 04:54:57 +00:00
|
|
|
const pkgconf_dependency_t *provider = node->data;
|
|
|
|
if (!strcmp(provider->package, pkgdep->package))
|
|
|
|
return pkgconf_pkg_scan_provides_vercmp(pkgdep, provider);
|
2016-09-09 03:10:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2017-01-20 00:17:29 +00:00
|
|
|
* pkgconf_pkg_scan_providers(client, pkgdep, eflags)
|
2016-09-09 03:10:24 +00:00
|
|
|
*
|
|
|
|
* scan all available packages to see if a Provides rule matches the pkgdep.
|
|
|
|
*/
|
|
|
|
static pkgconf_pkg_t *
|
2017-01-20 00:17:29 +00:00
|
|
|
pkgconf_pkg_scan_providers(pkgconf_client_t *client, pkgconf_dependency_t *pkgdep, unsigned int *eflags)
|
2016-09-09 03:10:24 +00:00
|
|
|
{
|
|
|
|
pkgconf_pkg_t *pkg;
|
|
|
|
pkgconf_pkg_scan_providers_ctx_t ctx = {
|
|
|
|
.pkgdep = pkgdep,
|
|
|
|
};
|
|
|
|
|
2016-12-01 21:05:03 +00:00
|
|
|
pkg = pkgconf_scan_all(client, &ctx, (pkgconf_pkg_iteration_func_t) pkgconf_pkg_scan_provides_entry);
|
2016-09-09 03:10:24 +00:00
|
|
|
if (pkg != NULL)
|
2018-02-08 20:25:47 +00:00
|
|
|
{
|
|
|
|
pkgdep->match = pkgconf_pkg_ref(client, pkg);
|
2016-09-09 03:10:24 +00:00
|
|
|
return pkg;
|
2018-02-08 20:25:47 +00:00
|
|
|
}
|
2016-09-09 03:10:24 +00:00
|
|
|
|
|
|
|
if (eflags != NULL)
|
|
|
|
*eflags |= PKGCONF_PKG_ERRF_PACKAGE_NOT_FOUND;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-07-26 17:17:45 +00:00
|
|
|
/*
|
2016-12-16 05:36:59 +00:00
|
|
|
* !doc
|
|
|
|
*
|
2017-01-20 00:17:29 +00:00
|
|
|
* .. c:function:: pkgconf_pkg_t *pkgconf_pkg_verify_dependency(pkgconf_client_t *client, pkgconf_dependency_t *pkgdep, unsigned int *eflags)
|
2016-12-16 05:36:59 +00:00
|
|
|
*
|
|
|
|
* Verify a pkgconf_dependency_t node in the depgraph. If the dependency is solvable,
|
|
|
|
* return the appropriate ``pkgconf_pkg_t`` object, else ``NULL``.
|
2011-07-26 17:17:45 +00:00
|
|
|
*
|
2016-12-16 05:36:59 +00:00
|
|
|
* :param pkgconf_client_t* client: The pkgconf client object to use for dependency resolution.
|
|
|
|
* :param pkgconf_dependency_t* pkgdep: The dependency graph node to solve.
|
|
|
|
* :param uint* eflags: An optional pointer that, if set, will be populated with an error code from the resolver.
|
|
|
|
* :return: On success, the appropriate ``pkgconf_pkg_t`` object to solve the dependency, else ``NULL``.
|
|
|
|
* :rtype: pkgconf_pkg_t *
|
2011-07-26 17:17:45 +00:00
|
|
|
*/
|
2015-09-06 16:20:48 +00:00
|
|
|
pkgconf_pkg_t *
|
2017-01-20 00:17:29 +00:00
|
|
|
pkgconf_pkg_verify_dependency(pkgconf_client_t *client, pkgconf_dependency_t *pkgdep, unsigned int *eflags)
|
2011-07-26 17:17:45 +00:00
|
|
|
{
|
2016-08-26 05:26:30 +00:00
|
|
|
pkgconf_pkg_t *pkg = NULL;
|
2011-07-26 17:17:45 +00:00
|
|
|
|
2012-05-03 17:42:04 +00:00
|
|
|
if (eflags != NULL)
|
2015-09-06 16:45:00 +00:00
|
|
|
*eflags = PKGCONF_PKG_ERRF_OK;
|
2012-05-03 17:42:04 +00:00
|
|
|
|
2017-02-25 21:53:50 +00:00
|
|
|
PKGCONF_TRACE(client, "trying to verify dependency: %s", pkgdep->package);
|
|
|
|
|
2017-12-05 23:34:01 +00:00
|
|
|
if (pkgdep->match != NULL)
|
|
|
|
{
|
|
|
|
PKGCONF_TRACE(client, "cached dependency: %s -> %s@%p", pkgdep->package, pkgdep->match->id, pkgdep->match);
|
|
|
|
return pkgconf_pkg_ref(client, pkgdep->match);
|
|
|
|
}
|
|
|
|
|
2017-01-20 00:17:29 +00:00
|
|
|
pkg = pkgconf_pkg_find(client, pkgdep->package);
|
2016-08-26 05:26:30 +00:00
|
|
|
if (pkg == NULL)
|
2012-05-03 17:42:04 +00:00
|
|
|
{
|
2017-01-20 00:17:29 +00:00
|
|
|
if (client->flags & PKGCONF_PKG_PKGF_SKIP_PROVIDES)
|
2016-09-09 03:10:24 +00:00
|
|
|
{
|
|
|
|
if (eflags != NULL)
|
|
|
|
*eflags |= PKGCONF_PKG_ERRF_PACKAGE_NOT_FOUND;
|
2012-05-03 17:42:04 +00:00
|
|
|
|
2016-09-09 03:10:24 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-01-20 00:17:29 +00:00
|
|
|
return pkgconf_pkg_scan_providers(client, pkgdep, eflags);
|
2012-05-03 17:42:04 +00:00
|
|
|
}
|
2011-07-26 17:17:45 +00:00
|
|
|
|
2012-05-07 02:30:14 +00:00
|
|
|
if (pkg->id == NULL)
|
|
|
|
pkg->id = strdup(pkgdep->package);
|
2011-07-27 01:37:01 +00:00
|
|
|
|
2017-12-05 23:34:01 +00:00
|
|
|
if (pkgconf_pkg_comparator_impls[pkgdep->compare](pkg->version, pkgdep->version) != true)
|
|
|
|
{
|
|
|
|
if (eflags != NULL)
|
|
|
|
*eflags |= PKGCONF_PKG_ERRF_PACKAGE_VER_MISMATCH;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
pkgdep->match = pkgconf_pkg_ref(client, pkg);
|
2012-05-03 17:42:04 +00:00
|
|
|
|
2012-05-03 17:55:06 +00:00
|
|
|
return pkg;
|
2011-07-26 17:17:45 +00:00
|
|
|
}
|
|
|
|
|
2011-07-25 22:44:05 +00:00
|
|
|
/*
|
2016-12-16 05:36:59 +00:00
|
|
|
* !doc
|
|
|
|
*
|
2017-01-20 00:17:29 +00:00
|
|
|
* .. c:function:: unsigned int pkgconf_pkg_verify_graph(pkgconf_client_t *client, pkgconf_pkg_t *root, int depth)
|
2016-12-16 05:36:59 +00:00
|
|
|
*
|
|
|
|
* Verify the graph dependency nodes are satisfiable by walking the tree using
|
|
|
|
* ``pkgconf_pkg_traverse()``.
|
2011-07-25 22:44:05 +00:00
|
|
|
*
|
2016-12-16 05:36:59 +00:00
|
|
|
* :param pkgconf_client_t* client: The pkgconf client object to use for dependency resolution.
|
|
|
|
* :param pkgconf_pkg_t* root: The root entry in the package dependency graph which should contain the top-level dependencies to resolve.
|
|
|
|
* :param int depth: The maximum allowed depth for dependency resolution.
|
|
|
|
* :return: On success, ``PKGCONF_PKG_ERRF_OK`` (0), else an error code.
|
|
|
|
* :rtype: unsigned int
|
2011-07-25 22:44:05 +00:00
|
|
|
*/
|
2012-05-07 02:42:15 +00:00
|
|
|
unsigned int
|
2017-01-20 00:17:29 +00:00
|
|
|
pkgconf_pkg_verify_graph(pkgconf_client_t *client, pkgconf_pkg_t *root, int depth)
|
2011-07-25 22:44:05 +00:00
|
|
|
{
|
2018-03-18 23:04:02 +00:00
|
|
|
return pkgconf_pkg_traverse(client, root, NULL, NULL, depth, 0);
|
2011-07-25 22:44:05 +00:00
|
|
|
}
|
|
|
|
|
2013-02-25 14:56:57 +00:00
|
|
|
static unsigned int
|
2016-12-02 06:29:33 +00:00
|
|
|
pkgconf_pkg_report_graph_error(pkgconf_client_t *client, pkgconf_pkg_t *parent, pkgconf_pkg_t *pkg, pkgconf_dependency_t *node, unsigned int eflags)
|
2012-05-03 17:55:06 +00:00
|
|
|
{
|
2015-09-06 16:45:00 +00:00
|
|
|
if (eflags & PKGCONF_PKG_ERRF_PACKAGE_NOT_FOUND)
|
2012-05-03 17:55:06 +00:00
|
|
|
{
|
2017-09-09 00:48:31 +00:00
|
|
|
if (!(client->flags & PKGCONF_PKG_PKGF_SIMPLIFY_ERRORS) & !client->already_sent_notice)
|
2013-03-16 01:09:54 +00:00
|
|
|
{
|
2016-12-01 21:09:54 +00:00
|
|
|
pkgconf_error(client, "Package %s was not found in the pkg-config search path.\n", node->package);
|
|
|
|
pkgconf_error(client, "Perhaps you should add the directory containing `%s.pc'\n", node->package);
|
|
|
|
pkgconf_error(client, "to the PKG_CONFIG_PATH environment variable\n");
|
2017-09-09 00:48:31 +00:00
|
|
|
client->already_sent_notice = true;
|
2013-03-16 01:09:54 +00:00
|
|
|
}
|
|
|
|
|
2016-12-01 21:09:54 +00:00
|
|
|
pkgconf_error(client, "Package '%s', required by '%s', not found\n", node->package, parent->id);
|
2016-12-02 06:34:48 +00:00
|
|
|
pkgconf_audit_log(client, "%s NOT-FOUND\n", node->package);
|
2012-05-03 17:55:06 +00:00
|
|
|
}
|
2015-09-06 16:45:00 +00:00
|
|
|
else if (eflags & PKGCONF_PKG_ERRF_PACKAGE_VER_MISMATCH)
|
2012-05-03 17:55:06 +00:00
|
|
|
{
|
2016-12-01 21:09:54 +00:00
|
|
|
pkgconf_error(client, "Package dependency requirement '%s %s %s' could not be satisfied.\n",
|
2015-09-06 15:57:26 +00:00
|
|
|
node->package, pkgconf_pkg_get_comparator(node), node->version);
|
2012-05-03 17:55:06 +00:00
|
|
|
|
|
|
|
if (pkg != NULL)
|
2016-12-01 21:09:54 +00:00
|
|
|
pkgconf_error(client, "Package '%s' has version '%s', required version is '%s %s'\n",
|
2015-09-06 15:57:26 +00:00
|
|
|
node->package, pkg->version, pkgconf_pkg_get_comparator(node), node->version);
|
2012-05-03 17:55:06 +00:00
|
|
|
}
|
|
|
|
|
2012-05-07 02:30:35 +00:00
|
|
|
if (pkg != NULL)
|
2016-12-02 06:29:33 +00:00
|
|
|
pkgconf_pkg_unref(client, pkg);
|
2012-05-07 02:30:35 +00:00
|
|
|
|
2012-05-07 02:42:15 +00:00
|
|
|
return eflags;
|
2012-05-03 17:55:06 +00:00
|
|
|
}
|
|
|
|
|
2012-05-07 02:42:15 +00:00
|
|
|
static inline unsigned int
|
2016-12-02 06:29:33 +00:00
|
|
|
pkgconf_pkg_walk_list(pkgconf_client_t *client,
|
2016-12-01 21:05:03 +00:00
|
|
|
pkgconf_pkg_t *parent,
|
2015-09-06 15:31:21 +00:00
|
|
|
pkgconf_list_t *deplist,
|
2015-09-06 16:20:48 +00:00
|
|
|
pkgconf_pkg_traverse_func_t func,
|
2011-07-25 06:22:04 +00:00
|
|
|
void *data,
|
2018-03-18 23:04:02 +00:00
|
|
|
int depth,
|
|
|
|
unsigned int skip_flags)
|
2011-07-25 02:03:17 +00:00
|
|
|
{
|
2015-09-06 16:45:00 +00:00
|
|
|
unsigned int eflags = PKGCONF_PKG_ERRF_OK;
|
2015-09-06 15:31:21 +00:00
|
|
|
pkgconf_node_t *node;
|
2011-07-25 02:03:17 +00:00
|
|
|
|
2015-09-06 15:31:21 +00:00
|
|
|
PKGCONF_FOREACH_LIST_ENTRY(deplist->head, node)
|
2011-07-25 04:20:22 +00:00
|
|
|
{
|
2015-09-06 16:45:00 +00:00
|
|
|
unsigned int eflags_local = PKGCONF_PKG_ERRF_OK;
|
2015-09-06 15:38:30 +00:00
|
|
|
pkgconf_dependency_t *depnode = node->data;
|
2015-09-06 16:20:48 +00:00
|
|
|
pkgconf_pkg_t *pkgdep;
|
2011-07-25 04:20:22 +00:00
|
|
|
|
2013-03-01 17:36:21 +00:00
|
|
|
if (*depnode->package == '\0')
|
2011-07-25 06:03:13 +00:00
|
|
|
continue;
|
|
|
|
|
2017-01-20 00:17:29 +00:00
|
|
|
pkgdep = pkgconf_pkg_verify_dependency(client, depnode, &eflags_local);
|
2013-03-16 01:09:54 +00:00
|
|
|
|
|
|
|
eflags |= eflags_local;
|
2017-01-20 00:17:29 +00:00
|
|
|
if (eflags_local != PKGCONF_PKG_ERRF_OK && !(client->flags & PKGCONF_PKG_PKGF_SKIP_ERRORS))
|
2013-03-16 01:09:54 +00:00
|
|
|
{
|
2016-12-01 21:09:54 +00:00
|
|
|
pkgconf_pkg_report_graph_error(client, parent, pkgdep, depnode, eflags_local);
|
2013-03-16 01:09:54 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (pkgdep == NULL)
|
|
|
|
continue;
|
|
|
|
|
2021-10-07 06:23:35 +00:00
|
|
|
if (pkgdep->serial == client->serial)
|
2013-02-26 05:29:57 +00:00
|
|
|
{
|
2022-06-26 07:22:56 +00:00
|
|
|
pkgdep->hits++;
|
2016-12-02 06:29:33 +00:00
|
|
|
pkgconf_pkg_unref(client, pkgdep);
|
2013-02-24 14:14:23 +00:00
|
|
|
continue;
|
2013-02-26 05:29:57 +00:00
|
|
|
}
|
2011-07-25 04:20:22 +00:00
|
|
|
|
2018-03-18 23:04:02 +00:00
|
|
|
if (skip_flags && (depnode->flags & skip_flags) == skip_flags)
|
|
|
|
{
|
|
|
|
pkgconf_pkg_unref(client, pkgdep);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-12-02 06:34:48 +00:00
|
|
|
pkgconf_audit_log_dependency(client, pkgdep, depnode);
|
2016-07-10 20:20:31 +00:00
|
|
|
|
2022-06-26 07:22:56 +00:00
|
|
|
pkgdep->hits++;
|
2021-10-07 06:23:35 +00:00
|
|
|
pkgdep->serial = client->serial;
|
2022-06-26 06:05:40 +00:00
|
|
|
eflags |= pkgconf_pkg_traverse_main(client, pkgdep, func, data, depth - 1, skip_flags);
|
2016-12-02 06:29:33 +00:00
|
|
|
pkgconf_pkg_unref(client, pkgdep);
|
2011-07-25 04:38:58 +00:00
|
|
|
}
|
2012-05-07 02:42:15 +00:00
|
|
|
|
|
|
|
return eflags;
|
2012-05-02 21:44:58 +00:00
|
|
|
}
|
|
|
|
|
2012-05-12 01:51:13 +00:00
|
|
|
static inline unsigned int
|
2016-12-02 06:29:33 +00:00
|
|
|
pkgconf_pkg_walk_conflicts_list(pkgconf_client_t *client,
|
2017-01-20 00:17:29 +00:00
|
|
|
pkgconf_pkg_t *root, pkgconf_list_t *deplist)
|
2012-05-12 01:51:13 +00:00
|
|
|
{
|
|
|
|
unsigned int eflags;
|
2015-09-06 15:31:21 +00:00
|
|
|
pkgconf_node_t *node, *childnode;
|
2012-05-12 01:51:13 +00:00
|
|
|
|
2015-09-06 15:31:21 +00:00
|
|
|
PKGCONF_FOREACH_LIST_ENTRY(deplist->head, node)
|
2012-05-12 01:51:13 +00:00
|
|
|
{
|
2015-09-06 15:38:30 +00:00
|
|
|
pkgconf_dependency_t *parentnode = node->data;
|
2013-03-01 17:36:21 +00:00
|
|
|
|
|
|
|
if (*parentnode->package == '\0')
|
2012-05-12 01:51:13 +00:00
|
|
|
continue;
|
|
|
|
|
2017-12-12 06:21:21 +00:00
|
|
|
PKGCONF_FOREACH_LIST_ENTRY(root->required.head, childnode)
|
2012-05-12 01:51:13 +00:00
|
|
|
{
|
2015-09-06 16:20:48 +00:00
|
|
|
pkgconf_pkg_t *pkgdep;
|
2015-09-06 15:38:30 +00:00
|
|
|
pkgconf_dependency_t *depnode = childnode->data;
|
2012-05-12 02:00:01 +00:00
|
|
|
|
2013-03-01 17:36:21 +00:00
|
|
|
if (*depnode->package == '\0' || strcmp(depnode->package, parentnode->package))
|
2012-07-30 07:46:03 +00:00
|
|
|
continue;
|
2012-05-12 02:20:00 +00:00
|
|
|
|
2017-01-20 00:17:29 +00:00
|
|
|
pkgdep = pkgconf_pkg_verify_dependency(client, parentnode, &eflags);
|
2015-09-06 16:45:00 +00:00
|
|
|
if (eflags == PKGCONF_PKG_ERRF_OK)
|
2012-07-30 07:46:03 +00:00
|
|
|
{
|
2016-12-01 21:09:54 +00:00
|
|
|
pkgconf_error(client, "Version '%s' of '%s' conflicts with '%s' due to satisfying conflict rule '%s %s%s%s'.\n",
|
2015-09-06 15:57:26 +00:00
|
|
|
pkgdep->version, pkgdep->realname, root->realname, parentnode->package, pkgconf_pkg_get_comparator(parentnode),
|
2013-03-01 17:36:21 +00:00
|
|
|
parentnode->version != NULL ? " " : "", parentnode->version != NULL ? parentnode->version : "");
|
2017-12-06 00:04:42 +00:00
|
|
|
|
|
|
|
if (!(client->flags & PKGCONF_PKG_PKGF_SIMPLIFY_ERRORS))
|
|
|
|
{
|
|
|
|
pkgconf_error(client, "It may be possible to ignore this conflict and continue, try the\n");
|
|
|
|
pkgconf_error(client, "PKG_CONFIG_IGNORE_CONFLICTS environment variable.\n");
|
|
|
|
}
|
2012-05-12 01:51:13 +00:00
|
|
|
|
2016-12-02 06:29:33 +00:00
|
|
|
pkgconf_pkg_unref(client, pkgdep);
|
2012-07-30 07:46:03 +00:00
|
|
|
|
2015-09-06 16:45:00 +00:00
|
|
|
return PKGCONF_PKG_ERRF_PACKAGE_CONFLICT;
|
2012-07-30 07:46:03 +00:00
|
|
|
}
|
|
|
|
|
2016-12-02 06:29:33 +00:00
|
|
|
pkgconf_pkg_unref(client, pkgdep);
|
2012-07-30 07:46:03 +00:00
|
|
|
}
|
2012-05-12 01:51:13 +00:00
|
|
|
}
|
|
|
|
|
2015-09-06 16:45:00 +00:00
|
|
|
return PKGCONF_PKG_ERRF_OK;
|
2012-05-12 01:51:13 +00:00
|
|
|
}
|
|
|
|
|
2012-05-02 21:44:58 +00:00
|
|
|
/*
|
2016-12-16 05:36:59 +00:00
|
|
|
* !doc
|
|
|
|
*
|
2018-03-18 23:04:02 +00:00
|
|
|
* .. c:function:: 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)
|
2016-12-16 05:36:59 +00:00
|
|
|
*
|
|
|
|
* Walk and resolve the dependency graph up to `maxdepth` levels.
|
|
|
|
*
|
|
|
|
* :param pkgconf_client_t* client: The pkgconf client object to use for dependency resolution.
|
|
|
|
* :param pkgconf_pkg_t* root: The root of the dependency graph.
|
|
|
|
* :param pkgconf_pkg_traverse_func_t func: A traversal function to call for each resolved node in the dependency graph.
|
|
|
|
* :param void* data: An opaque pointer to data to be passed to the traversal function.
|
|
|
|
* :param int maxdepth: The maximum depth to walk the dependency graph for. -1 means infinite recursion.
|
2018-03-18 23:04:02 +00:00
|
|
|
* :param uint skip_flags: Skip over dependency nodes containing the specified flags. A setting of 0 skips no dependency nodes.
|
2016-12-16 05:36:59 +00:00
|
|
|
* :return: ``PKGCONF_PKG_ERRF_OK`` on success, else an error code.
|
|
|
|
* :rtype: unsigned int
|
2012-05-02 21:44:58 +00:00
|
|
|
*/
|
2022-06-26 06:05:40 +00:00
|
|
|
static unsigned int
|
|
|
|
pkgconf_pkg_traverse_main(pkgconf_client_t *client,
|
2016-12-01 21:05:03 +00:00
|
|
|
pkgconf_pkg_t *root,
|
2015-09-06 16:20:48 +00:00
|
|
|
pkgconf_pkg_traverse_func_t func,
|
2012-05-02 21:44:58 +00:00
|
|
|
void *data,
|
2018-03-18 23:04:02 +00:00
|
|
|
int maxdepth,
|
|
|
|
unsigned int skip_flags)
|
2012-05-02 21:44:58 +00:00
|
|
|
{
|
2015-09-06 16:45:00 +00:00
|
|
|
unsigned int eflags = PKGCONF_PKG_ERRF_OK;
|
2012-05-07 02:42:15 +00:00
|
|
|
|
2012-05-02 21:44:58 +00:00
|
|
|
if (maxdepth == 0)
|
2012-05-07 02:42:15 +00:00
|
|
|
return eflags;
|
2012-05-02 21:44:58 +00:00
|
|
|
|
2022-06-26 06:05:40 +00:00
|
|
|
PKGCONF_TRACE(client, "%s: level %d, serial %lu", root->id, maxdepth, client->serial);
|
2017-03-24 05:59:53 +00:00
|
|
|
|
2017-01-22 10:23:24 +00:00
|
|
|
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)
|
2012-08-08 15:20:08 +00:00
|
|
|
{
|
|
|
|
if (func != NULL)
|
2017-01-20 00:17:29 +00:00
|
|
|
func(client, root, data);
|
2012-08-08 15:20:08 +00:00
|
|
|
}
|
|
|
|
|
2017-01-20 00:17:29 +00:00
|
|
|
if (!(client->flags & PKGCONF_PKG_PKGF_SKIP_CONFLICTS))
|
2012-05-12 01:51:13 +00:00
|
|
|
{
|
2017-01-20 00:17:29 +00:00
|
|
|
eflags = pkgconf_pkg_walk_conflicts_list(client, root, &root->conflicts);
|
2015-09-06 16:45:00 +00:00
|
|
|
if (eflags != PKGCONF_PKG_ERRF_OK)
|
2012-05-12 01:51:13 +00:00
|
|
|
return eflags;
|
|
|
|
}
|
|
|
|
|
2017-02-25 21:53:50 +00:00
|
|
|
PKGCONF_TRACE(client, "%s: walking requires list", root->id);
|
2018-03-18 23:04:02 +00:00
|
|
|
eflags = pkgconf_pkg_walk_list(client, root, &root->required, func, data, maxdepth, skip_flags);
|
2015-09-06 16:45:00 +00:00
|
|
|
if (eflags != PKGCONF_PKG_ERRF_OK)
|
2012-05-07 02:42:15 +00:00
|
|
|
return eflags;
|
2011-07-25 04:20:22 +00:00
|
|
|
|
2017-01-20 00:17:29 +00:00
|
|
|
if (client->flags & PKGCONF_PKG_PKGF_SEARCH_PRIVATE)
|
2012-05-07 02:42:15 +00:00
|
|
|
{
|
2017-02-25 21:53:50 +00:00
|
|
|
PKGCONF_TRACE(client, "%s: walking requires.private list", root->id);
|
|
|
|
|
2017-01-20 00:17:29 +00:00
|
|
|
/* XXX: ugly */
|
|
|
|
client->flags |= PKGCONF_PKG_PKGF_ITER_PKG_IS_PRIVATE;
|
2018-03-18 23:04:02 +00:00
|
|
|
eflags = pkgconf_pkg_walk_list(client, root, &root->requires_private, func, data, maxdepth, skip_flags);
|
2017-01-20 00:17:29 +00:00
|
|
|
client->flags &= ~PKGCONF_PKG_PKGF_ITER_PKG_IS_PRIVATE;
|
|
|
|
|
2015-09-06 16:45:00 +00:00
|
|
|
if (eflags != PKGCONF_PKG_ERRF_OK)
|
2012-05-07 02:42:15 +00:00
|
|
|
return eflags;
|
|
|
|
}
|
2012-05-02 21:47:02 +00:00
|
|
|
|
2012-05-07 02:42:15 +00:00
|
|
|
return eflags;
|
2011-07-25 04:38:58 +00:00
|
|
|
}
|
2012-05-12 01:13:03 +00:00
|
|
|
|
2022-06-26 06:05:40 +00:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
client->serial++;
|
|
|
|
|
|
|
|
return pkgconf_pkg_traverse_main(client, root, func, data, maxdepth, skip_flags);
|
|
|
|
}
|
|
|
|
|
2012-05-12 01:13:03 +00:00
|
|
|
static void
|
2017-01-20 00:17:29 +00:00
|
|
|
pkgconf_pkg_cflags_collect(pkgconf_client_t *client, pkgconf_pkg_t *pkg, void *data)
|
2012-05-12 01:13:03 +00:00
|
|
|
{
|
2015-09-06 15:31:21 +00:00
|
|
|
pkgconf_list_t *list = data;
|
|
|
|
pkgconf_node_t *node;
|
2012-05-12 01:13:03 +00:00
|
|
|
|
2015-09-06 15:31:21 +00:00
|
|
|
PKGCONF_FOREACH_LIST_ENTRY(pkg->cflags.head, node)
|
2013-03-01 17:10:43 +00:00
|
|
|
{
|
2015-09-06 15:44:10 +00:00
|
|
|
pkgconf_fragment_t *frag = node->data;
|
2017-01-20 00:23:25 +00:00
|
|
|
pkgconf_fragment_copy(client, list, frag, false);
|
2013-03-01 17:10:43 +00:00
|
|
|
}
|
2012-05-12 01:13:03 +00:00
|
|
|
}
|
|
|
|
|
2013-08-14 05:36:43 +00:00
|
|
|
static void
|
2017-01-20 00:17:29 +00:00
|
|
|
pkgconf_pkg_cflags_private_collect(pkgconf_client_t *client, pkgconf_pkg_t *pkg, void *data)
|
2013-08-14 05:36:43 +00:00
|
|
|
{
|
2015-09-06 15:31:21 +00:00
|
|
|
pkgconf_list_t *list = data;
|
|
|
|
pkgconf_node_t *node;
|
2013-08-14 05:36:43 +00:00
|
|
|
|
2015-09-06 15:31:21 +00:00
|
|
|
PKGCONF_FOREACH_LIST_ENTRY(pkg->cflags_private.head, node)
|
2013-08-14 05:36:43 +00:00
|
|
|
{
|
2015-09-06 15:44:10 +00:00
|
|
|
pkgconf_fragment_t *frag = node->data;
|
2017-01-20 00:23:25 +00:00
|
|
|
pkgconf_fragment_copy(client, list, frag, true);
|
2013-08-14 05:36:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-16 05:36:59 +00:00
|
|
|
/*
|
|
|
|
* !doc
|
|
|
|
*
|
2017-01-20 00:17:29 +00:00
|
|
|
* .. c:function:: int pkgconf_pkg_cflags(pkgconf_client_t *client, pkgconf_pkg_t *root, pkgconf_list_t *list, int maxdepth)
|
2016-12-16 05:36:59 +00:00
|
|
|
*
|
|
|
|
* Walks a dependency graph and extracts relevant ``CFLAGS`` fragments.
|
|
|
|
*
|
|
|
|
* :param pkgconf_client_t* client: The pkgconf client object to use for dependency resolution.
|
|
|
|
* :param pkgconf_pkg_t* root: The root of the dependency graph.
|
|
|
|
* :param pkgconf_list_t* list: The fragment list to add the extracted ``CFLAGS`` fragments to.
|
|
|
|
* :param int maxdepth: The maximum allowed depth for dependency resolution. -1 means infinite recursion.
|
|
|
|
* :return: ``PKGCONF_PKG_ERRF_OK`` if successful, otherwise an error code.
|
|
|
|
* :rtype: unsigned int
|
|
|
|
*/
|
|
|
|
unsigned int
|
2017-01-20 00:17:29 +00:00
|
|
|
pkgconf_pkg_cflags(pkgconf_client_t *client, pkgconf_pkg_t *root, pkgconf_list_t *list, int maxdepth)
|
2012-05-12 01:13:03 +00:00
|
|
|
{
|
2016-12-16 05:36:59 +00:00
|
|
|
unsigned int eflag;
|
2018-03-18 23:04:02 +00:00
|
|
|
unsigned int skip_flags = (client->flags & PKGCONF_PKG_PKGF_DONT_FILTER_INTERNAL_CFLAGS) == 0 ? PKGCONF_PKG_DEPF_INTERNAL : 0;
|
2019-01-14 19:48:23 +00:00
|
|
|
pkgconf_list_t frags = PKGCONF_LIST_INITIALIZER;
|
2012-08-12 10:32:31 +00:00
|
|
|
|
2019-01-14 19:48:23 +00:00
|
|
|
eflag = pkgconf_pkg_traverse(client, root, pkgconf_pkg_cflags_collect, &frags, maxdepth, skip_flags);
|
2012-05-12 01:13:03 +00:00
|
|
|
|
2019-01-14 19:48:23 +00:00
|
|
|
if (eflag == PKGCONF_PKG_ERRF_OK && client->flags & PKGCONF_PKG_PKGF_MERGE_PRIVATE_FRAGMENTS)
|
|
|
|
eflag = pkgconf_pkg_traverse(client, root, pkgconf_pkg_cflags_private_collect, &frags, maxdepth, skip_flags);
|
|
|
|
|
|
|
|
if (eflag != PKGCONF_PKG_ERRF_OK)
|
2013-08-14 05:36:43 +00:00
|
|
|
{
|
2019-01-14 19:48:23 +00:00
|
|
|
pkgconf_fragment_free(&frags);
|
|
|
|
return eflag;
|
2013-08-14 05:36:43 +00:00
|
|
|
}
|
|
|
|
|
2019-01-14 19:48:23 +00:00
|
|
|
pkgconf_fragment_copy_list(client, list, &frags);
|
|
|
|
pkgconf_fragment_free(&frags);
|
|
|
|
|
2012-08-20 20:47:10 +00:00
|
|
|
return eflag;
|
2012-05-12 01:13:03 +00:00
|
|
|
}
|
|
|
|
|
2012-05-12 01:16:22 +00:00
|
|
|
static void
|
2017-01-20 00:17:29 +00:00
|
|
|
pkgconf_pkg_libs_collect(pkgconf_client_t *client, pkgconf_pkg_t *pkg, void *data)
|
2012-05-12 01:16:22 +00:00
|
|
|
{
|
2015-09-06 15:31:21 +00:00
|
|
|
pkgconf_list_t *list = data;
|
|
|
|
pkgconf_node_t *node;
|
2012-05-12 01:16:22 +00:00
|
|
|
|
2015-09-06 15:31:21 +00:00
|
|
|
PKGCONF_FOREACH_LIST_ENTRY(pkg->libs.head, node)
|
2013-03-01 17:10:43 +00:00
|
|
|
{
|
2015-09-06 15:44:10 +00:00
|
|
|
pkgconf_fragment_t *frag = node->data;
|
2017-01-20 00:23:25 +00:00
|
|
|
pkgconf_fragment_copy(client, list, frag, (client->flags & PKGCONF_PKG_PKGF_ITER_PKG_IS_PRIVATE) != 0);
|
2013-03-01 17:10:43 +00:00
|
|
|
}
|
2012-08-08 16:15:13 +00:00
|
|
|
|
2017-01-20 00:17:29 +00:00
|
|
|
if (client->flags & PKGCONF_PKG_PKGF_MERGE_PRIVATE_FRAGMENTS)
|
2013-03-01 17:10:43 +00:00
|
|
|
{
|
2015-09-06 15:31:21 +00:00
|
|
|
PKGCONF_FOREACH_LIST_ENTRY(pkg->libs_private.head, node)
|
2015-05-22 03:14:37 +00:00
|
|
|
{
|
2015-09-06 15:44:10 +00:00
|
|
|
pkgconf_fragment_t *frag = node->data;
|
2017-01-20 00:23:25 +00:00
|
|
|
pkgconf_fragment_copy(client, list, frag, true);
|
2015-05-22 03:14:37 +00:00
|
|
|
}
|
2013-03-01 17:10:43 +00:00
|
|
|
}
|
2012-05-12 01:16:22 +00:00
|
|
|
}
|
|
|
|
|
2016-12-16 05:36:59 +00:00
|
|
|
/*
|
|
|
|
* !doc
|
|
|
|
*
|
2017-01-20 00:17:29 +00:00
|
|
|
* .. c:function:: int pkgconf_pkg_libs(pkgconf_client_t *client, pkgconf_pkg_t *root, pkgconf_list_t *list, int maxdepth)
|
2016-12-16 05:36:59 +00:00
|
|
|
*
|
|
|
|
* Walks a dependency graph and extracts relevant ``LIBS`` fragments.
|
|
|
|
*
|
|
|
|
* :param pkgconf_client_t* client: The pkgconf client object to use for dependency resolution.
|
|
|
|
* :param pkgconf_pkg_t* root: The root of the dependency graph.
|
|
|
|
* :param pkgconf_list_t* list: The fragment list to add the extracted ``LIBS`` fragments to.
|
|
|
|
* :param int maxdepth: The maximum allowed depth for dependency resolution. -1 means infinite recursion.
|
|
|
|
* :return: ``PKGCONF_PKG_ERRF_OK`` if successful, otherwise an error code.
|
|
|
|
* :rtype: unsigned int
|
|
|
|
*/
|
|
|
|
unsigned int
|
2017-01-20 00:17:29 +00:00
|
|
|
pkgconf_pkg_libs(pkgconf_client_t *client, pkgconf_pkg_t *root, pkgconf_list_t *list, int maxdepth)
|
2012-05-12 01:16:22 +00:00
|
|
|
{
|
2016-12-16 05:36:59 +00:00
|
|
|
unsigned int eflag;
|
2012-08-12 10:32:31 +00:00
|
|
|
|
2018-03-18 23:04:02 +00:00
|
|
|
eflag = pkgconf_pkg_traverse(client, root, pkgconf_pkg_libs_collect, list, maxdepth, 0);
|
2012-08-12 10:32:31 +00:00
|
|
|
|
2015-09-06 16:45:00 +00:00
|
|
|
if (eflag != PKGCONF_PKG_ERRF_OK)
|
2012-08-12 10:32:31 +00:00
|
|
|
{
|
2015-09-06 15:44:10 +00:00
|
|
|
pkgconf_fragment_free(list);
|
2012-08-20 20:47:10 +00:00
|
|
|
return eflag;
|
2012-08-12 10:32:31 +00:00
|
|
|
}
|
2012-05-12 01:16:22 +00:00
|
|
|
|
2012-08-20 20:47:10 +00:00
|
|
|
return eflag;
|
2012-05-12 01:16:22 +00:00
|
|
|
}
|