Merge "allow rpm to custom systemd installation" into tizen
[platform/upstream/rpm.git] / build / rpmbuild_internal.h
1 #ifndef _RPMBUILD_INTERNAL_H
2 #define _RPMBUILD_INTERNAL_H
3
4 #include <rpm/rpmbuild.h>
5 #include <rpm/rpmutil.h>
6 #include "build/rpmbuild_misc.h"
7
8 struct TriggerFileEntry {
9     int index;
10     char * fileName;
11     char * script;
12     char * prog;
13     uint32_t flags;
14     struct TriggerFileEntry * next;
15 };
16
17 typedef struct ReadLevelEntry {
18     int reading;
19     int lineNum;
20     struct ReadLevelEntry * next;
21 } RLE_t;
22
23 /** \ingroup rpmbuild
24  */
25 struct Source {
26     char * fullSource;
27     const char * source;     /* Pointer into fullSource */
28     int flags;
29     uint32_t num;
30 struct Source * next;
31 };
32
33 typedef struct Package_s * Package;
34
35 /** \ingroup rpmbuild
36  * The structure used to store values parsed from a spec file.
37  */
38 struct rpmSpec_s {
39     char * specFile;    /*!< Name of the spec file. */
40     char * buildRoot;
41     char * buildSubdir;
42     const char * rootDir;
43
44     struct OpenFileInfo * fileStack;
45     char *lbuf;
46     size_t lbufSize;
47     size_t lbufOff;
48     char nextpeekc;
49     char * nextline;
50     char * line;
51     int lineNum;
52
53     struct ReadLevelEntry * readStack;
54
55     Header buildRestrictions;
56     rpmSpec * BASpecs;
57     const char ** BANames;
58     int BACount;
59     int recursing;              /*!< parse is recursive? */
60
61     rpmSpecFlags flags;
62
63     struct Source * sources;
64     int numSources;
65     int noSource;
66
67     char * sourceRpmName;
68     unsigned char * sourcePkgId;
69     Header sourceHeader;
70     rpmfi sourceCpioList;
71
72     rpmMacroContext macros;
73
74     StringBuf prep;             /*!< %prep scriptlet. */
75     StringBuf build;            /*!< %build scriptlet. */
76     StringBuf install;          /*!< %install scriptlet. */
77     StringBuf check;            /*!< %check scriptlet. */
78     StringBuf clean;            /*!< %clean scriptlet. */
79
80     StringBuf parsed;           /*!< parsed spec contents */
81
82     Package packages;           /*!< Package list. */
83 };
84
85 /** \ingroup rpmbuild
86  * The structure used to store values for a package.
87  */
88 struct Package_s {
89     Header header;
90     rpmds ds;                   /*!< Requires: N = EVR */
91     rpmfi cpioList;
92
93     struct Source * icon;
94
95     int autoReq;
96     int autoProv;
97
98     char * preInFile;   /*!< %pre scriptlet. */
99     char * postInFile;  /*!< %post scriptlet. */
100     char * preUnFile;   /*!< %preun scriptlet. */
101     char * postUnFile;  /*!< %postun scriptlet. */
102     char * preTransFile;        /*!< %pretrans scriptlet. */
103     char * postTransFile;       /*!< %posttrans scriptlet. */
104     char * verifyFile;  /*!< %verifyscript scriptlet. */
105
106     struct TriggerFileEntry * triggerFiles;
107
108     ARGV_t fileFile;
109     ARGV_t fileList;            /* If NULL, package will not be written */
110     ARGV_t policyList;
111
112     Package next;
113 };
114
115 #define PART_SUBNAME  0
116 #define PART_NAME     1
117
118 /** \ingroup rpmbuild
119  * rpmSpec file parser states.
120  */
121 #define PART_BASE       0 
122 typedef enum rpmParseState_e { 
123     PART_ERROR          =  -1, /*!< */ 
124     PART_NONE           =  0+PART_BASE, /*!< */ 
125     /* leave room for RPMRC_NOTFOUND returns. */ 
126     PART_PREAMBLE       = 11+PART_BASE, /*!< */ 
127     PART_PREP           = 12+PART_BASE, /*!< */ 
128     PART_BUILD          = 13+PART_BASE, /*!< */ 
129     PART_INSTALL        = 14+PART_BASE, /*!< */ 
130     PART_CHECK          = 15+PART_BASE, /*!< */ 
131     PART_CLEAN          = 16+PART_BASE, /*!< */ 
132     PART_FILES          = 17+PART_BASE, /*!< */ 
133     PART_PRE            = 18+PART_BASE, /*!< */ 
134     PART_POST           = 19+PART_BASE, /*!< */ 
135     PART_PREUN          = 20+PART_BASE, /*!< */ 
136     PART_POSTUN         = 21+PART_BASE, /*!< */ 
137     PART_PRETRANS       = 22+PART_BASE, /*!< */ 
138     PART_POSTTRANS      = 23+PART_BASE, /*!< */ 
139     PART_DESCRIPTION    = 24+PART_BASE, /*!< */ 
140     PART_CHANGELOG      = 25+PART_BASE, /*!< */ 
141     PART_TRIGGERIN      = 26+PART_BASE, /*!< */ 
142     PART_TRIGGERUN      = 27+PART_BASE, /*!< */ 
143     PART_VERIFYSCRIPT   = 28+PART_BASE, /*!< */ 
144     PART_BUILDARCHITECTURES= 29+PART_BASE,/*!< */ 
145     PART_TRIGGERPOSTUN  = 30+PART_BASE, /*!< */ 
146     PART_TRIGGERPREIN   = 31+PART_BASE, /*!< */ 
147     PART_POLICIES       = 32+PART_BASE, /*!< */
148     PART_LAST           = 33+PART_BASE  /*!< */
149 } rpmParseState; 
150
151
152 #define STRIP_NOTHING             0
153 #define STRIP_TRAILINGSPACE (1 << 0)
154 #define STRIP_COMMENTS      (1 << 1)
155
156 #ifdef __cplusplus
157 extern "C" {
158 #endif
159
160 /** \ingroup rpmbuild
161  * Create and initialize rpmSpec structure.
162  * @return spec         spec file control structure
163  */
164 RPM_GNUC_INTERNAL
165 rpmSpec newSpec(void);
166
167 /** \ingroup rpmbuild
168  * Stop reading from spec file, freeing resources.
169  * @param spec          spec file control structure
170  */
171 RPM_GNUC_INTERNAL
172 void closeSpec(rpmSpec spec);
173
174 /** \ingroup rpmbuild
175  * Read next line from spec file.
176  * @param spec          spec file control structure
177  * @param strip         truncate comments?
178  * @return              0 on success, 1 on EOF, <0 on error
179  */
180 RPM_GNUC_INTERNAL
181 int readLine(rpmSpec spec, int strip);
182
183 /** \ingroup rpmbuild
184  * Check line for section separator, return next parser state.
185  * @param               line from spec file
186  * @return              next parser state
187  */
188 RPM_GNUC_INTERNAL
189 int isPart(const char * line)   ;
190
191 /** \ingroup rpmbuild
192  * Parse %%build/%%install/%%clean section(s) of a spec file.
193  * @param spec          spec file control structure
194  * @param parsePart     current rpmParseState
195  * @return              >= 0 next rpmParseState, < 0 on error
196  */
197 RPM_GNUC_INTERNAL
198 int parseBuildInstallClean(rpmSpec spec, int parsePart);
199
200 /** \ingroup rpmbuild
201  * Parse %%changelog section of a spec file.
202  * @param spec          spec file control structure
203  * @return              >= 0 next rpmParseState, < 0 on error
204  */
205 RPM_GNUC_INTERNAL
206 int parseChangelog(rpmSpec spec);
207
208 /** \ingroup rpmbuild
209  * Parse %%description section of a spec file.
210  * @param spec          spec file control structure
211  * @return              >= 0 next rpmParseState, < 0 on error
212  */
213 RPM_GNUC_INTERNAL
214 int parseDescription(rpmSpec spec);
215
216 /** \ingroup rpmbuild
217  * Parse %%files section of a spec file.
218  * @param spec          spec file control structure
219  * @return              >= 0 next rpmParseState, < 0 on error
220  */
221 RPM_GNUC_INTERNAL
222 int parseFiles(rpmSpec spec);
223
224 /** \ingroup rpmbuild
225  * Parse %%sepolicy section of a spec file.
226  * @param spec          spec file control structure
227  * @return              >= 0 next rpmParseState, < 0 on error
228  */
229 RPM_GNUC_INTERNAL
230 int parsePolicies(rpmSpec spec);
231
232 /** \ingroup rpmbuild
233  * Parse tags from preamble of a spec file.
234  * @param spec          spec file control structure
235  * @param initialPackage
236  * @return              >= 0 next rpmParseState, < 0 on error
237  */
238 RPM_GNUC_INTERNAL
239 int parsePreamble(rpmSpec spec, int initialPackage);
240
241 /** \ingroup rpmbuild
242  * Parse %%prep section of a spec file.
243  * @param spec          spec file control structure
244  * @return              >= 0 next rpmParseState, < 0 on error
245  */
246 RPM_GNUC_INTERNAL
247 int parsePrep(rpmSpec spec);
248
249 /** \ingroup rpmbuild
250  * Parse %%pre et al scriptlets from a spec file.
251  * @param spec          spec file control structure
252  * @param parsePart     current rpmParseState
253  * @return              >= 0 next rpmParseState, < 0 on error
254  */
255 RPM_GNUC_INTERNAL
256 int parseScript(rpmSpec spec, int parsePart);
257
258 /** \ingroup rpmbuild
259  * Check for inappropriate characters. All alphanums are considered sane.
260  * @param spec          spec
261  * @param field         string to check
262  * @param fsize         size of string to check
263  * @param whitelist     string of permitted characters
264  * @return              RPMRC_OK if OK
265  */
266 RPM_GNUC_INTERNAL
267 rpmRC rpmCharCheck(rpmSpec spec, const char *field, size_t fsize, const char *whitelist);
268
269 /** \ingroup rpmbuild
270  * Parse dependency relations from spec file and/or autogenerated output buffer.
271  * @param spec          spec file control structure
272  * @param pkg           package control structure
273  * @param field         text to parse (e.g. "foo < 0:1.2-3, bar = 5:6.7")
274  * @param tagN          tag, identifies type of dependency
275  * @param index         (0 always)
276  * @param tagflags      dependency flags already known from context
277  * @return              RPMRC_OK on success, RPMRC_FAIL on failure
278  */
279 RPM_GNUC_INTERNAL
280 rpmRC parseRCPOT(rpmSpec spec, Package pkg, const char * field, rpmTagVal tagN,
281                 int index, rpmsenseFlags tagflags);
282
283 /** \ingroup rpmbuild
284  * Evaluate boolean expression.
285  * @param spec          spec file control structure
286  * @param expr          expression to parse
287  * @return
288  */
289 RPM_GNUC_INTERNAL
290 int parseExpressionBoolean(rpmSpec spec, const char * expr);
291
292 /** \ingroup rpmbuild
293  * Run a build script, assembled from spec file scriptlet section.
294  *
295  * @param spec          spec file control structure
296  * @param what          type of script
297  * @param name          name of scriptlet section
298  * @param sb            lines that compose script body
299  * @param test          don't execute scripts or package if testing
300  * @return              RPMRC_OK on success
301  */
302 RPM_GNUC_INTERNAL
303 rpmRC doScript(rpmSpec spec, rpmBuildFlags what, const char * name,
304                 const char * sb, int test);
305
306 /** \ingroup rpmbuild
307  * Find sub-package control structure by name.
308  * @param spec          spec file control structure
309  * @param name          (sub-)package name
310  * @param flag          if PART_SUBNAME, then 1st package name is prepended
311  * @retval pkg          package control structure
312  * @return              0 on success, 1 on failure
313  */
314 RPM_GNUC_INTERNAL
315 rpmRC lookupPackage(rpmSpec spec, const char * name, int flag,
316                 Package * pkg);
317
318 /** \ingroup rpmbuild
319  * Create and initialize package control structure.
320  * @param spec          spec file control structure
321  * @return              package control structure
322  */
323 RPM_GNUC_INTERNAL
324 Package newPackage(rpmSpec spec);
325
326 /** \ingroup rpmbuild
327  * Post-build processing for binary package(s).
328  * @param spec          spec file control structure
329  * @param pkgFlags      bit(s) to control package generation
330  * @param installSpecialDoc
331  * @param test          don't execute scripts or package if testing
332  * @return              0 on success
333  */
334 RPM_GNUC_INTERNAL
335 rpmRC processBinaryFiles(rpmSpec spec, rpmBuildPkgFlags pkgFlags,
336                         int installSpecialDoc, int test);
337
338 /** \ingroup rpmfc
339  * Generate package dependencies.
340  * @param spec          spec file control
341  * @param pkg           package control
342  * @return              RPMRC_OK on success
343  */
344 RPM_GNUC_INTERNAL
345 rpmRC rpmfcGenerateDepends(const rpmSpec spec, Package pkg);
346
347 /** \ingroup rpmfc
348  * Return helper output.
349  * @param av            helper argv (with possible macros)
350  * @param sb_stdin      helper input
351  * @retval *sb_stdoutp  helper output
352  * @param failnonzero   IS non-zero helper exit status a failure?
353  * @param buildRoot     buildRoot directory (or NULL)
354  */
355 RPM_GNUC_INTERNAL
356 int rpmfcExec(ARGV_const_t av, StringBuf sb_stdin, StringBuf * sb_stdoutp,
357                 int failnonzero, const char *buildRoot);
358
359 /** \ingroup rpmbuild
360  * Post-build processing for policies in binary package(s).
361  * @param spec          spec file control structure
362  * @param test          don't execute scripts or package if testing
363  * @return              0 on success
364  */
365 RPM_GNUC_INTERNAL
366 rpmRC processBinaryPolicies(rpmSpec spec, int test);
367
368 /** \ingroup rpmbuild
369  * Post-build processing for source package.
370  * @param spec          spec file control structure
371  * @param pkgFlags      bit(s) to control package generation
372  * @return              0 on success
373  */
374 RPM_GNUC_INTERNAL
375 rpmRC processSourceFiles(rpmSpec spec, rpmBuildPkgFlags pkgFlags);
376
377 /** \ingroup rpmbuild
378  * Generate binary package(s).
379  * @param spec          spec file control structure
380  * @param cookie        build identifier "cookie" or NULL
381  * @param cheating      was build shortcircuited?
382  * @return              RPMRC_OK on success
383  */
384 RPM_GNUC_INTERNAL
385 rpmRC packageBinaries(rpmSpec spec, const char *cookie, int cheating);
386
387 /** \ingroup rpmbuild
388  * Generate source package.
389  * @param spec          spec file control structure
390  * @retval cookie       build identifier "cookie" or NULL
391  * @return              RPMRC_OK on success
392  */
393 RPM_GNUC_INTERNAL
394 rpmRC packageSources(rpmSpec spec, char **cookie);
395
396 #ifdef __cplusplus
397 }
398 #endif
399
400 #endif /* _RPMBUILD_INTERNAL_H */