]> git.pld-linux.org Git - packages/rpm.git/blob - rpm-rpmspec.patch
- port rpmspec tool from rpm.org, usefull to see how spec will look like after parsing
[packages/rpm.git] / rpm-rpmspec.patch
1 diff -urN rpm-5.4.13/build/parseSpec.c rpm-5.4.13-rpmspec/build/parseSpec.c
2 --- rpm-5.4.13/build/parseSpec.c        2013-10-22 20:18:34.483039876 +0200
3 +++ rpm-5.4.13-rpmspec/build/parseSpec.c        2013-10-22 18:52:02.550664732 +0200
4 @@ -474,6 +474,11 @@
5         spec->line[0] = '\0';
6      }
7  
8 +    /* Collect parsed line */
9 +    if (spec->parsed == NULL)
10 +       spec->parsed = rpmiobNew(0);
11 +    spec->parsed = rpmiobAppend(spec->parsed, spec->line, 1);
12 +
13      /*@-compmempass@*/ /* FIX: spec->readStack->next should be dependent */
14      return 0;
15      /*@=compmempass@*/
16 diff -urN rpm-5.4.13/build/rpmspec.h rpm-5.4.13-rpmspec/build/rpmspec.h
17 --- rpm-5.4.13/build/rpmspec.h  2013-10-22 20:18:34.449706143 +0200
18 +++ rpm-5.4.13-rpmspec/build/rpmspec.h  2013-10-22 18:44:37.729692113 +0200
19 @@ -193,6 +193,8 @@
20  /*@only@*/
21      rpmiob clean;              /*!< %clean scriptlet. */
22  
23 +    rpmiob parsed;
24 +
25      size_t nfoo;
26  /*@only@*/ /*@relnull@*/
27      tagStore_t foo;
28 diff -urN rpm-5.4.13/tools/Makefile.am rpm-5.4.13-rpmspec/tools/Makefile.am
29 --- rpm-5.4.13/tools/Makefile.am        2013-10-22 20:18:34.426372530 +0200
30 +++ rpm-5.4.13-rpmspec/tools/Makefile.am        2013-10-22 20:02:30.365350944 +0200
31 @@ -61,7 +61,7 @@
32  pkgbin_PROGRAMS =      \
33         @WITH_AUGEAS_AUGTOOL@ chroot cp @WITH_CUDF_CUDFTOOL@ find mtree \
34         @WITH_SEMANAGE_SEMODULE@ wget \
35 -       rpmcache rpmdigest rpmrepo rpmspecdump \
36 +       rpmcache rpmdigest rpmrepo rpmspecdump rpmspec \
37         rpmcmp rpmdeps sqlite3 @WITH_KEYUTILS_RPMKEY@ @WITH_LIBELF_DEBUGEDIT@
38  if WITH_DB
39  pkgbin_PROGRAMS +=     dbconvert
40 @@ -195,6 +195,9 @@
41  rpmspecdump_SOURCES =  rpmspecdump.c
42  rpmspecdump_LDADD =    $(RPMBUILD_LDADD_COMMON)
43  
44 +rpmspec_SOURCES =      rpmspec.c
45 +rpmspec_LDADD =        $(RPMBUILD_LDADD_COMMON)
46 +
47  semodule_SOURCES =     semodule.c
48  semodule_LDADD =       $(RPMIO_LDADD_COMMON)
49  
50 diff -urN rpm-5.4.13/tools/rpmspec.c rpm-5.4.13-rpmspec/tools/rpmspec.c
51 --- rpm-5.4.13/tools/rpmspec.c  1970-01-01 01:00:00.000000000 +0100
52 +++ rpm-5.4.13-rpmspec/tools/rpmspec.c  2013-10-22 20:00:06.075242852 +0200
53 @@ -0,0 +1,176 @@
54 +#include "system.h"
55 +const char *__progname;
56 +
57 +#define        _AUTOHELP
58 +
59 +#if defined(IAM_RPM) || defined(__LCLINT__)
60 +#define        IAM_RPMBT
61 +#define        IAM_RPMDB
62 +#define        IAM_RPMEIU
63 +#define        IAM_RPMQV
64 +#define        IAM_RPMK
65 +#endif
66 +
67 +#include <rpmio.h>
68 +#include <rpmiotypes.h>
69 +#include <poptIO.h>
70 +
71 +#include <rpmtypes.h>
72 +#include <rpmtag.h>
73 +#include "rpmdb.h"
74 +
75 +#include "rpmversion.h"
76 +#include "rpmps.h"
77 +#include "rpmts.h"
78 +
79 +#include <rpmbuild.h>
80 +
81 +#ifdef IAM_RPMBT
82 +#include "build.h"
83 +#define GETOPT_REBUILD         1003
84 +#define GETOPT_RECOMPILE       1004
85 +#endif
86 +
87 +#include <rpmcli.h>
88 +
89 +#include "debug.h"
90 +
91 +enum modes {
92 +    MODE_UNKNOWN       = 0,
93 +    MODE_QUERY         = (1 <<  0),
94 +    MODE_PARSE         = (1 <<  1),
95 +};
96 +
97 +static int mode = MODE_UNKNOWN;
98 +static rpmQVSources source = RPMQV_RPM;
99 +static const char *target = NULL;
100 +static char *queryformat = NULL;
101 +
102 +static struct poptOption specOptsTable[] = {
103 +    { "parse", 'P', POPT_ARG_VAL, &mode, MODE_PARSE,
104 +       N_("parse spec file(s) to stdout"), NULL },
105 +    { "query", 'q', POPT_ARG_VAL, &mode, MODE_QUERY,
106 +       N_("query spec file(s)"), NULL },
107 +    { "rpms", 0, POPT_ARG_VAL, &source, RPMQV_RPM,
108 +       N_("operate on binary rpms generated by spec (default)"), NULL },
109 +    { "srpm", 0, POPT_ARG_VAL, &source, RPMQV_SPECSRPM,
110 +       N_("operate on source rpm generated by spec"), NULL },
111 +    { "target", 0, POPT_ARG_STRING, &target, 0,
112 +       N_("override target platform"), NULL },
113 +    { "queryformat", 0, POPT_ARG_STRING, &queryformat, 0,
114 +       N_("use the following query format"), "QUERYFORMAT" },
115 +    { "qf", 0, (POPT_ARG_STRING | POPT_ARGFLAG_DOC_HIDDEN), &queryformat, 0,
116 +       NULL, NULL },
117 +    POPT_TABLEEND
118 +};
119 +
120 +/* the structure describing the options we take and the defaults */
121 +static struct poptOption optionsTable[] = {
122 +    { NULL, '\0', POPT_ARG_INCLUDE_TABLE, specOptsTable, 0,
123 +       N_("Spec options:"), NULL },
124 +
125 +    { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmcliAllPoptTable, 0,
126 +       N_("Common options for all rpm modes and executables:"), NULL },
127 +
128 +   POPT_AUTOALIAS
129 +   POPT_AUTOHELP
130 +   POPT_TABLEEND
131 +};
132 +
133 +/*@exits@*/ static void argerror(const char * desc)
134 +       /*@globals __assert_program_name, fileSystem @*/
135 +       /*@modifies fileSystem @*/
136 +{
137 +    fprintf(stderr, _("%s: %s\n"), __progname, desc);
138 +    exit(EXIT_FAILURE);
139 +}
140 +
141 +#ifdef DYING /* XXX rpmIsVerbose alone stops usage spewage with every --eval */
142 +static void printVersion(FILE * fp)
143 +       /*@globals rpmEVR, fileSystem @*/
144 +       /*@modifies *fp, fileSystem @*/
145 +{
146 +    fprintf(fp, "%s (" RPM_NAME ") %s\n", __progname, rpmEVR);
147 +    if (rpmIsVerbose())
148 +       fprintf(fp, "rpmlib 0x%08x,0x%08x,0x%08x\n",
149 +           rpmlibVersion(), rpmlibTimestamp(), rpmlibVendor());
150 +}
151 +
152 +static void printUsage(poptContext con, FILE * fp, int flags)
153 +       /*@globals rpmEVR, fileSystem, internalState @*/
154 +       /*@modifies *fp, fileSystem, internalState @*/
155 +{
156 +    printVersion(fp);
157 +    fprintf(fp, "\n");
158 +
159 +    if (rpmIsVerbose())
160 +       poptPrintHelp(con, fp, flags);
161 +    else
162 +       poptPrintUsage(con, fp, flags);
163 +}
164 +#endif
165 +
166 +int main(int argc, char *argv[])
167 +{
168 +    rpmts ts = NULL;
169 +    QVA_t qva = &rpmQVKArgs;
170 +
171 +    poptContext optCon;
172 +    int ec = 0;
173 +
174 +    optCon = rpmcliInit(argc, argv, optionsTable);
175 +
176 +    if (target) {
177 +       rpmFreeMacros(NULL);
178 +       rpmFreeRpmrc();
179 +        rpmcliConfigured();
180 +    }
181 +
182 +    ts = rpmtsCreate();
183 +    switch (mode) {
184 +
185 +    case MODE_QUERY:
186 +       if (!poptPeekArg(optCon))
187 +           argerror(_("no arguments given for query"));
188 +
189 +       qva->qva_queryFormat = queryformat;
190 +       qva->qva_source = source;
191 +       qva->qva_specQuery = rpmspecQuery;
192 +       ec = rpmcliQuery(ts, qva, (const char **) poptGetArgs(optCon));
193 +       break;
194 +
195 +    case MODE_PARSE: {
196 +       const char * spath;
197 +       if (!poptPeekArg(optCon))
198 +           argerror(_("no arguments given for parse"));
199 +
200 +       while ((spath = poptGetArg(optCon)) != NULL) {
201 +           int ret = parseSpec(ts, spath, "/", 0, NULL, NULL, 1, 1, 0);
202 +           if (ret != 0) {
203 +               ec++;
204 +               continue;
205 +           }
206 +           Spec spec = rpmtsSpec(ts);
207 +           fprintf(stdout, "%s", rpmiobStr(spec->parsed));
208 +       }
209 +       break;
210 +    }
211 +
212 +    case MODE_UNKNOWN:
213 +#ifdef DYING /* XXX rpmIsVerbose alone stops usage spewage with every --eval */
214 +       if (poptPeekArg(optCon) != NULL || argc <= 1 || rpmIsVerbose()) {
215 +           printUsage(optCon, stderr, 0);
216 +           ec = argc;
217 +       }
218 +#endif
219 +       break;
220 +    }
221 +
222 +    rpmtsFree(ts);
223 +
224 +    free(qva->qva_queryFormat);
225 +
226 +    rpmcliFini(optCon);
227 +
228 +    return ec;
229 +}
This page took 0.046179 seconds and 4 git commands to generate.