Gentoo Archives: gentoo-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-dev@l.g.o
Cc: "Michał Górny" <mgorny@g.o>
Subject: [gentoo-dev] [PATCH] out-of-source.eclass: A new eclass to help with out-of-source builds
Date: Thu, 16 Nov 2017 13:48:30
Message-Id: 20171116134818.13899-1-mgorny@gentoo.org
1 // NB: I'm not sure if I haven't submitted it already but that was
2 // a long time ago, so let's try again. Requested by soap.
3
4 The out-of-source.eclass is a simple multilib-minimal-style wrapper
5 to perform out of source builds of autotools (and other) packages. It is
6 mostly derived from the function served in the past by autotools-utils
7 since a number of developers found it useful. However, in order to avoid
8 the mistakes of autotools-utils, it is meant to be focused on a single
9 feature and have a better API.
10
11 This eclass has two use cases:
12
13 1. Ensuring that packages are tested with out-of-source builds.
14
15 2. Improving consistency between multilib and non-multilib packages.
16
17 In the most basic form, it just redefines the phases from src_configure()
18 to src_install() with out-of-source wrappers. However, each phase can
19 be overriden using my_src_*() sub-phase that is run inside build dir
20 (alike multilib_src_*() in multilib-minimal). There is also
21 my_src_install_all() for the trailing source-dir actions.
22 ---
23 eclass/out-of-source.eclass | 124 ++++++++++++++++++++++++++++++++++++++++++++
24 1 file changed, 124 insertions(+)
25 create mode 100644 eclass/out-of-source.eclass
26
27 diff --git a/eclass/out-of-source.eclass b/eclass/out-of-source.eclass
28 new file mode 100644
29 index 000000000000..4d9c8d05fd64
30 --- /dev/null
31 +++ b/eclass/out-of-source.eclass
32 @@ -0,0 +1,124 @@
33 +# Copyright 1999-2017 Gentoo Foundation
34 +# Distributed under the terms of the GNU General Public License v2
35 +
36 +# @ECLASS: out-of-source.eclass
37 +# @MAINTAINER:
38 +# Michał Górny <mgorny@g.o>
39 +# @BLURB: convenient wrapper to build autotools packages out-of-source
40 +# @DESCRIPTION:
41 +# This eclass provides a minimalistic wrapper interface to easily
42 +# build autotools (and alike) packages out-of-source. It is meant
43 +# to resemble the interface used by multilib-minimal without actually
44 +# requiring the package to be multilib.
45 +#
46 +# For the simplest ebuilds, it is enough to inherit the eclass
47 +# and the new phase functions will automatically build the package
48 +# out-of-source. If you need to redefine one of the default phases
49 +# src_configure() through src_install(), you need to define
50 +# the matching sub-phases: my_src_configure(), my_src_compile(),
51 +# my_src_test() and/or my_src_install(). Those sub-phase functions
52 +# will be run inside the build directory. Additionally,
53 +# my_src_install_all() is provided to perform doc-install and other
54 +# common tasks that are done in source directory.
55 +#
56 +# Example use:
57 +# @CODE
58 +# inherit out-of-source
59 +#
60 +# my_src_configure() {
61 +# econf \
62 +# --disable-static
63 +# }
64 +# @CODE
65 +
66 +case ${EAPI} in
67 + 6);;
68 + *) die "EAPI ${EAPI:-0} unsupported (too old)";;
69 +esac
70 +
71 +EXPORT_FUNCTIONS src_configure src_compile src_test src_install
72 +
73 +if [[ ! ${_OUT_OF_SOURCE_ECLASS} ]]; then
74 +
75 +# @FUNCTION: out-of-source_src_configure
76 +# @DESCRIPTION:
77 +# The default src_configure() implementation establishes a BUILD_DIR,
78 +# sets ECONF_SOURCE to the current directory (usually S), and runs
79 +# my_src_configure() (or the default) inside it.
80 +out-of-source_src_configure() {
81 + debug-print-function ${FUNCNAME} "$@"
82 +
83 + # set some BUILD_DIR if we don't have one yet
84 + : "${BUILD_DIR:=${WORKDIR}/${P}_build}"
85 + local ECONF_SOURCE=${PWD}
86 +
87 + mkdir -p "${BUILD_DIR}" || die
88 + pushd "${BUILD_DIR}" >/dev/null || die
89 + if declare -f my_src_configure >/dev/null ; then
90 + my_src_configure
91 + else
92 + default_src_configure
93 + fi
94 + popd >/dev/null || die
95 +}
96 +
97 +# @FUNCTION: out-of-source_src_compile
98 +# @DESCRIPTION:
99 +# The default src_compile() implementation runs my_src_compile()
100 +# (or the default) inside the build directory.
101 +out-of-source_src_compile() {
102 + debug-print-function ${FUNCNAME} "$@"
103 +
104 + pushd "${BUILD_DIR}" >/dev/null || die
105 + if declare -f my_src_compile >/dev/null ; then
106 + my_src_compile
107 + else
108 + default_src_compile
109 + fi
110 + popd >/dev/null || die
111 +}
112 +
113 +# @FUNCTION: out-of-source_src_test
114 +# @DESCRIPTION:
115 +# The default src_test() implementation runs my_src_test()
116 +# (or the default) inside the build directory.
117 +out-of-source_src_test() {
118 + debug-print-function ${FUNCNAME} "$@"
119 +
120 + pushd "${BUILD_DIR}" >/dev/null || die
121 + if declare -f my_src_test >/dev/null ; then
122 + my_src_test
123 + else
124 + default_src_test
125 + fi
126 + popd >/dev/null || die
127 +}
128 +
129 +# @FUNCTION: out-of-source_src_install
130 +# @DESCRIPTION:
131 +# The default src_install() implementation runs my_src_install()
132 +# (or the 'make install' part of the default) inside the build directory,
133 +# followed by a call to my_src_install_all() (or 'einstalldocs' part
134 +# of the default) in the original working directory.
135 +out-of-source_src_install() {
136 + debug-print-function ${FUNCNAME} "$@"
137 +
138 + pushd "${BUILD_DIR}" >/dev/null || die
139 + if declare -f my_src_install >/dev/null ; then
140 + my_src_install
141 + else
142 + if [[ -f Makefile || -f GNUmakefile || -f makefile ]] ; then
143 + emake DESTDIR="${D}" install
144 + fi
145 + fi
146 + popd >/dev/null || die
147 +
148 + if declare -f my_src_install_all >/dev/null ; then
149 + my_src_install_all
150 + else
151 + einstalldocs
152 + fi
153 +}
154 +
155 +_OUT_OF_SOURCE_ECLASS=1
156 +fi
157 --
158 2.15.0

Replies