Skip to content

Commit

Permalink
Add support for automatic patch and source numbering
Browse files Browse the repository at this point in the history
Up to now, Patch: and Source: without number has been special-cased to
mean Patch0 and Source0 respectively. However with the advent of
%autosetup, patch numbers in particular are getting increasingly
irrelevant: the order is what matters but manually maintaining
a set of increasing numbers is only tedious. GOTO 10 anyone?

Redefine numberless Patch: and Source: to mean automatic numbering
incremented by one, starting from zero or the last manually defined number.
This means you can mix and match automatic numbering and manual numbering
to some degree: for example you can start using autonumbered patches
without converting all of the spec to that syntax at once.

This is backwards compatible with most common cases, but certainly there
are cases that are not: if numberless Patch/Source follows numbered ones
then it'll behave differently and possibly break builds. And obviously
specs using more than one numberless Patch/Source will not be buildable
with older rpm versions.
  • Loading branch information
pmatilai committed Jun 12, 2018
1 parent b4667e9 commit 5303626
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion build/parsePreamble.c
Expand Up @@ -186,17 +186,20 @@ static int addSource(rpmSpec spec, Package pkg, const char *field, rpmTagVal tag
char *fieldp = NULL;
char *buf = NULL;
uint32_t num = 0;
int *autonum = NULL;

switch (tag) {
case RPMTAG_SOURCE:
flag = RPMBUILD_ISSOURCE;
name = "source";
fieldp = spec->line + 6;
autonum = &spec->autonum_source;
break;
case RPMTAG_PATCH:
flag = RPMBUILD_ISPATCH;
name = "patch";
fieldp = spec->line + 5;
autonum = &spec->autonum_patch;
break;
case RPMTAG_ICON:
flag = RPMBUILD_ISICON;
Expand Down Expand Up @@ -225,14 +228,16 @@ static int addSource(rpmSpec spec, Package pkg, const char *field, rpmTagVal tag
nump = fieldp_backup;
SKIPSPACE(nump);
if (nump == NULL || *nump == '\0') {
num = flag == RPMBUILD_ISSOURCE ? 0 : INT_MAX;
(*autonum)++;
num = *autonum;
} else {
if (parseUnsignedNum(fieldp_backup, &num)) {
rpmlog(RPMLOG_ERR, _("line %d: Bad %s number: %s\n"),
spec->lineNum, name, spec->line);
*fieldp = ch;
return RPMRC_FAIL;
}
*autonum = num;
}
*fieldp = ch;
}
Expand Down
2 changes: 2 additions & 0 deletions build/rpmbuild_internal.h
Expand Up @@ -81,6 +81,8 @@ struct rpmSpec_s {
struct Source * sources;
int numSources;
int noSource;
int autonum_patch;
int autonum_source;

char * sourceRpmName;
unsigned char * sourcePkgId;
Expand Down
2 changes: 2 additions & 0 deletions build/spec.c
Expand Up @@ -281,6 +281,8 @@ rpmSpec newSpec(void)
spec->packages = NULL;
spec->noSource = 0;
spec->numSources = 0;
spec->autonum_patch = -1;
spec->autonum_source = -1;

spec->sourceRpmName = NULL;
spec->sourcePkgId = NULL;
Expand Down

0 comments on commit 5303626

Please sign in to comment.