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
|
|
|
*/
|
|
|
|
|
2015-09-06 14:35:08 +00:00
|
|
|
#include <libpkgconf/libpkgconf.h>
|
2011-07-25 02:03:17 +00:00
|
|
|
|
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"
|
2012-05-07 08:09:59 +00:00
|
|
|
#endif
|
|
|
|
|
2012-02-17 21:35:23 +00:00
|
|
|
#define PKG_CONFIG_EXT ".pc"
|
|
|
|
#define PKG_CONFIG_PATH_SZ (65535)
|
|
|
|
|
2012-05-02 09:24:58 +00:00
|
|
|
/* pkg-config uses ';' on win32 as ':' is part of path */
|
2012-05-02 19:07:38 +00:00
|
|
|
#ifdef _WIN32
|
2012-05-02 09:24:58 +00:00
|
|
|
#define PKG_CONFIG_PATH_SEP_S ";"
|
|
|
|
#else
|
|
|
|
#define PKG_CONFIG_PATH_SEP_S ":"
|
|
|
|
#endif
|
|
|
|
|
2012-08-14 14:04:56 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
#define PKG_DIR_SEP_S '\\'
|
|
|
|
#else
|
|
|
|
#define PKG_DIR_SEP_S '/'
|
|
|
|
#endif
|
|
|
|
|
2013-03-15 22:55:44 +00:00
|
|
|
typedef struct {
|
|
|
|
char *path;
|
2015-09-06 15:31:21 +00:00
|
|
|
pkgconf_node_t node;
|
2013-03-15 22:55:44 +00:00
|
|
|
} pkg_path_t;
|
|
|
|
|
2013-03-15 23:11:43 +00:00
|
|
|
static inline void
|
2015-09-06 15:31:21 +00:00
|
|
|
path_add(const char *text, pkgconf_list_t *dirlist)
|
2013-03-15 23:11:43 +00:00
|
|
|
{
|
|
|
|
pkg_path_t *pkg_path;
|
|
|
|
|
|
|
|
pkg_path = calloc(sizeof(pkg_path_t), 1);
|
|
|
|
pkg_path->path = strdup(text);
|
|
|
|
|
2015-09-06 15:31:21 +00:00
|
|
|
pkgconf_node_insert_tail(&pkg_path->node, pkg_path, dirlist);
|
2013-03-15 23:11:43 +00:00
|
|
|
}
|
|
|
|
|
2012-05-02 19:06:32 +00:00
|
|
|
static inline size_t
|
2015-09-06 15:31:21 +00:00
|
|
|
path_split(const char *text, pkgconf_list_t *dirlist)
|
2012-05-02 18:38:31 +00:00
|
|
|
{
|
2012-05-02 19:06:32 +00:00
|
|
|
size_t count = 0;
|
|
|
|
char *workbuf, *p, *iter;
|
2012-05-02 18:38:31 +00:00
|
|
|
|
|
|
|
if (text == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2012-05-02 19:06:32 +00:00
|
|
|
iter = workbuf = strdup(text);
|
2012-05-02 19:07:38 +00:00
|
|
|
while ((p = strtok(iter, PKG_CONFIG_PATH_SEP_S)) != NULL)
|
2012-05-02 18:38:31 +00:00
|
|
|
{
|
2013-03-15 23:11:43 +00:00
|
|
|
path_add(p, dirlist);
|
2013-03-15 22:55:44 +00:00
|
|
|
|
|
|
|
count++, iter = NULL;
|
2012-05-02 18:38:31 +00:00
|
|
|
}
|
2012-05-02 19:06:32 +00:00
|
|
|
free(workbuf);
|
2012-05-02 18:38:31 +00:00
|
|
|
|
2012-05-06 01:21:47 +00:00
|
|
|
return count;
|
2012-05-02 18:38:31 +00:00
|
|
|
}
|
|
|
|
|
2012-05-07 02:09:26 +00:00
|
|
|
static inline void
|
2015-09-06 15:31:21 +00:00
|
|
|
path_free(pkgconf_list_t *dirlist)
|
2012-05-07 02:09:26 +00:00
|
|
|
{
|
2015-09-06 15:31:21 +00:00
|
|
|
pkgconf_node_t *n, *tn;
|
2012-05-07 02:09:26 +00:00
|
|
|
|
2015-09-06 15:31:21 +00:00
|
|
|
PKGCONF_FOREACH_LIST_ENTRY_SAFE(dirlist->head, tn, n)
|
2013-03-15 22:55:44 +00:00
|
|
|
{
|
|
|
|
pkg_path_t *pkg_path = n->data;
|
2012-05-07 02:09:26 +00:00
|
|
|
|
2013-03-15 22:55:44 +00:00
|
|
|
free(pkg_path->path);
|
|
|
|
free(pkg_path);
|
|
|
|
}
|
2012-05-07 02:09:26 +00:00
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2012-05-12 07:21:11 +00:00
|
|
|
static inline const char *
|
|
|
|
get_pkgconfig_path(void)
|
|
|
|
{
|
|
|
|
const char *env_path;
|
2012-05-12 07:26:55 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
static char outbuf[MAX_PATH];
|
|
|
|
char namebuf[MAX_PATH];
|
|
|
|
char *p;
|
|
|
|
#endif
|
2012-05-12 07:21:11 +00:00
|
|
|
|
|
|
|
env_path = getenv("PKG_CONFIG_LIBDIR");
|
|
|
|
if (env_path != NULL)
|
|
|
|
return env_path;
|
|
|
|
|
2012-05-12 07:26:55 +00:00
|
|
|
#ifdef _WIN32
|
2014-08-08 09:19:34 +00:00
|
|
|
int sizepath = GetModuleFileName(NULL, namebuf, sizeof namebuf);
|
|
|
|
char * winslash;
|
|
|
|
namebuf[sizepath] = '\0';
|
|
|
|
while ((winslash = strchr (namebuf, '\\')) != NULL)
|
|
|
|
{
|
|
|
|
*winslash = '/';
|
|
|
|
}
|
|
|
|
p = strrchr(namebuf, '/');
|
2012-05-12 07:26:55 +00:00
|
|
|
if (p == NULL)
|
|
|
|
return PKG_DEFAULT_PATH;
|
|
|
|
|
|
|
|
*p = '\0';
|
|
|
|
strlcpy(outbuf, namebuf, sizeof outbuf);
|
2014-08-08 09:19:34 +00:00
|
|
|
strlcat(outbuf, "/", sizeof outbuf);
|
2012-07-02 03:41:08 +00:00
|
|
|
strlcat(outbuf, "../lib/pkgconfig", sizeof outbuf);
|
2014-08-08 09:19:34 +00:00
|
|
|
strlcat(outbuf, ";", sizeof outbuf);
|
2012-07-02 03:41:08 +00:00
|
|
|
strlcat(outbuf, namebuf, sizeof outbuf);
|
2014-08-08 09:19:34 +00:00
|
|
|
strlcat(outbuf, "/", sizeof outbuf);
|
2012-07-02 03:41:08 +00:00
|
|
|
strlcat(outbuf, "../share/pkgconfig", sizeof outbuf);
|
2012-05-12 07:26:55 +00:00
|
|
|
|
|
|
|
return outbuf;
|
|
|
|
#endif
|
|
|
|
|
2012-05-12 07:21:11 +00:00
|
|
|
return PKG_DEFAULT_PATH;
|
|
|
|
}
|
|
|
|
|
2012-07-21 19:49:55 +00:00
|
|
|
static const char *
|
|
|
|
pkg_get_parent_dir(pkg_t *pkg)
|
|
|
|
{
|
|
|
|
static char buf[PKG_BUFSIZE];
|
|
|
|
char *pathbuf;
|
|
|
|
|
2012-08-14 14:04:56 +00:00
|
|
|
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
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2015-09-06 15:31:21 +00:00
|
|
|
static pkgconf_list_t pkg_dir_list = PKGCONF_LIST_INITIALIZER;
|
2013-03-15 23:11:43 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
pkg_dir_list_build(unsigned int flags)
|
|
|
|
{
|
|
|
|
const char *env_path;
|
|
|
|
|
|
|
|
if (pkg_dir_list.head != NULL || pkg_dir_list.tail != NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* PKG_CONFIG_PATH has to take precedence */
|
|
|
|
env_path = getenv("PKG_CONFIG_PATH");
|
|
|
|
if (env_path)
|
|
|
|
path_split(env_path, &pkg_dir_list);
|
|
|
|
|
|
|
|
if (!(flags & PKGF_ENV_ONLY))
|
|
|
|
{
|
|
|
|
env_path = get_pkgconfig_path();
|
|
|
|
path_split(env_path, &pkg_dir_list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
pkg_dir_list_free(void)
|
|
|
|
{
|
|
|
|
path_free(&pkg_dir_list);
|
|
|
|
}
|
|
|
|
|
2012-05-07 04:00:06 +00:00
|
|
|
/*
|
2013-02-24 14:58:35 +00:00
|
|
|
* pkg_new_from_file(filename, file, flags)
|
2012-05-07 04:00:06 +00:00
|
|
|
*
|
|
|
|
* Parse a .pc file into a pkg_t object structure.
|
|
|
|
*/
|
|
|
|
pkg_t *
|
2013-02-24 14:58:35 +00:00
|
|
|
pkg_new_from_file(const char *filename, FILE *f, unsigned int flags)
|
2012-05-07 04:00:06 +00:00
|
|
|
{
|
|
|
|
pkg_t *pkg;
|
2012-07-21 19:38:13 +00:00
|
|
|
char readbuf[PKG_BUFSIZE];
|
2012-07-26 05:12:29 +00:00
|
|
|
char *idptr;
|
2012-05-07 04:00:06 +00:00
|
|
|
|
|
|
|
pkg = calloc(sizeof(pkg_t), 1);
|
|
|
|
pkg->filename = strdup(filename);
|
2015-09-06 15:41:40 +00:00
|
|
|
pkgconf_tuple_add(&pkg->vars, "pcfiledir", pkg_get_parent_dir(pkg));
|
2012-05-07 04:00:06 +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++;
|
|
|
|
else
|
|
|
|
idptr = pkg->filename;
|
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';
|
|
|
|
|
2012-07-21 19:38:13 +00:00
|
|
|
while (pkg_fgetline(readbuf, PKG_BUFSIZE, f) != NULL)
|
2012-05-07 04:00:06 +00:00
|
|
|
{
|
2012-08-14 14:16:06 +00:00
|
|
|
char op, *p, *key, *value;
|
2012-05-07 04:00:06 +00:00
|
|
|
|
|
|
|
p = readbuf;
|
|
|
|
while (*p && (isalpha(*p) || isdigit(*p) || *p == '_' || *p == '.'))
|
|
|
|
p++;
|
|
|
|
|
2012-08-14 14:16:06 +00:00
|
|
|
key = readbuf;
|
2012-05-07 04:00:06 +00:00
|
|
|
if (!isalpha(*key) && !isdigit(*p))
|
2012-08-14 14:16:06 +00:00
|
|
|
continue;
|
2012-05-07 04:00:06 +00:00
|
|
|
|
2012-08-14 14:16:06 +00:00
|
|
|
while (*p && isspace(*p)) {
|
|
|
|
/* set to null to avoid trailing spaces in key */
|
|
|
|
*p = '\0';
|
2012-05-07 04:00:06 +00:00
|
|
|
p++;
|
2012-08-14 14:16:06 +00:00
|
|
|
}
|
2012-05-07 04:00:06 +00:00
|
|
|
|
2012-08-14 14:16:06 +00:00
|
|
|
op = *p;
|
|
|
|
*p = '\0';
|
|
|
|
p++;
|
2012-05-07 04:00:06 +00:00
|
|
|
|
|
|
|
while (*p && isspace(*p))
|
|
|
|
p++;
|
|
|
|
|
2012-08-14 14:16:06 +00:00
|
|
|
value = p;
|
2012-05-07 04:00:06 +00:00
|
|
|
|
|
|
|
switch (op)
|
|
|
|
{
|
|
|
|
case ':':
|
2014-02-10 23:57:50 +00:00
|
|
|
if (!strcmp(key, "Name"))
|
2015-09-06 15:41:40 +00:00
|
|
|
pkg->realname = pkgconf_tuple_parse(&pkg->vars, value);
|
2014-02-10 23:57:50 +00:00
|
|
|
else if (!strcmp(key, "Description"))
|
2015-09-06 15:41:40 +00:00
|
|
|
pkg->description = pkgconf_tuple_parse(&pkg->vars, value);
|
2014-02-10 23:57:50 +00:00
|
|
|
else if (!strcmp(key, "Version"))
|
2015-09-06 15:41:40 +00:00
|
|
|
pkg->version = pkgconf_tuple_parse(&pkg->vars, value);
|
2012-05-07 04:00:06 +00:00
|
|
|
else if (!strcasecmp(key, "CFLAGS"))
|
2015-09-06 15:44:10 +00:00
|
|
|
pkgconf_fragment_parse(&pkg->cflags, &pkg->vars, value, flags);
|
2013-08-14 05:36:43 +00:00
|
|
|
else if (!strcasecmp(key, "CFLAGS.private"))
|
2015-09-06 15:44:10 +00:00
|
|
|
pkgconf_fragment_parse(&pkg->cflags_private, &pkg->vars, value, flags);
|
2012-05-07 04:00:06 +00:00
|
|
|
else if (!strcasecmp(key, "LIBS"))
|
2015-09-06 15:44:10 +00:00
|
|
|
pkgconf_fragment_parse(&pkg->libs, &pkg->vars, value, flags);
|
2012-05-07 04:00:06 +00:00
|
|
|
else if (!strcasecmp(key, "LIBS.private"))
|
2015-09-06 15:44:10 +00:00
|
|
|
pkgconf_fragment_parse(&pkg->libs_private, &pkg->vars, value, flags);
|
2014-02-10 23:57:50 +00:00
|
|
|
else if (!strcmp(key, "Requires"))
|
2015-09-06 15:38:30 +00:00
|
|
|
pkgconf_dependency_parse(pkg, &pkg->requires, value);
|
2014-02-10 23:57:50 +00:00
|
|
|
else if (!strcmp(key, "Requires.private"))
|
2015-09-06 15:38:30 +00:00
|
|
|
pkgconf_dependency_parse(pkg, &pkg->requires_private, value);
|
2014-02-10 23:57:50 +00:00
|
|
|
else if (!strcmp(key, "Conflicts"))
|
2015-09-06 15:38:30 +00:00
|
|
|
pkgconf_dependency_parse(pkg, &pkg->conflicts, value);
|
2012-05-07 04:00:06 +00:00
|
|
|
break;
|
|
|
|
case '=':
|
2015-09-06 15:41:40 +00:00
|
|
|
pkgconf_tuple_add(&pkg->vars, key, value);
|
2012-05-07 04:00:06 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(f);
|
2013-02-26 05:29:57 +00:00
|
|
|
return pkg_ref(pkg);
|
2012-05-07 04:00:06 +00:00
|
|
|
}
|
|
|
|
|
2012-05-07 01:30:50 +00:00
|
|
|
void
|
|
|
|
pkg_free(pkg_t *pkg)
|
|
|
|
{
|
2012-07-23 04:16:39 +00:00
|
|
|
if (pkg == NULL || pkg->flags & PKG_PROPF_VIRTUAL)
|
2012-05-07 02:09:26 +00:00
|
|
|
return;
|
|
|
|
|
2013-02-26 04:40:30 +00:00
|
|
|
pkg_cache_remove(pkg);
|
2013-02-24 14:14:23 +00:00
|
|
|
|
2015-09-06 15:38:30 +00:00
|
|
|
pkgconf_dependency_free(&pkg->requires);
|
|
|
|
pkgconf_dependency_free(&pkg->requires_private);
|
|
|
|
pkgconf_dependency_free(&pkg->conflicts);
|
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
|
|
|
|
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);
|
|
|
|
|
|
|
|
free(pkg);
|
|
|
|
}
|
|
|
|
|
2013-02-26 05:29:57 +00:00
|
|
|
pkg_t *
|
|
|
|
pkg_ref(pkg_t *pkg)
|
|
|
|
{
|
|
|
|
pkg->refcount++;
|
|
|
|
return pkg;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
pkg_unref(pkg_t *pkg)
|
|
|
|
{
|
|
|
|
pkg->refcount--;
|
|
|
|
if (pkg->refcount <= 0)
|
|
|
|
pkg_free(pkg);
|
|
|
|
}
|
|
|
|
|
2012-05-07 08:57:28 +00:00
|
|
|
static inline pkg_t *
|
|
|
|
pkg_try_specific_path(const char *path, const char *name, unsigned int flags)
|
|
|
|
{
|
|
|
|
pkg_t *pkg = NULL;
|
|
|
|
FILE *f;
|
|
|
|
char locbuf[PKG_CONFIG_PATH_SZ];
|
|
|
|
char uninst_locbuf[PKG_CONFIG_PATH_SZ];
|
|
|
|
|
|
|
|
snprintf(locbuf, sizeof locbuf, "%s/%s" PKG_CONFIG_EXT, path, name);
|
|
|
|
snprintf(uninst_locbuf, sizeof uninst_locbuf, "%s/%s-uninstalled" PKG_CONFIG_EXT, path, name);
|
|
|
|
|
|
|
|
if (!(flags & PKGF_NO_UNINSTALLED) && (f = fopen(uninst_locbuf, "r")) != NULL)
|
|
|
|
{
|
2013-02-24 14:58:35 +00:00
|
|
|
pkg = pkg_new_from_file(uninst_locbuf, f, flags);
|
2013-03-01 18:06:52 +00:00
|
|
|
pkg->flags |= PKG_PROPF_UNINSTALLED;
|
2012-05-07 08:57:28 +00:00
|
|
|
}
|
|
|
|
else if ((f = fopen(locbuf, "r")) != NULL)
|
2013-02-24 14:58:35 +00:00
|
|
|
pkg = pkg_new_from_file(locbuf, f, flags);
|
2012-05-07 08:57:28 +00:00
|
|
|
|
|
|
|
return pkg;
|
|
|
|
}
|
|
|
|
|
2012-07-26 04:49:07 +00:00
|
|
|
static void
|
|
|
|
pkg_scan_dir(const char *path, pkg_iteration_func_t func)
|
|
|
|
{
|
|
|
|
DIR *dir;
|
|
|
|
struct dirent *dirent;
|
|
|
|
|
|
|
|
dir = opendir(path);
|
|
|
|
if (dir == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (dirent = readdir(dir); dirent != NULL; dirent = readdir(dir))
|
|
|
|
{
|
2012-07-26 05:01:40 +00:00
|
|
|
static char filebuf[PKG_BUFSIZE];
|
2012-07-26 04:49:07 +00:00
|
|
|
pkg_t *pkg;
|
|
|
|
FILE *f;
|
2012-07-26 05:07:27 +00:00
|
|
|
struct stat st;
|
2012-07-26 04:49:07 +00:00
|
|
|
|
2012-07-26 05:01:40 +00:00
|
|
|
strlcpy(filebuf, path, sizeof filebuf);
|
|
|
|
strlcat(filebuf, "/", sizeof filebuf);
|
|
|
|
strlcat(filebuf, dirent->d_name, sizeof filebuf);
|
|
|
|
|
2012-07-26 05:07:27 +00:00
|
|
|
stat(filebuf, &st);
|
|
|
|
if (!(S_ISREG(st.st_mode)))
|
|
|
|
continue;
|
|
|
|
|
2012-07-26 05:01:40 +00:00
|
|
|
f = fopen(filebuf, "r");
|
2012-07-26 04:49:07 +00:00
|
|
|
if (f == NULL)
|
|
|
|
continue;
|
|
|
|
|
2013-02-24 14:58:35 +00:00
|
|
|
pkg = pkg_new_from_file(filebuf, f, 0);
|
2012-07-26 04:49:07 +00:00
|
|
|
if (pkg != NULL)
|
2012-07-26 05:01:40 +00:00
|
|
|
{
|
2012-07-26 04:49:07 +00:00
|
|
|
func(pkg);
|
2013-02-26 05:29:57 +00:00
|
|
|
pkg_unref(pkg);
|
2012-07-26 05:01:40 +00:00
|
|
|
}
|
2012-07-26 04:49:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
closedir(dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-03-15 23:11:43 +00:00
|
|
|
pkg_scan_all(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;
|
2012-07-26 04:49:07 +00:00
|
|
|
|
2013-03-15 23:11:43 +00:00
|
|
|
pkg_dir_list_build(0);
|
2012-07-26 04:49:07 +00:00
|
|
|
|
2015-09-06 15:31:21 +00:00
|
|
|
PKGCONF_FOREACH_LIST_ENTRY(pkg_dir_list.head, n)
|
2013-03-15 22:55:44 +00:00
|
|
|
{
|
|
|
|
pkg_path_t *pkg_path = n->data;
|
|
|
|
|
|
|
|
pkg_scan_dir(pkg_path->path, func);
|
|
|
|
}
|
2012-07-26 04:49:07 +00:00
|
|
|
}
|
|
|
|
|
2012-05-07 08:09:59 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
pkg_t *
|
|
|
|
pkg_find_in_registry_key(HKEY hkey, const char *name, unsigned int flags)
|
|
|
|
{
|
|
|
|
pkg_t *pkg = NULL;
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2012-07-02 03:41:08 +00:00
|
|
|
char pathbuf[PKG_CONFIG_PATH_SZ];
|
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)
|
|
|
|
{
|
2012-05-07 08:57:28 +00:00
|
|
|
pkg = pkg_try_specific_path(pathbuf, name, flags);
|
|
|
|
if (pkg != NULL)
|
2012-05-07 08:09:59 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
bufsize = sizeof buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
RegCloseKey(key);
|
|
|
|
return pkg;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-07-25 02:03:17 +00:00
|
|
|
pkg_t *
|
2012-05-02 23:14:53 +00:00
|
|
|
pkg_find(const char *name, unsigned int flags)
|
2011-07-25 02:03:17 +00:00
|
|
|
{
|
2012-05-07 02:09:26 +00:00
|
|
|
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
|
|
|
|
2013-03-20 16:52:17 +00:00
|
|
|
pkg_dir_list_build(flags);
|
|
|
|
|
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
|
|
|
{
|
|
|
|
pkg_t *pkg;
|
|
|
|
|
|
|
|
pkg = pkg_new_from_file(name, f, flags);
|
|
|
|
path_add(pkg_get_parent_dir(pkg), &pkg_dir_list);
|
|
|
|
|
|
|
|
return pkg;
|
|
|
|
}
|
2012-05-06 05:12:27 +00:00
|
|
|
}
|
|
|
|
|
2013-02-24 14:14:23 +00:00
|
|
|
/* check cache */
|
|
|
|
if (!(flags & PKGF_NO_CACHE))
|
|
|
|
{
|
2013-02-26 04:40:30 +00:00
|
|
|
if ((pkg = pkg_cache_lookup(name)) != NULL)
|
2013-02-26 04:47:32 +00:00
|
|
|
{
|
|
|
|
pkg->flags |= PKG_PROPF_CACHED;
|
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
|
|
|
}
|
|
|
|
|
2015-09-06 15:31:21 +00:00
|
|
|
PKGCONF_FOREACH_LIST_ENTRY(pkg_dir_list.head, n)
|
2012-05-02 23:16:32 +00:00
|
|
|
{
|
2013-03-15 23:11:43 +00:00
|
|
|
pkg_path_t *pkg_path = n->data;
|
2013-03-15 22:55:44 +00:00
|
|
|
|
2013-03-15 23:11:43 +00:00
|
|
|
pkg = pkg_try_specific_path(pkg_path->path, name, flags);
|
|
|
|
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 */
|
|
|
|
pkg = pkg_find_in_registry_key(HKEY_CURRENT_USER, name, flags);
|
|
|
|
if (!pkg)
|
|
|
|
pkg = pkg_find_in_registry_key(HKEY_LOCAL_MACHINE, name, flags);
|
|
|
|
#endif
|
|
|
|
|
2012-05-07 02:09:26 +00:00
|
|
|
out:
|
2013-02-26 04:40:30 +00:00
|
|
|
pkg_cache_add(pkg);
|
|
|
|
|
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
|
|
|
/*
|
|
|
|
* pkg_compare_version(a, b)
|
|
|
|
*
|
|
|
|
* compare versions using RPM version comparison rules as described in the LSB.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
pkg_compare_version(const char *a, const char *b)
|
|
|
|
{
|
|
|
|
char oldch1, oldch2;
|
2012-07-21 19:38:13 +00:00
|
|
|
char buf1[PKG_BUFSIZE], buf2[PKG_BUFSIZE];
|
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. */
|
|
|
|
if (!strcasecmp(a, b))
|
|
|
|
return 0;
|
|
|
|
|
2012-05-11 18:59:18 +00:00
|
|
|
strlcpy(buf1, a, sizeof buf1);
|
|
|
|
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
|
|
|
{
|
2012-07-24 02:07:57 +00:00
|
|
|
while (*one && !isalnum(*one) && *one != '~')
|
2011-07-26 16:56:59 +00:00
|
|
|
one++;
|
2012-07-24 02:07:57 +00:00
|
|
|
while (*two && !isalnum(*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;
|
|
|
|
|
|
|
|
if (isdigit(*str1))
|
|
|
|
{
|
|
|
|
while (*str1 && isdigit(*str1))
|
|
|
|
str1++;
|
|
|
|
|
|
|
|
while (*str2 && isdigit(*str2))
|
|
|
|
str2++;
|
|
|
|
|
|
|
|
isnum = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while (*str1 && isalpha(*str1))
|
|
|
|
str1++;
|
|
|
|
|
|
|
|
while (*str2 && isalpha(*str2))
|
|
|
|
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);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
*str1 = oldch1;
|
|
|
|
*str2 = oldch2;
|
|
|
|
|
|
|
|
one = str1;
|
|
|
|
two = str2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((!*one) && (!*two))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (!*one)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-02-24 13:20:50 +00:00
|
|
|
static pkg_t pkg_config_virtual = {
|
|
|
|
.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,
|
2013-02-24 13:20:50 +00:00
|
|
|
.flags = PKG_PROPF_VIRTUAL,
|
2013-03-01 16:45:55 +00:00
|
|
|
.vars = {
|
2015-09-06 15:31:21 +00:00
|
|
|
.head = &(pkgconf_node_t){
|
2013-03-01 16:45:55 +00:00
|
|
|
.prev = NULL,
|
|
|
|
.next = NULL,
|
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,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
.tail = NULL,
|
2013-02-24 13:20:50 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2015-09-06 15:38:30 +00:00
|
|
|
typedef bool (*pkg_vercmp_res_func_t)(pkg_t *pkg, pkgconf_dependency_t *pkgdep);
|
2013-02-24 13:20:50 +00:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
const char *name;
|
|
|
|
pkg_comparator_t compare;
|
|
|
|
} pkg_comparator_name_t;
|
|
|
|
|
|
|
|
static pkg_comparator_name_t pkg_comparator_names[PKG_CMP_SIZE + 1] = {
|
|
|
|
{"<", PKG_LESS_THAN},
|
|
|
|
{">", PKG_GREATER_THAN},
|
|
|
|
{"<=", PKG_LESS_THAN_EQUAL},
|
|
|
|
{">=", PKG_GREATER_THAN_EQUAL},
|
|
|
|
{"=", PKG_EQUAL},
|
|
|
|
{"!=", PKG_NOT_EQUAL},
|
|
|
|
{"(any)", PKG_ANY},
|
|
|
|
{"???", PKG_CMP_SIZE},
|
|
|
|
};
|
|
|
|
|
2015-09-06 15:38:30 +00:00
|
|
|
static bool pkg_comparator_lt(pkg_t *pkg, pkgconf_dependency_t *pkgdep)
|
2013-02-24 13:32:26 +00:00
|
|
|
{
|
|
|
|
return (pkg_compare_version(pkg->version, pkgdep->version) < 0);
|
|
|
|
}
|
|
|
|
|
2015-09-06 15:38:30 +00:00
|
|
|
static bool pkg_comparator_gt(pkg_t *pkg, pkgconf_dependency_t *pkgdep)
|
2013-02-24 13:32:26 +00:00
|
|
|
{
|
|
|
|
return (pkg_compare_version(pkg->version, pkgdep->version) > 0);
|
|
|
|
}
|
|
|
|
|
2015-09-06 15:38:30 +00:00
|
|
|
static bool pkg_comparator_lte(pkg_t *pkg, pkgconf_dependency_t *pkgdep)
|
2013-02-24 13:32:26 +00:00
|
|
|
{
|
|
|
|
return (pkg_compare_version(pkg->version, pkgdep->version) <= 0);
|
|
|
|
}
|
|
|
|
|
2015-09-06 15:38:30 +00:00
|
|
|
static bool pkg_comparator_gte(pkg_t *pkg, pkgconf_dependency_t *pkgdep)
|
2013-02-24 13:32:26 +00:00
|
|
|
{
|
|
|
|
return (pkg_compare_version(pkg->version, pkgdep->version) >= 0);
|
|
|
|
}
|
|
|
|
|
2015-09-06 15:38:30 +00:00
|
|
|
static bool pkg_comparator_eq(pkg_t *pkg, pkgconf_dependency_t *pkgdep)
|
2013-02-24 13:32:26 +00:00
|
|
|
{
|
|
|
|
return (pkg_compare_version(pkg->version, pkgdep->version) == 0);
|
|
|
|
}
|
|
|
|
|
2015-09-06 15:38:30 +00:00
|
|
|
static bool pkg_comparator_ne(pkg_t *pkg, pkgconf_dependency_t *pkgdep)
|
2013-02-24 13:32:26 +00:00
|
|
|
{
|
|
|
|
return (pkg_compare_version(pkg->version, pkgdep->version) != 0);
|
|
|
|
}
|
|
|
|
|
2015-09-06 15:38:30 +00:00
|
|
|
static bool pkg_comparator_any(pkg_t *pkg, pkgconf_dependency_t *pkgdep)
|
2013-02-24 13:32:26 +00:00
|
|
|
{
|
|
|
|
(void) pkg;
|
|
|
|
(void) pkgdep;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-09-06 15:38:30 +00:00
|
|
|
static bool pkg_comparator_unimplemented(pkg_t *pkg, pkgconf_dependency_t *pkgdep)
|
2013-02-24 13:32:26 +00:00
|
|
|
{
|
|
|
|
(void) pkg;
|
|
|
|
(void) pkgdep;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static pkg_vercmp_res_func_t pkg_comparator_impls[PKG_CMP_SIZE + 1] = {
|
|
|
|
[PKG_ANY] = pkg_comparator_any,
|
|
|
|
[PKG_LESS_THAN] = pkg_comparator_lt,
|
|
|
|
[PKG_GREATER_THAN] = pkg_comparator_gt,
|
|
|
|
[PKG_LESS_THAN_EQUAL] = pkg_comparator_lte,
|
|
|
|
[PKG_GREATER_THAN_EQUAL] = pkg_comparator_gte,
|
|
|
|
[PKG_EQUAL] = pkg_comparator_eq,
|
|
|
|
[PKG_NOT_EQUAL] = pkg_comparator_ne,
|
|
|
|
[PKG_CMP_SIZE] = pkg_comparator_unimplemented,
|
|
|
|
};
|
|
|
|
|
2011-07-27 00:59:46 +00:00
|
|
|
/*
|
|
|
|
* pkg_get_comparator(pkgdep)
|
|
|
|
*
|
|
|
|
* returns the comparator used in a depgraph dependency node as a string.
|
|
|
|
*/
|
|
|
|
const char *
|
2015-09-06 15:38:30 +00:00
|
|
|
pkg_get_comparator(pkgconf_dependency_t *pkgdep)
|
2011-07-27 00:59:46 +00:00
|
|
|
{
|
2013-02-24 13:20:50 +00:00
|
|
|
const pkg_comparator_name_t *i;
|
|
|
|
|
|
|
|
for (i = pkg_comparator_names; i->compare != PKG_CMP_SIZE; i++)
|
2011-07-27 00:59:46 +00:00
|
|
|
{
|
2013-02-24 13:20:50 +00:00
|
|
|
if (i->compare == pkgdep->compare)
|
|
|
|
return i->name;
|
2011-07-27 00:59:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return "???";
|
|
|
|
}
|
|
|
|
|
2013-02-24 13:37:20 +00:00
|
|
|
/*
|
|
|
|
* pkg_comparator_lookup_by_name(name)
|
|
|
|
*
|
|
|
|
* look up the appropriate comparator bytecode in the comparator set (defined
|
|
|
|
* above, see pkg_comparator_names and pkg_comparator_impls).
|
|
|
|
*
|
|
|
|
* XXX: on error return PKG_ANY or maybe we should return PKG_CMP_SIZE which
|
|
|
|
* is poisoned?
|
|
|
|
*/
|
|
|
|
pkg_comparator_t
|
|
|
|
pkg_comparator_lookup_by_name(const char *name)
|
|
|
|
{
|
|
|
|
const pkg_comparator_name_t *i;
|
|
|
|
|
|
|
|
for (i = pkg_comparator_names; i->compare != PKG_CMP_SIZE; i++)
|
|
|
|
{
|
|
|
|
if (!strcmp(i->name, name))
|
|
|
|
return i->compare;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PKG_ANY;
|
|
|
|
}
|
|
|
|
|
2011-07-26 17:17:45 +00:00
|
|
|
/*
|
2012-05-02 23:14:53 +00:00
|
|
|
* pkg_verify_dependency(pkgdep, flags)
|
2011-07-26 17:17:45 +00:00
|
|
|
*
|
2015-09-06 15:38:30 +00:00
|
|
|
* verify a pkgconf_dependency_t node in the depgraph. if the dependency is solvable,
|
2011-07-26 17:17:45 +00:00
|
|
|
* return the appropriate pkg_t object, else NULL.
|
|
|
|
*/
|
|
|
|
pkg_t *
|
2015-09-06 15:38:30 +00:00
|
|
|
pkg_verify_dependency(pkgconf_dependency_t *pkgdep, unsigned int flags, unsigned int *eflags)
|
2011-07-26 17:17:45 +00:00
|
|
|
{
|
2012-05-06 03:00:47 +00:00
|
|
|
pkg_t *pkg = &pkg_config_virtual;
|
2011-07-26 17:17:45 +00:00
|
|
|
|
2012-05-03 17:42:04 +00:00
|
|
|
if (eflags != NULL)
|
|
|
|
*eflags = PKG_ERRF_OK;
|
|
|
|
|
2012-05-06 03:00:47 +00:00
|
|
|
/* pkg-config package name is special cased. */
|
|
|
|
if (strcasecmp(pkgdep->package, "pkg-config"))
|
2012-05-03 17:42:04 +00:00
|
|
|
{
|
2012-05-06 03:00:47 +00:00
|
|
|
pkg = pkg_find(pkgdep->package, flags);
|
|
|
|
if (pkg == NULL)
|
|
|
|
{
|
|
|
|
if (eflags != NULL)
|
|
|
|
*eflags |= PKG_ERRF_PACKAGE_NOT_FOUND;
|
2012-05-03 17:42:04 +00:00
|
|
|
|
2012-05-06 03:00:47 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
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
|
|
|
|
2013-02-24 13:32:26 +00:00
|
|
|
if (pkg_comparator_impls[pkgdep->compare](pkg, pkgdep) == true)
|
2011-07-26 17:17:45 +00:00
|
|
|
return pkg;
|
|
|
|
|
2012-05-03 17:42:04 +00:00
|
|
|
if (eflags != NULL)
|
|
|
|
*eflags |= PKG_ERRF_PACKAGE_VER_MISMATCH;
|
|
|
|
|
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
|
|
|
/*
|
|
|
|
* pkg_verify_graph(root, depth)
|
|
|
|
*
|
|
|
|
* verify the graph dependency nodes are satisfiable by walking the tree using
|
|
|
|
* pkg_traverse().
|
|
|
|
*/
|
2012-05-07 02:42:15 +00:00
|
|
|
unsigned int
|
2012-05-02 23:29:35 +00:00
|
|
|
pkg_verify_graph(pkg_t *root, int depth, unsigned int flags)
|
2011-07-25 22:44:05 +00:00
|
|
|
{
|
2012-05-07 02:42:15 +00:00
|
|
|
return pkg_traverse(root, NULL, NULL, depth, flags);
|
2011-07-25 22:44:05 +00:00
|
|
|
}
|
|
|
|
|
2013-02-25 14:56:57 +00:00
|
|
|
static unsigned int
|
2015-09-06 15:38:30 +00:00
|
|
|
pkg_report_graph_error(pkg_t *parent, pkg_t *pkg, pkgconf_dependency_t *node, unsigned int eflags)
|
2012-05-03 17:55:06 +00:00
|
|
|
{
|
2013-03-16 01:09:54 +00:00
|
|
|
static bool already_sent_notice = false;
|
|
|
|
|
2012-05-03 17:55:06 +00:00
|
|
|
if (eflags & PKG_ERRF_PACKAGE_NOT_FOUND)
|
|
|
|
{
|
2013-03-16 01:09:54 +00:00
|
|
|
if (!already_sent_notice)
|
|
|
|
{
|
|
|
|
fprintf(error_msgout, "Package %s was not found in the pkg-config search path.\n", node->package);
|
|
|
|
fprintf(error_msgout, "Perhaps you should add the directory containing `%s.pc'\n", node->package);
|
|
|
|
fprintf(error_msgout, "to the PKG_CONFIG_PATH environment variable\n");
|
|
|
|
already_sent_notice = true;
|
|
|
|
}
|
|
|
|
|
2013-03-15 22:40:25 +00:00
|
|
|
fprintf(error_msgout, "Package '%s', required by '%s', not found\n", node->package, parent->id);
|
2012-05-03 17:55:06 +00:00
|
|
|
}
|
|
|
|
else if (eflags & PKG_ERRF_PACKAGE_VER_MISMATCH)
|
|
|
|
{
|
2012-07-02 02:21:31 +00:00
|
|
|
fprintf(error_msgout, "Package dependency requirement '%s %s %s' could not be satisfied.\n",
|
2012-05-03 17:55:06 +00:00
|
|
|
node->package, pkg_get_comparator(node), node->version);
|
|
|
|
|
|
|
|
if (pkg != NULL)
|
2012-07-02 02:21:31 +00:00
|
|
|
fprintf(error_msgout, "Package '%s' has version '%s', required version is '%s %s'\n",
|
2012-05-03 17:55:06 +00:00
|
|
|
node->package, pkg->version, pkg_get_comparator(node), node->version);
|
|
|
|
}
|
|
|
|
|
2012-05-07 02:30:35 +00:00
|
|
|
if (pkg != NULL)
|
2013-02-26 05:29:57 +00:00
|
|
|
pkg_unref(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
|
2013-03-15 22:40:25 +00:00
|
|
|
pkg_walk_list(pkg_t *parent,
|
2015-09-06 15:31:21 +00:00
|
|
|
pkgconf_list_t *deplist,
|
2012-05-12 00:56:38 +00:00
|
|
|
pkg_traverse_func_t func,
|
2011-07-25 06:22:04 +00:00
|
|
|
void *data,
|
2012-05-06 01:52:17 +00:00
|
|
|
int depth,
|
2012-05-02 21:44:58 +00:00
|
|
|
unsigned int flags)
|
2011-07-25 02:03:17 +00:00
|
|
|
{
|
2012-05-07 02:42:15 +00:00
|
|
|
unsigned int eflags = 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
|
|
|
{
|
2013-03-16 01:09:54 +00:00
|
|
|
unsigned int eflags_local = PKG_ERRF_OK;
|
2015-09-06 15:38:30 +00:00
|
|
|
pkgconf_dependency_t *depnode = node->data;
|
2011-07-25 04:38:58 +00:00
|
|
|
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;
|
|
|
|
|
2013-03-16 01:09:54 +00:00
|
|
|
pkgdep = pkg_verify_dependency(depnode, flags, &eflags_local);
|
|
|
|
|
|
|
|
eflags |= eflags_local;
|
|
|
|
if (eflags_local != PKG_ERRF_OK && !(flags & PKGF_SKIP_ERRORS))
|
|
|
|
{
|
|
|
|
pkg_report_graph_error(parent, pkgdep, depnode, eflags_local);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (pkgdep == NULL)
|
|
|
|
continue;
|
|
|
|
|
2013-02-26 05:29:57 +00:00
|
|
|
if (pkgdep->flags & PKG_PROPF_SEEN)
|
|
|
|
{
|
|
|
|
pkg_unref(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
|
|
|
|
2013-02-26 05:29:57 +00:00
|
|
|
pkgdep->flags |= PKG_PROPF_SEEN;
|
2013-03-17 22:45:51 +00:00
|
|
|
eflags |= pkg_traverse(pkgdep, func, data, depth - 1, flags);
|
2013-02-26 05:29:57 +00:00
|
|
|
pkgdep->flags &= ~PKG_PROPF_SEEN;
|
|
|
|
pkg_unref(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
|
2015-09-06 15:31:21 +00:00
|
|
|
pkg_walk_conflicts_list(pkg_t *root, pkgconf_list_t *deplist, unsigned int flags)
|
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;
|
|
|
|
|
2015-09-06 15:31:21 +00:00
|
|
|
PKGCONF_FOREACH_LIST_ENTRY(root->requires.head, childnode)
|
2012-05-12 01:51:13 +00:00
|
|
|
{
|
2012-07-30 07:46:03 +00:00
|
|
|
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
|
|
|
|
2013-03-01 17:36:21 +00:00
|
|
|
pkgdep = pkg_verify_dependency(parentnode, flags, &eflags);
|
2012-07-30 07:46:03 +00:00
|
|
|
if (eflags == PKG_ERRF_OK)
|
|
|
|
{
|
|
|
|
fprintf(error_msgout, "Version '%s' of '%s' conflicts with '%s' due to satisfying conflict rule '%s %s%s%s'.\n",
|
2013-03-01 17:36:21 +00:00
|
|
|
pkgdep->version, pkgdep->realname, root->realname, parentnode->package, pkg_get_comparator(parentnode),
|
|
|
|
parentnode->version != NULL ? " " : "", parentnode->version != NULL ? parentnode->version : "");
|
2012-07-30 07:46:03 +00:00
|
|
|
fprintf(error_msgout, "It may be possible to ignore this conflict and continue, try the\n");
|
|
|
|
fprintf(error_msgout, "PKG_CONFIG_IGNORE_CONFLICTS environment variable.\n");
|
2012-05-12 01:51:13 +00:00
|
|
|
|
2013-02-26 05:29:57 +00:00
|
|
|
pkg_unref(pkgdep);
|
2012-07-30 07:46:03 +00:00
|
|
|
|
|
|
|
return PKG_ERRF_PACKAGE_CONFLICT;
|
|
|
|
}
|
|
|
|
|
2013-02-26 05:29:57 +00:00
|
|
|
pkg_unref(pkgdep);
|
2012-07-30 07:46:03 +00:00
|
|
|
}
|
2012-05-12 01:51:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return PKG_ERRF_OK;
|
|
|
|
}
|
|
|
|
|
2012-05-02 21:44:58 +00:00
|
|
|
/*
|
2012-05-12 00:56:38 +00:00
|
|
|
* pkg_traverse(root, func, data, maxdepth, flags)
|
2012-05-02 21:44:58 +00:00
|
|
|
*
|
|
|
|
* walk the dependency graph up to maxdepth levels. -1 means infinite recursion.
|
|
|
|
*/
|
2012-05-07 02:42:15 +00:00
|
|
|
unsigned int
|
2012-05-02 21:44:58 +00:00
|
|
|
pkg_traverse(pkg_t *root,
|
2012-05-12 00:56:38 +00:00
|
|
|
pkg_traverse_func_t func,
|
2012-05-02 21:44:58 +00:00
|
|
|
void *data,
|
|
|
|
int maxdepth,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
2012-05-07 04:28:42 +00:00
|
|
|
unsigned int rflags = flags & ~PKGF_SKIP_ROOT_VIRTUAL;
|
2012-05-07 02:42:15 +00:00
|
|
|
unsigned int eflags = PKG_ERRF_OK;
|
|
|
|
|
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
|
|
|
|
2012-08-08 15:20:08 +00:00
|
|
|
if ((root->flags & PKG_PROPF_VIRTUAL) != PKG_PROPF_VIRTUAL || (flags & PKGF_SKIP_ROOT_VIRTUAL) != PKGF_SKIP_ROOT_VIRTUAL)
|
|
|
|
{
|
|
|
|
if (func != NULL)
|
|
|
|
func(root, data, flags);
|
|
|
|
}
|
|
|
|
|
2012-05-12 01:51:13 +00:00
|
|
|
if (!(flags & PKGF_SKIP_CONFLICTS))
|
|
|
|
{
|
2013-03-01 17:36:21 +00:00
|
|
|
eflags = pkg_walk_conflicts_list(root, &root->conflicts, rflags);
|
2012-05-12 01:51:13 +00:00
|
|
|
if (eflags != PKG_ERRF_OK)
|
|
|
|
return eflags;
|
|
|
|
}
|
|
|
|
|
2013-03-15 22:40:25 +00:00
|
|
|
eflags = pkg_walk_list(root, &root->requires, func, data, maxdepth, rflags);
|
2012-05-07 02:42:15 +00:00
|
|
|
if (eflags != PKG_ERRF_OK)
|
|
|
|
return eflags;
|
2011-07-25 04:20:22 +00:00
|
|
|
|
2012-05-02 21:47:02 +00:00
|
|
|
if (flags & PKGF_SEARCH_PRIVATE)
|
2012-05-07 02:42:15 +00:00
|
|
|
{
|
2015-05-22 04:06:38 +00:00
|
|
|
eflags = pkg_walk_list(root, &root->requires_private, func, data, maxdepth, rflags | PKGF_ITER_PKG_IS_PRIVATE);
|
2012-05-07 02:42:15 +00:00
|
|
|
if (eflags != PKG_ERRF_OK)
|
|
|
|
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
|
|
|
|
|
|
|
static void
|
|
|
|
pkg_cflags_collect(pkg_t *pkg, void *data, unsigned int flags)
|
|
|
|
{
|
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
|
|
|
(void) flags;
|
|
|
|
|
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;
|
|
|
|
pkgconf_fragment_copy(list, frag, flags, 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
|
|
|
|
pkg_cflags_private_collect(pkg_t *pkg, void *data, unsigned int flags)
|
|
|
|
{
|
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
|
|
|
(void) flags;
|
|
|
|
|
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;
|
2013-08-14 05:36:43 +00:00
|
|
|
|
2015-09-06 15:44:10 +00:00
|
|
|
pkgconf_fragment_copy(list, frag, flags, true);
|
2013-08-14 05:36:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-20 20:47:10 +00:00
|
|
|
int
|
2015-09-06 15:31:21 +00:00
|
|
|
pkg_cflags(pkg_t *root, pkgconf_list_t *list, int maxdepth, unsigned int flags)
|
2012-05-12 01:13:03 +00:00
|
|
|
{
|
2012-08-12 10:32:31 +00:00
|
|
|
int eflag;
|
|
|
|
|
|
|
|
eflag = pkg_traverse(root, pkg_cflags_collect, list, maxdepth, flags);
|
|
|
|
if (eflag != PKG_ERRF_OK)
|
2015-09-06 15:44:10 +00:00
|
|
|
pkgconf_fragment_free(list);
|
2012-05-12 01:13:03 +00:00
|
|
|
|
2013-08-14 05:36:43 +00:00
|
|
|
if (flags & PKGF_MERGE_PRIVATE_FRAGMENTS)
|
|
|
|
{
|
|
|
|
eflag = pkg_traverse(root, pkg_cflags_private_collect, list, maxdepth, flags);
|
|
|
|
if (eflag != PKG_ERRF_OK)
|
2015-09-06 15:44:10 +00:00
|
|
|
pkgconf_fragment_free(list);
|
2013-08-14 05:36:43 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
pkg_libs_collect(pkg_t *pkg, void *data, unsigned int flags)
|
|
|
|
{
|
2015-09-06 15:31:21 +00:00
|
|
|
pkgconf_list_t *list = data;
|
|
|
|
pkgconf_node_t *node;
|
2012-08-08 16:15:13 +00:00
|
|
|
(void) flags;
|
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;
|
|
|
|
pkgconf_fragment_copy(list, frag, flags, (flags & PKGF_ITER_PKG_IS_PRIVATE) != 0);
|
2013-03-01 17:10:43 +00:00
|
|
|
}
|
2012-08-08 16:15:13 +00:00
|
|
|
|
2015-05-22 03:14:37 +00:00
|
|
|
if (flags & 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;
|
|
|
|
pkgconf_fragment_copy(list, frag, flags, 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
|
|
|
}
|
|
|
|
|
2012-08-20 20:47:10 +00:00
|
|
|
int
|
2015-09-06 15:31:21 +00:00
|
|
|
pkg_libs(pkg_t *root, pkgconf_list_t *list, int maxdepth, unsigned int flags)
|
2012-05-12 01:16:22 +00:00
|
|
|
{
|
2012-08-12 10:32:31 +00:00
|
|
|
int eflag;
|
|
|
|
|
|
|
|
eflag = pkg_traverse(root, pkg_libs_collect, list, maxdepth, flags);
|
|
|
|
|
|
|
|
if (eflag != PKG_ERRF_OK)
|
|
|
|
{
|
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
|
|
|
}
|