build/parseBuildInstallClean.c

Go to the documentation of this file.
00001 
00005 #include "system.h"
00006 
00007 #include "rpmbuild.h"
00008 #include "debug.h"
00009 
00010 /*@access StringBuf @*/
00011 
00012 /*@-boundswrite@*/
00013 int parseBuildInstallClean(Spec spec, rpmParseState parsePart)
00014 {
00015     int nextPart, rc;
00016     StringBuf *sbp = NULL;
00017     const char *name = NULL;
00018 
00019     /*@-branchstate@*/
00020     if (parsePart == PART_BUILD) {
00021         sbp = &spec->build;
00022         name = "%build";
00023     } else if (parsePart == PART_INSTALL) {
00024         sbp = &spec->install;
00025         name = "%install";
00026     } else if (parsePart == PART_CHECK) {
00027         sbp = &spec->check;
00028         name = "%check";
00029     } else if (parsePart == PART_CLEAN) {
00030         sbp = &spec->clean;
00031         name = "%clean";
00032     }
00033     /*@=branchstate@*/
00034     
00035     if (*sbp != NULL) {
00036         rpmError(RPMERR_BADSPEC, _("line %d: second %s\n"),
00037                 spec->lineNum, name);
00038         return RPMERR_BADSPEC;
00039     }
00040     
00041     *sbp = newStringBuf();
00042 
00043     /* Make sure the buildroot is removed where needed. */
00044     if (parsePart == PART_INSTALL) {
00045         const char * s = rpmExpand("%{!?__spec_install_pre:%{?buildroot:rm -rf '%{buildroot}'\n}}\n", NULL);
00046         if (s && *s)
00047             appendStringBuf(*sbp, s);
00048         s = _free(s);
00049     } else if (parsePart == PART_CLEAN) {
00050         const char * s = rpmExpand("%{?__spec_clean_body}%{!?__spec_clean_body:%{?buildroot:rm -rf '%{buildroot}'\n}}\n", NULL);
00051         if (s && *s)
00052             appendStringBuf(*sbp, s);
00053         s = _free(s);
00054         sbp = NULL;     /* XXX skip %clean from spec file. */
00055     }
00056 
00057     /* There are no options to %build, %install, %check, or %clean */
00058     if ((rc = readLine(spec, STRIP_NOTHING)) > 0)
00059         return PART_NONE;
00060     if (rc)
00061         return rc;
00062     
00063     while (! (nextPart = isPart(spec->line))) {
00064         if (sbp)
00065             appendStringBuf(*sbp, spec->line);
00066         if ((rc = readLine(spec, STRIP_NOTHING)) > 0)
00067             return PART_NONE;
00068         if (rc)
00069             return rc;
00070     }
00071 
00072     return nextPart;
00073 }
00074 /*@=boundswrite@*/

Generated on Fri Aug 31 10:50:44 2007 for rpm by  doxygen 1.5.1