diff --git a/build/build.c b/build/build.c index 8d0b9d0fd9..5bff9cc170 100644 --- a/build/build.c +++ b/build/build.c @@ -195,6 +195,11 @@ rpmRC doScript(rpmSpec spec, rpmBuildFlags what, const char *name, fprintf(fp, "cd '%s'\n", buildSubdir); if (what == RPMBUILD_RMBUILD) { + if (rpmMacroIsDefined(spec->macros, "specpartsdir")) { + char * buf = rpmExpand("%{specpartsdir}", NULL); + fprintf(fp, "rm -rf '%s'\n", buf); + free(buf); + } if (buildSubdir[0] != '\0') fprintf(fp, "rm -rf '%s' '%s.gemspec'\n", buildSubdir, buildSubdir); diff --git a/build/parsePrep.c b/build/parsePrep.c index ea8faa9531..ca32eea001 100644 --- a/build/parsePrep.c +++ b/build/parsePrep.c @@ -274,13 +274,14 @@ static int doSetupMacro(rpmSpec spec, const char *line) } /* mkdir for dynamic specparts */ - buf = rpmExpand("%{__mkdir_p} SPECPARTS", NULL); - appendBuf(spec, buf, 1); - free(buf); - - buf = rpmGenPath("%{_builddir}", "%{buildsubdir}", "SPECPARTS"); - rpmPushMacro(spec->macros, "specpartsdir", NULL, buf, RMIL_SPEC); - free(buf); + if (rpmMacroIsDefined(spec->macros, "specpartsdir")) { + buf = rpmExpand("rm -rf '%{specpartsdir}'", NULL); + appendBuf(spec, buf, 1); + free(buf); + buf = rpmExpand("%{__mkdir_p} '%{specpartsdir}'", NULL); + appendBuf(spec, buf, 1); + free(buf); + } appendBuf(spec, getStringBuf(after), 0); diff --git a/docs/manual/dynamic_specs.md b/docs/manual/dynamic_specs.md index 195d4c0380..44e6ca2fc4 100644 --- a/docs/manual/dynamic_specs.md +++ b/docs/manual/dynamic_specs.md @@ -13,14 +13,16 @@ build results. The files need to be placed in the **%{specpartsdir}** (also available as **$RPM_SPECPARTS_DIR** in the build scripts) and have a -**.specpart** postfix. The directory is created by **%setup** in the -**buildsubdir**. Scripts must not create it themselves but must either -fail if it is not present or switch to an alternative that does not -require the feature. They should give an error message that dynamic -spec generation is not supported on the given RPM version when failing. +**.specpart** postfix. The directory is created by **%setup**. Default +location is **%{_builddir}/%{buildsubdir}-SPECPARTS** which is beside +the **%{buildsubdir}**. Scripts must not create it themselves but must +either fail if it is not present or switch to an alternative that does +not require the feature. They should give an error message that +dynamic spec generation is not supported on the given RPM version when +failing. The **.specparts** files are read in alphabetical order. If build -script rely on a specific order they should use a common prefix and +scripts rely on a specific order they should use a common prefix and have postfixes take care of the ordering. Generally the specparts should be generated by separate scripts and not diff --git a/macros.in b/macros.in index 0b651bcbb6..a3005ab1d1 100644 --- a/macros.in +++ b/macros.in @@ -262,6 +262,9 @@ Supplements: (%{name} = %{version}-%{release} and langpacks-%{1})\ # Build root path, where %install installs the package during build. %buildroot %{_buildrootdir}/%{NAME}-%{VERSION}-%{RELEASE}.%{_arch} +# Path for spec file snippets generated during build +%specpartsdir %{_builddir}/%{buildsubdir}-SPECPARTS + # Directory where temporaray files can be created. %_tmppath %{_var}/tmp diff --git a/tests/rpmspec.at b/tests/rpmspec.at index 564479391a..431b7678e3 100644 --- a/tests/rpmspec.at +++ b/tests/rpmspec.at @@ -333,7 +333,8 @@ if [ $STATUS -ne 0 ]; then exit $STATUS fi cd 'hello-1.0' -/usr/bin/mkdir -p SPECPARTS +rm -rf '/build/BUILD/hello-1.0-SPECPARTS' +/usr/bin/mkdir -p '/build/BUILD/hello-1.0-SPECPARTS' /usr/bin/chmod -Rf a+rX,u+w,g-w,o-w . echo "Patch #0 (hello-1.0-modernize.patch):" /usr/bin/patch --no-backup-if-mismatch -f -p1 -b --suffix .modernize --fuzz=0 < /build/SOURCES/hello-1.0-modernize.patch