1 #ifndef _RPMBUILD_INTERNAL_H
2 #define _RPMBUILD_INTERNAL_H
4 #include <rpm/rpmbuild.h>
5 #include <rpm/rpmutil.h>
6 #include <rpm/rpmstrpool.h>
7 #include "build/rpmbuild_misc.h"
12 #define HASHTYPE fileRenameHash
13 #define HTKEYTYPE const char *
14 #define HTDATATYPE const char *
15 #include "lib/rpmhash.H"
20 #define WHITELIST_NAME ".-_+%{}"
22 struct TriggerFileEntry {
28 struct TriggerFileEntry * next;
32 typedef struct ReadLevelEntry {
35 struct ReadLevelEntry * next;
42 const char * source; /* Pointer into fullSource */
48 typedef struct Package_s * Package;
51 * The structure used to store values parsed from a spec file.
57 char * specFile; /*!< Name of the spec file. */
62 struct OpenFileInfo * fileStack;
71 struct ReadLevelEntry * readStack;
73 Header buildRestrictions;
75 const char ** BANames;
77 int recursing; /*!< parse is recursive? */
81 struct Source * sources;
86 unsigned char * sourcePkgId;
87 Package sourcePackage;
89 rpmMacroContext macros;
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. */
98 StringBuf parsed; /*!< parsed spec contents */
100 Package packages; /*!< Package list. */
103 #define PACKAGE_NUM_DEPS 12
105 /** \ingroup rpmbuild
106 * The structure used to store values for a package.
112 rpmds ds; /*!< Requires: N = EVR */
113 rpmds dependencies[PACKAGE_NUM_DEPS];
117 struct Source * icon;
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. */
130 struct TriggerFileEntry * triggerFiles;
131 struct TriggerFileEntry * fileTriggerFiles;
132 struct TriggerFileEntry * transFileTriggerFiles;
135 ARGV_t fileList; /* If NULL, package will not be written */
136 ARGV_t fileExcludeList;
137 ARGV_t removePostfixes;
138 fileRenameHash fileRenameMap;
144 #define PART_SUBNAME 0
148 /** \ingroup rpmbuild
149 * rpmSpec file parser states.
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 /*!< */
189 #define STRIP_NOTHING 0
190 #define STRIP_TRAILINGSPACE (1 << 0)
191 #define STRIP_COMMENTS (1 << 1)
197 /** \ingroup rpmbuild
198 * Create and initialize rpmSpec structure.
199 * @return spec spec file control structure
202 rpmSpec newSpec(void);
204 /** \ingroup rpmbuild
205 * Stop reading from spec file, freeing resources.
206 * @param spec spec file control structure
209 void closeSpec(rpmSpec spec);
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
218 int readLine(rpmSpec spec, int strip);
220 /** \ingroup rpmbuild
221 * Check line for section separator, return next parser state.
222 * @param line from spec file
223 * @return next parser state
226 int isPart(const char * line) ;
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
235 int parseBuildInstallClean(rpmSpec spec, int parsePart);
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
243 int parseChangelog(rpmSpec spec);
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
251 int parseDescription(rpmSpec spec);
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
259 int parseFiles(rpmSpec spec);
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
267 int parsePolicies(rpmSpec spec);
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
276 int parsePreamble(rpmSpec spec, int initialPackage);
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
284 int parsePrep(rpmSpec spec);
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
293 int parseScript(rpmSpec spec, int parsePart);
295 /** \ingroup rpmbuild
296 * Check for inappropriate characters. All alphanums are considered sane.
298 * @param field string to check
299 * @param whitelist string of permitted characters
300 * @return RPMRC_OK if OK
303 rpmRC rpmCharCheck(rpmSpec spec, const char *field, const char *whitelist);
305 typedef rpmRC (*addReqProvFunction) (void *cbdata, rpmTagVal tagN,
306 const char * N, const char * EVR, rpmsenseFlags Flags,
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
322 rpmRC parseRCPOT(rpmSpec spec, Package pkg, const char * field, rpmTagVal tagN,
323 int index, rpmsenseFlags tagflags, addReqProvFunction cb, void *cbdata);
325 /** \ingroup rpmbuild
326 * Evaluate boolean expression.
327 * @param expr expression to parse
331 int parseExpressionBoolean(const char * expr);
333 /** \ingroup rpmbuild
334 * Run a build script, assembled from spec file scriptlet section.
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
344 rpmRC doScript(rpmSpec spec, rpmBuildFlags what, const char * name,
345 const char * sb, int test);
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
356 rpmRC lookupPackage(rpmSpec spec, const char * name, int flag,
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
367 Package newPackage(const char *name, rpmstrPool pool, Package * pkglist);
370 /** \ingroup rpmbuild
371 * Return rpmds containing the dependencies of a given type
373 * @param tag name tag denominating the dependency
374 * @return pointer to dependency set
377 rpmds * packageDependencies(Package pkg, rpmTagVal tag);
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
388 rpmRC processBinaryFiles(rpmSpec spec, rpmBuildPkgFlags pkgFlags,
389 int didInstall, int test);
392 * Generate package dependencies.
393 * @param spec spec file control
394 * @param pkg package control
395 * @return RPMRC_OK on success
398 rpmRC rpmfcGenerateDepends(const rpmSpec spec, Package pkg);
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)
409 int rpmfcExec(ARGV_const_t av, StringBuf sb_stdin, StringBuf * sb_stdoutp,
410 int failnonzero, const char *buildRoot);
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
419 rpmRC processBinaryPolicies(rpmSpec spec, int test);
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
428 rpmRC processSourceFiles(rpmSpec spec, rpmBuildPkgFlags pkgFlags);
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
438 rpmRC packageBinaries(rpmSpec spec, const char *cookie, int cheating);
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
447 rpmRC packageSources(rpmSpec spec, char **cookie);
450 int addLangTag(rpmSpec spec, Header h, rpmTagVal tag,
451 const char *field, const char *lang);
453 /** \ingroup rpmbuild
454 * Add dependency to package, filtering duplicates.
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
464 int addReqProv(Package pkg, rpmTagVal tagN,
465 const char * N, const char * EVR, rpmsenseFlags Flags,
469 rpmRC addReqProvPkg(void *cbdata, rpmTagVal tagN,
470 const char * N, const char * EVR, rpmsenseFlags Flags,
473 /** \ingroup rpmbuild
474 * Add self-provides to package.
478 void addPackageProvides(Package pkg);
480 /** \ingroup rpmbuild
481 * Add rpmlib feature dependency.
483 * @param feature rpm feature name (i.e. "rpmlib(Foo)" for feature Foo)
484 * @param featureEVR rpm feature epoch/version/release
488 int rpmlibNeedsFeature(Package pkg, const char * feature, const char * featureEVR);
491 rpmRC checkForEncoding(Header h, int addtag);
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
500 void copyInheritedTags(Header h, Header fromh);
506 #endif /* _RPMBUILD_INTERNAL_H */