Add macro %isu_package to generate ISU Package
[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 <rpm/rpmstrpool.h>
7 #include "build/rpmbuild_misc.h"
8
9 #undef HASHTYPE
10 #undef HTKEYTYPE
11 #undef HTDATATYPE
12 #define HASHTYPE fileRenameHash
13 #define HTKEYTYPE const char *
14 #define HTDATATYPE const char *
15 #include "lib/rpmhash.H"
16 #undef HASHTYPE
17 #undef HTKEYTYPE
18 #undef HTDATATYPE
19
20 #define WHITELIST_NAME ".-_+%{}"
21
22 struct TriggerFileEntry {
23     int index;
24     char * fileName;
25     char * script;
26     char * prog;
27     uint32_t flags;
28     struct TriggerFileEntry * next;
29     uint32_t priority;
30 };
31
32 typedef struct ReadLevelEntry {
33     int reading;
34     int lineNum;
35     struct ReadLevelEntry * next;
36 } RLE_t;
37
38 /** \ingroup rpmbuild
39  */
40 struct Source {
41     char * fullSource;
42     const char * source;     /* Pointer into fullSource */
43     int flags;
44     uint32_t num;
45 struct Source * next;
46 };
47
48 typedef struct Package_s * Package;
49
50 /** \ingroup rpmbuild
51  * The structure used to store values parsed from a spec file.
52  */
53 struct rpmSpec_s {
54     char * buildHost;
55     rpm_time_t buildTime;
56
57     char * specFile;    /*!< Name of the spec file. */
58     char * buildRoot;
59     char * buildSubdir;
60     const char * rootDir;
61
62     struct OpenFileInfo * fileStack;
63     char *lbuf;
64     size_t lbufSize;
65     size_t lbufOff;
66     char nextpeekc;
67     char * nextline;
68     char * line;
69     int lineNum;
70
71     struct ReadLevelEntry * readStack;
72
73     Header buildRestrictions;
74     rpmSpec * BASpecs;
75     const char ** BANames;
76     int BACount;
77     int recursing;              /*!< parse is recursive? */
78
79     rpmSpecFlags flags;
80
81     struct Source * sources;
82     int numSources;
83     int noSource;
84
85     char * sourceRpmName;
86     unsigned char * sourcePkgId;
87     Package sourcePackage;
88
89     rpmMacroContext macros;
90     rpmstrPool pool;
91
92     StringBuf prep;             /*!< %prep scriptlet. */
93     StringBuf build;            /*!< %build scriptlet. */
94     StringBuf install;          /*!< %install scriptlet. */
95     StringBuf check;            /*!< %check scriptlet. */
96     StringBuf clean;            /*!< %clean scriptlet. */
97
98     StringBuf parsed;           /*!< parsed spec contents */
99
100     Package packages;           /*!< Package list. */
101 };
102
103 #define PACKAGE_NUM_DEPS 12
104
105 /** \ingroup rpmbuild
106  * The structure used to store values for a package.
107  */
108 struct Package_s {
109     rpmsid name;
110     rpmstrPool pool;
111     Header header;
112     rpmds ds;                   /*!< Requires: N = EVR */
113     rpmds dependencies[PACKAGE_NUM_DEPS];
114     rpmfiles cpioList;
115     ARGV_t dpaths;
116
117     struct Source * icon;
118
119     int autoReq;
120     int autoProv;
121
122     char * preInFile;   /*!< %pre scriptlet. */
123     char * postInFile;  /*!< %post scriptlet. */
124     char * preUnFile;   /*!< %preun scriptlet. */
125     char * postUnFile;  /*!< %postun scriptlet. */
126     char * preTransFile;        /*!< %pretrans scriptlet. */
127     char * postTransFile;       /*!< %posttrans scriptlet. */
128     char * verifyFile;  /*!< %verifyscript scriptlet. */
129
130     struct TriggerFileEntry * triggerFiles;
131     struct TriggerFileEntry * fileTriggerFiles;
132     struct TriggerFileEntry * transFileTriggerFiles;
133
134     ARGV_t fileFile;
135     ARGV_t fileList;            /* If NULL, package will not be written */
136     ARGV_t fileExcludeList;
137     ARGV_t removePostfixes;
138     fileRenameHash fileRenameMap;
139     ARGV_t policyList;
140
141     Package next;
142 };
143
144 #define PART_SUBNAME  0
145 #define PART_NAME     1
146 #define PART_QUIET    2
147
148 /** \ingroup rpmbuild
149  * rpmSpec file parser states.
150  */
151 #define PART_BASE       0 
152 typedef enum rpmParseState_e { 
153     PART_ERROR          =  -1, /*!< */ 
154     PART_NONE           =  0+PART_BASE, /*!< */ 
155     /* leave room for RPMRC_NOTFOUND returns. */ 
156     PART_PREAMBLE       = 11+PART_BASE, /*!< */ 
157     PART_PREP           = 12+PART_BASE, /*!< */ 
158     PART_BUILD          = 13+PART_BASE, /*!< */ 
159     PART_INSTALL        = 14+PART_BASE, /*!< */ 
160     PART_CHECK          = 15+PART_BASE, /*!< */ 
161     PART_CLEAN          = 16+PART_BASE, /*!< */ 
162     PART_FILES          = 17+PART_BASE, /*!< */ 
163     PART_PRE            = 18+PART_BASE, /*!< */ 
164     PART_POST           = 19+PART_BASE, /*!< */ 
165     PART_PREUN          = 20+PART_BASE, /*!< */ 
166     PART_POSTUN         = 21+PART_BASE, /*!< */ 
167     PART_PRETRANS       = 22+PART_BASE, /*!< */ 
168     PART_POSTTRANS      = 23+PART_BASE, /*!< */ 
169     PART_DESCRIPTION    = 24+PART_BASE, /*!< */ 
170     PART_CHANGELOG      = 25+PART_BASE, /*!< */ 
171     PART_TRIGGERIN      = 26+PART_BASE, /*!< */ 
172     PART_TRIGGERUN      = 27+PART_BASE, /*!< */ 
173     PART_VERIFYSCRIPT   = 28+PART_BASE, /*!< */ 
174     PART_BUILDARCHITECTURES= 29+PART_BASE,/*!< */ 
175     PART_TRIGGERPOSTUN  = 30+PART_BASE, /*!< */ 
176     PART_TRIGGERPREIN   = 31+PART_BASE, /*!< */ 
177     PART_POLICIES       = 32+PART_BASE, /*!< */
178     PART_FILETRIGGERIN          = 33+PART_BASE, /*!< */
179     PART_FILETRIGGERUN          = 34+PART_BASE, /*!< */
180     PART_FILETRIGGERPOSTUN      = 35+PART_BASE, /*!< */
181     PART_TRANSFILETRIGGERIN     = 36+PART_BASE, /*!< */
182     PART_TRANSFILETRIGGERUN     = 37+PART_BASE, /*!< */
183     PART_TRANSFILETRIGGERPOSTUN = 38+PART_BASE, /*!< */
184     PART_EMPTY                  = 39+PART_BASE, /*!< */
185     PART_LAST                   = 40+PART_BASE  /*!< */
186 } rpmParseState; 
187
188
189 #define STRIP_NOTHING             0
190 #define STRIP_TRAILINGSPACE (1 << 0)
191 #define STRIP_COMMENTS      (1 << 1)
192
193 #ifdef __cplusplus
194 extern "C" {
195 #endif
196
197 /** \ingroup rpmbuild
198  * Create and initialize rpmSpec structure.
199  * @return spec         spec file control structure
200  */
201 RPM_GNUC_INTERNAL
202 rpmSpec newSpec(void);
203
204 /** \ingroup rpmbuild
205  * Stop reading from spec file, freeing resources.
206  * @param spec          spec file control structure
207  */
208 RPM_GNUC_INTERNAL
209 void closeSpec(rpmSpec spec);
210
211 /** \ingroup rpmbuild
212  * Read next line from spec file.
213  * @param spec          spec file control structure
214  * @param strip         truncate comments?
215  * @return              0 on success, 1 on EOF, <0 on error
216  */
217 RPM_GNUC_INTERNAL
218 int readLine(rpmSpec spec, int strip);
219
220 /** \ingroup rpmbuild
221  * Check line for section separator, return next parser state.
222  * @param               line from spec file
223  * @return              next parser state
224  */
225 RPM_GNUC_INTERNAL
226 int isPart(const char * line)   ;
227
228 /** \ingroup rpmbuild
229  * Parse %%build/%%install/%%clean section(s) of a spec file.
230  * @param spec          spec file control structure
231  * @param parsePart     current rpmParseState
232  * @return              >= 0 next rpmParseState, < 0 on error
233  */
234 RPM_GNUC_INTERNAL
235 int parseBuildInstallClean(rpmSpec spec, int parsePart);
236
237 /** \ingroup rpmbuild
238  * Parse %%changelog section of a spec file.
239  * @param spec          spec file control structure
240  * @return              >= 0 next rpmParseState, < 0 on error
241  */
242 RPM_GNUC_INTERNAL
243 int parseChangelog(rpmSpec spec);
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 RPM_GNUC_INTERNAL
251 int parseDescription(rpmSpec spec);
252
253 /** \ingroup rpmbuild
254  * Parse %%files section of a spec file.
255  * @param spec          spec file control structure
256  * @return              >= 0 next rpmParseState, < 0 on error
257  */
258 RPM_GNUC_INTERNAL
259 int parseFiles(rpmSpec spec);
260
261 /** \ingroup rpmbuild
262  * Parse %%sepolicy section of a spec file.
263  * @param spec          spec file control structure
264  * @return              >= 0 next rpmParseState, < 0 on error
265  */
266 RPM_GNUC_INTERNAL
267 int parsePolicies(rpmSpec spec);
268
269 /** \ingroup rpmbuild
270  * Parse tags from preamble of a spec file.
271  * @param spec          spec file control structure
272  * @param initialPackage
273  * @return              >= 0 next rpmParseState, < 0 on error
274  */
275 RPM_GNUC_INTERNAL
276 int parsePreamble(rpmSpec spec, int initialPackage);
277
278 /** \ingroup rpmbuild
279  * Parse %%prep section of a spec file.
280  * @param spec          spec file control structure
281  * @return              >= 0 next rpmParseState, < 0 on error
282  */
283 RPM_GNUC_INTERNAL
284 int parsePrep(rpmSpec spec);
285
286 /** \ingroup rpmbuild
287  * Parse %%pre et al scriptlets from a spec file.
288  * @param spec          spec file control structure
289  * @param parsePart     current rpmParseState
290  * @return              >= 0 next rpmParseState, < 0 on error
291  */
292 RPM_GNUC_INTERNAL
293 int parseScript(rpmSpec spec, int parsePart);
294
295 /** \ingroup rpmbuild
296  * Check for inappropriate characters. All alphanums are considered sane.
297  * @param spec          spec
298  * @param field         string to check
299  * @param whitelist     string of permitted characters
300  * @return              RPMRC_OK if OK
301  */
302 RPM_GNUC_INTERNAL
303 rpmRC rpmCharCheck(rpmSpec spec, const char *field, const char *whitelist);
304
305 typedef rpmRC (*addReqProvFunction) (void *cbdata, rpmTagVal tagN,
306                                      const char * N, const char * EVR, rpmsenseFlags Flags,
307                                      int index);
308
309 /** \ingroup rpmbuild
310  * Parse dependency relations from spec file and/or autogenerated output buffer.
311  * @param spec          spec file control structure
312  * @param pkg           package control structure
313  * @param field         text to parse (e.g. "foo < 0:1.2-3, bar = 5:6.7")
314  * @param tagN          tag, identifies type of dependency
315  * @param index         (0 always)
316  * @param tagflags      dependency flags already known from context
317  * @param cb            Callback for adding dependency (nullable)
318  * @param cbdata        Callback data (@pkg if NULL)
319  * @return              RPMRC_OK on success, RPMRC_FAIL on failure
320  */
321 RPM_GNUC_INTERNAL
322 rpmRC parseRCPOT(rpmSpec spec, Package pkg, const char * field, rpmTagVal tagN,
323                 int index, rpmsenseFlags tagflags, addReqProvFunction cb, void *cbdata);
324
325 /** \ingroup rpmbuild
326  * Evaluate boolean expression.
327  * @param expr          expression to parse
328  * @return
329  */
330 RPM_GNUC_INTERNAL
331 int parseExpressionBoolean(const char * expr);
332
333 /** \ingroup rpmbuild
334  * Run a build script, assembled from spec file scriptlet section.
335  *
336  * @param spec          spec file control structure
337  * @param what          type of script
338  * @param name          name of scriptlet section
339  * @param sb            lines that compose script body
340  * @param test          don't execute scripts or package if testing
341  * @return              RPMRC_OK on success
342  */
343 RPM_GNUC_INTERNAL
344 rpmRC doScript(rpmSpec spec, rpmBuildFlags what, const char * name,
345                 const char * sb, int test);
346
347 /** \ingroup rpmbuild
348  * Find sub-package control structure by name.
349  * @param spec          spec file control structure
350  * @param name          (sub-)package name
351  * @param flag          if PART_SUBNAME, then 1st package name is prepended
352  * @retval pkg          package control structure
353  * @return              0 on success, 1 on failure
354  */
355 RPM_GNUC_INTERNAL
356 rpmRC lookupPackage(rpmSpec spec, const char * name, int flag,
357                 Package * pkg);
358
359 /** \ingroup rpmbuild
360  * Create and initialize package control structure.
361  * @param name          package name for sub-packages (or NULL)
362  * @param pool          string pool
363  * @param pkglist       package list pointer to append to (or NULL)
364  * @return              package control structure
365  */
366 RPM_GNUC_INTERNAL
367 Package newPackage(const char *name, rpmstrPool pool, Package * pkglist);
368
369
370 /** \ingroup rpmbuild
371  * Return rpmds containing the dependencies of a given type
372  * @param pkg           package
373  * @param tag           name tag denominating the dependency
374  * @return              pointer to dependency set
375  */
376 RPM_GNUC_INTERNAL
377 rpmds * packageDependencies(Package pkg, rpmTagVal tag);
378
379 /** \ingroup rpmbuild
380  * Post-build processing for binary package(s).
381  * @param spec          spec file control structure
382  * @param pkgFlags      bit(s) to control package generation
383  * @param didInstall    was %install executed?
384  * @param test          don't execute scripts or package if testing
385  * @return              0 on success
386  */
387 RPM_GNUC_INTERNAL
388 rpmRC processBinaryFiles(rpmSpec spec, rpmBuildPkgFlags pkgFlags,
389                         int didInstall, int test);
390
391 /** \ingroup rpmfc
392  * Generate package dependencies.
393  * @param spec          spec file control
394  * @param pkg           package control
395  * @return              RPMRC_OK on success
396  */
397 RPM_GNUC_INTERNAL
398 rpmRC rpmfcGenerateDepends(const rpmSpec spec, Package pkg);
399
400 /** \ingroup rpmfc
401  * Return helper output.
402  * @param av            helper argv (with possible macros)
403  * @param sb_stdin      helper input
404  * @retval *sb_stdoutp  helper output
405  * @param failnonzero   IS non-zero helper exit status a failure?
406  * @param buildRoot     buildRoot directory (or NULL)
407  */
408 RPM_GNUC_INTERNAL
409 int rpmfcExec(ARGV_const_t av, StringBuf sb_stdin, StringBuf * sb_stdoutp,
410                 int failnonzero, const char *buildRoot);
411
412 /** \ingroup rpmbuild
413  * Post-build processing for policies in binary package(s).
414  * @param spec          spec file control structure
415  * @param test          don't execute scripts or package if testing
416  * @return              0 on success
417  */
418 RPM_GNUC_INTERNAL
419 rpmRC processBinaryPolicies(rpmSpec spec, int test);
420
421 /** \ingroup rpmbuild
422  * Post-build processing for source package.
423  * @param spec          spec file control structure
424  * @param pkgFlags      bit(s) to control package generation
425  * @return              0 on success
426  */
427 RPM_GNUC_INTERNAL
428 rpmRC processSourceFiles(rpmSpec spec, rpmBuildPkgFlags pkgFlags);
429
430 /** \ingroup rpmbuild
431  * Generate binary package(s).
432  * @param spec          spec file control structure
433  * @param cookie        build identifier "cookie" or NULL
434  * @param cheating      was build shortcircuited?
435  * @return              RPMRC_OK on success
436  */
437 RPM_GNUC_INTERNAL
438 rpmRC packageBinaries(rpmSpec spec, const char *cookie, int cheating);
439
440 /** \ingroup rpmbuild
441  * Generate source package.
442  * @param spec          spec file control structure
443  * @retval cookie       build identifier "cookie" or NULL
444  * @return              RPMRC_OK on success
445  */
446 RPM_GNUC_INTERNAL
447 rpmRC packageSources(rpmSpec spec, char **cookie);
448
449 RPM_GNUC_INTERNAL
450 int addLangTag(rpmSpec spec, Header h, rpmTagVal tag,
451                 const char *field, const char *lang);
452
453 /** \ingroup rpmbuild
454  * Add dependency to package, filtering duplicates.
455  * @param pkg           package
456  * @param tagN          tag, identifies type of dependency
457  * @param N             (e.g. Requires: foo < 0:1.2-3, "foo")
458  * @param EVR           (e.g. Requires: foo < 0:1.2-3, "0:1.2-3")
459  * @param Flags         (e.g. Requires: foo < 0:1.2-3, both "Requires:" and "<")
460  * @param index         (# trigger script for triggers, 0 for others)
461  * @return              0 on success, 1 on error
462  */
463 RPM_GNUC_INTERNAL
464 int addReqProv(Package pkg, rpmTagVal tagN,
465                const char * N, const char * EVR, rpmsenseFlags Flags,
466                uint32_t index);
467
468 RPM_GNUC_INTERNAL
469 rpmRC addReqProvPkg(void *cbdata, rpmTagVal tagN,
470                     const char * N, const char * EVR, rpmsenseFlags Flags,
471                     int index);
472
473 /** \ingroup rpmbuild
474  * Add self-provides to package.
475  * @param pkg           package
476  */
477 RPM_GNUC_INTERNAL
478 void addPackageProvides(Package pkg);
479
480 /** \ingroup rpmbuild
481  * Add rpmlib feature dependency.
482  * @param pkg           package
483  * @param feature       rpm feature name (i.e. "rpmlib(Foo)" for feature Foo)
484  * @param featureEVR    rpm feature epoch/version/release
485  * @return              0 always
486  */
487 RPM_GNUC_INTERNAL
488 int rpmlibNeedsFeature(Package pkg, const char * feature, const char * featureEVR);
489
490 RPM_GNUC_INTERNAL
491 rpmRC checkForEncoding(Header h, int addtag);
492
493
494 /** \ingroup rpmbuild
495  * Copy tags inherited by subpackages from the source header to the target header
496  * @param h             target header
497  * @param fromh         source header
498  */
499 RPM_GNUC_INTERNAL
500 void copyInheritedTags(Header h, Header fromh);
501
502 #ifdef __cplusplus
503 }
504 #endif
505
506 #endif /* _RPMBUILD_INTERNAL_H */