Splint fiddles.
[tools/librpm-tizen.git] / build / rpmbuild.h
1 #ifndef _H_RPMBUILD_
2 #define _H_RPMBUILD_
3
4 /** \ingroup rpmbuild
5  * \file build/rpmbuild.h
6  *  This is the *only* module users of librpmbuild should need to include.
7  */
8
9 #include "rpmcli.h"
10
11 /* and it shouldn't need these :-( */
12 #include "stringbuf.h"
13 #include "misc.h"
14
15 /* but this will be needed */
16 #include "rpmspec.h"
17
18 /** \ingroup rpmbuild
19  * Bit(s) to control buildSpec() operation.
20  */
21 /*@-typeuse@*/
22 typedef enum rpmBuildFlags_e {
23 /*@-enummemuse@*/
24     RPMBUILD_NONE       = 0,
25 /*@=enummemuse@*/
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. */
38 } rpmBuildFlags;
39 /*@=typeuse@*/
40
41 #include <ctype.h>
42
43 #define SKIPSPACE(s) { while (*(s) && xisspace(*(s))) (s)++; }
44 #define SKIPNONSPACE(s) { while (*(s) && !xisspace(*(s))) (s)++; }
45
46 #define PART_SUBNAME  0
47 #define PART_NAME     1
48
49 /** \ingroup rpmbuild
50  * Spec file parser states.
51  */
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,   /*!< */
61     PART_PRE            =  8,   /*!< */
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    /*!< */
75 } rpmParseState;
76
77 #define STRIP_NOTHING             0
78 #define STRIP_TRAILINGSPACE (1 << 0)
79 #define STRIP_COMMENTS      (1 << 1)
80
81 #ifdef __cplusplus
82 extern "C" {
83 #endif
84 /*@-redecl@*/
85
86 /** \ingroup rpmbuild
87  * Destroy uid/gid caches.
88  */
89 void freeNames(void)
90         /*@globals internalState@*/
91         /*@modifies internalState */;
92
93 /** \ingroup rpmbuild
94  * Return cached user name from user id.
95  * @todo Implement using hash.
96  * @param uid           user id
97  * @return              cached user name
98  */
99 extern /*@observer@*/ const char * getUname(uid_t uid)
100         /*@globals internalState @*/
101         /*@modifies internalState @*/;
102
103 /** \ingroup rpmbuild
104  * Return cached user name.
105  * @todo Implement using hash.
106  * @param uname         user name
107  * @return              cached user name
108  */
109 extern /*@observer@*/ const char * getUnameS(const char * uname)
110         /*@globals internalState @*/
111         /*@modifies internalState @*/;
112
113 /** \ingroup rpmbuild
114  * Return cached user id.
115  * @todo Implement using hash.
116  * @param uname         user name
117  * @return              cached uid
118  */
119 uid_t getUidS(const char * uname)
120         /*@globals internalState @*/
121         /*@modifies internalState @*/;
122
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
128  */
129 extern /*@observer@*/ const char * getGname(gid_t gid)
130         /*@globals internalState @*/
131         /*@modifies internalState @*/;
132
133 /** \ingroup rpmbuild
134  * Return cached group name.
135  * @todo Implement using hash.
136  * @param gname         group name
137  * @return              cached group name
138  */
139 extern /*@observer@*/ const char * getGnameS(const char * gname)
140         /*@globals internalState @*/
141         /*@modifies internalState @*/;
142
143 /** \ingroup rpmbuild
144  * Return cached group id.
145  * @todo Implement using hash.
146  * @param gname         group name
147  * @return              cached gid
148  */
149 gid_t getGidS(const char * gname)
150         /*@globals internalState @*/
151         /*@modifies internalState @*/;
152
153 /** \ingroup rpmbuild
154  * Return build hostname.
155  * @return              build hostname
156  */
157 extern /*@observer@*/ const char * const buildHost(void)        /*@*/;
158
159 /** \ingroup rpmbuild
160  * Return build time stamp.
161  * @return              build time stamp
162  */
163 extern /*@observer@*/ int_32 * const getBuildTime(void) /*@*/;
164
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
170  */
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  @*/;
176
177 /** \ingroup rpmbuild
178  * Stop reading from spec file, freeing resources.
179  * @param spec          spec file control structure
180  */
181 void closeSpec(/*@partial@*/ Spec spec)
182         /*@globals fileSystem, internalState @*/
183         /*@modifies spec->fileStack, fileSystem, internalState @*/;
184
185 /** \ingroup rpmbuild
186  * Truncate comment lines.
187  * @param s             skip white space, truncate line at '#'
188  */
189 void handleComments(char * s)
190         /*@modifies s @*/;
191
192 /** \ingroup rpmbuild
193  * Check line for section separator, return next parser state.
194  * @param               line from spec file
195  * @return              next parser state
196  */
197 rpmParseState isPart(const char * line) /*@*/;
198
199 /** \ingroup rpmbuild
200  * Parse a number.
201  * @param               line from spec file
202  * @retval res          pointer to int
203  * @return              0 on success, 1 on failure
204  */
205 int parseNum(/*@null@*/ const char * line, /*@null@*/ /*@out@*/int * res)
206         /*@modifies *res @*/;
207
208 /** \ingroup rpmbuild
209  * Add changelog entry to header.
210  * @param h             header
211  * @param time          time of change
212  * @param name          person who made the change
213  * @param text          description of change
214  */
215 void addChangelogEntry(Header h, time_t time, const char * name,
216                 const char * text)
217         /*@modifies h @*/;
218
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
224  */
225 int parseBuildInstallClean(Spec spec, rpmParseState parsePart)
226         /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
227         /*@modifies spec->build, spec->install, spec->check, spec->clean,
228                 spec->macros,
229                 spec->fileStack, spec->readStack, spec->line, spec->lineNum,
230                 spec->nextline, spec->nextpeekc, spec->lbuf, spec->sl,
231                 rpmGlobalMacroContext, fileSystem, internalState @*/;
232
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
237  */
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 @*/;
244
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
249  */
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,
255                 spec->st,
256                 rpmGlobalMacroContext, fileSystem, internalState  @*/;
257
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
262  */
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 @*/;
269
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
275  */
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,
281                 spec->buildSubdir,
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 @*/;
288
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
293  */
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 @*/;
300
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
310  */
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 @*/;
315
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
321  */
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  @*/;
328
329 /** \ingroup rpmbuild
330  * Evaluate boolean expression.
331  * @param spec          spec file control structure
332  * @param expr          expression to parse
333  * @return
334  */
335 int parseExpressionBoolean(Spec spec, const char * expr)
336         /*@globals rpmGlobalMacroContext, h_errno @*/
337         /*@modifies rpmGlobalMacroContext @*/;
338
339 /** \ingroup rpmbuild
340  * Evaluate string expression.
341  * @param spec          spec file control structure
342  * @param expr          expression to parse
343  * @return
344  */
345 /*@unused@*/ /*@null@*/
346 char * parseExpressionString(Spec spec, const char * expr)
347         /*@globals rpmGlobalMacroContext, h_errno @*/
348         /*@modifies rpmGlobalMacroContext @*/;
349
350 /** \ingroup rpmbuild
351  * Run a build script, assembled from spec file scriptlet section.
352  *
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
359  */
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 @*/;
366
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
374  */
375 int lookupPackage(Spec spec, /*@null@*/ const char * name, int flag,
376                 /*@out@*/ Package * pkg)
377         /*@modifies spec->packages, *pkg @*/;
378
379 /** \ingroup rpmbuild
380  * Create and initialize package control structure.
381  * @param spec          spec file control structure
382  * @return              package control structure
383  */
384 /*@only@*/
385 Package newPackage(Spec spec)
386         /*@modifies spec->packages, spec->packages->next @*/;
387
388 /** \ingroup rpmbuild
389  * Destroy all packages associated with spec file.
390  * @param packages      package control structure chain
391  * @return              NULL
392  */
393 /*@null@*/
394 Package freePackages(/*@only@*/ /*@null@*/ Package packages)
395         /*@globals fileSystem @*/
396         /*@modifies packages, fileSystem @*/;
397
398 /** \ingroup rpmbuild
399  * Destroy package control structure.
400  * @param pkg           package control structure
401  * @return              NULL
402  */
403 /*@null@*/
404 Package  freePackage(/*@only@*/ /*@null@*/ Package pkg)
405         /*@globals fileSystem @*/
406         /*@modifies pkg, fileSystem @*/;
407
408 /** \ingroup rpmbuild
409  * Add dependency to header, filtering duplicates.
410  * @param spec          spec file control structure
411  * @param h             header
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)
417  * @return              0 always
418  */
419 int addReqProv(/*@unused@*/Spec spec, Header h, rpmTag tagN,
420                 const char * N, const char * EVR, rpmsenseFlags Flags,
421                 int index)
422         /*@modifies h @*/;
423
424 /** \ingroup rpmbuild
425  * Add rpmlib feature dependency.
426  * @param h             header
427  * @param feature       rpm feature name (i.e. "rpmlib(Foo)" for feature Foo)
428  * @param featureEVR    rpm feature epoch/version/release
429  * @return              0 always
430  */
431 int rpmlibNeedsFeature(Header h, const char * feature, const char * featureEVR)
432         /*@modifies h @*/;
433
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
440  */
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 @*/;
447
448 /** \ingroup rpmbuild
449  * Create and initialize header for source package.
450  * @param spec          spec file control structure
451  */
452 void initSourceHeader(Spec spec)
453         /*@modifies spec->sourceHeader,
454                 spec->buildRestrictions, spec->BANames,
455                 spec->packages->header @*/;
456
457 /** \ingroup rpmbuild
458  * Post-build processing for source package.
459  * @param spec          spec file control structure
460  * @return              0 on success
461  */
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 @*/;
468
469 /** \ingroup rpmbuild
470  * Parse spec file into spec control structure.
471  * @param ts            transaction set (spec file control in ts->spec)
472  * @param specFile
473  * @param rootURL
474  * @param buildRootURL
475  * @param recursing     parse is recursive?
476  * @param passPhrase
477  * @param cookie
478  * @param anyarch
479  * @param force
480  * @return
481  */
482 int parseSpec(rpmts ts, const char * specFile,
483                 /*@null@*/ const char * rootURL,
484                 /*@null@*/ const char * buildRootURL,
485                 int recursing,
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 @*/;
491
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
499  */
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 @*/;
509
510 /** \ingroup rpmbuild
511  * Generate binary package(s).
512  * @param spec          spec file control structure
513  * @return              0 on success
514  */
515 int packageBinaries(Spec spec)
516         /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
517         /*@modifies spec->packages->header, spec->packages->cpioList,
518                 spec->sourceRpmName,
519                 rpmGlobalMacroContext, fileSystem, internalState @*/;
520
521 /** \ingroup rpmbuild
522  * Generate source package.
523  * @param spec          spec file control structure
524  * @return              0 on success
525  */
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 @*/;
531
532 /*@=redecl@*/
533 #ifdef __cplusplus
534 }
535 #endif
536
537 #endif  /* _H_RPMBUILD_ */