rpm  5.2.1
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  if (parsePart == PART_BUILD) {
22  iobp = &spec->build;
23  name = "build";
24  } else if (parsePart == PART_INSTALL) {
25  iobp = &spec->install;
26  name = "install";
27  } else if (parsePart == PART_CHECK) {
28  iobp = &spec->check;
29  name = "check";
30  } else if (parsePart == PART_CLEAN) {
31  iobp = &spec->clean;
32  name = "clean";
33  } else if (parsePart == PART_ARBITRARY) {
34 assert(spec->nfoo > 0);
35  iobp = &spec->foo[spec->nfoo-1].iob;
36  name = spec->foo[spec->nfoo-1].str;
37  }
38 
39  if (*iobp != NULL) {
40  rpmlog(RPMLOG_ERR, _("line %d: second %%%s section\n"),
41  spec->lineNum, name);
42  return RPMRC_FAIL;
43  }
44 
45  *iobp = rpmiobNew(0);
46 
47  /* Make sure the buildroot is removed where needed. */
48  if (parsePart == PART_INSTALL) {
49  const char * s = rpmExpand("%{!?__spec_install_pre:%{?buildroot:%{__rm} -rf '%{buildroot}'\n%{__mkdir_p} '%{buildroot}'\n}}\n", NULL);
50  if (s && *s)
51  *iobp = rpmiobAppend(*iobp, s, 0);
52  s = _free(s);
53  } else if (parsePart == PART_CLEAN) {
54  const char * s = rpmExpand("%{?__spec_clean_body}%{!?__spec_clean_body:%{?buildroot:rm -rf '%{buildroot}'\n}}\n", NULL);
55  if (s && *s)
56  *iobp = rpmiobAppend(*iobp, s, 0);
57  s = _free(s);
58 #if !defined(RPM_VENDOR_OPENPKG) /* still-support-section-clean */
59  /* OpenPKG still wishes to use "%clean" script/section */
60  iobp = NULL; /* XXX skip %clean from spec file. */
61 #endif
62  }
63 
64  /* There are no options to %build, %install, %check, or %clean */
65  if ((rc = readLine(spec, STRIP_NOTHING)) > 0)
66  return PART_NONE;
67  if (rc != RPMRC_OK)
68  return rc;
69 
70  while ((nextPart = isPart(spec)) == PART_NONE) {
71  if (iobp)
72  *iobp = rpmiobAppend(*iobp, spec->line, 0);
73  if ((rc = readLine(spec, STRIP_NOTHING)) > 0)
74  return PART_NONE;
75  if (rc)
76  return rc;
77  }
78 
79  return nextPart;
80 }