rpm  5.4.15
parseBuildInstallClean.c
Go to the documentation of this file.
1 
5 #include "system.h"
6 
7 #include <rpmio.h>
8 #include <rpmiotypes.h>
9 #include <rpmlog.h>
10 #define _RPMTAG_INTERNAL
11 #include "rpmbuild.h"
12 #include "debug.h"
13 
15 {
16  rpmParseState nextPart;
17  rpmiob *iobp = NULL;
18  const char *name = NULL;
19  rpmRC rc;
20 
21  switch (parsePart) {
22  case PART_BUILD:
23  iobp = &spec->build;
24  name = "build";
25  break;
26  case PART_INSTALL:
27  iobp = &spec->install;
28  name = "install";
29  break;
30  case PART_CHECK:
31  iobp = &spec->check;
32  name = "check";
33  break;
34  case PART_CLEAN:
35  iobp = &spec->clean;
36  name = "clean";
37  break;
38  case PART_ARBITRARY:
39 assert(spec->nfoo > 0);
40  iobp = &spec->foo[spec->nfoo-1].iob;
41  name = spec->foo[spec->nfoo-1].str;
42  break;
43  default:
44  rpmlog(RPMLOG_ERR, _("line %d: unknown specfile section\n"),
45  spec->lineNum);
46  return RPMRC_FAIL;
47  break;
48  }
49 
50  if (*iobp != NULL) {
51  rpmlog(RPMLOG_ERR, _("line %d: second %%%s section\n"),
52  spec->lineNum, name);
53  return RPMRC_FAIL;
54  }
55 
56  *iobp = rpmiobNew(0);
57 
58  /* Make sure the buildroot is removed where needed. */
59  if (parsePart == PART_INSTALL) {
60  const char * s = rpmExpand("%{!?__spec_install_pre:%{?buildroot:%{__rm} -rf '%{buildroot}'\n%{__mkdir_p} '%{buildroot}'\n}}\n", NULL);
61  if (s && *s)
62  *iobp = rpmiobAppend(*iobp, s, 0);
63  s = _free(s);
64  } else if (parsePart == PART_CLEAN) {
65  const char * s = rpmExpand("%{?__spec_clean_body}%{!?__spec_clean_body:%{?buildroot:rm -rf '%{buildroot}'\n}}\n", NULL);
66  if (s && *s)
67  *iobp = rpmiobAppend(*iobp, s, 0);
68  s = _free(s);
69 #if !defined(RPM_VENDOR_OPENPKG) && !defined(RPM_VENDOR_PLD) /* still-support-section-clean */
70  /* OpenPKG still wishes to use "%clean" script/section */
71  iobp = NULL; /* XXX skip %clean from spec file. */
72 #endif
73  }
74 
75  /* There are no options to %build, %install, %check, or %clean */
76  if ((rc = readLine(spec, STRIP_NOTHING)) > 0)
77  return PART_NONE;
78  if (rc != RPMRC_OK)
79  return rc;
80 
81  while ((nextPart = isPart(spec)) == PART_NONE) {
82  if (iobp)
83  *iobp = rpmiobAppend(*iobp, spec->line, 0);
84  if ((rc = readLine(spec, STRIP_NOTHING)) > 0)
85  return PART_NONE;
86  if (rc)
87  return rc;
88  }
89 
90  return nextPart;
91 }
rpmiob build
Definition: rpmspec.h:188
rpmParseState isPart(Spec spec)
Check line for section separator, return next parser state.
Definition: parseSpec.c:64
rpmiob clean
Definition: rpmspec.h:194
int parseBuildInstallClean(Spec spec, rpmParseState parsePart)
Parse %build/%install/%clean section(s) of a spec file.
rpmiob check
Definition: rpmspec.h:192
static void rpmlog(int code, const char *fmt,...)
Definition: rpmlog.h:299
rpmiob rpmiobAppend(rpmiob iob, const char *s, size_t nl)
Append string to I/O buffer.
Definition: rpmiob.c:77
int readLine(Spec spec, rpmStripFlags strip)
Read next line from spec file.
Definition: parseSpec.c:351
Yet Another syslog(3) API clone.
char * line
Definition: rpmspec.h:138
The structure used to store values parsed from a spec file.
Definition: rpmspec.h:113
char * rpmExpand(const char *arg,...)
Return (malloc'ed) concatenated macro expansion(s).
Definition: macro.c:3238
size_t nfoo
Definition: rpmspec.h:198
rpmiob rpmiobNew(size_t len)
Create an I/O buffer.
Definition: rpmiob.c:44
enum rpmRC_e rpmRC
RPM return codes.
This is the only module users of librpmbuild should need to include.
static void * _free(const void *p)
Wrapper to free(3), hides const compilation noise, permit NULL, return NULL.
Definition: rpmiotypes.h:756
struct rpmiob_s * rpmiob
Definition: rpmiotypes.h:60
enum rpmParseState_e rpmParseState
int lineNum
Definition: rpmspec.h:139
static const char * name
#define _(Text)
Definition: system.h:29
rpmiob install
Definition: rpmspec.h:190
tagStore_t foo
Definition: rpmspec.h:200