Bug 523652

Summary: Build/prep failure when kernel not present in default %{_specdir}
Product: Red Hat Enterprise Linux 6 Reporter: Stephen Tweedie <sct>
Component: kernelAssignee: Aristeu Rozanski <arozansk>
Status: CLOSED CURRENTRELEASE QA Contact: Martin Jenner <mjenner>
Severity: medium Docs Contact:
Priority: medium    
Version: 6.0   
Target Milestone: rc   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2010-04-26 14:38:05 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Stephen Tweedie 2009-09-16 10:56:14 UTC
Description of problem:
The kernel spec file always looks for the kernel.spec in the user/system's current %{_specdir} when determining if a Patch: line is present for a file in ApplyPatch().

This causes two problems if the user is trying to build the kernel from a different directory:

* If there is already a kernel build present in the default %{_specdir}, then the ApplyPatch will be checking in the wrong place for the spec file consistency; and

* If there is not a kernel build present in that location, then the build in the non-standard directory will always fail completely on the first ApplyPatch

Version-Release number of selected component (if applicable):
kernel-2_6_31-0_125_4_2_rc5_git2_el6

How reproducible:
100%

Steps to Reproduce:
1. Checkout a kernel from CVS
2. Make sure no kernel.spec is present in $HOME/rpmbuild/SPECS/kernel.spec
3. "make prep"
  
Actual results:
Build fails at first patch with:

+ ApplyPatch linux-2.6-build-nonintconfig.patch
+ local patch=linux-2.6-build-nonintconfig.patch
+ shift
+ '[' '!' -f /tmp/k6/kernel-RHEL-6/kernel/linux-2.6-build-nonintconfig.patch ']'
ERROR: Patch  linux-2.6-build-nonintconfig.patch  not listed as a source patch in specfile
error: Bad exit status from /var/tmp/rpm-tmp.MqmBkw (%prep)


Expected results:
Builds.


Additional info:
The breaking part of the kernel.spec is here:

  if ! egrep "^Patch[0-9]+: $patch\$" %{_specdir}/${RPM_PACKAGE_NAME%%%%%{?variant}}.spec ; then
    if [ "${patch:0:10}" != "patch-2.6." ] ; then
      echo "ERROR: Patch  $patch  not listed as a source patch in specfile"

where %{_specdir} is not initialised by the kernel CVS Makefile.  This line can never work correctly if we're not building in the standard rpmbuild directory.

The Makefile.common is partly to blame here.  It already passes the correct %{_sourcedir} to the build process:

# RPM with all the overrides in place; you can override this in your
# .cvsdistrc also, to use a default rpm setup
# the rpm build command line
ifndef RPM
RPM := $(shell if test -f /usr/bin/rpmbuild ; then echo rpmbuild ; else echo rpm ; fi)
endif
ifndef RPM_WITH_DIRS
RPM_WITH_DIRS = $(RPM) --define "_sourcedir $(SOURCEDIR)" \
		--define "_builddir $(BUILDDIR)" \
		--define "_srcrpmdir $(SRCRPMDIR)" \
		--define "_rpmdir $(RPMDIR)"
endif

Adding the line

		--define "_specdir $(SOURCEDIR)" \

to the above fixes the problem for me, but that's not correct for all cases (building from an srpm will install spec and sources to different locations, so we really need a separate $(SPECDIR) here.)  The Fedora F-12 Makefile.common gets it right, with

ifndef SPECDIR
SPECDIR := $(shell pwd)
endif

ifndef RPM_DEFINES
RPM_DEFINES := --define "_sourcedir $(SOURCEDIR)" \
		--define "_specdir $(SPECDIR)" \
		--define "_builddir $(BUILDDIR)" \
		--define "_srcrpmdir $(SRCRPMDIR)" \
		--define "_rpmdir $(RPMDIR)" \
                $(DIST_DEFINES)
endif

Comment 2 RHEL Program Management 2009-09-16 11:37:04 UTC
This request was evaluated by Red Hat Product Management for inclusion in a Red
Hat Enterprise Linux major release.  Product Management has requested further
review of this request by Red Hat Engineering, for potential inclusion in a Red
Hat Enterprise Linux Major release.  This request is not yet committed for
inclusion.

Comment 3 Aristeu Rozanski 2010-04-21 17:41:26 UTC
Hm, latest version of Makefile.commonn on ../common has:

## SOURCEDIR is special; it has to match the CVS checkout directory, 
## because the CVS checkout directory contains the patch files. So it basically 
## can't be overridden without breaking things. But we leave it a variable
## for consistency, and in hopes of convincing it to work sometime.
ifndef SOURCEDIR
SOURCEDIR := $(shell pwd)
endif
ifndef SPECDIR
SPECDIR := $(shell pwd)                                                                                                                                                                         
endif

(...)
ifneq (,$(BRANCHINFO))
DIST_DEFINES := --define "dist $(DIST)" --define "$(DISTVAR) $(DISTVAL)"
endif

RPM_DEFINES ?= --define "_sourcedir $(SOURCEDIR)" \
                --define "_specdir $(SPECDIR)" \
                --define "_builddir $(BUILDDIR)" \
                --define "_srcrpmdir $(SRCRPMDIR)" \
                --define "_rpmdir $(RPMDIR)" \
                $(DIST_DEFINES)

This is Makefile.common revision 1.211.
Stephen, what version you have there?

Comment 4 Aristeu Rozanski 2010-04-21 17:43:03 UTC
Oh, just noticed the date. Just knew about this bug now. make prep works on the
checkout I just did. Can you confirm if it works for you?

Comment 5 Stephen Tweedie 2010-04-22 10:18:19 UTC
Seems to work fine in current kernel+common, thanks.

Comment 6 Aristeu Rozanski 2010-04-26 14:38:05 UTC
Ok, closing it.