Move the deptest code from frontend to backend.
The deptest code (pacman -T) used by makepkg was mostly in the frontend. There were 2 drawbacks: 1) the public splitdep function returns a pmdepend_t struct, but the _alpm_dep_free function for freeing it is private. So there was a memleak. 2) there is a helper in the backend (satisfycmp in deps.c) which makes this function much easier. So this adds a new public alpm_deptest in libalpm/deps.c, which cleans pacman_deptest in pacman/deptest.c a lot. Besides, alpm_splitdep was made private, because the frontend no longer requires it, and _alpm_dep_free is also private. Finally the deptest001 pactest was extended. Signed-off-by: Chantry Xavier <shiningxc@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
927af790ee
commit
b2914bf0af
8 changed files with 51 additions and 58 deletions
|
@ -377,10 +377,10 @@ typedef enum _pmdepmod_t {
|
||||||
PM_DEP_MOD_LT
|
PM_DEP_MOD_LT
|
||||||
} pmdepmod_t;
|
} pmdepmod_t;
|
||||||
|
|
||||||
pmdepend_t *alpm_splitdep(const char *depstring);
|
|
||||||
int alpm_depcmp(pmpkg_t *pkg, pmdepend_t *dep);
|
int alpm_depcmp(pmpkg_t *pkg, pmdepend_t *dep);
|
||||||
alpm_list_t *alpm_checkdeps(pmdb_t *db, int reversedeps,
|
alpm_list_t *alpm_checkdeps(pmdb_t *db, int reversedeps,
|
||||||
alpm_list_t *remove, alpm_list_t *upgrade);
|
alpm_list_t *remove, alpm_list_t *upgrade);
|
||||||
|
alpm_list_t *alpm_deptest(pmdb_t *db, alpm_list_t *targets);
|
||||||
|
|
||||||
const char *alpm_miss_get_target(const pmdepmissing_t *miss);
|
const char *alpm_miss_get_target(const pmdepmissing_t *miss);
|
||||||
pmdepend_t *alpm_miss_get_dep(pmdepmissing_t *miss);
|
pmdepend_t *alpm_miss_get_dep(pmdepmissing_t *miss);
|
||||||
|
|
|
@ -458,7 +458,7 @@ int _alpm_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq)
|
||||||
_alpm_strtrim(line);
|
_alpm_strtrim(line);
|
||||||
if(strcmp(line, "%DEPENDS%") == 0) {
|
if(strcmp(line, "%DEPENDS%") == 0) {
|
||||||
while(fgets(line, 512, fp) && strlen(_alpm_strtrim(line))) {
|
while(fgets(line, 512, fp) && strlen(_alpm_strtrim(line))) {
|
||||||
pmdepend_t *dep = alpm_splitdep(_alpm_strtrim(line));
|
pmdepend_t *dep = _alpm_splitdep(_alpm_strtrim(line));
|
||||||
info->depends = alpm_list_add(info->depends, dep);
|
info->depends = alpm_list_add(info->depends, dep);
|
||||||
}
|
}
|
||||||
} else if(strcmp(line, "%OPTDEPENDS%") == 0) {
|
} else if(strcmp(line, "%OPTDEPENDS%") == 0) {
|
||||||
|
|
|
@ -93,7 +93,7 @@ static int does_conflict(pmpkg_t *pkg1, const char *conflict, pmpkg_t *pkg2)
|
||||||
{
|
{
|
||||||
const char *pkg1name = alpm_pkg_get_name(pkg1);
|
const char *pkg1name = alpm_pkg_get_name(pkg1);
|
||||||
const char *pkg2name = alpm_pkg_get_name(pkg2);
|
const char *pkg2name = alpm_pkg_get_name(pkg2);
|
||||||
pmdepend_t *conf = alpm_splitdep(conflict);
|
pmdepend_t *conf = _alpm_splitdep(conflict);
|
||||||
int match = 0;
|
int match = 0;
|
||||||
|
|
||||||
match = alpm_depcmp(pkg2, conf);
|
match = alpm_depcmp(pkg2, conf);
|
||||||
|
|
|
@ -223,6 +223,31 @@ static int satisfycmp(const void *pkg, const void *depend)
|
||||||
return(!alpm_depcmp((pmpkg_t*) pkg, (pmdepend_t*) depend));
|
return(!alpm_depcmp((pmpkg_t*) pkg, (pmdepend_t*) depend));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Checks dependencies and returns missing ones in a list.
|
||||||
|
* Dependencies can include versions with depmod operators.
|
||||||
|
* @param db pointer to the local package database
|
||||||
|
* @param targets an alpm_list_t* of dependencies strings to satisfy
|
||||||
|
* @return an alpm_list_t* of missing dependencies strings
|
||||||
|
*/
|
||||||
|
alpm_list_t SYMEXPORT *alpm_deptest(pmdb_t *db, alpm_list_t *targets)
|
||||||
|
{
|
||||||
|
alpm_list_t *i, *ret = NULL;
|
||||||
|
|
||||||
|
for(i = targets; i; i = alpm_list_next(i)) {
|
||||||
|
pmdepend_t *dep;
|
||||||
|
char *target;
|
||||||
|
|
||||||
|
target = alpm_list_getdata(i);
|
||||||
|
dep = _alpm_splitdep(target);
|
||||||
|
|
||||||
|
if(!alpm_list_find(_alpm_db_get_pkgcache(db), dep, satisfycmp)) {
|
||||||
|
ret = alpm_list_add(ret, target);
|
||||||
|
}
|
||||||
|
_alpm_dep_free(dep);
|
||||||
|
}
|
||||||
|
return(ret);
|
||||||
|
}
|
||||||
|
|
||||||
/** Checks dependencies and returns missing ones in a list.
|
/** Checks dependencies and returns missing ones in a list.
|
||||||
* Dependencies can include versions with depmod operators.
|
* Dependencies can include versions with depmod operators.
|
||||||
* @param db pointer to the local package database
|
* @param db pointer to the local package database
|
||||||
|
@ -364,7 +389,7 @@ int SYMEXPORT alpm_depcmp(pmpkg_t *pkg, pmdepend_t *dep)
|
||||||
return(satisfy);
|
return(satisfy);
|
||||||
}
|
}
|
||||||
|
|
||||||
pmdepend_t SYMEXPORT *alpm_splitdep(const char *depstring)
|
pmdepend_t *_alpm_splitdep(const char *depstring)
|
||||||
{
|
{
|
||||||
pmdepend_t *depend;
|
pmdepend_t *depend;
|
||||||
char *ptr = NULL;
|
char *ptr = NULL;
|
||||||
|
|
|
@ -56,7 +56,9 @@ void _alpm_depmiss_free(pmdepmissing_t *miss);
|
||||||
alpm_list_t *_alpm_sortbydeps(alpm_list_t *targets, pmtranstype_t mode);
|
alpm_list_t *_alpm_sortbydeps(alpm_list_t *targets, pmtranstype_t mode);
|
||||||
void _alpm_recursedeps(pmdb_t *db, alpm_list_t *targs, int include_explicit);
|
void _alpm_recursedeps(pmdb_t *db, alpm_list_t *targs, int include_explicit);
|
||||||
int _alpm_resolvedeps(pmdb_t *local, alpm_list_t *dbs_sync, pmpkg_t *syncpkg,
|
int _alpm_resolvedeps(pmdb_t *local, alpm_list_t *dbs_sync, pmpkg_t *syncpkg,
|
||||||
alpm_list_t **list, alpm_list_t *remove, pmtrans_t *trans, alpm_list_t **data);
|
alpm_list_t **list, alpm_list_t *remove, pmtrans_t *trans, alpm_list_t
|
||||||
|
**data);
|
||||||
|
pmdepend_t *_alpm_splitdep(const char *depstring);
|
||||||
|
|
||||||
#endif /* _ALPM_DEPS_H */
|
#endif /* _ALPM_DEPS_H */
|
||||||
|
|
||||||
|
|
|
@ -962,7 +962,7 @@ static int parse_descfile(const char *descfile, pmpkg_t *info)
|
||||||
/* size in the raw package is uncompressed (installed) size */
|
/* size in the raw package is uncompressed (installed) size */
|
||||||
info->isize = atol(ptr);
|
info->isize = atol(ptr);
|
||||||
} else if(!strcmp(key, "depend")) {
|
} else if(!strcmp(key, "depend")) {
|
||||||
pmdepend_t *dep = alpm_splitdep(ptr);
|
pmdepend_t *dep = _alpm_splitdep(ptr);
|
||||||
info->depends = alpm_list_add(info->depends, dep);
|
info->depends = alpm_list_add(info->depends, dep);
|
||||||
} else if(!strcmp(key, "optdepend")) {
|
} else if(!strcmp(key, "optdepend")) {
|
||||||
info->optdepends = alpm_list_add(info->optdepends, strdup(ptr));
|
info->optdepends = alpm_list_add(info->optdepends, strdup(ptr));
|
||||||
|
|
|
@ -1,20 +1,16 @@
|
||||||
self.description = "test deptest (-T) functionality"
|
self.description = "test deptest (-T) functionality"
|
||||||
|
|
||||||
sp1 = pmpkg("pkg1")
|
lp1 = pmpkg("pkg1")
|
||||||
sp1.depends = ["dep"]
|
self.addpkg2db("local", lp1)
|
||||||
self.addpkg2db("sync", sp1)
|
|
||||||
|
|
||||||
sp1dep = pmpkg("dep")
|
lp3 = pmpkg("pkg3", "2.0-1")
|
||||||
self.addpkg2db("sync", sp1dep)
|
lp3.provides = ("prov=3.0")
|
||||||
|
self.addpkg2db("local", lp3)
|
||||||
|
|
||||||
sp2 = pmpkg("pkg2")
|
self.args = "-T pkg1 pkg2 pkg3\>2.1 prov\>\=3.0"
|
||||||
self.addpkg2db("sync", sp2)
|
|
||||||
|
|
||||||
lp2 = pmpkg("pkg2")
|
|
||||||
self.addpkg2db("local", lp2)
|
|
||||||
|
|
||||||
self.args = "-T pkg1 pkg2"
|
|
||||||
|
|
||||||
self.addrule("PACMAN_RETCODE=127")
|
self.addrule("PACMAN_RETCODE=127")
|
||||||
self.addrule("PACMAN_OUTPUT=pkg1")
|
self.addrule("!PACMAN_OUTPUT=pkg1")
|
||||||
self.addrule("!PACMAN_OUTPUT=pkg2")
|
self.addrule("PACMAN_OUTPUT=pkg2")
|
||||||
|
self.addrule("PACMAN_OUTPUT=pkg3")
|
||||||
|
self.addrule("!PACMAN_OUTPUT=prov")
|
||||||
|
|
|
@ -31,53 +31,23 @@
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
|
|
||||||
/* TODO: This should use _alpm_checkdeps() */
|
|
||||||
int pacman_deptest(alpm_list_t *targets)
|
int pacman_deptest(alpm_list_t *targets)
|
||||||
{
|
{
|
||||||
int retval = 0;
|
|
||||||
alpm_list_t *i;
|
alpm_list_t *i;
|
||||||
|
|
||||||
if(targets == NULL) {
|
alpm_list_t *deps = alpm_deptest(alpm_option_get_localdb(), targets);
|
||||||
|
if(deps == NULL) {
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i = targets; i; i = alpm_list_next(i)) {
|
for(i = deps; i; i = alpm_list_next(i)) {
|
||||||
int found = 0;
|
const char *dep;
|
||||||
pmpkg_t *pkg;
|
|
||||||
pmdepend_t *dep;
|
|
||||||
const char *target;
|
|
||||||
alpm_list_t *j, *provides;
|
|
||||||
|
|
||||||
target = alpm_list_getdata(i);
|
dep = alpm_list_getdata(i);
|
||||||
dep = alpm_splitdep(target);
|
printf("%s\n", dep);
|
||||||
|
|
||||||
pkg = alpm_db_get_pkg(alpm_option_get_localdb(),
|
|
||||||
alpm_dep_get_name(dep));
|
|
||||||
if(pkg && alpm_depcmp(pkg, dep)) {
|
|
||||||
found = 1;
|
|
||||||
} else {
|
|
||||||
/* not found, can we find anything that provides this in the local DB? */
|
|
||||||
provides = alpm_db_whatprovides(alpm_option_get_localdb(),
|
|
||||||
alpm_dep_get_name(dep));
|
|
||||||
for(j = provides; j; j = alpm_list_next(j)) {
|
|
||||||
pmpkg_t *pkg;
|
|
||||||
pkg = alpm_list_getdata(j);
|
|
||||||
|
|
||||||
if(pkg && alpm_depcmp(pkg, dep)) {
|
|
||||||
found = 1;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
alpm_list_free(deps);
|
||||||
alpm_list_free(provides);
|
return(127);
|
||||||
}
|
|
||||||
|
|
||||||
if(!found) {
|
|
||||||
printf("%s\n", target);
|
|
||||||
retval = 127;
|
|
||||||
}
|
|
||||||
free(dep);
|
|
||||||
}
|
|
||||||
return(retval);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* vim: set ts=2 sw=2 noet: */
|
/* vim: set ts=2 sw=2 noet: */
|
||||||
|
|
Loading…
Add table
Reference in a new issue