Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for special system-level %include path #685

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ install-data-local:
@$(MKDIR_P) $(DESTDIR)$(localstatedir)/tmp
@$(MKDIR_P) $(DESTDIR)$(rpmconfigdir)/macros.d
@$(MKDIR_P) $(DESTDIR)$(rpmconfigdir)/lua
@$(MKDIR_P) $(DESTDIR)$(rpmconfigdir)/include

# XXX to appease distcheck we need to remove "stuff" here...
uninstall-local:
Expand All @@ -259,6 +260,7 @@ uninstall-local:
@rm -f $(DESTDIR)$(rpmconfigdir)/macros
@rm -rf $(DESTDIR)$(rpmconfigdir)/macros.d
@rm -rf $(DESTDIR)$(rpmconfigdir)/lua
@rm -rf $(DESTDIR)$(rpmconfigdir)/include

MAINTAINERCLEANFILES = ChangeLog

Expand Down
31 changes: 25 additions & 6 deletions build/parseSpec.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ typedef struct OpenFileInfo {
char *readBuf;
size_t readBufLen;
const char * readPtr;
int missingok;
struct OpenFileInfo * next;
} OFI_t;

Expand Down Expand Up @@ -127,7 +128,7 @@ int handleComments(char *s)
}

/* Push a file to spec's file stack, return the newly pushed entry */
static OFI_t * pushOFI(rpmSpec spec, const char *fn)
static OFI_t * pushOFI(rpmSpec spec, const char *fn, int missingok)
{
OFI_t *ofi = xcalloc(1, sizeof(*ofi));

Expand All @@ -138,6 +139,7 @@ static OFI_t * pushOFI(rpmSpec spec, const char *fn)
ofi->readBuf = xmalloc(ofi->readBufLen);
ofi->readBuf[0] = '\0';
ofi->readPtr = NULL;
ofi->missingok = missingok;
ofi->next = spec->fileStack;

spec->fileStack = ofi;
Expand Down Expand Up @@ -372,9 +374,15 @@ static int readLineFromOFI(rpmSpec spec, OFI_t *ofi)
if (ofi->fp == NULL) {
ofi->fp = fopen(ofi->fileName, "r");
if (ofi->fp == NULL) {
rpmlog(RPMLOG_ERR, _("Unable to open %s: %s\n"),
ofi->fileName, strerror(errno));
return PART_ERROR;
/* Try to ignore missing includes on forced parse */
rpmlog(ofi->missingok ? RPMLOG_WARNING : RPMLOG_ERR,
_("Unable to open %s: %s\n"), ofi->fileName, strerror(errno));
if (ofi->missingok) {
ofi = popOFI(spec);
goto retry;
} else {
return PART_ERROR;
}
}
spec->lineNum = ofi->lineNum = 0;
}
Expand Down Expand Up @@ -508,6 +516,7 @@ int readLine(rpmSpec spec, int strip)
spec->line[0] = '\0';
} else if (spec->readStack->reading && (lineType->id == LINE_INCLUDE)) {
char *fileName, *endFileName, *p;
char *sysinc = NULL;

fileName = s+8;
SKIPSPACE(fileName);
Expand All @@ -525,7 +534,17 @@ int readLine(rpmSpec spec, int strip)
}
*endFileName = '\0';

ofi = pushOFI(spec, fileName);
/* System includes live in a special path and become buildrequires */
if (*fileName == '<' && *(endFileName-1) == '>') {
*(endFileName-1) = '\0';
sysinc = rpmGetPath("%{_rpmincludedir}/", fileName + 1, NULL);
addReqProv(spec->sourcePackage, RPMTAG_REQUIRENAME,
sysinc, NULL, 0, 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about this one, because you are technically do not depend on exact /usr/lib/rpm/include/… file, but rather that path will be present...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point is that other tooling knows how to look at buildrequires, but they dont (and should not) try to parse rpmbuild output for missing files.

fileName = sysinc;
}

ofi = pushOFI(spec, fileName, (spec->flags & RPMSPEC_FORCE));
free(sysinc);
goto retry;
}

Expand Down Expand Up @@ -860,7 +879,7 @@ static rpmSpec parseSpec(const char *specFile, rpmSpecFlags flags,
spec = newSpec();

spec->specFile = rpmGetPath(specFile, NULL);
pushOFI(spec, spec->specFile);
pushOFI(spec, spec->specFile, 0);
/* If buildRoot not specified, use default %{buildroot} */
if (buildRoot) {
spec->buildRoot = xstrdup(buildRoot);
Expand Down
1 change: 1 addition & 0 deletions macros.in
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,7 @@ package or when debugging this package.\
# %__myattr_exclude_path exclude by path regex
#
%_fileattrsdir %{_rpmconfigdir}/fileattrs
%_rpmincludedir %{_rpmconfigdir}/include

# This macro defines how much space (in bytes) in package should be
# reserved for gpg signatures during building of a package. If this space is
Expand Down
1 change: 1 addition & 0 deletions tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ EXTRA_DIST += data/SPECS/filedep.spec
EXTRA_DIST += data/SPECS/flangtest.spec
EXTRA_DIST += data/SPECS/hlinktest.spec
EXTRA_DIST += data/SPECS/iftest.spec
EXTRA_DIST += data/SPECS/inctest.spec
EXTRA_DIST += data/SPECS/symlinktest.spec
EXTRA_DIST += data/SPECS/deptest.spec
EXTRA_DIST += data/SPECS/verifyscript.spec
Expand Down
11 changes: 11 additions & 0 deletions tests/data/SPECS/inctest.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Name: inctest
Version: 1.0
Release: 1
Group: Testing
License: GPL
BuildArch: noarch
Summary: Testing include directive

%description
%include %{incfile}

27 changes: 27 additions & 0 deletions tests/rpmbuild.at
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,33 @@ run rpmbuild \
[ignore])
AT_CLEANUP

AT_SETUP([rpmbuild include])
AT_KEYWORDS([build])
AT_CHECK([
dsc="/tmp/description"
echo "Describe me" > "${RPMTEST}/${dsc}"
runroot rpmspec -q "/data/SPECS/notthere.spec" 2>&1; echo $?
runroot rpmspec -q --define "incfile /not/there" "/data/SPECS/inctest.spec" 2>&1; echo $?
runroot rpmspec -q --define "incfile ${dsc}" --qf "%{description}\n" "/data/SPECS/inctest.spec" 2>&1; echo $?
runroot rpmspec -q --define "%_rpmincludedir /usr/lib/rpm/include" --define "incfile <system.inc>" --buildrequires "/data/SPECS/inctest.spec" 2>&1; echo $?
rm -f "${RPMTEST}/${dsc}"
],
[0],
[error: Unable to open /data/SPECS/notthere.spec: No such file or directory
error: query of specfile /data/SPECS/notthere.spec failed, can't parse
1
warning: Unable to open /not/there: No such file or directory
inctest-1.0-1.noarch
0
Describe me
0
warning: Unable to open /usr/lib/rpm/include/system.inc: No such file or directory
/usr/lib/rpm/include/system.inc
0
],
[])
AT_CLEANUP

# ------------------------------
# %attr/%defattr tests
AT_SETUP([rpmbuild %attr and %defattr])
Expand Down