Gentoo Archives: gentoo-dev

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

Attachments

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

Replies