2000-08-28 03:18:25 +08:00
|
|
|
/** \ingroup rpmbuild
|
|
|
|
* \file build/parseFiles.c
|
2000-01-25 04:02:32 +08:00
|
|
|
* Parse %files section from spec file.
|
|
|
|
*/
|
|
|
|
|
1998-07-26 05:00:26 +08:00
|
|
|
#include "system.h"
|
1998-01-13 05:31:29 +08:00
|
|
|
|
2007-12-08 20:02:32 +08:00
|
|
|
#include <rpm/rpmlog.h>
|
|
|
|
#include <rpm/rpmfileutil.h>
|
2010-08-25 20:41:09 +08:00
|
|
|
#include "build/rpmbuild_internal.h"
|
2000-12-13 04:03:45 +08:00
|
|
|
#include "debug.h"
|
1998-07-31 06:09:42 +08:00
|
|
|
|
2007-09-21 20:23:02 +08:00
|
|
|
int parseFiles(rpmSpec spec)
|
1998-01-13 05:31:29 +08:00
|
|
|
{
|
2008-05-05 16:00:45 +08:00
|
|
|
int nextPart, res = PART_ERROR;
|
1998-01-13 05:31:29 +08:00
|
|
|
Package pkg;
|
|
|
|
int rc, argc;
|
1998-04-03 02:31:12 +08:00
|
|
|
int arg;
|
2001-05-06 03:28:32 +08:00
|
|
|
const char ** argv = NULL;
|
2008-12-09 19:47:50 +08:00
|
|
|
const char *name = NULL;
|
1998-01-13 05:31:29 +08:00
|
|
|
int flag = PART_SUBNAME;
|
|
|
|
poptContext optCon = NULL;
|
2008-12-09 19:47:50 +08:00
|
|
|
struct poptOption optionsTable[] = {
|
|
|
|
{ NULL, 'n', POPT_ARG_STRING, &name, 'n', NULL, NULL},
|
2009-07-09 14:28:45 +08:00
|
|
|
{ NULL, 'f', POPT_ARG_STRING, NULL, 'f', NULL, NULL},
|
2008-12-09 19:47:50 +08:00
|
|
|
{ 0, 0, 0, 0, 0, NULL, NULL}
|
|
|
|
};
|
1998-01-13 05:31:29 +08:00
|
|
|
|
2012-05-15 19:23:35 +08:00
|
|
|
/* XXX unmask %license while parsing %files */
|
|
|
|
addMacro(spec->macros, "license", NULL, "%%license", RMIL_SPEC);
|
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
if ((rc = poptParseArgvString(spec->line, &argc, &argv))) {
|
2007-11-19 22:25:24 +08:00
|
|
|
rpmlog(RPMLOG_ERR, _("line %d: Error parsing %%files: %s\n"),
|
1998-01-13 05:31:29 +08:00
|
|
|
spec->lineNum, poptStrerror(rc));
|
2000-02-22 11:09:53 +08:00
|
|
|
goto exit;
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
optCon = poptGetContext(NULL, argc, argv, optionsTable, 0);
|
|
|
|
while ((arg = poptGetNextOpt(optCon)) > 0) {
|
|
|
|
if (arg == 'n') {
|
|
|
|
flag = PART_NAME;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (arg < -1) {
|
2007-11-19 22:25:24 +08:00
|
|
|
rpmlog(RPMLOG_ERR, _("line %d: Bad option %s: %s\n"),
|
1998-01-13 05:31:29 +08:00
|
|
|
spec->lineNum,
|
|
|
|
poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
|
|
|
|
spec->line);
|
2000-02-22 11:09:53 +08:00
|
|
|
goto exit;
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (poptPeekArg(optCon)) {
|
1999-10-28 07:18:10 +08:00
|
|
|
if (name == NULL)
|
1998-01-13 05:31:29 +08:00
|
|
|
name = poptGetArg(optCon);
|
|
|
|
if (poptPeekArg(optCon)) {
|
2007-11-19 22:25:24 +08:00
|
|
|
rpmlog(RPMLOG_ERR, _("line %d: Too many names: %s\n"),
|
1998-01-13 05:31:29 +08:00
|
|
|
spec->lineNum,
|
|
|
|
spec->line);
|
2000-02-22 11:09:53 +08:00
|
|
|
goto exit;
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lookupPackage(spec, name, flag, &pkg)) {
|
2007-11-19 22:25:24 +08:00
|
|
|
rpmlog(RPMLOG_ERR, _("line %d: Package does not exist: %s\n"),
|
1998-01-13 05:31:29 +08:00
|
|
|
spec->lineNum, spec->line);
|
2000-02-22 11:09:53 +08:00
|
|
|
goto exit;
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
|
|
|
|
2009-06-23 17:05:06 +08:00
|
|
|
for (arg=1; arg<argc; arg++) {
|
2009-08-31 16:08:05 +08:00
|
|
|
if (rstreq(argv[arg], "-f") && argv[arg+1]) {
|
2009-07-09 14:28:45 +08:00
|
|
|
char *file = rpmGetPath(argv[arg+1], NULL);
|
2010-10-28 15:24:20 +08:00
|
|
|
argvAdd(&(pkg->fileFile), file);
|
2009-06-23 17:05:06 +08:00
|
|
|
free(file);
|
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
2000-02-22 11:09:53 +08:00
|
|
|
|
2010-12-23 15:24:25 +08:00
|
|
|
pkg->fileList = argvNew();
|
|
|
|
|
1998-05-21 01:05:26 +08:00
|
|
|
if ((rc = readLine(spec, STRIP_COMMENTS)) > 0) {
|
1998-01-13 05:31:29 +08:00
|
|
|
nextPart = PART_NONE;
|
2008-05-05 16:00:45 +08:00
|
|
|
} else if (rc < 0) {
|
|
|
|
goto exit;
|
1998-01-13 05:31:29 +08:00
|
|
|
} else {
|
|
|
|
while (! (nextPart = isPart(spec->line))) {
|
2010-10-28 15:24:20 +08:00
|
|
|
argvAdd(&(pkg->fileList), spec->line);
|
1998-05-21 01:05:26 +08:00
|
|
|
if ((rc = readLine(spec, STRIP_COMMENTS)) > 0) {
|
1998-01-13 05:31:29 +08:00
|
|
|
nextPart = PART_NONE;
|
|
|
|
break;
|
2008-05-05 16:00:45 +08:00
|
|
|
} else if (rc < 0) {
|
2000-02-22 11:09:53 +08:00
|
|
|
goto exit;
|
2008-05-05 16:00:45 +08:00
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
|
|
|
}
|
2008-05-05 16:00:45 +08:00
|
|
|
res = nextPart;
|
1998-01-13 05:31:29 +08:00
|
|
|
|
2000-02-22 11:09:53 +08:00
|
|
|
exit:
|
2012-05-15 19:23:35 +08:00
|
|
|
delMacro(NULL, "license");
|
2011-05-27 19:44:03 +08:00
|
|
|
free(argv);
|
|
|
|
poptFreeContext(optCon);
|
1998-01-13 05:31:29 +08:00
|
|
|
|
2008-05-05 16:00:45 +08:00
|
|
|
return res;
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|