8 #include <rpm/rpmcli.h>
9 #include <rpm/rpmlib.h>
10 #include <rpm/rpmbuild.h>
11 #include <rpm/rpmlog.h>
12 #include <rpm/rpmfileutil.h>
13 #include <rpm/rpmdb.h>
14 #include <rpm/rpmps.h>
15 #include <rpm/rpmts.h>
16 #include "lib/signature.h"
23 #define POPT_NOLANG -1012
24 #define POPT_RMSOURCE -1013
25 #define POPT_RMBUILD -1014
26 #define POPT_BUILDROOT -1015
27 #define POPT_TARGETPLATFORM -1016
28 #define POPT_NOBUILD -1017
29 #define POPT_RMSPEC -1019
30 #define POPT_NODIRTOKENS -1020
32 #define POPT_REBUILD 0x4262
33 #define POPT_RECOMPILE 0x4369
34 #define POPT_BA 0x6261
35 #define POPT_BB 0x6262
36 #define POPT_BC 0x6263
37 #define POPT_BI 0x6269
38 #define POPT_BL 0x626c
39 #define POPT_BP 0x6270
40 #define POPT_BS 0x6273
41 #define POPT_RA 0x4261
42 #define POPT_RB 0x4262
43 #define POPT_RC 0x4263
44 #define POPT_RI 0x4269
45 #define POPT_RL 0x426c
46 #define POPT_RP 0x4270
47 #define POPT_RS 0x4273
48 #define POPT_TA 0x7461
49 #define POPT_TB 0x7462
50 #define POPT_TC 0x7463
51 #define POPT_TI 0x7469
52 #define POPT_TL 0x746c
53 #define POPT_TP 0x7470
54 #define POPT_TS 0x7473
67 enum poptCallbackReason reason,
68 const struct poptOption * opt,
const char * arg,
100 buildMode = (((unsigned)opt->val) >> 8) & 0xff;
130 { NULL,
'\0', POPT_ARG_CALLBACK | POPT_CBFLAG_INC_DATA | POPT_CBFLAG_CONTINUE,
133 {
"bp", 0, POPT_ARGFLAG_ONEDASH, 0,
POPT_BP,
134 N_(
"build through %prep (unpack sources and apply patches) from <specfile>"),
136 {
"bc", 0, POPT_ARGFLAG_ONEDASH, 0,
POPT_BC,
137 N_(
"build through %build (%prep, then compile) from <specfile>"),
139 {
"bi", 0, POPT_ARGFLAG_ONEDASH, 0,
POPT_BI,
140 N_(
"build through %install (%prep, %build, then install) from <specfile>"),
142 {
"bl", 0, POPT_ARGFLAG_ONEDASH, 0,
POPT_BL,
143 N_(
"verify %files section from <specfile>"),
145 {
"ba", 0, POPT_ARGFLAG_ONEDASH, 0,
POPT_BA,
146 N_(
"build source and binary packages from <specfile>"),
148 {
"bb", 0, POPT_ARGFLAG_ONEDASH, 0,
POPT_BB,
149 N_(
"build binary package only from <specfile>"),
151 {
"bs", 0, POPT_ARGFLAG_ONEDASH, 0,
POPT_BS,
152 N_(
"build source package only from <specfile>"),
155 {
"rp", 0, POPT_ARGFLAG_ONEDASH, 0,
POPT_RP,
156 N_(
"build through %prep (unpack sources and apply patches) from <source package>"),
157 N_(
"<source package>") },
158 {
"rc", 0, POPT_ARGFLAG_ONEDASH, 0,
POPT_RC,
159 N_(
"build through %build (%prep, then compile) from <source package>"),
160 N_(
"<source package>") },
161 {
"ri", 0, POPT_ARGFLAG_ONEDASH, 0,
POPT_RI,
162 N_(
"build through %install (%prep, %build, then install) from <source package>"),
163 N_(
"<source package>") },
164 {
"rl", 0, POPT_ARGFLAG_ONEDASH, 0,
POPT_RL,
165 N_(
"verify %files section from <source package>"),
166 N_(
"<source package>") },
167 {
"ra", 0, POPT_ARGFLAG_ONEDASH, 0,
POPT_RA,
168 N_(
"build source and binary packages from <source package>"),
169 N_(
"<source package>") },
170 {
"rb", 0, POPT_ARGFLAG_ONEDASH, 0,
POPT_RB,
171 N_(
"build binary package only from <source package>"),
172 N_(
"<source package>") },
173 {
"rs", 0, POPT_ARGFLAG_ONEDASH, 0,
POPT_RS,
174 N_(
"build source package only from <source package>"),
175 N_(
"<source package>") },
177 {
"tp", 0, POPT_ARGFLAG_ONEDASH, 0,
POPT_TP,
178 N_(
"build through %prep (unpack sources and apply patches) from <tarball>"),
180 {
"tc", 0, POPT_ARGFLAG_ONEDASH, 0,
POPT_TC,
181 N_(
"build through %build (%prep, then compile) from <tarball>"),
183 {
"ti", 0, POPT_ARGFLAG_ONEDASH, 0,
POPT_TI,
184 N_(
"build through %install (%prep, %build, then install) from <tarball>"),
186 {
"tl", 0, POPT_ARGFLAG_ONEDASH|POPT_ARGFLAG_DOC_HIDDEN, 0,
POPT_TL,
187 N_(
"verify %files section from <tarball>"),
189 {
"ta", 0, POPT_ARGFLAG_ONEDASH, 0,
POPT_TA,
190 N_(
"build source and binary packages from <tarball>"),
192 {
"tb", 0, POPT_ARGFLAG_ONEDASH, 0,
POPT_TB,
193 N_(
"build binary package only from <tarball>"),
195 {
"ts", 0, POPT_ARGFLAG_ONEDASH, 0,
POPT_TS,
196 N_(
"build source package only from <tarball>"),
200 N_(
"build binary package from <source package>"),
201 N_(
"<source package>") },
203 N_(
"build through %install (%prep, %build, then install) from <source package>"),
204 N_(
"<source package>") },
207 N_(
"override build root"),
"DIRECTORY" },
209 N_(
"remove build tree when done"), NULL},
211 N_(
"ignore ExcludeArch: directives from spec file"), NULL},
212 {
"fsmdebug",
'\0', (POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN), &
_fsm_debug, -1,
213 N_(
"debug file state machine"), NULL},
215 N_(
"do not execute any stages of the build"), NULL },
216 {
"nodeps",
'\0', POPT_ARG_VAL, &
noDeps, 1,
217 N_(
"do not verify build dependencies"), NULL },
219 N_(
"generate package header(s) compatible with (legacy) rpm v3 packaging"),
223 N_(
"do not execute %clean stage of the build"), NULL },
225 N_(
"do not execute %prep stage of the build"), NULL },
227 N_(
"do not execute %check stage of the build"), NULL },
229 {
"nolang",
'\0', POPT_ARGFLAG_DOC_HIDDEN, 0,
POPT_NOLANG,
230 N_(
"do not accept i18N msgstr's from specfile"), NULL},
232 N_(
"remove sources when done"), NULL},
234 N_(
"remove specfile when done"), NULL},
235 {
"short-circuit",
'\0', POPT_ARG_VAL, &
shortCircuit, 1,
236 N_(
"skip straight to specified stage (only for c,i)"), NULL },
238 N_(
"override target platform"),
"CPU-VENDOR-OS" },
255 N_(
"Build options with [ <specfile> | <tarball> | <source package> ]:"),
258 {
"quiet",
'\0', POPT_ARGFLAG_DOC_HIDDEN, &
quiet, 0, NULL, NULL},
261 N_(
"Common options for all rpm modes and executables:"),
291 f = fopen(specfile,
"r");
294 specfile, strerror(errno));
297 count = fread(buf,
sizeof(buf[0]),
sizeof(buf), f);
304 for (s = buf; count--; s++) {
315 if (checking && !(isprint(*s) || isspace(*s)))
return 0;
318 if (checking && !(isprint(*s) || isspace(*s)) && *(
unsigned char *)s < 32)
return 0;
332 char *specFile = NULL;
338 int gotspec = 0, res;
339 static const char *tryspec[] = {
"Specfile",
"\\*.spec", NULL };
342 tmpSpecFile =
rpmGetPath(
"%{_specdir}/",
"rpm-spec.XXXXXX", NULL);
344 (void) close(mkstemp(tmpSpecFile));
346 for (spec = tryspec; *spec != NULL; spec++) {
351 cmd =
rpmExpand(
"%{uncompress: ", arg,
"} | ",
352 "%{__tar} xOvof - --wildcards ", *spec,
353 " 2>&1 > ", tmpSpecFile, NULL);
355 if (!(fp = popen(cmd,
"r"))) {
360 fok = fgets(tarbuf,
sizeof(tarbuf) - 1, fp);
363 if (strstr(fok,
"tar: ")) {
369 gotspec = (specfiles == 1) &&
isSpecFile(tmpSpecFile);
386 specBase = basename(tarbuf);
388 specBase[strlen(specBase)-1] =
'\0';
390 rasprintf(&specFile,
"%s/%s", specDir, specBase);
391 res = rename(tmpSpecFile, specFile);
395 tmpSpecFile, specFile);
401 umask(mask = umask(0));
402 (void) chmod(specFile, 0666 & ~mask);
406 (void) unlink(tmpSpecFile);
415 char * buildRootURL = NULL;
416 char * specFile = NULL;
426 const char * buildtree =
"%{_topdir}:%{_specdir}:%{_sourcedir}:%{_builddir}:%{_rpmdir}:%{_srcrpmdir}:%{_buildrootdir}";
433 char *srcdir = NULL, *dir;
447 srcdir = dirname(dir);
454 if (*specFile !=
'/') {
464 if (stat(specFile, &st) < 0) {
468 if (! S_ISREG(st.st_mode)) {
476 _(
"File %s does not appear to be a specfile.\n"), specFile);
482 rc = unlink(specFile);
487 #define _anyarch(_f) \
488 (((_f)&(RPMBUILD_PREP|RPMBUILD_BUILD|RPMBUILD_INSTALL|RPMBUILD_PACKAGEBINARY)) == 0)
508 (void) unlink(specFile);
522 #define buildCleanMask (RPMBUILD_RMSOURCE|RPMBUILD_RMSPEC)
542 printf(
_(
"Building target platforms: %s\n"), targets);
547 if (*(target + 1) == NULL)
550 printf(
_(
"Building for target %s\n"), *target);
572 int main(
int argc,
char *argv[])
578 const char *pkg = NULL;
580 poptContext optCon =
rpmcliInit(argc, argv, optionsTable);
583 if (ba->
buildAmount && poptPeekArg(optCon) == NULL) {
596 argerror(
_(
"arguments to --root (-r) must begin with a /"));
651 while ((pkg = poptGetArg(optCon))) {
652 char * specFile = NULL;
661 specFile =
_free(specFile);
670 while ((pkg = poptGetArg(optCon))) {
static struct poptOption rpmBuildPoptTable[]
static rpmBuildFlags nobuildAmount
const char * rpmcliRcfile
int rpmtsSetRootDir(rpmts ts, const char *rootDir)
Set transaction rootDir, i.e.
rpmQueryFlags rpmcliQueryFlags
Bit(s) from common command line options.
void printUsage(poptContext con, FILE *fp, int flags)
rpmps rpmSpecCheckDeps(rpmts ts, rpmSpec spec)
Verify build depencies of a spec against.
static int buildForTarget(rpmts ts, const char *arg, BTA_t ba)
static rpmSpecFlags spec_flags
static int build(rpmts ts, const char *arg, BTA_t ba, const char *rcfile)
static struct rpmBuildArguments_s rpmBTArgs
char * rstrscat(char **dest, const char *arg,...) RPM_GNUC_NULL_TERMINATED
Concatenate multiple strings with dynamically (re)allocated memory.
static int isSpecFile(const char *specfile)
poptContext rpmcliInit(int argc, char *const argv[], struct poptOption *optionsTable)
Initialize most everything needed by an rpm CLI executable context.
poptContext rpmcliFini(poptContext optCon)
Destroy most everything needed by an rpm CLI executable context.
rpmSpec rpmSpecFree(rpmSpec spec)
Destroy Spec structure.
static ARGV_t build_targets
rpmBuildPkgFlags pkgFlags
const char * rpmtsRootDir(rpmts ts)
Get transaction rootDir, i.e.
rpmRC rpmSpecBuild(rpmSpec spec, BTA_t buildArgs)
Spec build stages state machine driver.
int rpmReadConfigFiles(const char *file, const char *target)
Read macro configuration file(s) for a target.
static void buildArgCallback(poptContext con, enum poptCallbackReason reason, const struct poptOption *opt, const char *arg, const void *data)
#define POPT_TARGETPLATFORM
int argvSplit(ARGV_t *argvp, const char *str, const char *seps)
Split a string into an argv array.
const char * rpmcliPipeOutput
void argerror(const char *desc)
rpmBuildFlags buildAmount
static int rstreq(const char *s1, const char *s2)
Test for string equality.
static char * getTarSpec(const char *arg)
int rpmExpandNumeric(const char *arg)
Return macro expansion as a numeric value.
int rpmInstallSource(rpmts ts, const char *arg, char **specFilePtr, char **cookie)
Install source rpm package.
static struct poptOption optionsTable[]
int rpmMkdirs(const char *root, const char *pathstr)
Create several directories (including parents if needed) in one go.
const char * rpmcliRootDir
rpmps rpmpsFree(rpmps ps)
Destroy a problem set.
char * rpmGetPath(const char *path,...) RPM_GNUC_NULL_TERMINATED
Return (malloc'ed) expanded, canonicalized, file path.
#define RPMCLI_POPT_FORCE
void addMacro(rpmMacroContext mc, const char *n, const char *o, const char *b, int level)
Add macro to context.
ARGV_t argvFree(ARGV_t argv)
Destroy an argv array.
char *const * ARGV_const_t
#define _RPMVSF_NOSIGNATURES
rpmts rpmtsFree(rpmts ts)
Destroy transaction set, closing the database as well.
static int checkSpec(rpmts ts, rpmSpec spec)
void rpmFreeMacros(rpmMacroContext mc)
Destroy macro context.
rpmSpec rpmSpecParse(const char *specFile, rpmSpecFlags flags, const char *buildRoot)
Parse spec file into spec control structure.
rpmVSFlags rpmtsSetVSFlags(rpmts ts, rpmVSFlags vsflags)
Set verify signatures flag(s).
char * rpmExpand(const char *arg,...) RPM_GNUC_NULL_TERMINATED
Return (malloc'ed) concatenated macro expansion(s).
struct rpmts_s * rpmts
The main types involved in transaction manipulation.
int rasprintf(char **strp, const char *fmt,...) RPM_GNUC_PRINTF(2
asprintf() clone
void rpmFreeRpmrc(void)
Destroy rpmrc arch/os compatibility tables.
#define _RPMVSF_NODIGESTS
#define rpmSetVerbosity(_lvl)
void rpmpsPrint(FILE *fp, rpmps ps)
Print problems to file handle.
rpmts rpmtsCreate(void)
Create an empty transaction set.
char * rpmGenPath(const char *urlroot, const char *urlmdir, const char *urlfile)
Merge 3 args into path, any or all of which may be a url.
char * rpmGetCwd(void)
Like getcwd() but the result is malloced.
struct poptOption rpmcliAllPoptTable[]
Popt option table for options shared by all modes and executables.
char * argvJoin(ARGV_const_t argv, const char *sep)
Join an argv array into a string.
int main(int argc, char *argv[])
void rpmlog(int code, const char *fmt,...) RPM_GNUC_PRINTF(2
Generate a log message using FMT string and option arguments.
struct rpmSpec_s * rpmSpec