Tighten up setting and checking of buildroot (ticket #10)

- expand, set and verify buildroot just once for after main package preamble
  is parsed to avoid sub-packages from overriding it
- spec can still mess with %buildroot by defining it to something else
  after preamble but that's another issue...
This commit is contained in:
Panu Matilainen 2008-12-05 13:38:30 +02:00
parent 23c55fa997
commit cc74d50a6d
2 changed files with 21 additions and 9 deletions

View File

@ -874,6 +874,27 @@ int parsePreamble(rpmSpec spec, int initialPackage)
}
}
/*
* Expand buildroot one more time to get %{version} and the like
* from the main package, validate sanity. The spec->buildRoot could
* still contain unexpanded macros but it cannot be empty or '/', and it
* can't be messed with by anything spec does beyond this point.
*/
if (initialPackage) {
char *buildRoot = rpmGetPath(spec->buildRoot, NULL);
if (*buildRoot == '\0') {
rpmlog(RPMLOG_ERR, _("%%{buildroot} couldn't be empty\n"));
goto exit;
}
if (!strcmp(buildRoot, "/")) {
rpmlog(RPMLOG_ERR, _("%%{buildroot} can not be \"/\"\n"));
goto exit;
}
free(spec->buildRoot);
spec->buildRoot = buildRoot;
addMacro(spec->macros, "buildroot", NULL, spec->buildRoot, RMIL_SPEC);
}
/* XXX Skip valid arch check if not building binary package */
if (!spec->anyarch && checkForValidArchitectures(spec)) {
goto exit;

View File

@ -433,15 +433,6 @@ int parseSpec(rpmts ts, const char *specFile, const char *rootDir,
} else {
spec->buildRoot = rpmGetPath("%{?buildroot:%{buildroot}}", NULL);
}
addMacro(spec->macros, "buildroot", NULL, spec->buildRoot, RMIL_SPEC);
if (*spec->buildRoot == '\0') {
rpmlog(RPMLOG_ERR, _("BuildRoot couldn't be empty\n"));
goto errxit;
}
if (!strcmp(spec->buildRoot, "/")) {
rpmlog(RPMLOG_ERR, _("BuildRoot can not be \"/\"\n"));
goto errxit;
}
addMacro(NULL, "_docdir", NULL, "%{_defaultdocdir}", RMIL_SPEC);
spec->recursing = recursing;
spec->anyarch = anyarch;