Add support for %patchlist and %sourcelist spec sections

This introduces two new spec sections, %patchlist and %sourcelist,
which can be used for adding patches and sources by just listing their
names instead of all the tedious Patch[n]: etc boilerplate, you can
just copy-paste file names into the list, the entries are always
autonumbered, eg:

    Patch0: popt-1.16-pkgconfig.patch
    Patch1: popt-1.16-execfail.patch
    Patch2: popt-1.16-man-page.patch
    ...

can now be replaced with

    %patchlist
    popt-1.16-pkgconfig.patch
    popt-1.16-execfail.patch
    popt-1.16-man-page.patch

Typical packages have far fewer sources than patches, so %sourcelist
is not as immediately useful but added anyway for symmetry and because
its so easy.

As of this commit, there can be multiple instances of both kinds of
lists because there's no technical reason to limit it, new lists
just add on the existing entries.
This commit is contained in:
Panu Matilainen 2019-04-24 12:32:00 +03:00
parent 3c284aac63
commit 8da6654e3a
8 changed files with 104 additions and 2 deletions

View File

@ -16,7 +16,7 @@ librpmbuild_la_SOURCES = \
build.c expression.c files.c misc.c pack.c \
parseSimpleScript.c parseChangelog.c parseDescription.c \
parseFiles.c parsePreamble.c parsePrep.c parseReqs.c parseScript.c \
parseSpec.c reqprov.c rpmfc.c spec.c \
parseSpec.c parseList.c reqprov.c rpmfc.c spec.c \
parsePolicies.c policies.c \
rpmbuild_internal.h rpmbuild_misc.h

32
build/parseList.c Normal file
View File

@ -0,0 +1,32 @@
/** \ingroup rpmbuild
* \file build/parseBuildInstallClean.c
* Parse %build/%install/%clean section from spec file.
*/
#include "system.h"
#include <rpm/rpmlog.h>
#include "build/rpmbuild_internal.h"
#include "debug.h"
int parseList(rpmSpec spec, const char *name, rpmTagVal tag)
{
int res = PART_ERROR;
ARGV_t lst = NULL;
/* There are no options to %patchlist and %sourcelist */
if ((res = parseLines(spec, (STRIP_TRAILINGSPACE | STRIP_COMMENTS),
&lst, NULL)) == PART_ERROR) {
goto exit;
}
for (ARGV_const_t l = lst; l && *l; l++) {
if (rstreq(*l, ""))
continue;
addSource(spec, 0, *l, tag);
}
exit:
argvFree(lst);
return res;
}

View File

@ -74,6 +74,8 @@ static const struct PartRec {
{ PART_TRANSFILETRIGGERUN, LEN_AND_STR("%transfiletriggerun")},
{ PART_TRANSFILETRIGGERPOSTUN, LEN_AND_STR("%transfiletriggerpostun")},
{ PART_EMPTY, LEN_AND_STR("%end")},
{ PART_PATCHLIST, LEN_AND_STR("%patchlist")},
{ PART_SOURCELIST, LEN_AND_STR("%sourcelist")},
{0, 0, 0}
};
@ -891,6 +893,12 @@ static rpmSpec parseSpec(const char *specFile, rpmSpecFlags flags,
parsePart = parsePreamble(spec, initialPackage);
initialPackage = 0;
break;
case PART_PATCHLIST:
parsePart = parseList(spec, "%patchlist", RPMTAG_PATCH);
break;
case PART_SOURCELIST:
parsePart = parseList(spec, "%sourcelist", RPMTAG_SOURCE);
break;
case PART_PREP:
parsePart = parsePrep(spec);
break;

View File

@ -187,7 +187,9 @@ typedef enum rpmParseState_e {
PART_TRANSFILETRIGGERUN = 37+PART_BASE, /*!< */
PART_TRANSFILETRIGGERPOSTUN = 38+PART_BASE, /*!< */
PART_EMPTY = 39+PART_BASE, /*!< */
PART_LAST = 40+PART_BASE /*!< */
PART_PATCHLIST = 40+PART_BASE, /*!< */
PART_SOURCELIST = 41+PART_BASE, /*!< */
PART_LAST = 42+PART_BASE /*!< */
} rpmParseState;
@ -308,6 +310,9 @@ int parsePrep(rpmSpec spec);
RPM_GNUC_INTERNAL
int parseScript(rpmSpec spec, int parsePart);
RPM_GNUC_INTERNAL
int parseList(rpmSpec spec, const char *name, int stype);
/** \ingroup rpmbuild
* Check for inappropriate characters. All alphanums are considered sane.
* @param spec spec

View File

@ -40,6 +40,7 @@ EXTRA_DIST += $(TESTSUITE_AT)
## testsuite data
EXTRA_DIST += data/SPECS/attrtest.spec
EXTRA_DIST += data/SPECS/hello.spec
EXTRA_DIST += data/SPECS/hello-auto.spec
EXTRA_DIST += data/SPECS/hello-r2.spec
EXTRA_DIST += data/SPECS/hello-script.spec
EXTRA_DIST += data/SPECS/hello2.spec
@ -75,6 +76,7 @@ EXTRA_DIST += data/SPECS/test-subpackages-exclude.spec
EXTRA_DIST += data/SPECS/test-subpackages-pathpostfixes.spec
EXTRA_DIST += data/SPECS/vattrtest.spec
EXTRA_DIST += data/SOURCES/hello-1.0-modernize.patch
EXTRA_DIST += data/SOURCES/hello-1.0-install.patch
EXTRA_DIST += data/SOURCES/hello-1.0.tar.gz
EXTRA_DIST += data/SOURCES/hello-2.0.tar.gz
EXTRA_DIST += data/RPMS/foo-1.0-1.noarch.rpm

View File

@ -0,0 +1,11 @@
diff -up hello-1.0/Makefile.flags hello-1.0/Makefile
--- hello-1.0/Makefile.flags 2019-04-25 12:26:37.684540172 +0300
+++ hello-1.0/Makefile 2019-04-25 12:27:22.438450581 +0300
@@ -1,6 +1,7 @@
all: hello
install:
+ mkdir -p $(DESTDIR)/usr/local/bin/
install -m 0755 hello $(DESTDIR)/usr/local/bin
clean:

View File

@ -0,0 +1,30 @@
Name: hello
Version: 1.0
Release: 1
Group: Testing
License: GPL
Summary: Simple rpm demonstration.
%sourcelist
hello-1.0.tar.gz
%patchlist
hello-1.0-modernize.patch
hello-1.0-install.patch
%description
Simple rpm demonstration.
%prep
%autosetup
%build
%make_build CFLAGS="$RPM_OPT_FLAGS"
%install
%make_install
%files
%doc FAQ
/usr/local/bin/hello

View File

@ -36,6 +36,20 @@ run rpmbuild \
[ignore])
AT_CLEANUP
AT_SETUP([rpmbuild -ba autosetup])
AT_KEYWORDS([build])
AT_CHECK([
rm -rf ${TOPDIR}
AS_MKDIR_P(${TOPDIR}/SOURCES)
cp "${abs_srcdir}"/data/SOURCES/hello-1.0.tar.gz "${abs_srcdir}"/data/SOURCES/hello-1.0-*.patch ${TOPDIR}/SOURCES
run rpmbuild \
-ba "${abs_srcdir}"/data/SPECS/hello-auto.spec
],
[0],
[ignore],
[ignore])
AT_CLEANUP
# ------------------------------
# Check if rpmbuild --rebuild *.src.rpm works
AT_SETUP([rpmbuild --rebuild])