5 * \file build/rpmbuild.h
6 * This is the *only* module users of librpmbuild should need to include.
11 /* and it shouldn't need these :-( */
12 #include "stringbuf.h"
15 /* but this will be needed */
19 * Bit(s) to control buildSpec() operation.
22 typedef enum rpmBuildFlags_e {
26 RPMBUILD_PREP = (1 << 0), /*!< Execute %%prep. */
27 RPMBUILD_BUILD = (1 << 1), /*!< Execute %%build. */
28 RPMBUILD_INSTALL = (1 << 2), /*!< Execute %%install. */
29 RPMBUILD_CHECK = (1 << 3), /*!< Execute %%check. */
30 RPMBUILD_CLEAN = (1 << 4), /*!< Execute %%clean. */
31 RPMBUILD_FILECHECK = (1 << 5), /*!< Check %%files manifest. */
32 RPMBUILD_PACKAGESOURCE = (1 << 6), /*!< Create source package. */
33 RPMBUILD_PACKAGEBINARY = (1 << 7), /*!< Create binary package(s). */
34 RPMBUILD_RMSOURCE = (1 << 8), /*!< Remove source(s) and patch(s). */
35 RPMBUILD_RMBUILD = (1 << 9), /*!< Remove build sub-tree. */
36 RPMBUILD_STRINGBUF = (1 << 10), /*!< only for doScript() */
37 RPMBUILD_RMSPEC = (1 << 11) /*!< Remove spec file. */
43 #define SKIPSPACE(s) { while (*(s) && xisspace(*(s))) (s)++; }
44 #define SKIPNONSPACE(s) { while (*(s) && !xisspace(*(s))) (s)++; }
46 #define PART_SUBNAME 0
50 * Spec file parser states.
52 typedef enum rpmParseState_e {
53 PART_NONE = 0, /*!< */
54 PART_PREAMBLE = 1, /*!< */
55 PART_PREP = 2, /*!< */
56 PART_BUILD = 3, /*!< */
57 PART_INSTALL = 4, /*!< */
58 PART_CHECK = 5, /*!< */
59 PART_CLEAN = 6, /*!< */
60 PART_FILES = 7, /*!< */
62 PART_POST = 9, /*!< */
63 PART_PREUN = 10, /*!< */
64 PART_POSTUN = 11, /*!< */
65 PART_PRETRANS = 12, /*!< */
66 PART_POSTTRANS = 13, /*!< */
67 PART_DESCRIPTION = 14, /*!< */
68 PART_CHANGELOG = 15, /*!< */
69 PART_TRIGGERIN = 16, /*!< */
70 PART_TRIGGERUN = 17, /*!< */
71 PART_VERIFYSCRIPT = 18, /*!< */
72 PART_BUILDARCHITECTURES= 19,/*!< */
73 PART_TRIGGERPOSTUN = 20, /*!< */
74 PART_LAST = 21 /*!< */
77 #define STRIP_NOTHING 0
78 #define STRIP_TRAILINGSPACE (1 << 0)
79 #define STRIP_COMMENTS (1 << 1)
87 * Destroy uid/gid caches.
90 /*@globals internalState@*/
91 /*@modifies internalState */;
94 * Return cached user name from user id.
95 * @todo Implement using hash.
97 * @return cached user name
99 extern /*@observer@*/ const char * getUname(uid_t uid)
100 /*@globals internalState @*/
101 /*@modifies internalState @*/;
103 /** \ingroup rpmbuild
104 * Return cached user name.
105 * @todo Implement using hash.
106 * @param uname user name
107 * @return cached user name
109 extern /*@observer@*/ const char * getUnameS(const char * uname)
110 /*@globals internalState @*/
111 /*@modifies internalState @*/;
113 /** \ingroup rpmbuild
114 * Return cached user id.
115 * @todo Implement using hash.
116 * @param uname user name
119 uid_t getUidS(const char * uname)
120 /*@globals internalState @*/
121 /*@modifies internalState @*/;
123 /** \ingroup rpmbuild
124 * Return cached group name from group id.
125 * @todo Implement using hash.
126 * @param gid group id
127 * @return cached group name
129 extern /*@observer@*/ const char * getGname(gid_t gid)
130 /*@globals internalState @*/
131 /*@modifies internalState @*/;
133 /** \ingroup rpmbuild
134 * Return cached group name.
135 * @todo Implement using hash.
136 * @param gname group name
137 * @return cached group name
139 extern /*@observer@*/ const char * getGnameS(const char * gname)
140 /*@globals internalState @*/
141 /*@modifies internalState @*/;
143 /** \ingroup rpmbuild
144 * Return cached group id.
145 * @todo Implement using hash.
146 * @param gname group name
149 gid_t getGidS(const char * gname)
150 /*@globals internalState @*/
151 /*@modifies internalState @*/;
153 /** \ingroup rpmbuild
154 * Return build hostname.
155 * @return build hostname
157 extern /*@observer@*/ const char * const buildHost(void) /*@*/;
159 /** \ingroup rpmbuild
160 * Return build time stamp.
161 * @return build time stamp
163 extern /*@observer@*/ int_32 * const getBuildTime(void) /*@*/;
165 /** \ingroup rpmbuild
166 * Read next line from spec file.
167 * @param spec spec file control structure
168 * @param strip truncate comments?
169 * @return 0 on success, 1 on EOF, <0 on error
171 int readLine(Spec spec, int strip)
172 /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
173 /*@modifies spec->fileStack, spec->readStack, spec->line, spec->lineNum,
174 spec->nextline, spec->nextpeekc, spec->lbuf, spec->sl,
175 rpmGlobalMacroContext, fileSystem, internalState @*/;
177 /** \ingroup rpmbuild
178 * Stop reading from spec file, freeing resources.
179 * @param spec spec file control structure
181 void closeSpec(/*@partial@*/ Spec spec)
182 /*@globals fileSystem, internalState @*/
183 /*@modifies spec->fileStack, fileSystem, internalState @*/;
185 /** \ingroup rpmbuild
186 * Truncate comment lines.
187 * @param s skip white space, truncate line at '#'
189 void handleComments(char * s)
192 /** \ingroup rpmbuild
193 * Check line for section separator, return next parser state.
194 * @param line from spec file
195 * @return next parser state
197 rpmParseState isPart(const char * line) /*@*/;
199 /** \ingroup rpmbuild
201 * @param line from spec file
202 * @retval res pointer to int
203 * @return 0 on success, 1 on failure
205 int parseNum(/*@null@*/ const char * line, /*@null@*/ /*@out@*/int * res)
206 /*@modifies *res @*/;
208 /** \ingroup rpmbuild
209 * Add changelog entry to header.
211 * @param time time of change
212 * @param name person who made the change
213 * @param text description of change
215 void addChangelogEntry(Header h, time_t time, const char * name,
219 /** \ingroup rpmbuild
220 * Parse %%build/%%install/%%clean section(s) of a spec file.
221 * @param spec spec file control structure
222 * @param parsePart current rpmParseState
223 * @return >= 0 next rpmParseState, < 0 on error
225 int parseBuildInstallClean(Spec spec, rpmParseState parsePart)
226 /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
227 /*@modifies spec->build, spec->install, spec->check, spec->clean,
229 spec->fileStack, spec->readStack, spec->line, spec->lineNum,
230 spec->nextline, spec->nextpeekc, spec->lbuf, spec->sl,
231 rpmGlobalMacroContext, fileSystem, internalState @*/;
233 /** \ingroup rpmbuild
234 * Parse %%changelog section of a spec file.
235 * @param spec spec file control structure
236 * @return >= 0 next rpmParseState, < 0 on error
238 int parseChangelog(Spec spec)
239 /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
240 /*@modifies spec->fileStack, spec->readStack, spec->line, spec->lineNum,
241 spec->nextline, spec->nextpeekc, spec->lbuf, spec->sl,
242 spec->packages->header,
243 rpmGlobalMacroContext, fileSystem, internalState @*/;
245 /** \ingroup rpmbuild
246 * Parse %%description section of a spec file.
247 * @param spec spec file control structure
248 * @return >= 0 next rpmParseState, < 0 on error
250 int parseDescription(Spec spec)
251 /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
252 /*@modifies spec->packages,
253 spec->fileStack, spec->readStack, spec->line, spec->lineNum,
254 spec->nextline, spec->nextpeekc, spec->lbuf, spec->sl,
256 rpmGlobalMacroContext, fileSystem, internalState @*/;
258 /** \ingroup rpmbuild
259 * Parse %%files section of a spec file.
260 * @param spec spec file control structure
261 * @return >= 0 next rpmParseState, < 0 on error
263 int parseFiles(Spec spec)
264 /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
265 /*@modifies spec->packages,
266 spec->fileStack, spec->readStack, spec->line, spec->lineNum,
267 spec->nextline, spec->nextpeekc, spec->lbuf, spec->sl,
268 rpmGlobalMacroContext, fileSystem, internalState @*/;
270 /** \ingroup rpmbuild
271 * Parse tags from preamble of a spec file.
272 * @param spec spec file control structure
273 * @param initialPackage
274 * @return >= 0 next rpmParseState, < 0 on error
276 int parsePreamble(Spec spec, int initialPackage)
277 /*@globals rpmGlobalMacroContext, h_errno,
278 fileSystem, internalState @*/
279 /*@modifies spec->packages,
280 spec->fileStack, spec->readStack, spec->line, spec->lineNum,
282 spec->macros, spec->st, spec->buildRootURL,
283 spec->sources, spec->numSources, spec->noSource,
284 spec->buildRestrictions, spec->BANames, spec->BACount,
285 spec->gotBuildRootURL,
286 spec->nextline, spec->nextpeekc, spec->lbuf, spec->sl,
287 rpmGlobalMacroContext, fileSystem, internalState @*/;
289 /** \ingroup rpmbuild
290 * Parse %%prep section of a spec file.
291 * @param spec spec file control structure
292 * @return >= 0 next rpmParseState, < 0 on error
294 int parsePrep(Spec spec)
295 /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
296 /*@modifies spec->prep, spec->buildSubdir, spec->macros,
297 spec->fileStack, spec->readStack, spec->line, spec->lineNum,
298 spec->nextline, spec->nextpeekc, spec->lbuf, spec->sl,
299 rpmGlobalMacroContext, fileSystem, internalState @*/;
301 /** \ingroup rpmbuild
302 * Parse dependency relations from spec file and/or autogenerated output buffer.
303 * @param spec spec file control structure
304 * @param pkg package control structure
305 * @param field text to parse (e.g. "foo < 0:1.2-3, bar = 5:6.7")
306 * @param tag tag, identifies type of dependency
307 * @param index (0 always)
308 * @param tagflags dependency flags already known from context
309 * @return 0 on success, RPMERR_BADSPEC on failure
311 int parseRCPOT(Spec spec, Package pkg, const char * field, rpmTag tagN,
312 int index, rpmsenseFlags tagflags)
313 /*@globals rpmGlobalMacroContext, h_errno @*/
314 /*@modifies rpmGlobalMacroContext @*/;
316 /** \ingroup rpmbuild
317 * Parse %%pre et al scriptlets from a spec file.
318 * @param spec spec file control structure
319 * @param parsePart current rpmParseState
320 * @return >= 0 next rpmParseState, < 0 on error
322 int parseScript(Spec spec, int parsePart)
323 /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
324 /*@modifies spec->packages,
325 spec->fileStack, spec->readStack, spec->line, spec->lineNum,
326 spec->nextline, spec->nextpeekc, spec->lbuf, spec->sl,
327 rpmGlobalMacroContext, fileSystem, internalState @*/;
329 /** \ingroup rpmbuild
330 * Evaluate boolean expression.
331 * @param spec spec file control structure
332 * @param expr expression to parse
335 int parseExpressionBoolean(Spec spec, const char * expr)
336 /*@globals rpmGlobalMacroContext, h_errno @*/
337 /*@modifies rpmGlobalMacroContext @*/;
339 /** \ingroup rpmbuild
340 * Evaluate string expression.
341 * @param spec spec file control structure
342 * @param expr expression to parse
345 /*@unused@*/ /*@null@*/
346 char * parseExpressionString(Spec spec, const char * expr)
347 /*@globals rpmGlobalMacroContext, h_errno @*/
348 /*@modifies rpmGlobalMacroContext @*/;
350 /** \ingroup rpmbuild
351 * Run a build script, assembled from spec file scriptlet section.
353 * @param spec spec file control structure
354 * @param what type of script
355 * @param name name of scriptlet section
356 * @param sb lines that compose script body
357 * @param test don't execute scripts or package if testing
358 * @return 0 on success, RPMERR_SCRIPT on failure
360 int doScript(Spec spec, int what, /*@null@*/ const char * name,
361 /*@null@*/ StringBuf sb, int test)
362 /*@globals rpmGlobalMacroContext, h_errno,
363 fileSystem, internalState @*/
364 /*@modifies spec->macros,
365 rpmGlobalMacroContext, fileSystem, internalState @*/;
367 /** \ingroup rpmbuild
368 * Find sub-package control structure by name.
369 * @param spec spec file control structure
370 * @param name (sub-)package name
371 * @param flag if PART_SUBNAME, then 1st package name is prepended
372 * @retval pkg package control structure
373 * @return 0 on success, 1 on failure
375 int lookupPackage(Spec spec, /*@null@*/ const char * name, int flag,
376 /*@out@*/ Package * pkg)
377 /*@modifies spec->packages, *pkg @*/;
379 /** \ingroup rpmbuild
380 * Create and initialize package control structure.
381 * @param spec spec file control structure
382 * @return package control structure
385 Package newPackage(Spec spec)
386 /*@modifies spec->packages, spec->packages->next @*/;
388 /** \ingroup rpmbuild
389 * Destroy all packages associated with spec file.
390 * @param packages package control structure chain
394 Package freePackages(/*@only@*/ /*@null@*/ Package packages)
395 /*@globals fileSystem @*/
396 /*@modifies packages, fileSystem @*/;
398 /** \ingroup rpmbuild
399 * Destroy package control structure.
400 * @param pkg package control structure
404 Package freePackage(/*@only@*/ /*@null@*/ Package pkg)
405 /*@globals fileSystem @*/
406 /*@modifies pkg, fileSystem @*/;
408 /** \ingroup rpmbuild
409 * Add dependency to header, filtering duplicates.
410 * @param spec spec file control structure
412 * @param tagN tag, identifies type of dependency
413 * @param N (e.g. Requires: foo < 0:1.2-3, "foo")
414 * @param EVR (e.g. Requires: foo < 0:1.2-3, "0:1.2-3")
415 * @param Flags (e.g. Requires: foo < 0:1.2-3, both "Requires:" and "<")
416 * @param index (0 always)
419 int addReqProv(/*@unused@*/Spec spec, Header h, rpmTag tagN,
420 const char * N, const char * EVR, rpmsenseFlags Flags,
424 /** \ingroup rpmbuild
425 * Add rpmlib feature dependency.
427 * @param feature rpm feature name (i.e. "rpmlib(Foo)" for feature Foo)
428 * @param featureEVR rpm feature epoch/version/release
431 int rpmlibNeedsFeature(Header h, const char * feature, const char * featureEVR)
434 /** \ingroup rpmbuild
435 * Post-build processing for binary package(s).
436 * @param spec spec file control structure
437 * @param installSpecialDoc
438 * @param test don't execute scripts or package if testing
439 * @return 0 on success
441 int processBinaryFiles(Spec spec, int installSpecialDoc, int test)
442 /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
443 /*@modifies spec->macros,
444 spec->packages->cpioList, spec->packages->fileList,
445 spec->packages->specialDoc, spec->packages->header,
446 rpmGlobalMacroContext, fileSystem, internalState @*/;
448 /** \ingroup rpmbuild
449 * Create and initialize header for source package.
450 * @param spec spec file control structure
452 void initSourceHeader(Spec spec)
453 /*@modifies spec->sourceHeader,
454 spec->buildRestrictions, spec->BANames,
455 spec->packages->header @*/;
457 /** \ingroup rpmbuild
458 * Post-build processing for source package.
459 * @param spec spec file control structure
460 * @return 0 on success
462 int processSourceFiles(Spec spec)
463 /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
464 /*@modifies spec->sourceHeader, spec->sourceCpioList,
465 spec->buildRestrictions, spec->BANames,
466 spec->packages->header,
467 rpmGlobalMacroContext, fileSystem, internalState @*/;
469 /** \ingroup rpmbuild
470 * Parse spec file into spec control structure.
471 * @param ts transaction set (spec file control in ts->spec)
474 * @param buildRootURL
475 * @param recursing parse is recursive?
482 int parseSpec(rpmts ts, const char * specFile,
483 /*@null@*/ const char * rootURL,
484 /*@null@*/ const char * buildRootURL,
486 /*@null@*/ const char * passPhrase,
487 /*@null@*/ char * cookie,
488 int anyarch, int force)
489 /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
490 /*@modifies ts, rpmGlobalMacroContext, fileSystem, internalState @*/;
492 /** \ingroup rpmbuild
493 * Build stages state machine driver.
494 * @param ts transaction set
495 * @param spec spec file control structure
496 * @param what bit(s) to enable stages of build
497 * @param test don't execute scripts or package if testing
498 * @return 0 on success
500 int buildSpec(rpmts ts, Spec spec, int what, int test)
501 /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
502 /*@modifies spec->sourceHeader, spec->sourceCpioList, spec->cookie,
503 spec->sourceRpmName, spec->sourcePkgId,
504 spec->macros, spec->BASpecs,
505 spec->buildRestrictions, spec->BANames,
506 spec->packages->cpioList, spec->packages->fileList,
507 spec->packages->specialDoc, spec->packages->header,
508 rpmGlobalMacroContext, fileSystem, internalState @*/;
510 /** \ingroup rpmbuild
511 * Generate binary package(s).
512 * @param spec spec file control structure
513 * @return 0 on success
515 int packageBinaries(Spec spec)
516 /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
517 /*@modifies spec->packages->header, spec->packages->cpioList,
519 rpmGlobalMacroContext, fileSystem, internalState @*/;
521 /** \ingroup rpmbuild
522 * Generate source package.
523 * @param spec spec file control structure
524 * @return 0 on success
526 int packageSources(Spec spec)
527 /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
528 /*@modifies spec->sourceHeader, spec->cookie, spec->sourceCpioList,
529 spec->sourceRpmName, spec->sourcePkgId,
530 rpmGlobalMacroContext, fileSystem, internalState @*/;
537 #endif /* _H_RPMBUILD_ */