From 2a19bcd79cde0fdbbf769505c5b357c9ff10dc78 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Tue, 29 Oct 2024 09:31:00 +0200 Subject: [PATCH] Convert a couple of rpmExpand() usages to the C++ versions --- build/build.cc | 24 +++++++++++++----------- build/rpmfc.cc | 7 ++++--- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/build/build.cc b/build/build.cc index 5ae1da45ac..3cf6191d48 100644 --- a/build/build.cc +++ b/build/build.cc @@ -19,9 +19,12 @@ #include #include "rpmbuild_internal.hh" #include "rpmbuild_misc.hh" +#include "rpmmacro_internal.hh" #include "debug.h" +using namespace rpm; + static rpm_time_t getBuildTime(void) { rpm_time_t buildTime = 0; @@ -321,28 +324,27 @@ static int doCheckBuildRequires(rpmts ts, rpmSpec spec, int test) static rpmRC doBuildDir(rpmSpec spec, int test, int inPlace, StringBuf *sbp) { - char *doDir = rpmExpand("test -d '", spec->buildDir, "' && ", - "%{_fixperms} '", spec->buildDir, "'\n", - "%{__rm} -rf '", spec->buildDir, "'\n", - "%{__mkdir_p} '", spec->buildDir, "'\n", - "%{__mkdir_p} '%{specpartsdir}'\n", - NULL); + auto [ ign, doDir ] = macros().expand({ + "test -d '", spec->buildDir, "' && ", + "%{_fixperms} '", spec->buildDir, "'\n", + "%{__rm} -rf '", spec->buildDir, "'\n", + "%{__mkdir_p} '", spec->buildDir, "'\n", + "%{__mkdir_p} '%{specpartsdir}'\n", + }); if (inPlace) { /* note that pwd needs to be from parse, not build time */ - char *buf = rpmExpand("%{__ln} -s %(pwd) %{builddir}/%{buildsubdir}", NULL); - doDir = rstrcat(&doDir, buf); - free(buf); + auto [ ign, buf ] = macros().expand("%{__ln} -s %(pwd) %{builddir}/%{buildsubdir}"); + doDir += buf; } rpmRC rc = doScript(spec, RPMBUILD_MKBUILDDIR, "%mkbuilddir", - doDir, test, sbp); + doDir.c_str(), test, sbp); if (rc) { rpmlog(RPMLOG_ERR, _("failed to create package build directory %s: %s\n"), spec->buildDir, strerror(errno)); } - free(doDir); return rc; } diff --git a/build/rpmfc.cc b/build/rpmfc.cc index b74459cb1a..f044c41b31 100644 --- a/build/rpmfc.cc +++ b/build/rpmfc.cc @@ -25,11 +25,13 @@ #include "rpmfi_internal.hh" /* rpmfiles stuff for now */ #include "rpmbuild_internal.hh" +#include "rpmmacro_internal.hh" #include "debug.h" using std::string; using std::vector; +using namespace rpm; struct matchRule { regex_t *path; @@ -239,9 +241,8 @@ static rpmds rpmdsSingleNS(rpmstrPool pool, { rpmds ds = NULL; if (namespc) { - char *NSN = rpmExpand(namespc, "(", N, ")", NULL); - ds = rpmdsSinglePool(pool, tagN, NSN, EVR, Flags); - free(NSN); + auto [ ign, NSN ] = macros().expand({namespc, "(", N, ")",}); + ds = rpmdsSinglePool(pool, tagN, NSN.c_str(), EVR, Flags); } else { ds = rpmdsSinglePool(pool, tagN, N, EVR, Flags); }