1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
|
/** \ingroup rpmbuild
* \file build/parseSpec.c
* Top level dispatcher for spec file parsing.
*/
#include "system.h"
#include <errno.h>
#include <rpm/rpmtypes.h>
#include <rpm/rpmlib.h> /* RPM_MACHTABLE & related */
#include <rpm/rpmds.h>
#include <rpm/rpmts.h>
#include <rpm/rpmlog.h>
#include <rpm/rpmfileutil.h>
#include "build/rpmbuild_internal.h"
#include "build/rpmbuild_misc.h"
#include "debug.h"
#define SKIPSPACE(s) { while (*(s) && risspace(*(s))) (s)++; }
#define SKIPNONSPACE(s) { while (*(s) && !risspace(*(s))) (s)++; }
#define ISMACRO(s,m) (rstreqn((s), (m), sizeof((m))-1) && !risalpha((s)[sizeof((m))-1]))
#define ISMACROWITHARG(s,m) (rstreqn((s), (m), sizeof((m))-1) && (risblank((s)[sizeof((m))-1]) || !(s)[sizeof((m))-1]))
#define LEN_AND_STR(_tag) (sizeof(_tag)-1), (_tag)
typedef struct OpenFileInfo {
char * fileName;
FILE *fp;
int lineNum;
char readBuf[BUFSIZ];
char * readPtr;
struct OpenFileInfo * next;
} OFI_t;
static const struct PartRec {
int part;
size_t len;
const char * token;
} partList[] = {
{ PART_PREAMBLE, LEN_AND_STR("%package")},
{ PART_PREP, LEN_AND_STR("%prep")},
{ PART_BUILD, LEN_AND_STR("%build")},
{ PART_INSTALL, LEN_AND_STR("%install")},
{ PART_CHECK, LEN_AND_STR("%check")},
{ PART_CLEAN, LEN_AND_STR("%clean")},
{ PART_PREUN, LEN_AND_STR("%preun")},
{ PART_POSTUN, LEN_AND_STR("%postun")},
{ PART_PRETRANS, LEN_AND_STR("%pretrans")},
{ PART_POSTTRANS, LEN_AND_STR("%posttrans")},
{ PART_PRE, LEN_AND_STR("%pre")},
{ PART_POST, LEN_AND_STR("%post")},
{ PART_FILES, LEN_AND_STR("%files")},
{ PART_CHANGELOG, LEN_AND_STR("%changelog")},
{ PART_DESCRIPTION, LEN_AND_STR("%description")},
{ PART_TRIGGERPOSTUN, LEN_AND_STR("%triggerpostun")},
{ PART_TRIGGERPREIN, LEN_AND_STR("%triggerprein")},
{ PART_TRIGGERUN, LEN_AND_STR("%triggerun")},
{ PART_TRIGGERIN, LEN_AND_STR("%triggerin")},
{ PART_TRIGGERIN, LEN_AND_STR("%trigger")},
{ PART_VERIFYSCRIPT, LEN_AND_STR("%verifyscript")},
{ PART_POLICIES, LEN_AND_STR("%sepolicy")},
{0, 0, 0}
};
int isPart(const char *line)
{
const struct PartRec *p;
for (p = partList; p->token != NULL; p++) {
char c;
if (rstrncasecmp(line, p->token, p->len))
continue;
c = *(line + p->len);
if (c == '\0' || risspace(c))
break;
}
return (p->token ? p->part : PART_NONE);
}
/**
*/
static int matchTok(const char *token, const char *line)
{
const char *b, *be = line;
size_t toklen = strlen(token);
int rc = 0;
while ( *(b = be) != '\0' ) {
SKIPSPACE(b);
be = b;
SKIPNONSPACE(be);
if (be == b)
break;
if (toklen != (be-b) || rstrncasecmp(token, b, (be-b)))
continue;
rc = 1;
break;
}
return rc;
}
void handleComments(char *s)
{
SKIPSPACE(s);
if (*s == '#')
*s = '\0';
}
/* Push a file to spec's file stack, return the newly pushed entry */
static OFI_t * pushOFI(rpmSpec spec, const char *fn)
{
OFI_t *ofi = xcalloc(1, sizeof(*ofi));
ofi->fp = NULL;
ofi->fileName = xstrdup(fn);
ofi->lineNum = 0;
ofi->readBuf[0] = '\0';
ofi->readPtr = NULL;
ofi->next = spec->fileStack;
spec->fileStack = ofi;
return spec->fileStack;
}
/* Pop from spec's file stack */
static OFI_t * popOFI(rpmSpec spec)
{
if (spec->fileStack) {
OFI_t * ofi = spec->fileStack;
spec->fileStack = ofi->next;
if (ofi->fp)
fclose(ofi->fp);
free(ofi->fileName);
free(ofi);
}
return spec->fileStack;
}
static int restoreFirstChar(rpmSpec spec)
{
/* Restore 1st char in (possible) next line */
if (spec->nextline != NULL && spec->nextpeekc != '\0') {
*spec->nextline = spec->nextpeekc;
spec->nextpeekc = '\0';
return 1;
}
return 0;
}
/* Return zero on success, 1 if we need to read more and -1 on errors. */
static int copyNextLineFromOFI(rpmSpec spec, OFI_t *ofi)
{
char ch;
/* Expand next line from file into line buffer */
if (!(spec->nextline && *spec->nextline)) {
int pc = 0, bc = 0, nc = 0;
char *from, *to, *p;
to = spec->lbufPtr ? spec->lbufPtr : spec->lbuf;
from = ofi->readPtr;
ch = ' ';
while (from && *from && ch != '\n')
ch = *to++ = *from++;
spec->lbufPtr = to;
*to = '\0';
ofi->readPtr = from;
/* Check if we need another line before expanding the buffer. */
for (p = spec->lbuf; *p; p++) {
switch (*p) {
case '\\':
switch (*(p+1)) {
case '\n': p++, nc = 1; break;
case '\0': break;
default: p++; break;
}
break;
case '\n': nc = 0; break;
case '%':
switch (*(p+1)) {
case '{': p++, bc++; break;
case '(': p++, pc++; break;
case '%': p++; break;
}
break;
case '{': if (bc > 0) bc++; break;
case '}': if (bc > 0) bc--; break;
case '(': if (pc > 0) pc++; break;
case ')': if (pc > 0) pc--; break;
}
}
/* If it doesn't, ask for one more line. */
if (pc || bc || nc ) {
spec->nextline = "";
return 1;
}
spec->lbufPtr = spec->lbuf;
/* Don't expand macros (eg. %define) in false branch of %if clause */
if (spec->readStack->reading &&
expandMacros(spec, spec->macros, spec->lbuf, sizeof(spec->lbuf))) {
rpmlog(RPMLOG_ERR, _("line %d: %s\n"),
spec->lineNum, spec->lbuf);
return -1;
}
spec->nextline = spec->lbuf;
}
return 0;
}
static void copyNextLineFinish(rpmSpec spec, int strip)
{
char *last;
char ch;
/* Find next line in expanded line buffer */
spec->line = last = spec->nextline;
ch = ' ';
while (*spec->nextline && ch != '\n') {
ch = *spec->nextline++;
if (!risspace(ch))
last = spec->nextline;
}
/* Save 1st char of next line in order to terminate current line. */
if (*spec->nextline != '\0') {
spec->nextpeekc = *spec->nextline;
*spec->nextline = '\0';
}
if (strip & STRIP_COMMENTS)
handleComments(spec->line);
if (strip & STRIP_TRAILINGSPACE)
*last = '\0';
}
static int readLineFromOFI(rpmSpec spec, OFI_t *ofi)
{
retry:
/* Make sure the current file is open */
if (ofi->fp == NULL) {
ofi->fp = fopen(ofi->fileName, "r");
if (ofi->fp == NULL) {
rpmlog(RPMLOG_ERR, _("Unable to open %s: %s\n"),
ofi->fileName, strerror(errno));
return PART_ERROR;
}
spec->lineNum = ofi->lineNum = 0;
}
/* Make sure we have something in the read buffer */
if (!(ofi->readPtr && *(ofi->readPtr))) {
if (!fgets(ofi->readBuf, BUFSIZ, ofi->fp)) {
/* EOF */
if (spec->readStack->next) {
rpmlog(RPMLOG_ERR, _("Unclosed %%if\n"));
return PART_ERROR;
}
/* remove this file from the stack */
ofi = popOFI(spec);
/* only on last file do we signal EOF to caller */
if (ofi == NULL)
return 1;
/* otherwise, go back and try the read again. */
goto retry;
}
ofi->readPtr = ofi->readBuf;
ofi->lineNum++;
spec->lineNum = ofi->lineNum;
}
return 0;
}
#define ARGMATCH(s,token,match) \
do { \
char *os = s; \
char *exp = rpmExpand(token, NULL); \
while(*s && !risblank(*s)) s++; \
while(*s && risblank(*s)) s++; \
if (!*s) { \
rpmlog(RPMLOG_ERR, _("%s:%d: Argument expected for %s\n"), ofi->fileName, ofi->lineNum, os); \
free(exp); \
return PART_ERROR; \
} \
match = matchTok(exp, s); \
free(exp); \
} while (0)
int readLine(rpmSpec spec, int strip)
{
char *s;
int match;
struct ReadLevelEntry *rl;
OFI_t *ofi = spec->fileStack;
int rc;
int startLine = 0;
if (!restoreFirstChar(spec)) {
retry:
if ((rc = readLineFromOFI(spec, ofi)) != 0) {
if (startLine > 0) {
rpmlog(RPMLOG_ERR,
_("line %d: unclosed macro or bad line continuation\n"),
startLine);
rc = PART_ERROR;
}
return rc;
}
ofi = spec->fileStack;
/* Copy next file line into the spec line buffer */
rc = copyNextLineFromOFI(spec, ofi);
if (rc > 0) {
if (startLine == 0)
startLine = spec->lineNum;
goto retry;
} else if (rc < 0) {
return PART_ERROR;
}
}
copyNextLineFinish(spec, strip);
s = spec->line;
SKIPSPACE(s);
match = -1;
if (!spec->readStack->reading && ISMACROWITHARG(s, "%if")) {
match = 0;
} else if (ISMACROWITHARG(s, "%ifarch")) {
ARGMATCH(s, "%{_target_cpu}", match);
} else if (ISMACROWITHARG(s, "%ifnarch")) {
ARGMATCH(s, "%{_target_cpu}", match);
match = !match;
} else if (ISMACROWITHARG(s, "%ifos")) {
ARGMATCH(s, "%{_target_os}", match);
} else if (ISMACROWITHARG(s, "%ifnos")) {
ARGMATCH(s, "%{_target_os}", match);
match = !match;
} else if (ISMACROWITHARG(s, "%if")) {
s += 3;
match = parseExpressionBoolean(spec, s);
if (match < 0) {
rpmlog(RPMLOG_ERR,
_("%s:%d: bad %%if condition\n"),
ofi->fileName, ofi->lineNum);
return PART_ERROR;
}
} else if (ISMACRO(s, "%else")) {
if (! spec->readStack->next) {
/* Got an else with no %if ! */
rpmlog(RPMLOG_ERR,
_("%s:%d: Got a %%else with no %%if\n"),
ofi->fileName, ofi->lineNum);
return PART_ERROR;
}
spec->readStack->reading =
spec->readStack->next->reading && ! spec->readStack->reading;
spec->line[0] = '\0';
} else if (ISMACRO(s, "%endif")) {
if (! spec->readStack->next) {
/* Got an end with no %if ! */
rpmlog(RPMLOG_ERR,
_("%s:%d: Got a %%endif with no %%if\n"),
ofi->fileName, ofi->lineNum);
return PART_ERROR;
}
rl = spec->readStack;
spec->readStack = spec->readStack->next;
free(rl);
spec->line[0] = '\0';
} else if (spec->readStack->reading && ISMACROWITHARG(s, "%include")) {
char *fileName, *endFileName, *p;
fileName = s+8;
SKIPSPACE(fileName);
endFileName = fileName;
SKIPNONSPACE(endFileName);
p = endFileName;
SKIPSPACE(p);
if (*p != '\0') {
rpmlog(RPMLOG_ERR, _("malformed %%include statement\n"));
return PART_ERROR;
}
*endFileName = '\0';
ofi = pushOFI(spec, fileName);
goto retry;
}
if (match != -1) {
rl = xmalloc(sizeof(*rl));
rl->reading = spec->readStack->reading && match;
rl->next = spec->readStack;
spec->readStack = rl;
spec->line[0] = '\0';
}
if (! spec->readStack->reading) {
spec->line[0] = '\0';
}
/* Collect parsed line */
if (spec->parsed == NULL)
spec->parsed = newStringBuf();
appendStringBufAux(spec->parsed, spec->line,(strip & STRIP_TRAILINGSPACE));
/* FIX: spec->readStack->next should be dependent */
return 0;
}
void closeSpec(rpmSpec spec)
{
while (popOFI(spec)) {};
}
static const rpmTagVal sourceTags[] = {
RPMTAG_NAME,
RPMTAG_VERSION,
RPMTAG_RELEASE,
RPMTAG_EPOCH,
RPMTAG_SUMMARY,
RPMTAG_DESCRIPTION,
RPMTAG_PACKAGER,
RPMTAG_DISTRIBUTION,
RPMTAG_DISTURL,
RPMTAG_VENDOR,
RPMTAG_LICENSE,
RPMTAG_GROUP,
RPMTAG_OS,
RPMTAG_ARCH,
RPMTAG_CHANGELOGTIME,
RPMTAG_CHANGELOGNAME,
RPMTAG_CHANGELOGTEXT,
RPMTAG_URL,
RPMTAG_BUGURL,
RPMTAG_HEADERI18NTABLE,
0
};
static void initSourceHeader(rpmSpec spec)
{
struct Source *srcPtr;
spec->sourceHeader = headerNew();
/* Only specific tags are added to the source package header */
headerCopyTags(spec->packages->header, spec->sourceHeader, sourceTags);
/* Add the build restrictions */
{
HeaderIterator hi = headerInitIterator(spec->buildRestrictions);
struct rpmtd_s td;
while (headerNext(hi, &td)) {
if (rpmtdCount(&td) > 0) {
(void) headerPut(spec->sourceHeader, &td, HEADERPUT_DEFAULT);
}
rpmtdFreeData(&td);
}
headerFreeIterator(hi);
}
if (spec->BANames && spec->BACount > 0) {
headerPutStringArray(spec->sourceHeader, RPMTAG_BUILDARCHS,
spec->BANames, spec->BACount);
}
/* Add tags for sources and patches */
for (srcPtr = spec->sources; srcPtr != NULL; srcPtr = srcPtr->next) {
if (srcPtr->flags & RPMBUILD_ISSOURCE) {
headerPutString(spec->sourceHeader, RPMTAG_SOURCE, srcPtr->source);
if (srcPtr->flags & RPMBUILD_ISNO) {
headerPutUint32(spec->sourceHeader, RPMTAG_NOSOURCE,
&srcPtr->num, 1);
}
}
if (srcPtr->flags & RPMBUILD_ISPATCH) {
headerPutString(spec->sourceHeader, RPMTAG_PATCH, srcPtr->source);
if (srcPtr->flags & RPMBUILD_ISNO) {
headerPutUint32(spec->sourceHeader, RPMTAG_NOPATCH,
&srcPtr->num, 1);
}
}
}
}
/* Add extra provides to package. */
static void addPackageProvides(Header h)
{
const char *arch, *name;
char *evr, *isaprov;
rpmsenseFlags pflags = RPMSENSE_EQUAL;
/* <name> = <evr> provide */
name = headerGetString(h, RPMTAG_NAME);
arch = headerGetString(h, RPMTAG_ARCH);
evr = headerGetAsString(h, RPMTAG_EVR);
headerPutString(h, RPMTAG_PROVIDENAME, name);
headerPutString(h, RPMTAG_PROVIDEVERSION, evr);
headerPutUint32(h, RPMTAG_PROVIDEFLAGS, &pflags, 1);
/*
* <name>(<isa>) = <evr> provide
* FIXME: noarch needs special casing for now as BuildArch: noarch doesn't
* cause reading in the noarch macros :-/
*/
isaprov = rpmExpand(name, "%{?_isa}", NULL);
if (!rstreq(arch, "noarch") && !rstreq(name, isaprov)) {
headerPutString(h, RPMTAG_PROVIDENAME, isaprov);
headerPutString(h, RPMTAG_PROVIDEVERSION, evr);
headerPutUint32(h, RPMTAG_PROVIDEFLAGS, &pflags, 1);
}
free(isaprov);
free(evr);
}
static void addTargets(Package Pkgs)
{
char *platform = rpmExpand("%{_target_platform}", NULL);
char *arch = rpmExpand("%{_target_cpu}", NULL);
char *os = rpmExpand("%{_target_os}", NULL);
char *optflags = rpmExpand("%{optflags}", NULL);
for (Package pkg = Pkgs; pkg != NULL; pkg = pkg->next) {
headerPutString(pkg->header, RPMTAG_OS, os);
/* noarch subpackages already have arch set here, leave it alone */
if (!headerIsEntry(pkg->header, RPMTAG_ARCH)) {
headerPutString(pkg->header, RPMTAG_ARCH, arch);
}
headerPutString(pkg->header, RPMTAG_PLATFORM, platform);
headerPutString(pkg->header, RPMTAG_OPTFLAGS, optflags);
pkg->ds = rpmdsThis(pkg->header, RPMTAG_REQUIRENAME, RPMSENSE_EQUAL);
addPackageProvides(pkg->header);
}
free(platform);
free(arch);
free(os);
free(optflags);
}
static rpmSpec parseSpec(const char *specFile, rpmSpecFlags flags,
const char *buildRoot, int recursing)
{
int parsePart = PART_PREAMBLE;
int initialPackage = 1;
rpmSpec spec;
/* Set up a new Spec structure with no packages. */
spec = newSpec();
spec->specFile = rpmGetPath(specFile, NULL);
pushOFI(spec, spec->specFile);
/* If buildRoot not specified, use default %{buildroot} */
if (buildRoot) {
spec->buildRoot = xstrdup(buildRoot);
} else {
spec->buildRoot = rpmGetPath("%{?buildroot:%{buildroot}}", NULL);
}
addMacro(NULL, "_docdir", NULL, "%{_defaultdocdir}", RMIL_SPEC);
spec->recursing = recursing;
spec->flags = flags;
/* All the parse*() functions expect to have a line pre-read */
/* in the spec's line buffer. Except for parsePreamble(), */
/* which handles the initial entry into a spec file. */
while (parsePart != PART_NONE) {
int goterror = 0;
switch (parsePart) {
case PART_ERROR: /* fallthrough */
default:
goterror = 1;
break;
case PART_PREAMBLE:
parsePart = parsePreamble(spec, initialPackage);
initialPackage = 0;
break;
case PART_PREP:
parsePart = parsePrep(spec);
break;
case PART_BUILD:
case PART_INSTALL:
case PART_CHECK:
case PART_CLEAN:
parsePart = parseBuildInstallClean(spec, parsePart);
break;
case PART_CHANGELOG:
parsePart = parseChangelog(spec);
break;
case PART_DESCRIPTION:
parsePart = parseDescription(spec);
break;
case PART_PRE:
case PART_POST:
case PART_PREUN:
case PART_POSTUN:
case PART_PRETRANS:
case PART_POSTTRANS:
case PART_VERIFYSCRIPT:
case PART_TRIGGERPREIN:
case PART_TRIGGERIN:
case PART_TRIGGERUN:
case PART_TRIGGERPOSTUN:
parsePart = parseScript(spec, parsePart);
break;
case PART_FILES:
parsePart = parseFiles(spec);
break;
case PART_POLICIES:
parsePart = parsePolicies(spec);
break;
case PART_NONE: /* XXX avoid gcc whining */
case PART_LAST:
case PART_BUILDARCHITECTURES:
break;
}
if (goterror || parsePart >= PART_LAST) {
goto errxit;
}
if (parsePart == PART_BUILDARCHITECTURES) {
int index;
int x;
closeSpec(spec);
spec->BASpecs = xcalloc(spec->BACount, sizeof(*spec->BASpecs));
index = 0;
if (spec->BANames != NULL)
for (x = 0; x < spec->BACount; x++) {
/* Skip if not arch is not compatible. */
if (!rpmMachineScore(RPM_MACHTABLE_BUILDARCH, spec->BANames[x]))
continue;
addMacro(NULL, "_target_cpu", NULL, spec->BANames[x], RMIL_RPMRC);
spec->BASpecs[index] = parseSpec(specFile, flags, buildRoot, 1);
if (spec->BASpecs[index] == NULL) {
spec->BACount = index;
goto errxit;
}
delMacro(NULL, "_target_cpu");
index++;
}
spec->BACount = index;
if (! index) {
rpmlog(RPMLOG_ERR,
_("No compatible architectures found for build\n"));
goto errxit;
}
/*
* Return the 1st child's fully parsed Spec structure.
* The restart of the parse when encountering BuildArch
* causes problems for "rpm -q --specfile". This is
* still a hack because there may be more than 1 arch
* specified (unlikely but possible.) There's also the
* further problem that the macro context, particularly
* %{_target_cpu}, disagrees with the info in the header.
*/
if (spec->BACount >= 1) {
rpmSpec nspec = spec->BASpecs[0];
spec->BASpecs = _free(spec->BASpecs);
rpmSpecFree(spec);
spec = nspec;
}
goto exit;
}
}
if (spec->clean == NULL) {
char *body = rpmExpand("%{?buildroot: %{__rm} -rf %{buildroot}}", NULL);
spec->clean = newStringBuf();
appendLineStringBuf(spec->clean, body);
free(body);
}
/* Check for description in each package */
for (Package pkg = spec->packages; pkg != NULL; pkg = pkg->next) {
if (!headerIsEntry(pkg->header, RPMTAG_DESCRIPTION)) {
rpmlog(RPMLOG_ERR, _("Package has no %%description: %s\n"),
headerGetString(pkg->header, RPMTAG_NAME));
goto errxit;
}
}
/* Add arch, os and platform, self-provides etc for each package */
addTargets(spec->packages);
closeSpec(spec);
exit:
/* Assemble source header from parsed components */
initSourceHeader(spec);
return spec;
errxit:
rpmSpecFree(spec);
return NULL;
}
rpmSpec rpmSpecParse(const char *specFile, rpmSpecFlags flags,
const char *buildRoot)
{
return parseSpec(specFile, flags, buildRoot, 0);
}
|