2000-08-28 03:18:25 +08:00
|
|
|
/** \ingroup rpmbuild
|
|
|
|
* \file build/parseChangelog.c
|
2000-01-25 04:02:32 +08:00
|
|
|
* Parse %changelog section from spec file.
|
|
|
|
*/
|
|
|
|
|
1998-07-26 05:00:26 +08:00
|
|
|
#include "system.h"
|
1998-03-05 00:51:06 +08:00
|
|
|
|
2008-02-03 22:24:07 +08:00
|
|
|
#include <rpm/header.h>
|
2007-12-08 20:02:32 +08:00
|
|
|
#include <rpm/rpmlog.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-01-13 05:31:29 +08:00
|
|
|
|
2008-03-18 15:10:13 +08:00
|
|
|
#define SKIPSPACE(s) { while (*(s) && risspace(*(s))) (s)++; }
|
|
|
|
#define SKIPNONSPACE(s) { while (*(s) && !risspace(*(s))) (s)++; }
|
2007-10-29 19:24:15 +08:00
|
|
|
|
2010-08-24 18:56:29 +08:00
|
|
|
static void addChangelogEntry(Header h, time_t time, const char *name, const char *text)
|
1998-07-31 06:09:42 +08:00
|
|
|
{
|
2008-02-04 17:50:39 +08:00
|
|
|
rpm_time_t mytime = time; /* XXX convert to header representation */
|
2008-06-17 17:55:01 +08:00
|
|
|
|
2008-06-19 20:44:29 +08:00
|
|
|
headerPutUint32(h, RPMTAG_CHANGELOGTIME, &mytime, 1);
|
|
|
|
headerPutString(h, RPMTAG_CHANGELOGNAME, name);
|
|
|
|
headerPutString(h, RPMTAG_CHANGELOGTEXT, text);
|
1998-07-31 06:09:42 +08:00
|
|
|
}
|
|
|
|
|
2012-07-30 19:59:35 +08:00
|
|
|
static int sameDate(const struct tm *ot, const struct tm *nt)
|
|
|
|
{
|
|
|
|
return (ot->tm_year == nt->tm_year &&
|
|
|
|
ot->tm_mon == nt->tm_mon &&
|
|
|
|
ot->tm_mday == nt->tm_mday &&
|
|
|
|
ot->tm_wday == nt->tm_wday);
|
|
|
|
}
|
|
|
|
|
2001-01-11 22:13:04 +08:00
|
|
|
/**
|
|
|
|
* Parse date string to seconds.
|
|
|
|
* @param datestr date string (e.g. 'Wed Jan 1 1997')
|
|
|
|
* @retval secs secs since the unix epoch
|
|
|
|
* @return 0 on success, -1 on error
|
|
|
|
*/
|
2007-09-12 05:03:27 +08:00
|
|
|
static int dateToTimet(const char * datestr, time_t * secs)
|
1998-07-31 06:09:42 +08:00
|
|
|
{
|
2008-04-25 16:55:14 +08:00
|
|
|
int rc = -1; /* assume failure */
|
2012-07-30 19:59:35 +08:00
|
|
|
struct tm time, ntime;
|
2008-03-07 02:17:20 +08:00
|
|
|
const char * const * idx;
|
2008-10-29 20:38:16 +08:00
|
|
|
char *p, *pe, *q, *date, *tz;
|
2007-12-14 21:17:59 +08:00
|
|
|
|
2008-04-25 16:55:14 +08:00
|
|
|
static const char * const days[] =
|
2001-06-06 03:26:22 +08:00
|
|
|
{ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", NULL };
|
2008-04-25 16:55:14 +08:00
|
|
|
static const char * const months[] =
|
2001-06-06 03:26:22 +08:00
|
|
|
{ "Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
|
|
|
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec", NULL };
|
2010-09-21 21:18:22 +08:00
|
|
|
static const char lengths[] =
|
2001-06-06 03:26:22 +08:00
|
|
|
{ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
1998-01-13 05:31:29 +08:00
|
|
|
|
1998-07-31 06:09:42 +08:00
|
|
|
memset(&time, 0, sizeof(time));
|
2012-07-30 19:59:35 +08:00
|
|
|
memset(&ntime, 0, sizeof(ntime));
|
1998-01-13 05:31:29 +08:00
|
|
|
|
2008-04-25 16:55:14 +08:00
|
|
|
date = xstrdup(datestr);
|
1999-07-04 06:58:08 +08:00
|
|
|
pe = date;
|
1998-01-13 05:31:29 +08:00
|
|
|
|
1998-07-31 06:09:42 +08:00
|
|
|
/* day of week */
|
1999-07-04 06:58:08 +08:00
|
|
|
p = pe; SKIPSPACE(p);
|
2008-04-25 16:55:14 +08:00
|
|
|
if (*p == '\0') goto exit;
|
2001-05-01 06:32:22 +08:00
|
|
|
pe = p; SKIPNONSPACE(pe); if (*pe != '\0') *pe++ = '\0';
|
2009-08-31 16:08:05 +08:00
|
|
|
for (idx = days; *idx && !rstreq(*idx, p); idx++)
|
2001-06-06 03:26:22 +08:00
|
|
|
{};
|
2008-04-25 16:55:14 +08:00
|
|
|
if (*idx == NULL) goto exit;
|
2012-07-30 19:59:35 +08:00
|
|
|
time.tm_wday = idx - days;
|
1998-07-31 06:09:42 +08:00
|
|
|
|
|
|
|
/* month */
|
1999-07-04 06:58:08 +08:00
|
|
|
p = pe; SKIPSPACE(p);
|
2008-04-25 16:55:14 +08:00
|
|
|
if (*p == '\0') goto exit;
|
2001-05-01 06:32:22 +08:00
|
|
|
pe = p; SKIPNONSPACE(pe); if (*pe != '\0') *pe++ = '\0';
|
2009-08-31 16:08:05 +08:00
|
|
|
for (idx = months; *idx && !rstreq(*idx, p); idx++)
|
2001-06-06 03:26:22 +08:00
|
|
|
{};
|
2008-04-25 16:55:14 +08:00
|
|
|
if (*idx == NULL) goto exit;
|
1998-07-31 06:09:42 +08:00
|
|
|
time.tm_mon = idx - months;
|
|
|
|
|
|
|
|
/* day */
|
1999-07-04 06:58:08 +08:00
|
|
|
p = pe; SKIPSPACE(p);
|
2008-04-25 16:55:14 +08:00
|
|
|
if (*p == '\0') goto exit;
|
2001-05-01 06:32:22 +08:00
|
|
|
pe = p; SKIPNONSPACE(pe); if (*pe != '\0') *pe++ = '\0';
|
1998-07-31 06:09:42 +08:00
|
|
|
|
|
|
|
/* make this noon so the day is always right (as we make this UTC) */
|
|
|
|
time.tm_hour = 12;
|
|
|
|
|
1999-07-04 06:58:08 +08:00
|
|
|
time.tm_mday = strtol(p, &q, 10);
|
2008-04-25 16:55:14 +08:00
|
|
|
if (!(q && *q == '\0')) goto exit;
|
|
|
|
if (time.tm_mday < 0 || time.tm_mday > lengths[time.tm_mon]) goto exit;
|
1998-07-31 06:09:42 +08:00
|
|
|
|
|
|
|
/* year */
|
1999-07-04 06:58:08 +08:00
|
|
|
p = pe; SKIPSPACE(p);
|
2008-04-25 16:55:14 +08:00
|
|
|
if (*p == '\0') goto exit;
|
2011-05-27 14:59:55 +08:00
|
|
|
pe = p; SKIPNONSPACE(pe); if (*pe != '\0') *pe = '\0';
|
1999-07-04 06:58:08 +08:00
|
|
|
time.tm_year = strtol(p, &q, 10);
|
2008-04-25 16:55:14 +08:00
|
|
|
if (!(q && *q == '\0')) goto exit;
|
|
|
|
if (time.tm_year < 1990 || time.tm_year >= 3000) goto exit;
|
1998-07-31 06:09:42 +08:00
|
|
|
time.tm_year -= 1900;
|
|
|
|
|
2008-10-29 20:38:16 +08:00
|
|
|
/* chnagelog date is always in UTC */
|
|
|
|
tz = getenv("TZ");
|
|
|
|
if (tz) tz = xstrdup(tz);
|
|
|
|
setenv("TZ", "UTC", 1);
|
2012-07-30 19:59:35 +08:00
|
|
|
ntime = time; /* struct assignment */
|
|
|
|
*secs = mktime(&ntime);
|
2008-10-29 20:38:16 +08:00
|
|
|
unsetenv("TZ");
|
|
|
|
if (tz) {
|
|
|
|
setenv("TZ", tz, 1);
|
|
|
|
free(tz);
|
|
|
|
}
|
2008-04-25 16:55:14 +08:00
|
|
|
if (*secs == -1) goto exit;
|
2012-08-02 00:03:15 +08:00
|
|
|
|
|
|
|
/* XXX Turn this into a hard error in a release or two */
|
|
|
|
if (!sameDate(&time, &ntime))
|
|
|
|
rpmlog(RPMLOG_WARNING, _("bogus date in %%changelog: %s\n"), datestr);
|
1998-07-31 06:09:42 +08:00
|
|
|
|
2008-04-25 16:55:14 +08:00
|
|
|
rc = 0;
|
1998-07-31 06:09:42 +08:00
|
|
|
|
2008-04-25 16:55:14 +08:00
|
|
|
exit:
|
|
|
|
free(date);
|
|
|
|
return rc;
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
|
|
|
|
2001-01-11 22:13:04 +08:00
|
|
|
/**
|
|
|
|
* Add %changelog section to header.
|
|
|
|
* @param h header
|
|
|
|
* @param sb changelog strings
|
2007-12-07 16:43:53 +08:00
|
|
|
* @return RPMRC_OK on success
|
2001-01-11 22:13:04 +08:00
|
|
|
*/
|
2010-10-28 16:39:28 +08:00
|
|
|
static rpmRC addChangelog(Header h, ARGV_const_t sb)
|
1998-01-13 05:31:29 +08:00
|
|
|
{
|
2012-08-02 00:17:09 +08:00
|
|
|
rpmRC rc = RPMRC_FAIL; /* assume failure */
|
2010-10-28 16:39:28 +08:00
|
|
|
char *s, *sp;
|
1998-01-13 05:31:29 +08:00
|
|
|
int i;
|
1999-07-07 01:32:49 +08:00
|
|
|
time_t time;
|
|
|
|
time_t lastTime = 0;
|
2009-04-16 20:13:34 +08:00
|
|
|
time_t trimtime = rpmExpandNumeric("%{?_changelog_trimtime}");
|
1998-01-13 05:31:29 +08:00
|
|
|
char *date, *name, *text, *next;
|
|
|
|
|
2010-10-28 16:39:28 +08:00
|
|
|
s = sp = argvJoin(sb, "");
|
1998-01-13 05:31:29 +08:00
|
|
|
|
|
|
|
/* skip space */
|
|
|
|
SKIPSPACE(s);
|
|
|
|
|
2001-05-01 06:32:22 +08:00
|
|
|
while (*s != '\0') {
|
1998-01-13 05:31:29 +08:00
|
|
|
if (*s != '*') {
|
2012-08-02 00:17:09 +08:00
|
|
|
rpmlog(RPMLOG_ERR, _("%%changelog entries must start with *\n"));
|
|
|
|
goto exit;
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* find end of line */
|
|
|
|
date = s;
|
1999-07-04 06:58:08 +08:00
|
|
|
while(*s && *s != '\n') s++;
|
1998-01-13 05:31:29 +08:00
|
|
|
if (! *s) {
|
2007-11-19 22:25:24 +08:00
|
|
|
rpmlog(RPMLOG_ERR, _("incomplete %%changelog entry\n"));
|
2012-08-02 00:17:09 +08:00
|
|
|
goto exit;
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
|
|
|
*s = '\0';
|
|
|
|
text = s + 1;
|
|
|
|
|
|
|
|
/* 4 fields of date */
|
|
|
|
date++;
|
|
|
|
s = date;
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
SKIPSPACE(s);
|
|
|
|
SKIPNONSPACE(s);
|
|
|
|
}
|
|
|
|
SKIPSPACE(date);
|
1999-07-07 01:32:49 +08:00
|
|
|
if (dateToTimet(date, &time)) {
|
2007-11-19 22:25:24 +08:00
|
|
|
rpmlog(RPMLOG_ERR, _("bad date in %%changelog: %s\n"), date);
|
2012-08-02 00:17:09 +08:00
|
|
|
goto exit;
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
|
|
|
if (lastTime && lastTime < time) {
|
2007-11-19 22:25:24 +08:00
|
|
|
rpmlog(RPMLOG_ERR,
|
2002-01-06 02:41:05 +08:00
|
|
|
_("%%changelog not in descending chronological order\n"));
|
2012-08-02 00:17:09 +08:00
|
|
|
goto exit;
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
|
|
|
lastTime = time;
|
|
|
|
|
|
|
|
/* skip space to the name */
|
|
|
|
SKIPSPACE(s);
|
|
|
|
if (! *s) {
|
2007-11-19 22:25:24 +08:00
|
|
|
rpmlog(RPMLOG_ERR, _("missing name in %%changelog\n"));
|
2012-08-02 00:17:09 +08:00
|
|
|
goto exit;
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* name */
|
|
|
|
name = s;
|
2001-05-01 06:32:22 +08:00
|
|
|
while (*s != '\0') s++;
|
2008-03-18 15:10:13 +08:00
|
|
|
while (s > name && risspace(*s)) {
|
1998-01-13 05:31:29 +08:00
|
|
|
*s-- = '\0';
|
|
|
|
}
|
|
|
|
if (s == name) {
|
2007-11-19 22:25:24 +08:00
|
|
|
rpmlog(RPMLOG_ERR, _("missing name in %%changelog\n"));
|
2012-08-02 00:17:09 +08:00
|
|
|
goto exit;
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* text */
|
|
|
|
SKIPSPACE(text);
|
|
|
|
if (! *text) {
|
2007-11-19 22:25:24 +08:00
|
|
|
rpmlog(RPMLOG_ERR, _("no description in %%changelog\n"));
|
2012-08-02 00:17:09 +08:00
|
|
|
goto exit;
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* find the next leading '*' (or eos) */
|
|
|
|
s = text;
|
|
|
|
do {
|
|
|
|
s++;
|
|
|
|
} while (*s && (*(s-1) != '\n' || *s != '*'));
|
|
|
|
next = s;
|
|
|
|
s--;
|
|
|
|
|
|
|
|
/* backup to end of description */
|
2008-03-18 15:10:13 +08:00
|
|
|
while ((s > text) && risspace(*s)) {
|
1998-01-13 05:31:29 +08:00
|
|
|
*s-- = '\0';
|
|
|
|
}
|
|
|
|
|
2009-04-16 20:13:34 +08:00
|
|
|
if ( !trimtime || time >= trimtime ) {
|
|
|
|
addChangelogEntry(h, time, name, text);
|
|
|
|
} else break;
|
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
s = next;
|
|
|
|
}
|
2012-08-02 00:17:09 +08:00
|
|
|
rc = RPMRC_OK;
|
|
|
|
|
|
|
|
exit:
|
2010-10-28 16:39:28 +08:00
|
|
|
free(sp);
|
1998-01-13 05:31:29 +08:00
|
|
|
|
2012-08-02 00:17:09 +08:00
|
|
|
return rc;
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
|
|
|
|
2007-09-21 20:23:02 +08:00
|
|
|
int parseChangelog(rpmSpec spec)
|
1998-01-13 05:31:29 +08:00
|
|
|
{
|
2008-05-05 15:42:41 +08:00
|
|
|
int nextPart, rc, res = PART_ERROR;
|
2010-10-28 16:39:28 +08:00
|
|
|
ARGV_t sb = NULL;
|
2014-01-29 20:02:48 +08:00
|
|
|
|
|
|
|
if (headerIsEntry(spec->packages->header, RPMTAG_CHANGELOGTIME)) {
|
|
|
|
rpmlog(RPMLOG_ERR, _("line %d: second %%changelog\n"), spec->lineNum);
|
|
|
|
goto exit;
|
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
|
1998-07-31 06:09:42 +08:00
|
|
|
/* There are no options to %changelog */
|
|
|
|
if ((rc = readLine(spec, STRIP_COMMENTS)) > 0) {
|
2008-05-05 15:42:41 +08:00
|
|
|
res = PART_NONE;
|
|
|
|
goto exit;
|
|
|
|
} else if (rc < 0) {
|
|
|
|
goto exit;
|
1998-07-31 06:09:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
while (! (nextPart = isPart(spec->line))) {
|
2010-10-28 16:39:28 +08:00
|
|
|
argvAdd(&sb, spec->line);
|
1998-07-31 06:09:42 +08:00
|
|
|
if ((rc = readLine(spec, STRIP_COMMENTS)) > 0) {
|
|
|
|
nextPart = PART_NONE;
|
|
|
|
break;
|
2008-05-05 15:42:41 +08:00
|
|
|
} else if (rc < 0) {
|
|
|
|
goto exit;
|
1998-07-31 06:09:42 +08:00
|
|
|
}
|
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
|
2011-05-24 13:51:56 +08:00
|
|
|
if (sb && addChangelog(spec->packages->header, sb)) {
|
2008-05-05 15:42:41 +08:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
res = nextPart;
|
|
|
|
|
|
|
|
exit:
|
2010-10-28 16:39:28 +08:00
|
|
|
argvFree(sb);
|
1998-01-13 05:31:29 +08:00
|
|
|
|
2008-05-05 15:42:41 +08:00
|
|
|
return res;
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|