summaryrefslogtreecommitdiff
path: root/build/spec.c
diff options
context:
space:
mode:
Diffstat (limited to 'build/spec.c')
-rw-r--r--build/spec.c137
1 files changed, 99 insertions, 38 deletions
diff --git a/build/spec.c b/build/spec.c
index 4b6b6805d..39599e284 100644
--- a/build/spec.c
+++ b/build/spec.c
@@ -13,6 +13,7 @@
#include <rpm/rpmfileutil.h>
#include "rpmio/rpmlua.h"
+#include "lib/rpmfi_internal.h" /* rpmfiles stuff */
#include "build/rpmbuild_internal.h"
#include "debug.h"
@@ -60,8 +61,8 @@ struct Source * freeSources(struct Source * s)
rpmRC lookupPackage(rpmSpec spec, const char *name, int flag,Package *pkg)
{
- const char *pname;
char *fullName = NULL;
+ rpmsid nameid = 0;
Package p;
/* "main" package */
@@ -71,46 +72,66 @@ rpmRC lookupPackage(rpmSpec spec, const char *name, int flag,Package *pkg)
return RPMRC_OK;
}
- /* Construct package name */
- if (flag == PART_SUBNAME) {
- pname = headerGetString(spec->packages->header, RPMTAG_NAME);
- rasprintf(&fullName, "%s-%s", pname, name);
- } else {
- fullName = xstrdup(name);
+ /* Construct partial package name */
+ if (!(flag & PART_NAME)) {
+ rasprintf(&fullName, "%s-%s",
+ headerGetString(spec->packages->header, RPMTAG_NAME), name);
+ name = fullName;
}
+ nameid = rpmstrPoolId(spec->pool, name, 1);
- /* Locate package with fullName */
+ /* Locate package the name */
for (p = spec->packages; p != NULL; p = p->next) {
- pname = headerGetString(p->header, RPMTAG_NAME);
- if (pname && (rstreq(fullName, pname))) {
+ if (p->name && p->name == nameid) {
break;
}
}
- free(fullName);
+
+ if (!(flag & PART_QUIET)) {
+ if (p == NULL && pkg != NULL) {
+ rpmlog(RPMLOG_ERR, _("line %d: %s: package %s does not exist\n"),
+ spec->lineNum, spec->line, name);
+ } else if (p != NULL && pkg == NULL) {
+ rpmlog(RPMLOG_ERR, _("line %d: %s: package %s already exists\n"),
+ spec->lineNum, spec->line, name);
+ }
+ }
+
+ if (fullName == name)
+ free(fullName);
if (pkg)
*pkg = p;
return ((p == NULL) ? RPMRC_FAIL : RPMRC_OK);
}
-Package newPackage(rpmSpec spec)
+Package newPackage(const char *name, rpmstrPool pool, Package *pkglist)
{
Package p = xcalloc(1, sizeof(*p));
p->header = headerNew();
p->autoProv = 1;
p->autoReq = 1;
p->fileList = NULL;
+ p->fileExcludeList = NULL;
p->fileFile = NULL;
p->policyList = NULL;
-
- if (spec->packages == NULL) {
- spec->packages = p;
- } else {
- Package pp;
- /* Always add package to end of list */
- for (pp = spec->packages; pp->next != NULL; pp = pp->next)
- {};
- pp->next = p;
+ p->fileRenameMap = NULL;
+ p->pool = rpmstrPoolLink(pool);
+ p->dpaths = NULL;
+
+ if (name)
+ p->name = rpmstrPoolId(p->pool, name, 1);
+
+ if (pkglist) {
+ if (*pkglist == NULL) {
+ *pkglist = p;
+ } else {
+ Package pp;
+ /* Always add package to end of list */
+ for (pp = *pkglist; pp->next != NULL; pp = pp->next)
+ {};
+ pp->next = p;
+ }
}
p->next = NULL;
@@ -129,13 +150,25 @@ static Package freePackage(Package pkg)
pkg->header = headerFree(pkg->header);
pkg->ds = rpmdsFree(pkg->ds);
+
+ for (int i=0; i<PACKAGE_NUM_DEPS; i++) {
+ pkg->dependencies[i] = rpmdsFree(pkg->dependencies[i]);
+ }
+
pkg->fileList = argvFree(pkg->fileList);
+ pkg->fileExcludeList = argvFree(pkg->fileExcludeList);
pkg->fileFile = argvFree(pkg->fileFile);
pkg->policyList = argvFree(pkg->policyList);
- pkg->cpioList = rpmfiFree(pkg->cpioList);
+ pkg->removePostfixes = argvFree(pkg->removePostfixes);
+ pkg->fileRenameMap = fileRenameHashFree(pkg->fileRenameMap);
+ pkg->cpioList = rpmfilesFree(pkg->cpioList);
+ pkg->dpaths = argvFree(pkg->dpaths);
pkg->icon = freeSources(pkg->icon);
pkg->triggerFiles = freeTriggerFiles(pkg->triggerFiles);
+ pkg->fileTriggerFiles = freeTriggerFiles(pkg->fileTriggerFiles);
+ pkg->transFileTriggerFiles = freeTriggerFiles(pkg->transFileTriggerFiles);
+ pkg->pool = rpmstrPoolFree(pkg->pool);
free(pkg);
return NULL;
@@ -153,6 +186,21 @@ static Package freePackages(Package packages)
return NULL;
}
+rpmds * packageDependencies(Package pkg, rpmTagVal tag)
+{
+ for (int i=0; i<PACKAGE_NUM_DEPS; i++) {
+ if (pkg->dependencies[i] == NULL) {
+ return &pkg->dependencies[i];
+ }
+ rpmTagVal tagN = rpmdsTagN(pkg->dependencies[i]);
+ if (tagN == tag || tagN == 0) {
+ return &pkg->dependencies[i];
+ }
+ }
+ return NULL;
+}
+
+
rpmSpec newSpec(void)
{
rpmSpec spec = xcalloc(1, sizeof(*spec));
@@ -186,8 +234,7 @@ rpmSpec newSpec(void)
spec->sourceRpmName = NULL;
spec->sourcePkgId = NULL;
- spec->sourceHeader = NULL;
- spec->sourceCpioList = NULL;
+ spec->sourcePackage = NULL;
spec->buildRoot = NULL;
spec->buildSubdir = NULL;
@@ -201,11 +248,14 @@ rpmSpec newSpec(void)
spec->flags = RPMSPEC_NONE;
spec->macros = rpmGlobalMacroContext;
+ spec->pool = rpmstrPoolCreate();
#ifdef WITH_LUA
{
/* make sure patches and sources tables always exist */
rpmlua lua = NULL; /* global state */
+ rpmluaDelVar(lua, "patches");
+ rpmluaDelVar(lua, "sources");
rpmluaPushTable(lua, "patches");
rpmluaPushTable(lua, "sources");
rpmluaPop(lua);
@@ -243,8 +293,7 @@ rpmSpec rpmSpecFree(rpmSpec spec)
spec->sourceRpmName = _free(spec->sourceRpmName);
spec->sourcePkgId = _free(spec->sourcePkgId);
- spec->sourceHeader = headerFree(spec->sourceHeader);
- spec->sourceCpioList = rpmfiFree(spec->sourceCpioList);
+ spec->sourcePackage = freePackage(spec->sourcePackage);
spec->buildRestrictions = headerFree(spec->buildRestrictions);
@@ -266,6 +315,7 @@ rpmSpec rpmSpecFree(rpmSpec spec)
spec->sources = freeSources(spec->sources);
spec->packages = freePackages(spec->packages);
+ spec->pool = rpmstrPoolFree(spec->pool);
spec = _free(spec);
@@ -274,12 +324,12 @@ rpmSpec rpmSpecFree(rpmSpec spec)
Header rpmSpecSourceHeader(rpmSpec spec)
{
- return spec->sourceHeader;
+ return (spec && spec->sourcePackage) ? spec->sourcePackage->header : NULL;
}
rpmds rpmSpecDS(rpmSpec spec, rpmTagVal tag)
{
- return (spec != NULL) ? rpmdsNew(spec->buildRestrictions, tag, 0) : NULL;
+ return (spec != NULL) ? rpmdsNew(spec->sourcePackage->header, tag, 0) : NULL;
}
rpmps rpmSpecCheckDeps(rpmts ts, rpmSpec spec)
@@ -341,6 +391,18 @@ Header rpmSpecPkgHeader(rpmSpecPkg pkg)
return (pkg != NULL) ? pkg->header : NULL;
}
+char* rpmSpecPkgGetSection(rpmSpecPkg pkg, int section)
+{
+ if (pkg) {
+ switch (section) {
+ case RPMBUILD_FILE_FILE: return argvJoin(pkg->fileFile, "");
+ case RPMBUILD_FILE_LIST: return argvJoin(pkg->fileList, "");
+ case RPMBUILD_POLICY: return argvJoin(pkg->policyList, "");
+ }
+ }
+ return NULL;
+}
+
rpmSpecSrcIter rpmSpecSrcIterInit(rpmSpec spec)
{
SPEC_LISTITER_INIT(rpmSpecSrcIter, sources);
@@ -405,21 +467,20 @@ int rpmspecQuery(rpmts ts, QVA_t qva, const char * arg)
goto exit;
}
- if (qva->qva_source == RPMQV_SPECRPMS) {
+ if (qva->qva_source == RPMQV_SPECRPMS ||
+ qva->qva_source == RPMQV_SPECBUILTRPMS) {
+
res = 0;
for (Package pkg = spec->packages; pkg != NULL; pkg = pkg->next) {
-#if 0
- /*
- * XXX FIXME: whether to show all or just the packages that
- * would be built needs to be made caller specifiable, for now
- * revert to "traditional" behavior as existing tools rely on this.
- */
- if (pkg->fileList == NULL) continue;
-#endif
+
+ if (qva->qva_source == RPMQV_SPECBUILTRPMS && pkg->fileList == NULL)
+ continue;
+
res += qva->qva_showPackage(qva, ts, pkg->header);
}
} else {
- res = qva->qva_showPackage(qva, ts, spec->sourceHeader);
+ Package sourcePkg = spec->sourcePackage;
+ res = qva->qva_showPackage(qva, ts, sourcePkg->header);
}
exit: