Skip to content

Commit

Permalink
Add %specpartsdir to macros.in
Browse files Browse the repository at this point in the history
so it can be configured from the spec file

Also move the dir beside the %buildsubdir as %{buildsubdir}-SPECPARTS so
it doesn't pollute the %buildsubdir.

Resolves: rpm-software-management#2532
(cherry picked from commit df8d1fb)
  • Loading branch information
ffesti authored and dmnks committed Aug 1, 2023
1 parent 1e0db9a commit 74593b2
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 14 deletions.
5 changes: 5 additions & 0 deletions build/build.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 8 additions & 7 deletions build/parsePrep.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
14 changes: 8 additions & 6 deletions docs/manual/dynamic_specs.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions macros.in
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion tests/rpmspec.at
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 74593b2

Please sign in to comment.