csomh / source-git / rpm

Forked from source-git/rpm 4 years ago
Clone
2ff057
#ifndef _RPMBUILD_INTERNAL_H
2ff057
#define _RPMBUILD_INTERNAL_H
2ff057
2ff057
#include <rpm/rpmbuild.h>
2ff057
#include <rpm/rpmutil.h>
2ff057
#include <rpm/rpmstrpool.h>
2ff057
#include "build/rpmbuild_misc.h"
2ff057
2ff057
#undef HASHTYPE
2ff057
#undef HTKEYTYPE
2ff057
#undef HTDATATYPE
2ff057
#define HASHTYPE fileRenameHash
2ff057
#define HTKEYTYPE const char *
2ff057
#define HTDATATYPE const char *
2ff057
#include "lib/rpmhash.H"
2ff057
#undef HASHTYPE
2ff057
#undef HTKEYTYPE
2ff057
#undef HTDATATYPE
2ff057
2ff057
struct TriggerFileEntry {
2ff057
    int index;
2ff057
    char * fileName;
2ff057
    char * script;
2ff057
    char * prog;
2ff057
    uint32_t flags;
2ff057
    struct TriggerFileEntry * next;
2ff057
    uint32_t priority;
2ff057
};
2ff057
2ff057
typedef struct ReadLevelEntry {
2ff057
    int reading;
2ff057
    int lineNum;
2ff057
    struct ReadLevelEntry * next;
2ff057
} RLE_t;
2ff057
2ff057
/** \ingroup rpmbuild
2ff057
 */
2ff057
struct Source {
2ff057
    char * fullSource;
2ff057
    const char * source;     /* Pointer into fullSource */
2ff057
    int flags;
2ff057
    uint32_t num;
2ff057
struct Source * next;
2ff057
};
2ff057
2ff057
typedef struct Package_s * Package;
2ff057
2ff057
/** \ingroup rpmbuild
2ff057
 * The structure used to store values parsed from a spec file.
2ff057
 */
2ff057
struct rpmSpec_s {
2ff057
    char * specFile;	/*!< Name of the spec file. */
2ff057
    char * buildRoot;
2ff057
    char * buildSubdir;
2ff057
    const char * rootDir;
2ff057
2ff057
    struct OpenFileInfo * fileStack;
2ff057
    char *lbuf;
2ff057
    size_t lbufSize;
2ff057
    size_t lbufOff;
2ff057
    char nextpeekc;
2ff057
    char * nextline;
2ff057
    char * line;
2ff057
    int lineNum;
2ff057
2ff057
    struct ReadLevelEntry * readStack;
2ff057
2ff057
    Header buildRestrictions;
2ff057
    rpmSpec * BASpecs;
2ff057
    const char ** BANames;
2ff057
    int BACount;
2ff057
    int recursing;		/*!< parse is recursive? */
2ff057
2ff057
    rpmSpecFlags flags;
2ff057
2ff057
    struct Source * sources;
2ff057
    int numSources;
2ff057
    int noSource;
2ff057
2ff057
    char * sourceRpmName;
2ff057
    unsigned char * sourcePkgId;
2ff057
    Package sourcePackage;
2ff057
2ff057
    rpmMacroContext macros;
2ff057
    rpmstrPool pool;
2ff057
2ff057
    StringBuf prep;		/*!< %prep scriptlet. */
2ff057
    StringBuf build;		/*!< %build scriptlet. */
2ff057
    StringBuf install;		/*!< %install scriptlet. */
2ff057
    StringBuf check;		/*!< %check scriptlet. */
2ff057
    StringBuf clean;		/*!< %clean scriptlet. */
2ff057
2ff057
    StringBuf parsed;		/*!< parsed spec contents */
2ff057
2ff057
    Package packages;		/*!< Package list. */
2ff057
};
2ff057
2ff057
#define PACKAGE_NUM_DEPS 12
2ff057
2ff057
/** \ingroup rpmbuild
2ff057
 * The structure used to store values for a package.
2ff057
 */
2ff057
struct Package_s {
2ff057
    rpmsid name;
2ff057
    rpmstrPool pool;
2ff057
    Header header;
2ff057
    rpmds ds;			/*!< Requires: N = EVR */
2ff057
    rpmds dependencies[PACKAGE_NUM_DEPS];
2ff057
    rpmfiles cpioList;
2ff057
    ARGV_t dpaths;
2ff057
2ff057
    struct Source * icon;
2ff057
2ff057
    int autoReq;
2ff057
    int autoProv;
2ff057
2ff057
    char * preInFile;	/*!< %pre scriptlet. */
2ff057
    char * postInFile;	/*!< %post scriptlet. */
2ff057
    char * preUnFile;	/*!< %preun scriptlet. */
2ff057
    char * postUnFile;	/*!< %postun scriptlet. */
2ff057
    char * preTransFile;	/*!< %pretrans scriptlet. */
2ff057
    char * postTransFile;	/*!< %posttrans scriptlet. */
2ff057
    char * verifyFile;	/*!< %verifyscript scriptlet. */
2ff057
2ff057
    struct TriggerFileEntry * triggerFiles;
2ff057
    struct TriggerFileEntry * fileTriggerFiles;
2ff057
    struct TriggerFileEntry * transFileTriggerFiles;
2ff057
2ff057
    ARGV_t fileFile;
2ff057
    ARGV_t fileList;		/* If NULL, package will not be written */
2ff057
    ARGV_t fileExcludeList;
2ff057
    ARGV_t removePostfixes;
2ff057
    fileRenameHash fileRenameMap;
2ff057
    ARGV_t policyList;
2ff057
2ff057
    Package next;
2ff057
};
2ff057
2ff057
#define PART_SUBNAME  0
2ff057
#define PART_NAME     1
2ff057
#define PART_QUIET    2
2ff057
2ff057
/** \ingroup rpmbuild
2ff057
 * rpmSpec file parser states.
2ff057
 */
2ff057
#define PART_BASE       0 
2ff057
typedef enum rpmParseState_e { 
2ff057
    PART_ERROR          =  -1, /*!< */ 
2ff057
    PART_NONE           =  0+PART_BASE, /*!< */ 
2ff057
    /* leave room for RPMRC_NOTFOUND returns. */ 
2ff057
    PART_PREAMBLE       = 11+PART_BASE, /*!< */ 
2ff057
    PART_PREP           = 12+PART_BASE, /*!< */ 
2ff057
    PART_BUILD          = 13+PART_BASE, /*!< */ 
2ff057
    PART_INSTALL        = 14+PART_BASE, /*!< */ 
2ff057
    PART_CHECK          = 15+PART_BASE, /*!< */ 
2ff057
    PART_CLEAN          = 16+PART_BASE, /*!< */ 
2ff057
    PART_FILES          = 17+PART_BASE, /*!< */ 
2ff057
    PART_PRE            = 18+PART_BASE, /*!< */ 
2ff057
    PART_POST           = 19+PART_BASE, /*!< */ 
2ff057
    PART_PREUN          = 20+PART_BASE, /*!< */ 
2ff057
    PART_POSTUN         = 21+PART_BASE, /*!< */ 
2ff057
    PART_PRETRANS       = 22+PART_BASE, /*!< */ 
2ff057
    PART_POSTTRANS      = 23+PART_BASE, /*!< */ 
2ff057
    PART_DESCRIPTION    = 24+PART_BASE, /*!< */ 
2ff057
    PART_CHANGELOG      = 25+PART_BASE, /*!< */ 
2ff057
    PART_TRIGGERIN      = 26+PART_BASE, /*!< */ 
2ff057
    PART_TRIGGERUN      = 27+PART_BASE, /*!< */ 
2ff057
    PART_VERIFYSCRIPT   = 28+PART_BASE, /*!< */ 
2ff057
    PART_BUILDARCHITECTURES= 29+PART_BASE,/*!< */ 
2ff057
    PART_TRIGGERPOSTUN  = 30+PART_BASE, /*!< */ 
2ff057
    PART_TRIGGERPREIN   = 31+PART_BASE, /*!< */ 
2ff057
    PART_POLICIES       = 32+PART_BASE, /*!< */
2ff057
    PART_FILETRIGGERIN		= 33+PART_BASE, /*!< */
2ff057
    PART_FILETRIGGERUN		= 34+PART_BASE, /*!< */
2ff057
    PART_FILETRIGGERPOSTUN	= 35+PART_BASE, /*!< */
2ff057
    PART_TRANSFILETRIGGERIN	= 36+PART_BASE, /*!< */
2ff057
    PART_TRANSFILETRIGGERUN	= 37+PART_BASE, /*!< */
2ff057
    PART_TRANSFILETRIGGERPOSTUN	= 38+PART_BASE, /*!< */
2ff057
    PART_EMPTY			= 39+PART_BASE, /*!< */
2ff057
    PART_LAST			= 40+PART_BASE  /*!< */
2ff057
} rpmParseState; 
2ff057
2ff057
2ff057
#define STRIP_NOTHING             0
2ff057
#define STRIP_TRAILINGSPACE (1 << 0)
2ff057
#define STRIP_COMMENTS      (1 << 1)
2ff057
2ff057
#ifdef __cplusplus
2ff057
extern "C" {
2ff057
#endif
2ff057
2ff057
/** \ingroup rpmbuild
2ff057
 * Create and initialize rpmSpec structure.
2ff057
 * @return spec		spec file control structure
2ff057
 */
2ff057
RPM_GNUC_INTERNAL
2ff057
rpmSpec newSpec(void);
2ff057
2ff057
/** \ingroup rpmbuild
2ff057
 * Stop reading from spec file, freeing resources.
2ff057
 * @param spec		spec file control structure
2ff057
 */
2ff057
RPM_GNUC_INTERNAL
2ff057
void closeSpec(rpmSpec spec);
2ff057
2ff057
/** \ingroup rpmbuild
2ff057
 * Read next line from spec file.
2ff057
 * @param spec		spec file control structure
2ff057
 * @param strip		truncate comments?
2ff057
 * @return		0 on success, 1 on EOF, <0 on error
2ff057
 */
2ff057
RPM_GNUC_INTERNAL
2ff057
int readLine(rpmSpec spec, int strip);
2ff057
2ff057
/** \ingroup rpmbuild
2ff057
 * Check line for section separator, return next parser state.
2ff057
 * @param		line from spec file
2ff057
 * @return		next parser state
2ff057
 */
2ff057
RPM_GNUC_INTERNAL
2ff057
int isPart(const char * line)	;
2ff057
2ff057
/** \ingroup rpmbuild
2ff057
 * Parse %%build/%%install/%%clean section(s) of a spec file.
2ff057
 * @param spec		spec file control structure
2ff057
 * @param parsePart	current rpmParseState
2ff057
 * @return		>= 0 next rpmParseState, < 0 on error
2ff057
 */
2ff057
RPM_GNUC_INTERNAL
2ff057
int parseBuildInstallClean(rpmSpec spec, int parsePart);
2ff057
2ff057
/** \ingroup rpmbuild
2ff057
 * Parse %%changelog section of a spec file.
2ff057
 * @param spec		spec file control structure
2ff057
 * @return		>= 0 next rpmParseState, < 0 on error
2ff057
 */
2ff057
RPM_GNUC_INTERNAL
2ff057
int parseChangelog(rpmSpec spec);
2ff057
2ff057
/** \ingroup rpmbuild
2ff057
 * Parse %%description section of a spec file.
2ff057
 * @param spec		spec file control structure
2ff057
 * @return		>= 0 next rpmParseState, < 0 on error
2ff057
 */
2ff057
RPM_GNUC_INTERNAL
2ff057
int parseDescription(rpmSpec spec);
2ff057
2ff057
/** \ingroup rpmbuild
2ff057
 * Parse %%files section of a spec file.
2ff057
 * @param spec		spec file control structure
2ff057
 * @return		>= 0 next rpmParseState, < 0 on error
2ff057
 */
2ff057
RPM_GNUC_INTERNAL
2ff057
int parseFiles(rpmSpec spec);
2ff057
2ff057
/** \ingroup rpmbuild
2ff057
 * Parse %%sepolicy section of a spec file.
2ff057
 * @param spec		spec file control structure
2ff057
 * @return		>= 0 next rpmParseState, < 0 on error
2ff057
 */
2ff057
RPM_GNUC_INTERNAL
2ff057
int parsePolicies(rpmSpec spec);
2ff057
2ff057
/** \ingroup rpmbuild
2ff057
 * Parse tags from preamble of a spec file.
2ff057
 * @param spec		spec file control structure
2ff057
 * @param initialPackage
2ff057
 * @return		>= 0 next rpmParseState, < 0 on error
2ff057
 */
2ff057
RPM_GNUC_INTERNAL
2ff057
int parsePreamble(rpmSpec spec, int initialPackage);
2ff057
2ff057
/** \ingroup rpmbuild
2ff057
 * Parse %%prep section of a spec file.
2ff057
 * @param spec		spec file control structure
2ff057
 * @return		>= 0 next rpmParseState, < 0 on error
2ff057
 */
2ff057
RPM_GNUC_INTERNAL
2ff057
int parsePrep(rpmSpec spec);
2ff057
2ff057
/** \ingroup rpmbuild
2ff057
 * Parse %%pre et al scriptlets from a spec file.
2ff057
 * @param spec		spec file control structure
2ff057
 * @param parsePart	current rpmParseState
2ff057
 * @return		>= 0 next rpmParseState, < 0 on error
2ff057
 */
2ff057
RPM_GNUC_INTERNAL
2ff057
int parseScript(rpmSpec spec, int parsePart);
2ff057
2ff057
/** \ingroup rpmbuild
2ff057
 * Check for inappropriate characters. All alphanums are considered sane.
2ff057
 * @param spec          spec
2ff057
 * @param field         string to check
2ff057
 * @param whitelist     string of permitted characters
2ff057
 * @return              RPMRC_OK if OK
2ff057
 */
2ff057
RPM_GNUC_INTERNAL
2ff057
rpmRC rpmCharCheck(rpmSpec spec, const char *field, const char *whitelist);
2ff057
2ff057
typedef rpmRC (*addReqProvFunction) (void *cbdata, rpmTagVal tagN,
2ff057
				     const char * N, const char * EVR, rpmsenseFlags Flags,
2ff057
				     int index);
2ff057
2ff057
/** \ingroup rpmbuild
2ff057
 * Parse dependency relations from spec file and/or autogenerated output buffer.
2ff057
 * @param spec		spec file control structure
2ff057
 * @param pkg		package control structure
2ff057
 * @param field		text to parse (e.g. "foo < 0:1.2-3, bar = 5:6.7")
2ff057
 * @param tagN		tag, identifies type of dependency
2ff057
 * @param index		(0 always)
2ff057
 * @param tagflags	dependency flags already known from context
2ff057
 * @param cb		Callback for adding dependency (nullable)
2ff057
 * @param cbdata	Callback data (@pkg if NULL)
2ff057
 * @return		RPMRC_OK on success, RPMRC_FAIL on failure
2ff057
 */
2ff057
RPM_GNUC_INTERNAL
2ff057
rpmRC parseRCPOT(rpmSpec spec, Package pkg, const char * field, rpmTagVal tagN,
2ff057
		int index, rpmsenseFlags tagflags, addReqProvFunction cb, void *cbdata);
2ff057
2ff057
/** \ingroup rpmbuild
2ff057
 * Evaluate boolean expression.
2ff057
 * @param expr		expression to parse
2ff057
 * @return
2ff057
 */
2ff057
RPM_GNUC_INTERNAL
2ff057
int parseExpressionBoolean(const char * expr);
2ff057
2ff057
/** \ingroup rpmbuild
2ff057
 * Run a build script, assembled from spec file scriptlet section.
2ff057
 *
2ff057
 * @param spec		spec file control structure
2ff057
 * @param what		type of script
2ff057
 * @param name		name of scriptlet section
2ff057
 * @param sb		lines that compose script body
2ff057
 * @param test		don't execute scripts or package if testing
2ff057
 * @return		RPMRC_OK on success
2ff057
 */
2ff057
RPM_GNUC_INTERNAL
2ff057
rpmRC doScript(rpmSpec spec, rpmBuildFlags what, const char * name,
2ff057
		const char * sb, int test);
2ff057
2ff057
/** \ingroup rpmbuild
2ff057
 * Find sub-package control structure by name.
2ff057
 * @param spec		spec file control structure
2ff057
 * @param name		(sub-)package name
2ff057
 * @param flag		if PART_SUBNAME, then 1st package name is prepended
2ff057
 * @retval pkg		package control structure
2ff057
 * @return		0 on success, 1 on failure
2ff057
 */
2ff057
RPM_GNUC_INTERNAL
2ff057
rpmRC lookupPackage(rpmSpec spec, const char * name, int flag,
2ff057
		Package * pkg);
2ff057
2ff057
/** \ingroup rpmbuild
2ff057
 * Create and initialize package control structure.
2ff057
 * @param name		package name for sub-packages (or NULL)
2ff057
 * @param pool		string pool
2ff057
 * @param pkglist	package list pointer to append to (or NULL)
2ff057
 * @return		package control structure
2ff057
 */
2ff057
RPM_GNUC_INTERNAL
2ff057
Package newPackage(const char *name, rpmstrPool pool, Package * pkglist);
2ff057
2ff057
2ff057
/** \ingroup rpmbuild
2ff057
 * Return rpmds containing the dependencies of a given type
2ff057
 * @param pkg		package
2ff057
 * @param tag		name tag denominating the dependency
2ff057
 * @return		pointer to dependency set
2ff057
 */
2ff057
RPM_GNUC_INTERNAL
2ff057
rpmds * packageDependencies(Package pkg, rpmTagVal tag);
2ff057
2ff057
/** \ingroup rpmbuild
2ff057
 * Post-build processing for binary package(s).
2ff057
 * @param spec		spec file control structure
2ff057
 * @param pkgFlags	bit(s) to control package generation
2ff057
 * @param didInstall	was %install executed?
2ff057
 * @param test		don't execute scripts or package if testing
2ff057
 * @return		0 on success
2ff057
 */
2ff057
RPM_GNUC_INTERNAL
2ff057
rpmRC processBinaryFiles(rpmSpec spec, rpmBuildPkgFlags pkgFlags,
2ff057
			int didInstall, int test);
2ff057
2ff057
/** \ingroup rpmfc
2ff057
 * Generate package dependencies.
2ff057
 * @param spec		spec file control
2ff057
 * @param pkg		package control
2ff057
 * @return		RPMRC_OK on success
2ff057
 */
2ff057
RPM_GNUC_INTERNAL
2ff057
rpmRC rpmfcGenerateDepends(const rpmSpec spec, Package pkg);
2ff057
2ff057
/** \ingroup rpmfc
2ff057
 * Return helper output.
2ff057
 * @param av		helper argv (with possible macros)
2ff057
 * @param sb_stdin	helper input
2ff057
 * @retval *sb_stdoutp	helper output
2ff057
 * @param failnonzero	IS non-zero helper exit status a failure?
2ff057
 * @param buildRoot	buildRoot directory (or NULL)
2ff057
 */
2ff057
RPM_GNUC_INTERNAL
2ff057
int rpmfcExec(ARGV_const_t av, StringBuf sb_stdin, StringBuf * sb_stdoutp,
2ff057
		int failnonzero, const char *buildRoot);
2ff057
2ff057
/** \ingroup rpmbuild
2ff057
 * Post-build processing for policies in binary package(s).
2ff057
 * @param spec		spec file control structure
2ff057
 * @param test		don't execute scripts or package if testing
2ff057
 * @return		0 on success
2ff057
 */
2ff057
RPM_GNUC_INTERNAL
2ff057
rpmRC processBinaryPolicies(rpmSpec spec, int test);
2ff057
2ff057
/** \ingroup rpmbuild
2ff057
 * Post-build processing for source package.
2ff057
 * @param spec		spec file control structure
2ff057
 * @param pkgFlags	bit(s) to control package generation
2ff057
 * @return		0 on success
2ff057
 */
2ff057
RPM_GNUC_INTERNAL
2ff057
rpmRC processSourceFiles(rpmSpec spec, rpmBuildPkgFlags pkgFlags);
2ff057
2ff057
/** \ingroup rpmbuild
2ff057
 * Generate binary package(s).
2ff057
 * @param spec		spec file control structure
2ff057
 * @param cookie	build identifier "cookie" or NULL
2ff057
 * @param cheating	was build shortcircuited?
2ff057
 * @return		RPMRC_OK on success
2ff057
 */
2ff057
RPM_GNUC_INTERNAL
2ff057
rpmRC packageBinaries(rpmSpec spec, const char *cookie, int cheating);
2ff057
2ff057
/** \ingroup rpmbuild
2ff057
 * Generate source package.
2ff057
 * @param spec		spec file control structure
2ff057
 * @retval cookie	build identifier "cookie" or NULL
2ff057
 * @return		RPMRC_OK on success
2ff057
 */
2ff057
RPM_GNUC_INTERNAL
2ff057
rpmRC packageSources(rpmSpec spec, char **cookie);
2ff057
2ff057
RPM_GNUC_INTERNAL
2ff057
int addLangTag(rpmSpec spec, Header h, rpmTagVal tag,
2ff057
		const char *field, const char *lang);
2ff057
2ff057
/** \ingroup rpmbuild
2ff057
 * Add dependency to package, filtering duplicates.
2ff057
 * @param pkg		package
2ff057
 * @param tagN		tag, identifies type of dependency
2ff057
 * @param N		(e.g. Requires: foo < 0:1.2-3, "foo")
2ff057
 * @param EVR		(e.g. Requires: foo < 0:1.2-3, "0:1.2-3")
2ff057
 * @param Flags		(e.g. Requires: foo < 0:1.2-3, both "Requires:" and "<")
2ff057
 * @param index         (# trigger script for triggers, 0 for others)
2ff057
 * @return		0 on success, 1 on error
2ff057
 */
2ff057
RPM_GNUC_INTERNAL
2ff057
int addReqProv(Package pkg, rpmTagVal tagN,
2ff057
	       const char * N, const char * EVR, rpmsenseFlags Flags,
2ff057
	       uint32_t index);
2ff057
2ff057
RPM_GNUC_INTERNAL
2ff057
rpmRC addReqProvPkg(void *cbdata, rpmTagVal tagN,
2ff057
		    const char * N, const char * EVR, rpmsenseFlags Flags,
2ff057
		    int index);
2ff057
2ff057
/** \ingroup rpmbuild
2ff057
 * Add self-provides to package.
2ff057
 * @param pkg		package
2ff057
 */
2ff057
RPM_GNUC_INTERNAL
2ff057
void addPackageProvides(Package pkg);
2ff057
2ff057
/** \ingroup rpmbuild
2ff057
 * Add rpmlib feature dependency.
2ff057
 * @param pkg		package
2ff057
 * @param feature	rpm feature name (i.e. "rpmlib(Foo)" for feature Foo)
2ff057
 * @param featureEVR	rpm feature epoch/version/release
2ff057
 * @return		0 always
2ff057
 */
2ff057
RPM_GNUC_INTERNAL
2ff057
int rpmlibNeedsFeature(Package pkg, const char * feature, const char * featureEVR);
2ff057
2ff057
RPM_GNUC_INTERNAL
2ff057
rpmRC checkForEncoding(Header h, int addtag);
2ff057
2ff057
2ff057
/** \ingroup rpmbuild
2ff057
 * Copy tags inherited by subpackages from the source header to the target header
2ff057
 * @param h		target header
2ff057
 * @param fromh		source header
2ff057
 */
2ff057
RPM_GNUC_INTERNAL
2ff057
void copyInheritedTags(Header h, Header fromh);
2ff057
2ff057
#ifdef __cplusplus
2ff057
}
2ff057
#endif
2ff057
2ff057
#endif /* _RPMBUILD_INTERNAL_H */