/[gentoo-x86]/eclass/scons-utils.eclass
Gentoo

Contents of /eclass/scons-utils.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show annotations) (download)
Mon Feb 7 14:55:08 2011 UTC (3 years, 6 months ago) by mgorny
Branch: MAIN
Changes since 1.2: +3 -3 lines
Translate --jobs with no count to safer --jobs=5.

Value-less --jobs is mostly used along with --load-average, which is not supported by SCons. Thus, we should use a safe number of jobs.

1 # Copyright 1999-2010 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /var/cvsroot/gentoo-x86/eclass/scons-utils.eclass,v 1.2 2010/10/27 18:23:58 mgorny Exp $
4
5 # @ECLASS: scons-utils.eclass
6 # @MAINTAINER:
7 # mgorny@gentoo.org
8 # @BLURB: helper functions to deal with SCons buildsystem
9 # @DESCRIPTION:
10 # This eclass provides a set of function to help developers sanely call
11 # dev-util/scons and pass parameters to it.
12 # @EXAMPLE:
13 #
14 # @CODE
15 # inherit scons-utils toolchain-funcs
16 #
17 # src_compile() {
18 # tc-export CC CXX
19 # escons \
20 # $(use_scons nls ENABLE_NLS) \
21 # || die
22 # }
23 # @CODE
24
25 # -- public variables --
26
27 # @ECLASS-VARIABLE: SCONS_MIN_VERSION
28 # @DEFAULT_UNSET
29 # @DESCRIPTION:
30 # The minimal version of SCons required for the build to work.
31
32 # @ECLASS-VARIABLE: SCONSOPTS
33 # @DEFAULT_UNSET
34 # @DESCRIPTION:
35 # The default set of options to pass to scons. Similar to MAKEOPTS,
36 # supposed to be set in make.conf. If unset, escons() will use cleaned
37 # up MAKEOPTS instead.
38
39 # @ECLASS-VARIABLE: EXTRA_ESCONS
40 # @DEFAULT_UNSET
41 # @DESCRIPTION:
42 # The additional parameters to pass to SCons whenever escons() is used.
43
44 # @ECLASS-VARIABLE: USE_SCONS_TRUE
45 # @DESCRIPTION:
46 # The default value for truth in scons-use() (1 by default).
47 : ${USE_SCONS_TRUE:=1}
48
49 # @ECLASS-VARIABLE: USE_SCONS_FALSE
50 # @DESCRIPTION:
51 # The default value for false in scons-use() (0 by default).
52 : ${USE_SCONS_FALSE:=0}
53
54 # -- ebuild variables setup --
55
56 if [[ -n ${SCONS_MIN_VERSION} ]]; then
57 DEPEND=">=dev-util/scons-${SCONS_MIN_VERSION}"
58 else
59 DEPEND="dev-util/scons"
60 fi
61
62 # -- public functions --
63
64 # @FUNCTION: escons
65 # @USAGE: [scons-arg] ...
66 # @DESCRIPTION:
67 # Call scons, passing the supplied arguments, ${MAKEOPTS} and
68 # ${EXTRA_ESCONS}. Similar to emake.
69 escons() {
70 debug-print-function ${FUNCNAME} "${@}"
71
72 # if SCONSOPTS are _unset_, use cleaned MAKEOPTS
73 set -- scons ${SCONSOPTS-$(scons_clean_makeopts)} ${EXTRA_ESCONS} "${@}"
74 echo "${@}" >&2
75 "${@}"
76 }
77
78 # @FUNCTION: scons_clean_makeopts
79 # @USAGE: [makeflags] [...]
80 # @DESCRIPTION:
81 # Strip the supplied makeflags (or ${MAKEOPTS} if called without
82 # an argument) of options not supported by SCons and make sure --jobs
83 # gets an argument. Output the resulting flag list (suitable
84 # for an assignment to SCONSOPTS).
85 scons_clean_makeopts() {
86 local new_makeopts
87
88 debug-print-function ${FUNCNAME} "${@}"
89
90 if [[ ${#} -eq 0 ]]; then
91 debug-print "Using MAKEOPTS: [${MAKEOPTS}]"
92 set -- ${MAKEOPTS}
93 else
94 # unquote if necessary
95 set -- ${*}
96 fi
97
98 # empty MAKEOPTS give out empty SCONSOPTS
99 # thus, we do need to worry about the initial setup
100 if [[ ${*} = ${_SCONS_CACHE_MAKEOPTS} ]]; then
101 set -- ${_SCONS_CACHE_SCONSOPTS}
102 debug-print "Cache hit: [${*}]"
103 echo ${*}
104 return
105 fi
106 export _SCONS_CACHE_MAKEOPTS=${*}
107
108 while [[ ${#} -gt 0 ]]; do
109 case ${1} in
110 # clean, simple to check -- we like that
111 --jobs=*|--keep-going)
112 new_makeopts=${new_makeopts+${new_makeopts} }${1}
113 ;;
114 # need to take a look at the next arg and guess
115 --jobs)
116 if [[ ${#} -gt 1 && ${2} =~ [0-9]+ ]]; then
117 new_makeopts="${new_makeopts+${new_makeopts} }${1} ${2}"
118 shift
119 else
120 # no value means no limit, let's pass a random int
121 new_makeopts=${new_makeopts+${new_makeopts} }${1}=5
122 fi
123 ;;
124 # strip other long options
125 --*)
126 ;;
127 # short option hell
128 -*)
129 local str new_optstr
130 new_optstr=
131 str=${1#-}
132
133 while [[ -n ${str} ]]; do
134 case ${str} in
135 k*)
136 new_optstr=${new_optstr}k
137 ;;
138 # -j needs to come last
139 j)
140 if [[ ${#} -gt 1 && ${2} =~ [0-9]+ ]]; then
141 new_optstr="${new_optstr}j ${2}"
142 shift
143 else
144 new_optstr="${new_optstr}j 5"
145 fi
146 ;;
147 # otherwise, everything after -j is treated as an arg
148 j*)
149 new_optstr=${new_optstr}${str}
150 break
151 ;;
152 esac
153 str=${str#?}
154 done
155
156 if [[ -n ${new_optstr} ]]; then
157 new_makeopts=${new_makeopts+${new_makeopts} }-${new_optstr}
158 fi
159 ;;
160 esac
161 shift
162 done
163
164 set -- ${new_makeopts}
165 export _SCONS_CACHE_SCONSOPTS=${*}
166 debug-print "New SCONSOPTS: [${*}]"
167 echo ${*}
168 }
169
170 # @FUNCTION: use_scons
171 # @USAGE: <use-flag> [var-name] [var-opt-true] [var-opt-false]
172 # @DESCRIPTION:
173 # Output a SCons parameter with value depending on the USE flag state.
174 # If the USE flag is set, output <var-name>=<var-opt-true>; otherwise
175 # <var-name>=<var-opt-false>.
176 #
177 # If <var-name> is omitted, <use-flag> will be used instead. However,
178 # if <use-flag> starts with an exclamation mark (!flag), 'no' will be
179 # prepended to the name (e.g. noflag).
180 #
181 # If <var-opt-true> and/or <var-opt-false> are omitted,
182 # ${USE_SCONS_TRUE} and/or ${USE_SCONS_FALSE} will be used instead.
183 use_scons() {
184 local flag=${1}
185 local varname=${2:-${flag/\!/no}}
186 local vartrue=${3:-${USE_SCONS_TRUE}}
187 local varfalse=${4:-${USE_SCONS_FALSE}}
188
189 debug-print-function ${FUNCNAME} "${@}"
190
191 if [[ ${#} -eq 0 ]]; then
192 eerror "Usage: scons-use <use-flag> [var-name] [var-opt-true] [var-opt-false]"
193 die 'scons-use(): not enough arguments'
194 fi
195
196 if use "${flag}"; then
197 echo "${varname}=${vartrue}"
198 else
199 echo "${varname}=${varfalse}"
200 fi
201 }

  ViewVC Help
Powered by ViewVC 1.1.20