rpm  5.4.10
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) /* 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 }