summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2010-12-10 14:14:44 +0200
committerPanu Matilainen <pmatilai@redhat.com>2010-12-10 17:05:22 +0200
commitbbc889541263669c3d94b7200dc051da9ca86317 (patch)
tree3444c91ac4dd4f49b311bdf764e3a23159adf3a2
parent558c775ecfe5be633aaeb907b1f529dfb445e36f (diff)
downloadrpm-bbc889541263669c3d94b7200dc051da9ca86317.tar.gz
rpm-bbc889541263669c3d94b7200dc051da9ca86317.tar.bz2
rpm-bbc889541263669c3d94b7200dc051da9ca86317.zip
Refactor the helper execution out of rpmfcHelper()
- Split the macro name generation and grabbing of argv-style output into yet another helper to reduce the clutter in rpmfcHelper() before adding more stuff in there. (cherry picked from commit ca3089f8bc4de7e2426b129f998a3c59daeebfd0)
-rw-r--r--build/rpmfc.c127
1 files changed, 67 insertions, 60 deletions
diff --git a/build/rpmfc.c b/build/rpmfc.c
index 955529dd7..e0581df54 100644
--- a/build/rpmfc.c
+++ b/build/rpmfc.c
@@ -409,6 +409,34 @@ static void rpmfcAddFileDep(ARGV_t * argvp, int ix, rpmds ds, char deptype)
}
}
+static ARGV_t runCmd(const char *nsdep, const char *depname,
+ const char *buildRoot, const char *fn)
+{
+ ARGV_t output = NULL;
+ char *buf = NULL;
+ char *mname = rstrscat(NULL, "__", nsdep, "_", depname, NULL);
+
+ rasprintf(&buf, "%%{?%s:%%{%s} %%{?%s_opts}}", mname, mname, mname);
+ if (!rstreq(buf, "")) {
+ ARGV_t av = NULL;
+ StringBuf sb_stdout = NULL;
+ StringBuf sb_stdin = newStringBuf();
+ argvAdd(&av, buf);
+
+ appendLineStringBuf(sb_stdin, fn);
+ if (rpmfcExec(av, sb_stdin, &sb_stdout, 0, buildRoot) == 0) {
+ argvSplit(&output, getStringBuf(sb_stdout), " \t\n\r");
+ }
+
+ argvFree(av);
+ freeStringBuf(sb_stdin);
+ freeStringBuf(sb_stdout);
+ }
+ free(buf);
+ free(mname);
+ return output;
+}
+
/**
* Run per-interpreter dependency helper.
* @param fc file classifier
@@ -418,16 +446,13 @@ static void rpmfcAddFileDep(ARGV_t * argvp, int ix, rpmds ds, char deptype)
*/
static int rpmfcHelper(rpmfc fc, unsigned char deptype, const char * nsdep)
{
+ ARGV_t pav = NULL;
const char * fn = fc->fn[fc->ix];
- char *buf = NULL;
- char *mname = NULL;
- StringBuf sb_stdout = NULL;
- StringBuf sb_stdin;
+ const char * depname = NULL;
rpmds * depsp;
rpmsenseFlags dsContext;
rpmTagVal tagN;
- ARGV_t av = NULL;
- int xx;
+ int pac;
switch (deptype) {
default:
@@ -436,7 +461,7 @@ static int rpmfcHelper(rpmfc fc, unsigned char deptype, const char * nsdep)
case 'P':
if (fc->skipProv)
return 0;
- mname = rstrscat(NULL, "__", nsdep, "_provides", NULL);
+ depname = "provides";
depsp = &fc->provides;
dsContext = RPMSENSE_FIND_PROVIDES;
tagN = RPMTAG_PROVIDENAME;
@@ -444,72 +469,54 @@ static int rpmfcHelper(rpmfc fc, unsigned char deptype, const char * nsdep)
case 'R':
if (fc->skipReq)
return 0;
- mname = rstrscat(NULL, "__", nsdep, "_requires", NULL);
+ depname = "requires";
depsp = &fc->requires;
dsContext = RPMSENSE_FIND_REQUIRES;
tagN = RPMTAG_REQUIRENAME;
break;
}
- rasprintf(&buf, "%%{?%s:%%{%s} %%{?%s_opts}}", mname, mname, mname);
- argvAdd(&av, buf);
- buf = _free(buf);
-
- sb_stdin = newStringBuf();
- appendLineStringBuf(sb_stdin, fn);
- sb_stdout = NULL;
- xx = rpmfcExec(av, sb_stdin, &sb_stdout, 0, fc->buildRoot);
- sb_stdin = freeStringBuf(sb_stdin);
- if (xx == 0 && sb_stdout != NULL) {
- ARGV_t pav = NULL;
- int pac;
- xx = argvSplit(&pav, getStringBuf(sb_stdout), " \t\n\r");
- pac = argvCount(pav);
- if (pav)
- for (int i = 0; i < pac; i++) {
- rpmds ds = NULL;
- const char *N = pav[i];
- const char *EVR = "";
- rpmsenseFlags Flags = dsContext;
- if (pav[i+1] && strchr("=<>", *pav[i+1])) {
- i++;
- for (const char *s = pav[i]; *s; s++) {
- switch(*s) {
- default:
-assert(*s != '\0');
- break;
- case '=':
- Flags |= RPMSENSE_EQUAL;
- break;
- case '<':
- Flags |= RPMSENSE_LESS;
- break;
- case '>':
- Flags |= RPMSENSE_GREATER;
- break;
- }
+ pav = runCmd(nsdep, depname, fc->buildRoot, fn);
+ pac = argvCount(pav);
+
+ for (int i = 0; i < pac; i++) {
+ rpmds ds = NULL;
+ const char *N = pav[i];
+ const char *EVR = "";
+ rpmsenseFlags Flags = dsContext;
+ if (pav[i+1] && strchr("=<>", *pav[i+1])) {
+ i++;
+ for (const char *s = pav[i]; *s; s++) {
+ switch(*s) {
+ default:
+ break;
+ case '=':
+ Flags |= RPMSENSE_EQUAL;
+ break;
+ case '<':
+ Flags |= RPMSENSE_LESS;
+ break;
+ case '>':
+ Flags |= RPMSENSE_GREATER;
+ break;
}
- i++;
- EVR = pav[i];
-assert(EVR != NULL);
}
+ i++;
+ EVR = pav[i];
+ }
- ds = rpmdsSingle(tagN, N, EVR, Flags);
-
- /* Add to package dependencies. */
- xx = rpmdsMerge(depsp, ds);
+ ds = rpmdsSingle(tagN, N, EVR, Flags);
- /* Add to file dependencies. */
- rpmfcAddFileDep(&fc->ddict, fc->ix, ds, deptype);
+ /* Add to package dependencies. */
+ (void) rpmdsMerge(depsp, ds);
- ds = rpmdsFree(ds);
- }
+ /* Add to file dependencies. */
+ rpmfcAddFileDep(&fc->ddict, fc->ix, ds, deptype);
- pav = argvFree(pav);
+ ds = rpmdsFree(ds);
}
- sb_stdout = freeStringBuf(sb_stdout);
- free(mname);
- argvFree(av);
+
+ argvFree(pav);
return 0;
}