/[gentoo-x86]/eclass/check-reqs.eclass
Gentoo

Diff of /eclass/check-reqs.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.1 Revision 1.2
1# Copyright 1999-2004 Gentoo Foundation 1# Copyright 1999-2004 Gentoo Foundation
2# Distributed under the terms of the GNU General Public License v2 2# Distributed under the terms of the GNU General Public License v2
3# $Header: /var/cvsroot/gentoo-x86/eclass/check-reqs.eclass,v 1.1 2004/11/19 20:57:31 ciaranm Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/check-reqs.eclass,v 1.2 2004/11/21 15:11:50 ciaranm Exp $
4# 4#
5# Original Author: Ciaran McCreesh <ciaranm@gentoo.org> 5# Original Author: Ciaran McCreesh <ciaranm@gentoo.org>
6# 6#
7# This eclass provides a uniform way of handling ebuilds which have very high 7# This eclass provides a uniform way of handling ebuilds which have very high
8# build requirements in terms of memory or disc space. It provides a function 8# build requirements in terms of memory or disc space. It provides a function
9# which should usually be called during pkg_setup(). 9# which should usually be called during pkg_setup().
10# 10#
11# From a user perspective, the variable BUILDREQS_ACTION can be set to: 11# From a user perspective, the variable CHECKREQS_ACTION can be set to:
12# * "warn" (default), which will display a warning and wait for 15s 12# * "warn" (default), which will display a warning and wait for 15s
13# * "error", which will make the ebuild error out 13# * "error", which will make the ebuild error out
14# * "ignore", which will not take any action 14# * "ignore", which will not take any action
15# The chosen action only happens when the system's resources are detected 15# The chosen action only happens when the system's resources are detected
16# correctly and only if they are below the threshold specified by the package. 16# correctly and only if they are below the threshold specified by the package.
22# 22#
23# pkg_setup() { 23# pkg_setup() {
24# # values in MBytes 24# # values in MBytes
25# 25#
26# # need this much memory (does *not* check swap) 26# # need this much memory (does *not* check swap)
27# BUILDREQS_MEMORY="256" 27# CHECKREQS_MEMORY="256"
28# 28#
29# # need this much temporary build space 29# # need this much temporary build space
30# BUILDREQS_DISK_BUILD="2048" 30# CHECKREQS_DISK_BUILD="2048"
31# 31#
32# # install will need this much space in /usr 32# # install will need this much space in /usr
33# BUILDREQS_DISK_USR="1024" 33# CHECKREQS_DISK_USR="1024"
34# 34#
35# # install will need this much space in /var 35# # install will need this much space in /var
36# BUILDREQS_DISK_VAR="1024" 36# CHECKREQS_DISK_VAR="1024"
37# 37#
38# # go! 38# # go!
39# check_reqs 39# check_reqs
40# } 40# }
41# 41#
42# You should *not* override the user's BUILDREQS_ACTION setting, nor should you 42# You should *not* override the user's CHECKREQS_ACTION setting, nor should you
43# attempt to provide a value if it is unset. Note that the environment variables 43# attempt to provide a value if it is unset. Note that the environment variables
44# are used rather than parameters for a few reasons: 44# are used rather than parameters for a few reasons:
45# * easier to do if use blah ; then things 45# * easier to do if use blah ; then things
46# * we might add in additional requirements things later 46# * we might add in additional requirements things later
47# If you don't specify a value for, say, BUILDREQS_MEMORY, then the test is not 47# If you don't specify a value for, say, CHECKREQS_MEMORY, then the test is not
48# carried out. 48# carried out.
49# 49#
50# These checks should probably mostly work on non-Linux, and they should 50# These checks should probably mostly work on non-Linux, and they should
51# probably degrade gracefully if they don't. Probably. 51# probably degrade gracefully if they don't. Probably.
52 52
56INHERITED="$INHERITED $ECLASS" 56INHERITED="$INHERITED $ECLASS"
57 57
58check_reqs() { 58check_reqs() {
59 [ -n "$1" ] && die "Usage: check_reqs" 59 [ -n "$1" ] && die "Usage: check_reqs"
60 60
61 export BUILDREQS_NEED_SLEEP="" BUILDREQS_NEED_DIE="" 61 export CHECKREQS_NEED_SLEEP="" CHECKREQS_NEED_DIE=""
62 if [ "$BUILDREQS_ACTION" != "ignore" ] ; then 62 if [ "$CHECKREQS_ACTION" != "ignore" ] ; then
63 [ -n "$BUILDREQS_MEMORY" ] && check_build_memory 63 [ -n "$CHECKREQS_MEMORY" ] && check_build_memory
64 [ -n "$BUILDREQS_DISK_BUILD" ] && check_build_disk \ 64 [ -n "$CHECKREQS_DISK_BUILD" ] && check_build_disk \
65 "${PORTAGE_TMPDIR}" "\${PORTAGE_TMPDIR}" "${BUILDREQS_DISK_BUILD}" 65 "${PORTAGE_TMPDIR}" "\${PORTAGE_TMPDIR}" "${CHECKREQS_DISK_BUILD}"
66 [ -n "$BUILDREQS_DISK_USR" ] && check_build_disk \ 66 [ -n "$CHECKREQS_DISK_USR" ] && check_build_disk \
67 "${ROOT}/usr" "\${ROOT}/usr" "${BUILDREQS_DISK_USR}" 67 "${ROOT}/usr" "\${ROOT}/usr" "${CHECKREQS_DISK_USR}"
68 [ -n "$BUILDREQS_DISK_VAR" ] && check_build_disk \ 68 [ -n "$CHECKREQS_DISK_VAR" ] && check_build_disk \
69 "${ROOT}/var" "\${ROOT}/var" "${BUILDREQS_DISK_VAR}" 69 "${ROOT}/var" "\${ROOT}/var" "${CHECKREQS_DISK_VAR}"
70 fi 70 fi
71 71
72 if [ -n "${BUILDREQS_NEED_SLEEP}" ] ; then 72 if [ -n "${CHECKREQS_NEED_SLEEP}" ] ; then
73 echo 73 echo
74 ewarn "Bad things may happen! You may abort the build by pressing ctrl+c in" 74 ewarn "Bad things may happen! You may abort the build by pressing ctrl+c in"
75 ewarn "the next 15 seconds." 75 ewarn "the next 15 seconds."
76 ewarn " " 76 ewarn " "
77 einfo "To make this kind of warning a fatal error, add a line to /etc/make.conf" 77 einfo "To make this kind of warning a fatal error, add a line to /etc/make.conf"
78 einfo "setting BUILDREQS_ACTION=\"error\". To skip build requirements checking," 78 einfo "setting CHECKREQS_ACTION=\"error\". To skip build requirements checking,"
79 einfo "set BUILDREQS_ACTION=\"ignore\"." 79 einfo "set CHECKREQS_ACTION=\"ignore\"."
80 epause 15 80 epause 15
81 fi 81 fi
82 82
83 if [ -n "${BUILDREQS_NEED_DIE}" ] ; then 83 if [ -n "${CHECKREQS_NEED_DIE}" ] ; then
84 eerror "Bailing out as specified by BUILDREQS_ACTION" 84 eerror "Bailing out as specified by CHECKREQS_ACTION"
85 die "Build requirements not met" 85 die "Build requirements not met"
86 fi 86 fi
87} 87}
88 88
89# internal use only! 89# internal use only!
90check_build_memory() { 90check_build_memory() {
91 [ -n "$1" ] && die "Usage: check_build_memory" 91 [ -n "$1" ] && die "Usage: check_build_memory"
92 check_build_msg_begin "${BUILDREQS_MEMORY}" "MBytes" "RAM" 92 check_build_msg_begin "${CHECKREQS_MEMORY}" "MBytes" "RAM"
93 if [ -r /proc/meminfo ] ; then 93 if [ -r /proc/meminfo ] ; then
94 actual_memory=$(sed -n -e '/MemTotal:/s/^[^:]*: *\([0-9]\+\) kB/\1/p' \ 94 actual_memory=$(sed -n -e '/MemTotal:/s/^[^:]*: *\([0-9]\+\) kB/\1/p' \
95 /proc/meminfo) 95 /proc/meminfo)
96 else 96 else
97 actual_memory=$(sysctl hw.physmem 2>/dev/null ) 97 actual_memory=$(sysctl hw.physmem 2>/dev/null )
98 [ "$?" == "0" ] && 98 [ "$?" == "0" ] &&
99 actual_memory=$(echo $actual_memory | sed -e 's/^[^:=]*[:=]//' ) 99 actual_memory=$(echo $actual_memory | sed -e 's/^[^:=]*[:=]//' )
100 fi 100 fi
101 if [ -n "${actual_memory}" ] ; then 101 if [ -n "${actual_memory}" ] ; then
102 if [ ${actual_memory} -lt $((1024 * ${BUILDREQS_MEMORY})) ] ; then 102 if [ ${actual_memory} -lt $((1024 * ${CHECKREQS_MEMORY})) ] ; then
103 eend 1 103 eend 1
104 check_build_msg_ick "${BUILDREQS_MEMORY}" "MBytes" "RAM" 104 check_build_msg_ick "${CHECKREQS_MEMORY}" "MBytes" "RAM"
105 else 105 else
106 eend 0 106 eend 0
107 fi 107 fi
108 else 108 else
109 eend 1 109 eend 1
142 ewarn "Skipping check for at least ${1}${2} ${3}" 142 ewarn "Skipping check for at least ${1}${2} ${3}"
143} 143}
144 144
145# internal use only! 145# internal use only!
146check_build_msg_ick() { 146check_build_msg_ick() {
147 if [ "${BUILDREQS_ACTION}" == "error" ] ; then 147 if [ "${CHECKREQS_ACTION}" == "error" ] ; then
148 eerror "Don't have at least ${1}${2} ${3}" 148 eerror "Don't have at least ${1}${2} ${3}"
149 echo 149 echo
150 export BUILDREQS_NEED_DIE="yes" 150 export CHECKREQS_NEED_DIE="yes"
151 else 151 else
152 ewarn "Don't have at least ${1}${2} ${3}" 152 ewarn "Don't have at least ${1}${2} ${3}"
153 echo 153 echo
154 export BUILDREQS_NEED_SLEEP="yes" 154 export CHECKREQS_NEED_SLEEP="yes"
155 fi 155 fi
156} 156}
157 157

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

  ViewVC Help
Powered by ViewVC 1.1.20