Skip to content

Commit 6caca84

Browse files
vathpelapmatilai
authored andcommitted
Make %{buildsubdir} more independent of %setup
Use the macro itself as ground truth and no longer store it in the spec object. This may allow implementing %setup as a proper macro in the future. Co-authord-by: Florian Festi <ffesti@redhat.com>
1 parent c8865bf commit 6caca84

File tree

5 files changed

+19
-21
lines changed

5 files changed

+19
-21
lines changed

build/build.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ rpmRC doScript(rpmSpec spec, rpmBuildFlags what, const char *name,
104104
{
105105
char *scriptName = NULL;
106106
char * buildDir = rpmGenPath(spec->rootDir, "%{_builddir}", "");
107+
char * buildSubdir = rpmGetPath("%{?buildsubdir}", NULL);
107108
char * buildCmd = NULL;
108109
char * buildTemplate = NULL;
109110
char * buildPost = NULL;
@@ -182,12 +183,12 @@ rpmRC doScript(rpmSpec spec, rpmBuildFlags what, const char *name,
182183

183184
(void) fputs(buildTemplate, fp);
184185

185-
if (what != RPMBUILD_PREP && what != RPMBUILD_RMBUILD && spec->buildSubdir)
186-
fprintf(fp, "cd '%s'\n", spec->buildSubdir);
186+
if (what != RPMBUILD_PREP && what != RPMBUILD_RMBUILD && buildSubdir[0] != '\0')
187+
fprintf(fp, "cd '%s'\n", buildSubdir);
187188

188189
if (what == RPMBUILD_RMBUILD) {
189-
if (spec->buildSubdir)
190-
fprintf(fp, "rm -rf '%s'\n", spec->buildSubdir);
190+
if (buildSubdir[0] != '\0')
191+
fprintf(fp, "rm -rf '%s'\n", buildSubdir);
191192
} else if (sb != NULL)
192193
fprintf(fp, "%s", sb);
193194

@@ -207,8 +208,7 @@ rpmRC doScript(rpmSpec spec, rpmBuildFlags what, const char *name,
207208
(void) poptParseArgvString(buildCmd, &argc, &argv);
208209

209210
rpmlog(RPMLOG_NOTICE, _("Executing(%s): %s\n"), name, buildCmd);
210-
if (rpmfcExec((ARGV_const_t)argv, NULL, sb_stdoutp, 1,
211-
spec->buildSubdir)) {
211+
if (rpmfcExec((ARGV_const_t)argv, NULL, sb_stdoutp, 1, buildSubdir)) {
212212
rpmlog(RPMLOG_ERR, _("Bad exit status from %s (%s)\n"),
213213
scriptName, name);
214214
goto exit;
@@ -226,6 +226,7 @@ rpmRC doScript(rpmSpec spec, rpmBuildFlags what, const char *name,
226226
free(buildCmd);
227227
free(buildTemplate);
228228
free(buildPost);
229+
free(buildSubdir);
229230
free(buildDir);
230231

231232
return rc;

build/files.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1625,7 +1625,6 @@ static rpmRC recurseDir(FileList fl, const char * diskPath)
16251625
static rpmRC processMetadataFile(Package pkg, FileList fl,
16261626
const char * fileName, rpmTagVal tag)
16271627
{
1628-
const char * buildDir = "%{_builddir}/%{?buildsubdir}/";
16291628
char * fn = NULL;
16301629
char * apkt = NULL;
16311630
uint8_t * pkt = NULL;
@@ -1638,7 +1637,7 @@ static rpmRC processMetadataFile(Package pkg, FileList fl,
16381637
fn = rpmGenPath(fl->buildRoot, NULL, fileName);
16391638
absolute = 1;
16401639
} else
1641-
fn = rpmGenPath(buildDir, NULL, fileName);
1640+
fn = rpmGenPath("%{_builddir}", "%{?buildsubdir}", fileName);
16421641

16431642
switch (tag) {
16441643
default:
@@ -2240,8 +2239,7 @@ int readManifest(rpmSpec spec, const char *path, const char *descr, int flags,
22402239
if (*path == '/') {
22412240
fn = rpmGetPath(path, NULL);
22422241
} else {
2243-
fn = rpmGetPath("%{_builddir}/",
2244-
(spec->buildSubdir ? spec->buildSubdir : "") , "/", path, NULL);
2242+
fn = rpmGenPath("%{_builddir}", "%{?buildsubdir}", path);
22452243
}
22462244
fd = fopen(fn, "r");
22472245

@@ -2413,7 +2411,7 @@ static void processSpecialDir(rpmSpec spec, Package pkg, FileList fl,
24132411
}
24142412
}
24152413

2416-
basepath = rpmGenPath(spec->rootDir, "%{_builddir}", spec->buildSubdir);
2414+
basepath = rpmGenPath(spec->rootDir, "%{_builddir}", "%{?buildsubdir}");
24172415
files = sd->files;
24182416
fi = 0;
24192417
while (*files != NULL) {

build/parsePrep.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -297,13 +297,15 @@ static int doSetupMacro(rpmSpec spec, const char *line)
297297
}
298298

299299
if (dirName) {
300-
spec->buildSubdir = xstrdup(dirName);
300+
rpmPushMacro(spec->macros, "buildsubdir", NULL, dirName, RMIL_SPEC);
301301
} else {
302-
rasprintf(&spec->buildSubdir, "%s-%s",
302+
char * buildSubdir = NULL;
303+
rasprintf(&buildSubdir, "%s-%s",
303304
headerGetString(spec->packages->header, RPMTAG_NAME),
304305
headerGetString(spec->packages->header, RPMTAG_VERSION));
306+
rpmPushMacro(spec->macros, "buildsubdir", NULL, buildSubdir, RMIL_SPEC);
307+
free(buildSubdir);
305308
}
306-
rpmPushMacroFlags(spec->macros, "buildsubdir", NULL, spec->buildSubdir, RMIL_SPEC, RPMMACRO_LITERAL);
307309

308310
/* cd to the build dir */
309311
{ char * buildDir = rpmGenPath(spec->rootDir, "%{_builddir}", "");
@@ -316,7 +318,7 @@ static int doSetupMacro(rpmSpec spec, const char *line)
316318

317319
/* delete any old sources */
318320
if (!leaveDirs) {
319-
rasprintf(&buf, "rm -rf '%s'", spec->buildSubdir);
321+
buf = rpmExpand("rm -rf '%{buildsubdir}'", NULL);
320322
appendLineStringBuf(spec->prep, buf);
321323
free(buf);
322324
}
@@ -325,8 +327,8 @@ static int doSetupMacro(rpmSpec spec, const char *line)
325327

326328
/* if necessary, create and cd into the proper dir */
327329
if (createDir) {
328-
buf = rpmExpand("%{__mkdir_p} ", spec->buildSubdir, "\n",
329-
"cd '", spec->buildSubdir, "'", NULL);
330+
buf = rpmExpand("%{__mkdir_p} '%{buildsubdir}'\n",
331+
"cd '%{buildsubdir}'", NULL);
330332
appendLineStringBuf(spec->prep, buf);
331333
free(buf);
332334
}
@@ -341,7 +343,7 @@ static int doSetupMacro(rpmSpec spec, const char *line)
341343
}
342344

343345
if (!createDir) {
344-
rasprintf(&buf, "cd '%s'", spec->buildSubdir);
346+
buf = rpmExpand("cd '%{buildsubdir}'", NULL);
345347
appendLineStringBuf(spec->prep, buf);
346348
free(buf);
347349
}

build/rpmbuild_internal.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ struct rpmSpec_s {
106106

107107
char * specFile; /*!< Name of the spec file. */
108108
char * buildRoot;
109-
char * buildSubdir;
110109
const char * rootDir;
111110

112111
struct OpenFileInfo * fileStack;

build/spec.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,6 @@ rpmSpec newSpec(void)
236236
spec->sourcePackage = NULL;
237237

238238
spec->buildRoot = NULL;
239-
spec->buildSubdir = NULL;
240239

241240
spec->buildRestrictions = headerNew();
242241
spec->BANames = NULL;
@@ -267,7 +266,6 @@ rpmSpec rpmSpecFree(rpmSpec spec)
267266
spec->buildrequires = freeStringBuf(spec->buildrequires);
268267

269268
spec->buildRoot = _free(spec->buildRoot);
270-
spec->buildSubdir = _free(spec->buildSubdir);
271269
spec->specFile = _free(spec->specFile);
272270

273271
closeSpec(spec);

0 commit comments

Comments
 (0)