[Rpm-maint] [PATCH #2] rpmbuild: clean up buildroot handling, set a default buildroot
Bill Nottingham
notting at redhat.com
Thu Feb 15 19:43:16 UTC 2007
Changes from original patch:
- move setting of default buildroot to macros. Can be left out if you want
to leave it up to distributors.
To repeat, the attached:
- moves buildroot setting into a single function, called when needed
- cleans up some of the noise
- allows setting of %{buildroot} to work in spec files without BuildRoot:
- sets a default buildroot if there isn't one set elsewher
Bill
-------------- next part --------------
diff -ru rpm-4.4.2-dist/build/parsePreamble.c rpm-4.4.2/build/parsePreamble.c
--- rpm-4.4.2-dist/build/parsePreamble.c 2005-07-12 06:44:26.000000000 -0400
+++ rpm-4.4.2/build/parsePreamble.c 2007-02-15 14:39:23.000000000 -0500
@@ -551,50 +551,17 @@
break;
case RPMTAG_BUILDROOT:
SINGLE_TOKEN_ONLY;
- { const char * buildRoot = NULL;
- const char * buildRootURL = spec->buildRootURL;
-
- /*
- * Note: rpmGenPath should guarantee a "canonical" path. That means
- * that the following pathologies should be weeded out:
- * //bin//sh
- * //usr//bin/
- * /.././../usr/../bin//./sh
- */
- if (buildRootURL == NULL) {
- buildRootURL = rpmGenPath(NULL, "%{?buildroot:%{buildroot}}", NULL);
- if (strcmp(buildRootURL, "/")) {
- spec->buildRootURL = buildRootURL;
- macro = NULL;
- } else {
- const char * specURL = field;
-
- buildRootURL = _free(buildRootURL);
- (void) urlPath(specURL, (const char **)&field);
- /*@-branchstate@*/
- if (*field == '\0') field = "/";
- /*@=branchstate@*/
- buildRootURL = rpmGenPath(spec->rootURL, field, NULL);
- spec->buildRootURL = buildRootURL;
- field = (char *) buildRootURL;
- }
- spec->gotBuildRootURL = 1;
- } else {
- macro = NULL;
- }
- buildRootURL = rpmGenPath(NULL, spec->buildRootURL, NULL);
- (void) urlPath(buildRootURL, &buildRoot);
- /*@-branchstate@*/
- if (*buildRoot == '\0') buildRoot = "/";
- /*@=branchstate@*/
- if (!strcmp(buildRoot, "/")) {
- rpmError(RPMERR_BADSPEC,
- _("BuildRoot can not be \"/\": %s\n"), spec->buildRootURL);
- buildRootURL = _free(buildRootURL);
- return RPMERR_BADSPEC;
+ if (spec->buildRootURL == NULL) {
+ int err;
+
+ err = setBuildRoot(spec, field);
+
+ if (err)
+ return err;
}
- buildRootURL = _free(buildRootURL);
- } break;
+ /* already set by setBuildRoot */
+ macro = NULL;
+ break;
case RPMTAG_PREFIXES:
addOrAppendListEntry(pkg->header, tag, field);
xx = hge(pkg->header, tag, &type, (void **)&array, &num);
diff -ru rpm-4.4.2-dist/build/parseSpec.c rpm-4.4.2/build/parseSpec.c
--- rpm-4.4.2-dist/build/parseSpec.c 2004-10-09 14:23:00.000000000 -0400
+++ rpm-4.4.2/build/parseSpec.c 2007-02-15 14:39:34.000000000 -0500
@@ -429,6 +429,28 @@
}
}
+/*@=boundswrite@*/
+int setBuildRoot(Spec spec, const char *buildRootURL)
+{
+ char *buildRoot = NULL;
+
+ if (!buildRootURL)
+ return 0;
+ (void) urlPath(buildRootURL, (const char **)&buildRoot);
+
+ if (*buildRoot == '\0') {
+ rpmError(RPMERR_BADSPEC,
+ _("BuildRoot can not be \"/\": %s\n"), buildRootURL);
+ return RPMERR_BADSPEC;
+ }
+
+ spec->gotBuildRootURL = 1;
+ spec->buildRootURL = xstrdup(buildRootURL);
+ addMacro(spec->macros, "buildroot", NULL, buildRoot, RMIL_SPEC);
+
+ return 0;
+}
+
/*@-redecl@*/
/*@unchecked@*/
extern int noLang; /* XXX FIXME: pass as arg */
@@ -461,20 +483,23 @@
spec->specFile = rpmGetPath(specFile, NULL);
spec->fileStack = newOpenFileInfo();
spec->fileStack->fileName = xstrdup(spec->specFile);
+
+
+ if (!buildRootURL) {
+ const char *tmpURL = rpmGenPath(NULL, "%{?buildroot:%{buildroot}}", NULL);
+
+ if (strcmp(tmpURL,"/")) {
+ buildRootURL = tmpURL;
+ }
+ }
+
if (buildRootURL) {
- const char * buildRoot;
- (void) urlPath(buildRootURL, &buildRoot);
- /*@-branchstate@*/
- if (*buildRoot == '\0') buildRoot = "/";
- /*@=branchstate@*/
- if (!strcmp(buildRoot, "/")) {
- rpmError(RPMERR_BADSPEC,
- _("BuildRoot can not be \"/\": %s\n"), buildRootURL);
- return RPMERR_BADSPEC;
+ int err;
+
+ err = setBuildRoot(spec, buildRootURL);
+ if (err) {
+ return err;
}
- spec->gotBuildRootURL = 1;
- spec->buildRootURL = xstrdup(buildRootURL);
- addMacro(spec->macros, "buildroot", NULL, buildRoot, RMIL_SPEC);
}
addMacro(NULL, "_docdir", NULL, "%{_defaultdocdir}", RMIL_SPEC);
spec->recursing = recursing;
diff -ru rpm-4.4.2-dist/build/rpmbuild.h rpm-4.4.2/build/rpmbuild.h
--- rpm-4.4.2-dist/build/rpmbuild.h 2004-10-09 17:58:33.000000000 -0400
+++ rpm-4.4.2/build/rpmbuild.h 2007-02-15 14:39:23.000000000 -0500
@@ -231,6 +231,15 @@
rpmGlobalMacroContext, fileSystem, internalState @*/;
/** \ingroup rpmbuild
+ * Parse BuildRoot: tags and/or settings
+ * @param spec spec file control structure
+ * @param buildRoot buildRoot to set
+ * @return 0 on success, RPMERR_BADSPEC on failure
+ */
+int setBuildRoot(Spec spec, const char *buildRoot)
+ /*@modifies spec->buildRootURL, spec->gotBuildRootURL @*/;
+
+/** \ingroup rpmbuild
* Parse %%changelog section of a spec file.
* @param spec spec file control structure
* @return >= 0 next rpmParseState, < 0 on error
diff -ru rpm-4.4.2-dist/macros.in rpm-4.4.2/macros.in
--- rpm-4.4.2-dist/macros.in 2007-02-15 14:38:53.000000000 -0500
+++ rpm-4.4.2/macros.in 2007-02-15 14:39:25.000000000 -0500
@@ -231,7 +231,7 @@
# Configurable build root path, same as BuildRoot: in a specfile.
# (Note: the configured macro value will override the spec file value).
#
-#%buildroot
+%buildroot %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
# The sub-directory (relative to %{_builddir}) where sources are compiled.
# This macro is set after processing %setup, either explicitly from the
More information about the Rpm-maint
mailing list