Gentoo Archives: gentoo-dev

From: Andreas Sturmlechner <asturm@g.o>
To: gentoo-dev@l.g.o
Subject: [gentoo-dev] [PATCH v2 1/4] cmake.eclass: Support EAPI-8
Date: Wed, 01 Sep 2021 17:58:51
Message-Id: 4471705.vXUDI8C0e8@tuxbrain
1 Move supported EAPI check on top, EXPORT_FUNCTIONS below guard.
2
3 Switch to using current working directory instead of ${S}
4 when initializing ${CMAKE_USE_DIR} and ${BUILD_DIR}.
5
6 Sort inherits.
7
8 Raise baseline cmake version to 3.20.5.
9
10 Bug: https://bugs.gentoo.org/704524
11 Thanks-to: Arfrever Frehtes Taifersar Arahesis <Arfrever@××××××.Org>
12 Signed-off-by: Andreas Sturmlechner <asturm@g.o>
13 ---
14 eclass/cmake.eclass | 95 +++++++++++++++++++++++++++++----------------
15 1 file changed, 62 insertions(+), 33 deletions(-)
16
17 diff --git a/eclass/cmake.eclass b/eclass/cmake.eclass
18 index 4bd09459ea6..137dbc66017 100644
19 --- a/eclass/cmake.eclass
20 +++ b/eclass/cmake.eclass
21 @@ -9,7 +9,7 @@
22 # Maciej Mrozowski <reavertm@g.o>
23 # (undisclosed contributors)
24 # Original author: Zephyrus (zephyrus@××××××.it)
25 -# @SUPPORTED_EAPIS: 7
26 +# @SUPPORTED_EAPIS: 7 8
27 # @BLURB: common ebuild functions for cmake-based packages
28 # @DESCRIPTION:
29 # The cmake eclass makes creating ebuilds for cmake-based packages much easier.
30 @@ -17,16 +17,25 @@
31 # out-of-source builds (default), in-source builds and an implementation of the
32 # well-known use_enable function for CMake.
33
34 +case ${EAPI} in
35 + 7|8) ;;
36 + *) die "${ECLASS}: EAPI=${EAPI:-0} is not supported" ;;
37 +esac
38 +
39 if [[ -z ${_CMAKE_ECLASS} ]]; then
40 _CMAKE_ECLASS=1
41
42 +inherit flag-o-matic multiprocessing ninja-utils toolchain-funcs xdg-utils
43 +
44 # @ECLASS-VARIABLE: BUILD_DIR
45 +# @DEFAULT_UNSET
46 # @DESCRIPTION:
47 # Build directory where all cmake processed files should be generated.
48 # For in-source build it's fixed to ${CMAKE_USE_DIR}.
49 # For out-of-source build it can be overridden, by default it uses
50 -# ${WORKDIR}/${P}_build.
51 -: ${BUILD_DIR:=${WORKDIR}/${P}_build}
52 +# ${CMAKE_USE_DIR}_build (in EAPI-7: ${WORKDIR}/${P}_build).
53 +[[ ${EAPI} == 7 ]] && : ${BUILD_DIR:=${WORKDIR}/${P}_build}
54 +# EAPI-8: set inside _cmake_check_build_dir
55
56 # @ECLASS-VARIABLE: CMAKE_BINARY
57 # @DESCRIPTION:
58 @@ -58,16 +67,16 @@ _CMAKE_ECLASS=1
59
60 # @ECLASS-VARIABLE: CMAKE_REMOVE_MODULES_LIST
61 # @DESCRIPTION:
62 -# Array of CMake modules that will be removed in $S during src_prepare,
63 -# in order to force packages to use the system version.
64 -# Set to "none" to disable removing modules entirely.
65 +# Array of CMake modules that will be removed in ${CMAKE_USE_DIR}
66 +# (in EAPI-7: ${S}) during src_prepare, in order to force packages to use the
67 +# system version. Set to empty to disable removing modules entirely.
68 : ${CMAKE_REMOVE_MODULES_LIST:=FindBLAS FindLAPACK}
69
70 # @ECLASS-VARIABLE: CMAKE_USE_DIR
71 # @DESCRIPTION:
72 # Sets the directory where we are working with cmake, for example when
73 # application uses autotools and only one plugin needs to be done by cmake.
74 -# By default it uses ${S}.
75 +# By default it uses current working directory (in EAPI-7: ${S}).
76
77 # @ECLASS-VARIABLE: CMAKE_VERBOSE
78 # @DESCRIPTION:
79 @@ -93,18 +102,9 @@ _CMAKE_ECLASS=1
80 # @USER_VARIABLE
81 # @DEFAULT_UNSET
82 # @DESCRIPTION:
83 -# After running cmake_src_prepare, sets ${S} to read-only. This is
84 -# a user flag and should under _no circumstances_ be set in the ebuild.
85 -# Helps in improving QA of build systems that write to source tree.
86 -
87 -case ${EAPI} in
88 - 7) ;;
89 - *) die "EAPI=${EAPI:-0} is not supported" ;;
90 -esac
91 -
92 -inherit toolchain-funcs ninja-utils flag-o-matic multiprocessing xdg-utils
93 -
94 -EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install
95 +# After running cmake_src_prepare, sets ${CMAKE_USE_DIR} (in EAPI-7: ${S}) to
96 +# read-only. This is a user flag and should under _no circumstances_ be set in
97 +# the ebuild. Helps in improving QA of build systems that write to source tree.
98
99 [[ ${CMAKE_MIN_VERSION} ]] && die "CMAKE_MIN_VERSION is banned; if necessary, set BDEPEND=\">=dev-util/cmake-${CMAKE_MIN_VERSION}\" directly"
100 [[ ${CMAKE_BUILD_DIR} ]] && die "The ebuild must be migrated to BUILD_DIR"
101 @@ -127,7 +127,7 @@ case ${CMAKE_MAKEFILE_GENERATOR} in
102 esac
103
104 if [[ ${PN} != cmake ]]; then
105 - BDEPEND+=" dev-util/cmake"
106 + BDEPEND+=" >=dev-util/cmake-3.20.5"
107 fi
108
109 # @FUNCTION: cmake_run_in
110 @@ -264,14 +264,22 @@ cmake-utils_useno() { _cmake_banned_func "" "$@" ; }
111 # @DESCRIPTION:
112 # Determine using IN or OUT source build
113 _cmake_check_build_dir() {
114 - : ${CMAKE_USE_DIR:=${S}}
115 + if [[ ${EAPI} == 7 ]]; then
116 + : ${CMAKE_USE_DIR:=${S}}
117 + else
118 + : ${CMAKE_USE_DIR:=${PWD}}
119 + fi
120 if [[ -n ${CMAKE_IN_SOURCE_BUILD} ]]; then
121 # we build in source dir
122 BUILD_DIR="${CMAKE_USE_DIR}"
123 + else
124 + : ${BUILD_DIR:=${CMAKE_USE_DIR}_build}
125 fi
126
127 + einfo "Source directory (CMAKE_USE_DIR): \"${CMAKE_USE_DIR}\""
128 + einfo "Build directory (BUILD_DIR): \"${BUILD_DIR}\""
129 +
130 mkdir -p "${BUILD_DIR}" || die
131 - einfo "Working in BUILD_DIR: \"$BUILD_DIR\""
132 }
133
134 # @FUNCTION: _cmake_modify-cmakelists
135 @@ -320,12 +328,14 @@ _cmake_modify-cmakelists() {
136 cmake_src_prepare() {
137 debug-print-function ${FUNCNAME} "$@"
138
139 - # FIXME: workaround from cmake-utils; use current working directory instead, bug #704524
140 - # esp. test with 'special' pkgs like: app-arch/brotli, media-gfx/gmic, net-libs/quiche
141 - pushd "${S}" > /dev/null || die
142 + if [[ ${EAPI} == 7 ]]; then
143 + pushd "${S}" > /dev/null || die # workaround from cmake-utils
144 + # in EAPI-8, we use current working directory instead, bug #704524
145 + # esp. test with 'special' pkgs like: app-arch/brotli, media-gfx/gmic, net-libs/quiche
146 + fi
147 + _cmake_check_build_dir
148
149 default_src_prepare
150 - _cmake_check_build_dir
151
152 # check if CMakeLists.txt exist and if no then die
153 if [[ ! -e ${CMAKE_USE_DIR}/CMakeLists.txt ]] ; then
154 @@ -351,17 +361,28 @@ cmake_src_prepare() {
155
156 local name
157 for name in "${modules_list[@]}" ; do
158 - find "${S}" -name ${name}.cmake -exec rm -v {} + || die
159 + if [[ ${EAPI} == 7 ]]; then
160 + find "${S}" -name ${name}.cmake -exec rm -v {} + || die
161 + else
162 + find -name "${name}.cmake" -exec rm -v {} + || die
163 + fi
164 done
165
166 # Remove dangerous things.
167 _cmake_modify-cmakelists
168
169 - popd > /dev/null || die
170 + if [[ ${EAPI} == 7 ]]; then
171 + popd > /dev/null || die
172 + fi
173
174 - # make ${S} read-only in order to detect broken build-systems
175 + # Make ${CMAKE_USE_DIR} (in EAPI-7: ${S}) read-only in order to detect
176 + # broken build systems.
177 if [[ ${CMAKE_QA_SRC_DIR_READONLY} && ! ${CMAKE_IN_SOURCE_BUILD} ]]; then
178 - chmod -R a-w "${S}"
179 + if [[ ${EAPI} == 7 ]]; then
180 + chmod -R a-w "${S}"
181 + else
182 + chmod -R a-w "${CMAKE_USE_DIR}"
183 + fi
184 fi
185
186 _CMAKE_SRC_PREPARE_HAS_RUN=1
187 @@ -657,9 +678,17 @@ cmake_src_install() {
188 die "died running ${CMAKE_MAKEFILE_GENERATOR} install"
189 popd > /dev/null || die
190
191 - pushd "${S}" > /dev/null || die
192 - einstalldocs
193 - popd > /dev/null || die
194 + if [[ ${EAPI} == 7 ]]; then
195 + pushd "${S}" > /dev/null || die
196 + einstalldocs
197 + popd > /dev/null || die
198 + else
199 + pushd "${CMAKE_USE_DIR}" > /dev/null || die
200 + einstalldocs
201 + popd > /dev/null || die
202 + fi
203 }
204
205 fi
206 +
207 +EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install
208 --
209 2.33.0

Attachments

File name MIME type
signature.asc application/pgp-signature

Replies