Skip to content

Commit

Permalink
PoC: Add native support for vpath-style builds outside the source tree
Browse files Browse the repository at this point in the history
NOT FOR MERGING YET, proof of concept state.

Add a new %setup switch -s to indicate building in a directory outside
the source directory, known as vpath build in some circles. Add a new
%{sourcesubdir} macro which by default equals %{buildsubdir}, but
when -s is used, we create and switch to a separate directory after
unpacking.

A one gotcha here is that special %doc and %license has traditionally
worked for both built and pre-existing content. With build and source trees
separated, both cannot work. As special %doc/%license is mostly used for
things like README's and COPYING which come as part of the source, we
define %doc on vpath builds to mean source directory, and assume built
content has its own means of installing (eg make install-doc).

Another potential issue is that we redefine %_configure to an absolute
path in the sourcesubdir, this would break some unusual cases where
%configure is used to invoke a configure-script outside the project
top directory. It's mainly redefined here to make testing -s on an
autotools project easy, a final implementation might do something else.
  • Loading branch information
pmatilai committed Feb 5, 2024
1 parent 80a60aa commit 3476fa9
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion build/files.c
Original file line number Diff line number Diff line change
Expand Up @@ -2389,7 +2389,7 @@ static void processSpecialDir(rpmSpec spec, Package pkg, FileList fl,
char *mkdocdir = rpmExpand("%{__mkdir_p} $", sdenv, NULL);
StringBuf docScript = newStringBuf();
int count = sd->entriesCount;
char *basepath = rpmGenPath(spec->rootDir, "%{_builddir}", "%{?buildsubdir}");
char *basepath = rpmGenPath(spec->rootDir, "%{_builddir}", "%{?sourcesubdir}");
ARGV_t *files = xmalloc(sizeof(*files) * count);
int i, j;

Expand Down
20 changes: 18 additions & 2 deletions build/parsePrep.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ void doSetupMacro(rpmMacroBuf mb, rpmMacroEntry me, ARGV_t margs, size_t *parsed
int xx;
uint32_t num;
int leaveDirs = 0, skipDefaultAction = 0;
int createDir = 0, quietly = 0, autoPath = 0;
int createDir = 0, quietly = 0, autoPath = 0, sourceDir = 0;
char * dirName = NULL;
struct poptOption optionsTable[] = {
{ NULL, 'a', POPT_ARG_STRING, NULL, 'a', NULL, NULL},
Expand All @@ -181,6 +181,7 @@ void doSetupMacro(rpmMacroBuf mb, rpmMacroEntry me, ARGV_t margs, size_t *parsed
{ NULL, 'n', POPT_ARG_STRING, &dirName, 0, NULL, NULL},
{ NULL, 'T', 0, &skipDefaultAction, 0, NULL, NULL},
{ NULL, 'q', 0, &quietly, 0, NULL, NULL},
{ NULL, 's', 0, &sourceDir, 0, NULL, NULL},
{ 0, 0, 0, 0, 0, NULL, NULL}
};

Expand Down Expand Up @@ -227,12 +228,14 @@ void doSetupMacro(rpmMacroBuf mb, rpmMacroEntry me, ARGV_t margs, size_t *parsed

if (dirName) {
rpmPushMacro(spec->macros, "buildsubdir", NULL, dirName, RMIL_SPEC);
rpmPushMacro(spec->macros, "sourcesubdir", NULL, dirName, RMIL_SPEC);
} else {
char * buildSubdir = NULL;
rasprintf(&buildSubdir, "%s-%s",
headerGetString(spec->packages->header, RPMTAG_NAME),
headerGetString(spec->packages->header, RPMTAG_VERSION));
rpmPushMacro(spec->macros, "buildsubdir", NULL, buildSubdir, RMIL_SPEC);
rpmPushMacro(spec->macros, "sourcesubdir", NULL, buildSubdir, RMIL_SPEC);
free(buildSubdir);
}

Expand Down Expand Up @@ -271,6 +274,19 @@ void doSetupMacro(rpmMacroBuf mb, rpmMacroEntry me, ARGV_t margs, size_t *parsed
free(chptr);
}

/* if using a separate build/source dirs, set it up now */
if (sourceDir) {
char *bsub = rpmExpand("%{_target_platform}", NULL);
char *ssub = rpmExpand("%{buildsubdir}", NULL);
rpmPushMacro(spec->macros, "buildsubdir", NULL, bsub, RMIL_SPEC);
rpmPushMacro(spec->macros, "sourcesubdir", NULL, ssub, RMIL_SPEC);
buf = rpmExpand("mkdir -p '%{buildsubdir}'", NULL);
appendMb(mb, buf, 1);
free(buf);
free(bsub);
free(ssub);
}

if (!createDir) {
buf = rpmExpand("cd '%{buildsubdir}'", NULL);
appendMb(mb, buf, 1);
Expand All @@ -290,7 +306,7 @@ void doSetupMacro(rpmMacroBuf mb, rpmMacroEntry me, ARGV_t margs, size_t *parsed
appendMb(mb, getStringBuf(after), 0);

/* Fix the permissions of the setup build tree */
{ char *fix = rpmExpand("%{_fixperms} .", NULL);
{ char *fix = rpmExpand("%{_fixperms} %{_builddir}/%{sourcesubdir}", NULL);
if (fix && *fix != '%') {
appendMb(mb, fix, 1);
}
Expand Down
1 change: 1 addition & 0 deletions docs/manual/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,7 @@ can just create the directory. It accepts a number of options:
-D do not delete the build directory prior to unpacking (used
when more than one source is to be unpacked with `-a` or `-b`)
-n DIR set the name of build directory (default is `%{name}-%{version}`)
-s use separate source and build directories (aka vpath build)
-T skip the default unpacking of the first source (used with
`-a` or `-b`)
-q operate quietly
Expand Down
6 changes: 3 additions & 3 deletions macros.in
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@ Supplements: (%{name} = %{version}-%{release} and langpacks-%{1})\
# directory structure (--prefix, --libdir etc) and compiler flags
# such as CFLAGS.
#
%_configure ./configure
%_configure %{_builddir}/%{sourcesubdir}/configure
%configure \
%{set_build_flags}; \
%{_configure} --host=%{_host} --build=%{_build} \\\
Expand Down Expand Up @@ -1309,8 +1309,8 @@ end
# usage of git repository and per-patch commits.
# -N Disable automatic patch application
# -p<num> Use -p<num> for patch application
%autosetup(a:b:cCDn:TvNS:p:)\
%setup %{-a} %{-b} %{-c} %{-C} %{-D} %{-n} %{-T} %{!-v:-q}\
%autosetup(a:b:cCDn:TvNS:p:s)\
%setup %{-a} %{-b} %{-c} %{-C} %{-D} %{-n} %{-T} %{!-v:-q} %{-s}\
%{-S:%global __scm %{-S*}}\
%{expand:%__scm_setup_%{__scm} %{!-v:-q}}\
%{!-N:%autopatch %{-v} %{-p:-p%{-p*}}}
Expand Down
2 changes: 1 addition & 1 deletion tests/rpmspec.at
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ fi
cd 'hello-1.0'
rm -rf '/build/BUILD/hello-1.0-PKG/SPECPARTS'
/usr/bin/mkdir -p '/build/BUILD/hello-1.0-PKG/SPECPARTS'
/usr/bin/chmod -Rf a+rX,u+w,g-w,o-w .
/usr/bin/chmod -Rf a+rX,u+w,g-w,o-w /build/BUILD/hello-1.0-PKG/hello-1.0

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 3476fa9

Please sign in to comment.