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
|
|
|
*
|
2012-02-17 21:35:23 +00:00
|
|
|
* Copyright (c) 2011, 2012 William Pitcock <nenolod@dereferenced.org>.
|
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.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
|
|
|
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
|
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
|
|
|
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "pkg.h"
|
2012-04-30 06:06:13 +00:00
|
|
|
#include "bsdstubs.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"
|
|
|
|
#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-05-02 19:06:32 +00:00
|
|
|
static inline size_t
|
|
|
|
path_split(const char *text, char ***parv)
|
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;
|
|
|
|
|
|
|
|
*parv = malloc(sizeof (void *));
|
|
|
|
|
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
|
|
|
{
|
2012-05-02 19:31:30 +00:00
|
|
|
(*parv)[count] = strdup(p);
|
2012-05-02 19:06:32 +00:00
|
|
|
count++, iter = NULL;
|
|
|
|
|
2012-05-07 01:59:03 +00:00
|
|
|
*parv = realloc(*parv, sizeof (void *) * (count + 1));
|
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
|
|
|
|
path_free(char **parv, size_t count)
|
|
|
|
{
|
|
|
|
size_t iter;
|
|
|
|
|
|
|
|
if (parv == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (iter = 0; iter < count; iter++)
|
|
|
|
free(parv[iter]);
|
|
|
|
|
|
|
|
free(parv);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
GetModuleFileName(NULL, namebuf, sizeof namebuf);
|
|
|
|
|
|
|
|
p = strrchr(namebuf, '\\');
|
|
|
|
if (p == NULL)
|
|
|
|
p = strrchr(namebuf, '/');
|
|
|
|
if (p == NULL)
|
|
|
|
return PKG_DEFAULT_PATH;
|
|
|
|
|
|
|
|
*p = '\0';
|
|
|
|
strlcpy(outbuf, namebuf, sizeof outbuf);
|
|
|
|
strlcat(outbuf, "/lib/pkgconfig", sizeof outbuf);
|
|
|
|
|
|
|
|
return outbuf;
|
|
|
|
#endif
|
|
|
|
|
2012-05-12 07:21:11 +00:00
|
|
|
return PKG_DEFAULT_PATH;
|
|
|
|
}
|
|
|
|
|
2012-05-07 04:00:06 +00:00
|
|
|
/*
|
|
|
|
* pkg_new_from_file(filename, file)
|
|
|
|
*
|
|
|
|
* Parse a .pc file into a pkg_t object structure.
|
|
|
|
*/
|
|
|
|
pkg_t *
|
|
|
|
pkg_new_from_file(const char *filename, FILE *f)
|
|
|
|
{
|
|
|
|
pkg_t *pkg;
|
|
|
|
char readbuf[BUFSIZ];
|
|
|
|
|
|
|
|
pkg = calloc(sizeof(pkg_t), 1);
|
|
|
|
pkg->filename = strdup(filename);
|
|
|
|
|
|
|
|
while (pkg_fgetline(readbuf, BUFSIZ, f) != NULL)
|
|
|
|
{
|
|
|
|
char op, *p, *key = NULL, *value = NULL;
|
|
|
|
|
|
|
|
readbuf[strlen(readbuf) - 1] = '\0';
|
|
|
|
|
|
|
|
p = readbuf;
|
|
|
|
while (*p && (isalpha(*p) || isdigit(*p) || *p == '_' || *p == '.'))
|
|
|
|
p++;
|
|
|
|
|
|
|
|
key = strndup(readbuf, p - readbuf);
|
|
|
|
if (!isalpha(*key) && !isdigit(*p))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
while (*p && isspace(*p))
|
|
|
|
p++;
|
|
|
|
|
|
|
|
op = *p++;
|
|
|
|
|
|
|
|
while (*p && isspace(*p))
|
|
|
|
p++;
|
|
|
|
|
|
|
|
value = strdup(p);
|
|
|
|
|
|
|
|
switch (op)
|
|
|
|
{
|
|
|
|
case ':':
|
|
|
|
if (!strcasecmp(key, "Name"))
|
|
|
|
pkg->realname = pkg_tuple_parse(pkg->vars, value);
|
|
|
|
else if (!strcasecmp(key, "Description"))
|
|
|
|
pkg->description = pkg_tuple_parse(pkg->vars, value);
|
|
|
|
else if (!strcasecmp(key, "Version"))
|
|
|
|
pkg->version = pkg_tuple_parse(pkg->vars, value);
|
|
|
|
else if (!strcasecmp(key, "CFLAGS"))
|
|
|
|
pkg->cflags = pkg_fragment_parse(pkg->cflags, pkg->vars, value);
|
|
|
|
else if (!strcasecmp(key, "LIBS"))
|
|
|
|
pkg->libs = pkg_fragment_parse(pkg->libs, pkg->vars, value);
|
|
|
|
else if (!strcasecmp(key, "LIBS.private"))
|
|
|
|
pkg->libs_private = pkg_fragment_parse(pkg->libs_private, pkg->vars, value);
|
|
|
|
else if (!strcasecmp(key, "Requires"))
|
|
|
|
pkg->requires = pkg_dependency_parse(pkg, value);
|
|
|
|
else if (!strcasecmp(key, "Requires.private"))
|
|
|
|
pkg->requires_private = pkg_dependency_parse(pkg, value);
|
|
|
|
else if (!strcasecmp(key, "Conflicts"))
|
|
|
|
pkg->conflicts = pkg_dependency_parse(pkg, value);
|
|
|
|
break;
|
|
|
|
case '=':
|
|
|
|
pkg->vars = pkg_tuple_add(pkg->vars, key, value);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (key)
|
|
|
|
free(key);
|
|
|
|
|
|
|
|
if (value)
|
|
|
|
free(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(f);
|
|
|
|
return pkg;
|
|
|
|
}
|
|
|
|
|
2012-05-07 01:30:50 +00:00
|
|
|
void
|
|
|
|
pkg_free(pkg_t *pkg)
|
|
|
|
{
|
2012-05-07 02:09:26 +00:00
|
|
|
if (pkg == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
pkg_dependency_free(pkg->requires);
|
|
|
|
pkg_dependency_free(pkg->requires_private);
|
|
|
|
pkg_dependency_free(pkg->conflicts);
|
|
|
|
|
|
|
|
pkg_fragment_free(pkg->cflags);
|
|
|
|
pkg_fragment_free(pkg->libs);
|
|
|
|
pkg_fragment_free(pkg->libs_private);
|
|
|
|
|
|
|
|
pkg_tuple_free(pkg->vars);
|
|
|
|
|
|
|
|
if (pkg->flags & PKG_PROPF_VIRTUAL)
|
2012-05-07 01:38:48 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
pkg = pkg_new_from_file(uninst_locbuf, f);
|
|
|
|
pkg->uninstalled = true;
|
|
|
|
}
|
|
|
|
else if ((f = fopen(locbuf, "r")) != NULL)
|
|
|
|
pkg = pkg_new_from_file(locbuf, f);
|
|
|
|
|
|
|
|
return pkg;
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
BYTE pathbuf[PKG_CONFIG_PATH_SZ];
|
|
|
|
DWORD type;
|
|
|
|
DWORD pathbuflen = sizeof pathbuf;
|
|
|
|
|
|
|
|
if (RegQueryValueEx(key, buf, NULL, &type, pathbuf, &pathbuflen)
|
|
|
|
== 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
|
|
|
char **path = NULL;
|
|
|
|
size_t count = 0, iter = 0;
|
2012-02-17 21:35:23 +00:00
|
|
|
const char *env_path;
|
2012-05-07 02:09:26 +00:00
|
|
|
pkg_t *pkg = NULL;
|
2012-01-16 01:03:54 +00:00
|
|
|
FILE *f;
|
2011-07-25 02:03:17 +00:00
|
|
|
|
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)
|
2012-05-07 03:24:36 +00:00
|
|
|
return pkg_new_from_file(name, f);
|
2012-05-06 05:12:27 +00:00
|
|
|
}
|
|
|
|
|
2012-05-02 13:55:13 +00:00
|
|
|
/* PKG_CONFIG_PATH has to take precedence */
|
|
|
|
env_path = getenv("PKG_CONFIG_PATH");
|
|
|
|
if (env_path)
|
2012-01-16 01:03:54 +00:00
|
|
|
{
|
2012-05-02 19:06:32 +00:00
|
|
|
count = path_split(env_path, &path);
|
2012-05-01 01:27:19 +00:00
|
|
|
|
2012-05-07 03:38:44 +00:00
|
|
|
for (iter = 0; iter < count; iter++)
|
2012-05-02 19:06:32 +00:00
|
|
|
{
|
2012-05-07 08:57:28 +00:00
|
|
|
pkg = pkg_try_specific_path(path[iter], name, flags);
|
|
|
|
if (pkg != NULL)
|
2012-05-07 02:09:26 +00:00
|
|
|
goto out;
|
2012-05-02 13:55:13 +00:00
|
|
|
}
|
2012-02-17 21:35:23 +00:00
|
|
|
|
2012-05-12 07:21:11 +00:00
|
|
|
path_free(path, count);
|
|
|
|
}
|
2012-05-07 00:44:22 +00:00
|
|
|
|
2012-05-12 07:21:11 +00:00
|
|
|
env_path = get_pkgconfig_path();
|
2012-05-02 23:16:32 +00:00
|
|
|
if (!(flags & PKGF_ENV_ONLY))
|
|
|
|
{
|
2012-05-07 00:44:22 +00:00
|
|
|
count = path_split(env_path, &path);
|
2012-05-06 01:24:45 +00:00
|
|
|
|
2012-05-07 03:38:44 +00:00
|
|
|
for (iter = 0; iter < count; iter++)
|
2012-05-06 01:24:45 +00:00
|
|
|
{
|
2012-05-07 08:57:28 +00:00
|
|
|
pkg = pkg_try_specific_path(path[iter], name, flags);
|
|
|
|
if (pkg != NULL)
|
2012-05-07 02:09:26 +00:00
|
|
|
goto out;
|
2012-05-06 01:24:45 +00:00
|
|
|
}
|
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:
|
|
|
|
path_free(path, count);
|
|
|
|
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-05-11 18:59:18 +00:00
|
|
|
char buf1[BUFSIZ], buf2[BUFSIZ];
|
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
|
|
|
|
|
|
|
while (*one && *two)
|
|
|
|
{
|
|
|
|
while (*one && !isalnum(*one))
|
|
|
|
one++;
|
|
|
|
while (*two && !isalnum(*two))
|
2011-07-26 17:05:14 +00:00
|
|
|
two++;
|
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;
|
|
|
|
}
|
|
|
|
|
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 *
|
|
|
|
pkg_get_comparator(pkg_dependency_t *pkgdep)
|
|
|
|
{
|
|
|
|
switch(pkgdep->compare)
|
|
|
|
{
|
|
|
|
case PKG_LESS_THAN:
|
|
|
|
return "<";
|
|
|
|
case PKG_GREATER_THAN:
|
|
|
|
return ">";
|
|
|
|
case PKG_LESS_THAN_EQUAL:
|
|
|
|
return "<=";
|
|
|
|
case PKG_GREATER_THAN_EQUAL:
|
|
|
|
return ">=";
|
|
|
|
case PKG_EQUAL:
|
|
|
|
return "=";
|
|
|
|
case PKG_NOT_EQUAL:
|
|
|
|
return "!=";
|
|
|
|
case PKG_ANY:
|
|
|
|
return "(any)";
|
2012-05-03 17:15:45 +00:00
|
|
|
default:
|
|
|
|
return "???";
|
2011-07-27 00:59:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return "???";
|
|
|
|
}
|
|
|
|
|
2012-05-06 03:00:47 +00:00
|
|
|
static pkg_t pkg_config_virtual = {
|
|
|
|
.id = "pkg-config",
|
|
|
|
.realname = "pkg-config",
|
|
|
|
.version = PKG_PKGCONFIG_VERSION_EQUIV,
|
2012-05-07 01:39:10 +00:00
|
|
|
.flags = PKG_PROPF_VIRTUAL,
|
2012-05-06 03:00:47 +00:00
|
|
|
};
|
|
|
|
|
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
|
|
|
*
|
|
|
|
* verify a pkg_dependency_t node in the depgraph. if the dependency is solvable,
|
|
|
|
* return the appropriate pkg_t object, else NULL.
|
|
|
|
*/
|
|
|
|
pkg_t *
|
2012-05-03 17:42:04 +00:00
|
|
|
pkg_verify_dependency(pkg_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
|
|
|
|
2011-07-26 17:17:45 +00:00
|
|
|
switch(pkgdep->compare)
|
|
|
|
{
|
|
|
|
case PKG_LESS_THAN:
|
2011-07-27 00:52:44 +00:00
|
|
|
if (pkg_compare_version(pkg->version, pkgdep->version) < 0)
|
2011-07-26 17:17:45 +00:00
|
|
|
return pkg;
|
|
|
|
break;
|
|
|
|
case PKG_GREATER_THAN:
|
2011-07-27 00:52:44 +00:00
|
|
|
if (pkg_compare_version(pkg->version, pkgdep->version) > 0)
|
2011-07-26 17:17:45 +00:00
|
|
|
return pkg;
|
|
|
|
break;
|
|
|
|
case PKG_LESS_THAN_EQUAL:
|
2011-07-27 00:52:44 +00:00
|
|
|
if (pkg_compare_version(pkg->version, pkgdep->version) <= 0)
|
2011-07-26 17:17:45 +00:00
|
|
|
return pkg;
|
|
|
|
break;
|
|
|
|
case PKG_GREATER_THAN_EQUAL:
|
2011-07-27 00:52:44 +00:00
|
|
|
if (pkg_compare_version(pkg->version, pkgdep->version) >= 0)
|
2011-07-26 17:17:45 +00:00
|
|
|
return pkg;
|
|
|
|
break;
|
|
|
|
case PKG_EQUAL:
|
2011-07-27 00:52:44 +00:00
|
|
|
if (pkg_compare_version(pkg->version, pkgdep->version) == 0)
|
2011-07-26 17:17:45 +00:00
|
|
|
return pkg;
|
|
|
|
break;
|
|
|
|
case PKG_NOT_EQUAL:
|
2011-07-27 00:52:44 +00:00
|
|
|
if (pkg_compare_version(pkg->version, pkgdep->version) != 0)
|
2011-07-26 17:17:45 +00:00
|
|
|
return pkg;
|
|
|
|
break;
|
|
|
|
case PKG_ANY:
|
|
|
|
default:
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-05-07 02:42:15 +00:00
|
|
|
unsigned int
|
2012-05-03 17:55:06 +00:00
|
|
|
pkg_report_graph_error(pkg_t *pkg, pkg_dependency_t *node, unsigned int eflags)
|
|
|
|
{
|
|
|
|
if (eflags & PKG_ERRF_PACKAGE_NOT_FOUND)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Package %s was not found in the pkg-config search path.\n", node->package);
|
|
|
|
fprintf(stderr, "Perhaps you should add the directory containing `%s.pc'\n", node->package);
|
|
|
|
fprintf(stderr, "to the PKG_CONFIG_PATH environment variable\n");
|
|
|
|
fprintf(stderr, "No package '%s' found\n", node->package);
|
|
|
|
}
|
|
|
|
else if (eflags & PKG_ERRF_PACKAGE_VER_MISMATCH)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Package dependency requirement '%s %s %s' could not be satisfied.\n",
|
|
|
|
node->package, pkg_get_comparator(node), node->version);
|
|
|
|
|
|
|
|
if (pkg != NULL)
|
|
|
|
fprintf(stderr, "Package '%s' has version '%s', required version is '%s %s'\n",
|
|
|
|
node->package, pkg->version, pkg_get_comparator(node), node->version);
|
|
|
|
}
|
|
|
|
|
2012-05-07 02:30:35 +00:00
|
|
|
if (pkg != NULL)
|
|
|
|
pkg_free(pkg);
|
|
|
|
|
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
|
2012-05-03 17:20:39 +00:00
|
|
|
pkg_walk_list(pkg_dependency_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;
|
2011-07-25 04:38:58 +00:00
|
|
|
pkg_dependency_t *node;
|
2011-07-25 02:03:17 +00:00
|
|
|
|
2012-05-07 03:55:00 +00:00
|
|
|
PKG_FOREACH_LIST_ENTRY(deplist, node)
|
2011-07-25 04:20:22 +00:00
|
|
|
{
|
2011-07-25 04:38:58 +00:00
|
|
|
pkg_t *pkgdep;
|
2011-07-25 04:20:22 +00:00
|
|
|
|
2011-07-25 06:03:13 +00:00
|
|
|
if (*node->package == '\0')
|
|
|
|
continue;
|
|
|
|
|
2012-05-03 17:42:04 +00:00
|
|
|
pkgdep = pkg_verify_dependency(node, flags, &eflags);
|
2012-05-03 17:55:06 +00:00
|
|
|
if (eflags != PKG_ERRF_OK)
|
|
|
|
return pkg_report_graph_error(pkgdep, node, eflags);
|
2011-07-25 04:20:22 +00:00
|
|
|
|
2012-05-12 01:59:35 +00:00
|
|
|
eflags = pkg_traverse(pkgdep, func, data, depth - 1, flags);
|
2012-05-07 01:39:26 +00:00
|
|
|
pkg_free(pkgdep);
|
2012-05-12 02:01:42 +00:00
|
|
|
|
|
|
|
/* optimization: if a break has been found in the depgraph, quit walking it */
|
|
|
|
if (eflags != PKG_ERRF_OK)
|
|
|
|
break;
|
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
|
|
|
|
pkg_walk_conflicts_list(pkg_t *root, pkg_dependency_t *deplist, unsigned int flags)
|
|
|
|
{
|
|
|
|
unsigned int eflags;
|
|
|
|
pkg_dependency_t *node;
|
|
|
|
|
|
|
|
PKG_FOREACH_LIST_ENTRY(deplist, node)
|
|
|
|
{
|
|
|
|
pkg_t *pkgdep;
|
|
|
|
|
|
|
|
if (*node->package == '\0')
|
|
|
|
continue;
|
|
|
|
|
|
|
|
pkgdep = pkg_verify_dependency(node, flags, &eflags);
|
|
|
|
if (eflags == PKG_ERRF_OK)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Version '%s' of '%s' conflicts with '%s' due to satisfying conflict rule '%s %s%s%s'.\n",
|
|
|
|
pkgdep->version, pkgdep->realname, root->realname, node->package, pkg_get_comparator(node),
|
|
|
|
node->version != NULL ? " " : "", node->version != NULL ? node->version : "");
|
|
|
|
fprintf(stderr, "It may be possible to ignore this conflict and continue, try the\n");
|
|
|
|
fprintf(stderr, "PKG_CONFIG_IGNORE_CONFLICTS environment variable.\n");
|
2012-05-12 02:00:01 +00:00
|
|
|
|
2012-05-12 02:20:00 +00:00
|
|
|
pkg_free(pkgdep);
|
|
|
|
|
2012-05-12 02:00:01 +00:00
|
|
|
return PKG_ERRF_PACKAGE_CONFLICT;
|
2012-05-12 01:51:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pkg_free(pkgdep);
|
|
|
|
}
|
|
|
|
|
|
|
|
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-05-12 01:51:13 +00:00
|
|
|
if (!(flags & PKGF_SKIP_CONFLICTS))
|
|
|
|
{
|
|
|
|
eflags = pkg_walk_conflicts_list(root, root->conflicts, rflags);
|
|
|
|
if (eflags != PKG_ERRF_OK)
|
|
|
|
return eflags;
|
|
|
|
}
|
|
|
|
|
2012-05-12 00:56:38 +00:00
|
|
|
eflags = pkg_walk_list(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
|
|
|
{
|
2012-05-12 00:56:38 +00:00
|
|
|
eflags = pkg_walk_list(root->requires_private, func, data, maxdepth, rflags);
|
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 04:26:21 +00:00
|
|
|
if ((root->flags & PKG_PROPF_VIRTUAL) && (flags & PKGF_SKIP_ROOT_VIRTUAL))
|
|
|
|
return eflags;
|
|
|
|
|
2012-05-12 00:56:38 +00:00
|
|
|
if (func != NULL)
|
2012-05-12 00:58:34 +00:00
|
|
|
func(root, data, flags);
|
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)
|
|
|
|
{
|
|
|
|
pkg_fragment_t **list = data;
|
|
|
|
pkg_fragment_t *frag;
|
|
|
|
(void) flags;
|
|
|
|
|
|
|
|
PKG_FOREACH_LIST_ENTRY(pkg->cflags, frag)
|
|
|
|
*list = pkg_fragment_copy(*list, frag);
|
|
|
|
}
|
|
|
|
|
|
|
|
pkg_fragment_t *
|
|
|
|
pkg_cflags(pkg_t *root, int maxdepth, unsigned int flags)
|
|
|
|
{
|
|
|
|
pkg_fragment_t *head = NULL;
|
|
|
|
|
|
|
|
pkg_traverse(root, pkg_cflags_collect, &head, maxdepth, flags);
|
|
|
|
|
|
|
|
return head;
|
|
|
|
}
|
|
|
|
|
2012-05-12 01:16:22 +00:00
|
|
|
static void
|
|
|
|
pkg_libs_collect(pkg_t *pkg, void *data, unsigned int flags)
|
|
|
|
{
|
|
|
|
pkg_fragment_t **list = data;
|
|
|
|
pkg_fragment_t *frag;
|
|
|
|
|
|
|
|
PKG_FOREACH_LIST_ENTRY(pkg->libs, frag)
|
|
|
|
*list = pkg_fragment_copy(*list, frag);
|
|
|
|
|
|
|
|
if (flags & PKGF_MERGE_PRIVATE_FRAGMENTS)
|
|
|
|
{
|
|
|
|
PKG_FOREACH_LIST_ENTRY(pkg->libs_private, frag)
|
|
|
|
*list = pkg_fragment_copy(*list, frag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pkg_fragment_t *
|
|
|
|
pkg_libs(pkg_t *root, int maxdepth, unsigned int flags)
|
|
|
|
{
|
|
|
|
pkg_fragment_t *head = NULL;
|
|
|
|
|
|
|
|
pkg_traverse(root, pkg_libs_collect, &head, maxdepth, flags);
|
|
|
|
|
|
|
|
return head;
|
|
|
|
}
|