| 1 |
vapier |
1.8 |
# Copyright 1999-2011 Gentoo Foundation
|
| 2 |
ciaranm |
1.1 |
# Distributed under the terms of the GNU General Public License v2
|
| 3 |
scarabeus |
1.9 |
# $Header: /var/cvsroot/gentoo-x86/eclass/check-reqs.eclass,v 1.8 2011/08/22 04:46:31 vapier Exp $
|
| 4 |
zlin |
1.6 |
|
| 5 |
|
|
# @ECLASS: check-reqs.eclass
|
| 6 |
|
|
# @MAINTAINER:
|
| 7 |
scarabeus |
1.9 |
# QA Team <qa@gentoo.org>
|
| 8 |
|
|
# @AUTHOR:
|
| 9 |
zlin |
1.6 |
# Bo Ørsted Andresen <zlin@gentoo.org>
|
| 10 |
ciaranm |
1.1 |
# Original Author: Ciaran McCreesh <ciaranm@gentoo.org>
|
| 11 |
zlin |
1.6 |
# @BLURB: Provides a uniform way of handling ebuild which have very high build requirements
|
| 12 |
|
|
# @DESCRIPTION:
|
| 13 |
ciaranm |
1.1 |
# This eclass provides a uniform way of handling ebuilds which have very high
|
| 14 |
zlin |
1.6 |
# build requirements in terms of memory or disk space. It provides a function
|
| 15 |
ciaranm |
1.1 |
# which should usually be called during pkg_setup().
|
| 16 |
|
|
#
|
| 17 |
|
|
# The chosen action only happens when the system's resources are detected
|
| 18 |
|
|
# correctly and only if they are below the threshold specified by the package.
|
| 19 |
|
|
#
|
| 20 |
zlin |
1.6 |
# @CODE
|
| 21 |
scarabeus |
1.9 |
# # need this much memory (does *not* check swap)
|
| 22 |
|
|
# CHECKREQS_MEMORY="256M"
|
| 23 |
ciaranm |
1.1 |
#
|
| 24 |
scarabeus |
1.9 |
# # need this much temporary build space
|
| 25 |
|
|
# CHECKREQS_DISK_BUILD="2G"
|
| 26 |
ciaranm |
1.1 |
#
|
| 27 |
scarabeus |
1.9 |
# # install will need this much space in /usr
|
| 28 |
|
|
# CHECKREQS_DISK_USR="1G"
|
| 29 |
ciaranm |
1.1 |
#
|
| 30 |
scarabeus |
1.9 |
# # install will need this much space in /var
|
| 31 |
|
|
# CHECKREQS_DISK_VAR="1024M"
|
| 32 |
ciaranm |
1.1 |
#
|
| 33 |
zlin |
1.6 |
# @CODE
|
| 34 |
ciaranm |
1.1 |
#
|
| 35 |
ciaranm |
1.2 |
# If you don't specify a value for, say, CHECKREQS_MEMORY, then the test is not
|
| 36 |
ciaranm |
1.1 |
# carried out.
|
| 37 |
|
|
#
|
| 38 |
|
|
# These checks should probably mostly work on non-Linux, and they should
|
| 39 |
|
|
# probably degrade gracefully if they don't. Probably.
|
| 40 |
|
|
|
| 41 |
|
|
inherit eutils
|
| 42 |
|
|
|
| 43 |
zlin |
1.6 |
# @ECLASS-VARIABLE: CHECKREQS_MEMORY
|
| 44 |
scarabeus |
1.9 |
# @DEFAULT_UNSET
|
| 45 |
zlin |
1.6 |
# @DESCRIPTION:
|
| 46 |
scarabeus |
1.9 |
# How much RAM is needed? Eg.: CHECKREQS_MEMORY=15M
|
| 47 |
zlin |
1.6 |
|
| 48 |
|
|
# @ECLASS-VARIABLE: CHECKREQS_DISK_BUILD
|
| 49 |
scarabeus |
1.9 |
# @DEFAULT_UNSET
|
| 50 |
zlin |
1.6 |
# @DESCRIPTION:
|
| 51 |
scarabeus |
1.9 |
# How much diskspace is needed to build the package? Eg.: CHECKREQS_DISK_BUILD=2T
|
| 52 |
zlin |
1.6 |
|
| 53 |
|
|
# @ECLASS-VARIABLE: CHECKREQS_DISK_USR
|
| 54 |
scarabeus |
1.9 |
# @DEFAULT_UNSET
|
| 55 |
zlin |
1.6 |
# @DESCRIPTION:
|
| 56 |
scarabeus |
1.9 |
# How much space in /usr is needed to install the package? Eg.: CHECKREQS_DISK_USR=15G
|
| 57 |
zlin |
1.6 |
|
| 58 |
|
|
# @ECLASS-VARIABLE: CHECKREQS_DISK_VAR
|
| 59 |
scarabeus |
1.9 |
# @DEFAULT_UNSET
|
| 60 |
zlin |
1.6 |
# @DESCRIPTION:
|
| 61 |
scarabeus |
1.9 |
# How much space is needed in /var? Eg.: CHECKREQS_DISK_VAR=3000M
|
| 62 |
|
|
|
| 63 |
|
|
EXPORT_FUNCTIONS pkg_setup
|
| 64 |
|
|
case "${EAPI:-0}" in
|
| 65 |
|
|
0|1|2|3) ;;
|
| 66 |
|
|
4) EXPORT_FUNCTIONS pkg_pretend ;;
|
| 67 |
|
|
*) die "EAPI=${EAPI} is not supported" ;;
|
| 68 |
|
|
esac
|
| 69 |
zlin |
1.6 |
|
| 70 |
|
|
# @FUNCTION: check_reqs
|
| 71 |
|
|
# @DESCRIPTION:
|
| 72 |
scarabeus |
1.9 |
# Obsolete function executing all the checks and priting out results
|
| 73 |
ciaranm |
1.1 |
check_reqs() {
|
| 74 |
scarabeus |
1.9 |
debug-print-function ${FUNCNAME} "$@"
|
| 75 |
|
|
|
| 76 |
|
|
echo
|
| 77 |
|
|
ewarn "QA: Package calling old ${FUNCNAME} function."
|
| 78 |
|
|
ewarn "QA: Please file a bug against the package."
|
| 79 |
|
|
ewarn "QA: It should call check-reqs_pkg_pretend and check-reqs_pkg_setup"
|
| 80 |
|
|
ewarn "QA: and possibly use EAPI=4 or later."
|
| 81 |
|
|
echo
|
| 82 |
|
|
|
| 83 |
|
|
check-reqs_pkg_setup "$@"
|
| 84 |
|
|
}
|
| 85 |
|
|
|
| 86 |
|
|
# @FUNCTION: check-reqs_pkg_setup
|
| 87 |
|
|
# @DESCRIPTION:
|
| 88 |
|
|
# Exported function running the resources checks in pkg_setup phase.
|
| 89 |
|
|
# It should be run in both phases to ensure condition changes between
|
| 90 |
|
|
# pkg_pretend and pkg_setup won't affect the build.
|
| 91 |
|
|
check-reqs_pkg_setup() {
|
| 92 |
|
|
debug-print-function ${FUNCNAME} "$@"
|
| 93 |
|
|
|
| 94 |
|
|
check-reqs_prepare
|
| 95 |
|
|
check-reqs_run
|
| 96 |
|
|
check-reqs_output
|
| 97 |
|
|
}
|
| 98 |
ciaranm |
1.1 |
|
| 99 |
scarabeus |
1.9 |
# @FUNCTION: check-reqs_pkg_pretend
|
| 100 |
|
|
# @DESCRIPTION:
|
| 101 |
|
|
# Exported function running the resources checks in pkg_pretend phase.
|
| 102 |
|
|
check-reqs_pkg_pretend() {
|
| 103 |
|
|
debug-print-function ${FUNCNAME} "$@"
|
| 104 |
|
|
|
| 105 |
|
|
check-reqs_pkg_setup "$@"
|
| 106 |
|
|
}
|
| 107 |
|
|
|
| 108 |
|
|
# @FUNCTION: check-reqs_prepare
|
| 109 |
|
|
# @DESCRIPTION:
|
| 110 |
|
|
# Internal function that checks the variables that should be defined.
|
| 111 |
|
|
check-reqs_prepare() {
|
| 112 |
|
|
debug-print-function ${FUNCNAME} "$@"
|
| 113 |
|
|
|
| 114 |
|
|
if [[ -z ${CHECKREQS_MEMORY} &&
|
| 115 |
|
|
-z ${CHECKREQS_DISK_BUILD} &&
|
| 116 |
|
|
-z ${CHECKREQS_DISK_USR} &&
|
| 117 |
|
|
-z ${CHECKREQS_DISK_VAR} ]]; then
|
| 118 |
|
|
eerror "Set some check-reqs eclass variables if you want to use it."
|
| 119 |
|
|
eerror "If you are user and see this message file a bug against the package."
|
| 120 |
|
|
die "${FUNCNAME}: check-reqs eclass called but not actualy used!"
|
| 121 |
ciaranm |
1.1 |
fi
|
| 122 |
scarabeus |
1.9 |
}
|
| 123 |
ciaranm |
1.1 |
|
| 124 |
scarabeus |
1.9 |
# @FUNCTION: check-reqs_run
|
| 125 |
|
|
# @DESCRIPTION:
|
| 126 |
|
|
# Internal function that runs the check based on variable settings.
|
| 127 |
|
|
check-reqs_run() {
|
| 128 |
|
|
debug-print-function ${FUNCNAME} "$@"
|
| 129 |
|
|
|
| 130 |
|
|
# some people are *censored*
|
| 131 |
|
|
unset CHECKREQS_FAILED
|
| 132 |
|
|
|
| 133 |
|
|
[[ -n ${CHECKREQS_MEMORY} ]] && \
|
| 134 |
|
|
check-reqs_memory \
|
| 135 |
|
|
${CHECKREQS_MEMORY}
|
| 136 |
|
|
|
| 137 |
|
|
[[ -n ${CHECKREQS_DISK_BUILD} ]] && \
|
| 138 |
|
|
check-reqs_disk \
|
| 139 |
|
|
"${T}" \
|
| 140 |
|
|
"${CHECKREQS_DISK_BUILD}"
|
| 141 |
|
|
|
| 142 |
|
|
[[ -n ${CHECKREQS_DISK_USR} ]] && \
|
| 143 |
|
|
check-reqs_disk \
|
| 144 |
|
|
"${EROOT}/usr" \
|
| 145 |
|
|
"${CHECKREQS_DISK_USR}"
|
| 146 |
|
|
|
| 147 |
|
|
[[ -n ${CHECKREQS_DISK_VAR} ]] && \
|
| 148 |
|
|
check-reqs_disk \
|
| 149 |
|
|
"${EROOT}/var" \
|
| 150 |
|
|
"${CHECKREQS_DISK_VAR}"
|
| 151 |
|
|
}
|
| 152 |
|
|
|
| 153 |
|
|
# @FUNCTION: check-reqs_get_mebibytes
|
| 154 |
|
|
# @DESCRIPTION:
|
| 155 |
|
|
# Internal function that returns number in mebibytes.
|
| 156 |
|
|
# Converts from 1G=1024 or 1T=1048576
|
| 157 |
|
|
check-reqs_get_mebibytes() {
|
| 158 |
|
|
debug-print-function ${FUNCNAME} "$@"
|
| 159 |
|
|
|
| 160 |
|
|
[[ -z ${1} ]] && die "Usage: ${FUNCNAME} [size]"
|
| 161 |
|
|
|
| 162 |
|
|
local unit=${1:(-1)}
|
| 163 |
|
|
local size=${1%[GMT]}
|
| 164 |
|
|
|
| 165 |
|
|
case ${unit} in
|
| 166 |
|
|
G) echo $((1024 * size)) ;;
|
| 167 |
|
|
[M0-9]) echo ${size} ;;
|
| 168 |
|
|
T) echo $((1024 * 1024 * size)) ;;
|
| 169 |
|
|
*)
|
| 170 |
|
|
die "${FUNCNAME}: Unknown unit: ${unit}"
|
| 171 |
|
|
;;
|
| 172 |
|
|
esac
|
| 173 |
|
|
}
|
| 174 |
|
|
|
| 175 |
|
|
# @FUNCTION: check-reqs_get_number
|
| 176 |
|
|
# @DESCRIPTION:
|
| 177 |
|
|
# Internal function that returns number without the unit.
|
| 178 |
|
|
# Converts from 1G=1 or 150T=150.
|
| 179 |
|
|
check-reqs_get_number() {
|
| 180 |
|
|
debug-print-function ${FUNCNAME} "$@"
|
| 181 |
|
|
|
| 182 |
|
|
[[ -z ${1} ]] && die "Usage: ${FUNCNAME} [size]"
|
| 183 |
|
|
|
| 184 |
|
|
local unit=${1:(-1)}
|
| 185 |
|
|
local size=${1%[GMT]}
|
| 186 |
|
|
|
| 187 |
|
|
# Check for unset units and warn about them.
|
| 188 |
|
|
# Backcompat.
|
| 189 |
|
|
if [[ ${size} == ${1} ]]; then
|
| 190 |
|
|
ewarn "QA: Package does not specify unit for the size check"
|
| 191 |
|
|
ewarn "QA: Assuming mebibytes."
|
| 192 |
|
|
ewarn "QA: File bug against the package. It should specify the unit."
|
| 193 |
ciaranm |
1.1 |
fi
|
| 194 |
|
|
|
| 195 |
scarabeus |
1.9 |
echo ${size}
|
| 196 |
|
|
}
|
| 197 |
|
|
|
| 198 |
|
|
# @FUNCTION: check-reqs_get_unit
|
| 199 |
|
|
# @DESCRIPTION:
|
| 200 |
|
|
# Internal function that returns number without the unit.
|
| 201 |
|
|
# Converts from 1G=1 or 150T=150.
|
| 202 |
|
|
check-reqs_get_unit() {
|
| 203 |
|
|
debug-print-function ${FUNCNAME} "$@"
|
| 204 |
|
|
|
| 205 |
|
|
[[ -z ${1} ]] && die "Usage: ${FUNCNAME} [size]"
|
| 206 |
|
|
|
| 207 |
|
|
local unit=${1:(-1)}
|
| 208 |
|
|
|
| 209 |
|
|
case ${unit} in
|
| 210 |
|
|
G) echo "gibibytes" ;;
|
| 211 |
|
|
[M0-9]) echo "mebibytes" ;;
|
| 212 |
|
|
T) echo "tebibytes" ;;
|
| 213 |
|
|
*)
|
| 214 |
|
|
die "${FUNCNAME}: Unknown unit: ${unit}"
|
| 215 |
|
|
;;
|
| 216 |
|
|
esac
|
| 217 |
ciaranm |
1.1 |
}
|
| 218 |
|
|
|
| 219 |
scarabeus |
1.9 |
# @FUNCTION: check-reqs_output
|
| 220 |
zlin |
1.6 |
# @DESCRIPTION:
|
| 221 |
scarabeus |
1.9 |
# Internal function that prints the warning and dies if required based on
|
| 222 |
|
|
# the test results.
|
| 223 |
|
|
check-reqs_output() {
|
| 224 |
|
|
debug-print-function ${FUNCNAME} "$@"
|
| 225 |
|
|
|
| 226 |
|
|
local msg="ewarn"
|
| 227 |
|
|
|
| 228 |
|
|
[[ ${EBUILD_PHASE} == "pretend" && -z ${I_KNOW_WHAT_I_AM_DOING} ]] && msg="eerror"
|
| 229 |
|
|
if [[ -n ${CHECKREQS_FAILED} ]]; then
|
| 230 |
|
|
${msg}
|
| 231 |
|
|
${msg} "Space constrains set in the ebuild were not met!"
|
| 232 |
|
|
${msg} "The build will most probably fail, you should enhance the space"
|
| 233 |
|
|
${msg} "as per failed tests."
|
| 234 |
|
|
${msg}
|
| 235 |
ciaranm |
1.5 |
|
| 236 |
scarabeus |
1.9 |
[[ ${EBUILD_PHASE} == "pretend" && -z ${I_KNOW_WHAT_I_AM_DOING} ]] && \
|
| 237 |
|
|
die "Build requirements not met!"
|
| 238 |
ciaranm |
1.5 |
fi
|
| 239 |
scarabeus |
1.9 |
}
|
| 240 |
ciaranm |
1.5 |
|
| 241 |
scarabeus |
1.9 |
# @FUNCTION: check-reqs_memory
|
| 242 |
|
|
# @DESCRIPTION:
|
| 243 |
|
|
# Internal function that checks size of RAM.
|
| 244 |
|
|
check-reqs_memory() {
|
| 245 |
|
|
debug-print-function ${FUNCNAME} "$@"
|
| 246 |
|
|
|
| 247 |
|
|
[[ -z ${1} ]] && die "Usage: ${FUNCNAME} [size]"
|
| 248 |
|
|
|
| 249 |
|
|
local size=${1}
|
| 250 |
|
|
local actual_memory
|
| 251 |
|
|
|
| 252 |
|
|
check-reqs_start_phase \
|
| 253 |
|
|
${size} \
|
| 254 |
|
|
"RAM"
|
| 255 |
ciaranm |
1.5 |
|
| 256 |
zlin |
1.6 |
if [[ -r /proc/meminfo ]] ; then
|
| 257 |
scarabeus |
1.9 |
actual_memory=$(awk '/MemTotal/ { print $2 }' /proc/meminfo)
|
| 258 |
ciaranm |
1.1 |
else
|
| 259 |
|
|
actual_memory=$(sysctl hw.physmem 2>/dev/null )
|
| 260 |
zlin |
1.6 |
[[ "$?" == "0" ]] &&
|
| 261 |
ciaranm |
1.1 |
actual_memory=$(echo $actual_memory | sed -e 's/^[^:=]*[:=]//' )
|
| 262 |
|
|
fi
|
| 263 |
scarabeus |
1.9 |
if [[ -n ${actual_memory} ]] ; then
|
| 264 |
|
|
if [[ ${actual_memory} -lt $((1024 * $(check-reqs_get_mebibytes ${size}))) ]] ; then
|
| 265 |
ciaranm |
1.1 |
eend 1
|
| 266 |
scarabeus |
1.9 |
check-reqs_unsatisfied \
|
| 267 |
|
|
${size} \
|
| 268 |
|
|
"RAM"
|
| 269 |
ciaranm |
1.1 |
else
|
| 270 |
|
|
eend 0
|
| 271 |
|
|
fi
|
| 272 |
|
|
else
|
| 273 |
|
|
eend 1
|
| 274 |
scarabeus |
1.9 |
ewarn "Couldn't determine amount of memory, skipping..."
|
| 275 |
ciaranm |
1.1 |
fi
|
| 276 |
|
|
}
|
| 277 |
|
|
|
| 278 |
scarabeus |
1.9 |
# @FUNCTION: check-reqs_disk
|
| 279 |
|
|
# @DESCRIPTION:
|
| 280 |
|
|
# Internal function that checks space on the harddrive.
|
| 281 |
|
|
check-reqs_disk() {
|
| 282 |
|
|
debug-print-function ${FUNCNAME} "$@"
|
| 283 |
|
|
|
| 284 |
|
|
[[ -z ${2} ]] && die "Usage: ${FUNCNAME} [path] [size]"
|
| 285 |
|
|
|
| 286 |
|
|
local path=${1}
|
| 287 |
|
|
local size=${2}
|
| 288 |
|
|
local space_megs
|
| 289 |
|
|
|
| 290 |
|
|
check-reqs_start_phase \
|
| 291 |
|
|
${size} \
|
| 292 |
|
|
"disk space at \"${path}\""
|
| 293 |
|
|
|
| 294 |
|
|
space_megs=$(df -Pm "${1}" 2>/dev/null | awk 'FNR == 2 {print $4}')
|
| 295 |
|
|
|
| 296 |
|
|
if [[ $? == 0 && -n ${space_megs} ]] ; then
|
| 297 |
|
|
if [[ ${space_megs} -lt $(check-reqs_get_mebibytes ${size}) ]] ; then
|
| 298 |
ciaranm |
1.1 |
eend 1
|
| 299 |
scarabeus |
1.9 |
check-reqs_unsatisfied \
|
| 300 |
|
|
${size} \
|
| 301 |
|
|
"disk space at \"${path}\""
|
| 302 |
ciaranm |
1.1 |
else
|
| 303 |
|
|
eend 0
|
| 304 |
|
|
fi
|
| 305 |
|
|
else
|
| 306 |
|
|
eend 1
|
| 307 |
scarabeus |
1.9 |
ewarn "Couldn't determine disk space, skipping..."
|
| 308 |
ciaranm |
1.1 |
fi
|
| 309 |
|
|
}
|
| 310 |
|
|
|
| 311 |
scarabeus |
1.9 |
# @FUNCTION: check-reqs_start_phase
|
| 312 |
|
|
# @DESCRIPTION:
|
| 313 |
|
|
# Internal function that inform about started check
|
| 314 |
|
|
check-reqs_start_phase() {
|
| 315 |
|
|
debug-print-function ${FUNCNAME} "$@"
|
| 316 |
|
|
|
| 317 |
|
|
[[ -z ${2} ]] && die "Usage: ${FUNCNAME} [size] [location]"
|
| 318 |
|
|
|
| 319 |
|
|
local size=${1}
|
| 320 |
|
|
local location=${2}
|
| 321 |
|
|
local sizeunit="$(check-reqs_get_number ${size}) $(check-reqs_get_unit ${size})"
|
| 322 |
ciaranm |
1.1 |
|
| 323 |
scarabeus |
1.9 |
ebegin "Checking for at least ${sizeunit} ${location}"
|
| 324 |
ciaranm |
1.1 |
}
|
| 325 |
|
|
|
| 326 |
scarabeus |
1.9 |
# @FUNCTION: check-reqs_unsatisfied
|
| 327 |
|
|
# @DESCRIPTION:
|
| 328 |
|
|
# Internal function that inform about check result.
|
| 329 |
|
|
# It has different output between pretend and setup phase,
|
| 330 |
|
|
# where in pretend phase it is fatal.
|
| 331 |
|
|
check-reqs_unsatisfied() {
|
| 332 |
|
|
debug-print-function ${FUNCNAME} "$@"
|
| 333 |
|
|
|
| 334 |
|
|
[[ -z ${2} ]] && die "Usage: ${FUNCNAME} [size] [location]"
|
| 335 |
|
|
|
| 336 |
|
|
local msg="ewarn"
|
| 337 |
|
|
local size=${1}
|
| 338 |
|
|
local location=${2}
|
| 339 |
|
|
local sizeunit="$(check-reqs_get_number ${size}) $(check-reqs_get_unit ${size})"
|
| 340 |
|
|
|
| 341 |
|
|
[[ ${EBUILD_PHASE} == "pretend" && -z ${I_KNOW_WHAT_I_AM_DOING} ]] && msg="eerror"
|
| 342 |
|
|
${msg} "Don't have at least ${sizeunit} ${location}"
|
| 343 |
|
|
|
| 344 |
|
|
# @ECLASS-VARIABLE: CHECKREQS_FAILED
|
| 345 |
|
|
# @DESCRIPTION:
|
| 346 |
|
|
# @INTERNAL
|
| 347 |
|
|
# If set the checks failed and eclass should abort the build.
|
| 348 |
|
|
# Internal, do not set yourself.
|
| 349 |
|
|
CHECKREQS_FAILED="true"
|
| 350 |
ciaranm |
1.1 |
}
|
| 351 |
|
|
|