diff options
Diffstat (limited to 'meta/classes/icecc.bbclass')
-rw-r--r-- | meta/classes/icecc.bbclass | 255 |
1 files changed, 255 insertions, 0 deletions
diff --git a/meta/classes/icecc.bbclass b/meta/classes/icecc.bbclass new file mode 100644 index 0000000000..cf3f23d93a --- /dev/null +++ b/meta/classes/icecc.bbclass | |||
@@ -0,0 +1,255 @@ | |||
1 | # IceCream distributed compiling support | ||
2 | # | ||
3 | # Stages directories with symlinks from gcc/g++ to icecc, for both | ||
4 | # native and cross compilers. Depending on each configure or compile, | ||
5 | # the directories are added at the head of the PATH list and ICECC_CXX | ||
6 | # and ICEC_CC are set. | ||
7 | # | ||
8 | # For the cross compiler, creates a tar.gz of our toolchain and sets | ||
9 | # ICECC_VERSION accordingly. | ||
10 | # | ||
11 | #The class now handles all 3 different compile 'stages' (i.e native ,cross-kernel and target) creating the | ||
12 | #necessary environment tar.gz file to be used by the remote machines. | ||
13 | #It also supports meta-toolchain generation | ||
14 | # | ||
15 | #If ICECC_PATH is not set in local.conf then the class will try to locate it using 'which' | ||
16 | #but nothing is sure ;) | ||
17 | # | ||
18 | #If ICECC_ENV_EXEC is set in local.conf should point to the icecc-create-env script provided by the user | ||
19 | #or the default one provided by icecc-create-env.bb will be used | ||
20 | #(NOTE that this is a modified version of the script need it and *not the one that comes with icecc* | ||
21 | # | ||
22 | #User can specify if specific packages or packages belonging to class should not use icecc to distribute | ||
23 | #compile jobs to remote machines, but handled localy, by defining ICECC_USER_CLASS_BL and ICECC_PACKAGE_BL | ||
24 | #with the appropriate values in local.conf | ||
25 | ######################################################################################### | ||
26 | #Error checking is kept to minimum so double check any parameters you pass to the class | ||
27 | ########################################################################################### | ||
28 | |||
29 | BB_HASHBASE_WHITELIST += "ICECC_PARALLEL_MAKE ICECC_DISABLED" | ||
30 | |||
31 | ICECC_ENV_EXEC ?= "${STAGING_BINDIR_NATIVE}/icecc-create-env" | ||
32 | |||
33 | def icecc_dep_prepend(d): | ||
34 | # INHIBIT_DEFAULT_DEPS doesn't apply to the patch command. Whether or not | ||
35 | # we need that built is the responsibility of the patch function / class, not | ||
36 | # the application. | ||
37 | if not d.getVar('INHIBIT_DEFAULT_DEPS'): | ||
38 | return "icecc-create-env-native" | ||
39 | return "" | ||
40 | |||
41 | DEPENDS_prepend += "${@icecc_dep_prepend(d)} " | ||
42 | |||
43 | def get_cross_kernel_cc(bb,d): | ||
44 | kernel_cc = d.expand('${KERNEL_CC}') | ||
45 | kernel_cc = kernel_cc.replace('ccache', '').strip() | ||
46 | kernel_cc = kernel_cc.split(' ')[0] | ||
47 | kernel_cc = kernel_cc.strip() | ||
48 | return kernel_cc | ||
49 | |||
50 | def get_icecc(d): | ||
51 | return d.getVar('ICECC_PATH') or os.popen("which icecc").read()[:-1] | ||
52 | |||
53 | def create_path(compilers, bb, d): | ||
54 | """ | ||
55 | Create Symlinks for the icecc in the staging directory | ||
56 | """ | ||
57 | staging = os.path.join(d.expand('${STAGING_BINDIR}'), "ice") | ||
58 | if icc_is_kernel(bb, d): | ||
59 | staging += "-kernel" | ||
60 | |||
61 | #check if the icecc path is set by the user | ||
62 | icecc = get_icecc(d) | ||
63 | |||
64 | # Create the dir if necessary | ||
65 | try: | ||
66 | os.stat(staging) | ||
67 | except: | ||
68 | try: | ||
69 | os.makedirs(staging) | ||
70 | except: | ||
71 | pass | ||
72 | |||
73 | for compiler in compilers: | ||
74 | gcc_path = os.path.join(staging, compiler) | ||
75 | try: | ||
76 | os.stat(gcc_path) | ||
77 | except: | ||
78 | try: | ||
79 | os.symlink(icecc, gcc_path) | ||
80 | except: | ||
81 | pass | ||
82 | |||
83 | return staging | ||
84 | |||
85 | def use_icc(bb,d): | ||
86 | package_tmp = d.expand('${PN}') | ||
87 | |||
88 | system_class_blacklist = [ "none" ] | ||
89 | user_class_blacklist = (d.getVar('ICECC_USER_CLASS_BL') or "none").split() | ||
90 | package_class_blacklist = system_class_blacklist + user_class_blacklist | ||
91 | |||
92 | for black in package_class_blacklist: | ||
93 | if bb.data.inherits_class(black, d): | ||
94 | #bb.note(package_tmp, ' class ', black, ' found in blacklist, disable icecc') | ||
95 | return "no" | ||
96 | |||
97 | #"system" package blacklist contains a list of packages that can not distribute compile tasks | ||
98 | #for one reason or the other | ||
99 | system_package_blacklist = [ "uclibc", "glibc", "gcc", "bind", "u-boot", "dhcp-forwarder", "enchant", "connman", "orbit2" ] | ||
100 | user_package_blacklist = (d.getVar('ICECC_USER_PACKAGE_BL') or "").split() | ||
101 | package_blacklist = system_package_blacklist + user_package_blacklist | ||
102 | |||
103 | for black in package_blacklist: | ||
104 | if black in package_tmp: | ||
105 | #bb.note(package_tmp, ' found in blacklist, disable icecc') | ||
106 | return "no" | ||
107 | |||
108 | if d.getVar('PARALLEL_MAKE') == "": | ||
109 | bb.note(package_tmp, " ", d.expand('${PV}'), " has empty PARALLEL_MAKE, disable icecc") | ||
110 | return "no" | ||
111 | |||
112 | return "yes" | ||
113 | |||
114 | def icc_is_kernel(bb, d): | ||
115 | return \ | ||
116 | bb.data.inherits_class("kernel", d); | ||
117 | |||
118 | def icc_is_native(bb, d): | ||
119 | return \ | ||
120 | bb.data.inherits_class("cross", d) or \ | ||
121 | bb.data.inherits_class("native", d); | ||
122 | |||
123 | def icc_version(bb, d): | ||
124 | if use_icc(bb, d) == "no": | ||
125 | return "" | ||
126 | |||
127 | parallel = d.getVar('ICECC_PARALLEL_MAKE') or "" | ||
128 | d.setVar("PARALLEL_MAKE", parallel) | ||
129 | |||
130 | if icc_is_native(bb, d): | ||
131 | archive_name = "local-host-env" | ||
132 | elif d.expand('${HOST_PREFIX}') == "": | ||
133 | bb.fatal(d.expand("${PN}"), " NULL prefix") | ||
134 | else: | ||
135 | prefix = d.expand('${HOST_PREFIX}' ) | ||
136 | distro = d.expand('${DISTRO}') | ||
137 | target_sys = d.expand('${TARGET_SYS}') | ||
138 | float = d.getVar('TARGET_FPU') or "hard" | ||
139 | archive_name = prefix + distro + "-" + target_sys + "-" + float | ||
140 | if icc_is_kernel(bb, d): | ||
141 | archive_name += "-kernel" | ||
142 | |||
143 | import socket | ||
144 | ice_dir = d.expand('${STAGING_DIR_NATIVE}${prefix_native}') | ||
145 | tar_file = os.path.join(ice_dir, 'ice', archive_name + "-@VERSION@-" + socket.gethostname() + '.tar.gz') | ||
146 | |||
147 | return tar_file | ||
148 | |||
149 | def icc_path(bb,d): | ||
150 | if icc_is_kernel(bb, d): | ||
151 | return create_path( [get_cross_kernel_cc(bb,d), ], bb, d) | ||
152 | |||
153 | else: | ||
154 | prefix = d.expand('${HOST_PREFIX}') | ||
155 | return create_path( [prefix+"gcc", prefix+"g++"], bb, d) | ||
156 | |||
157 | def icc_get_external_tool(bb, d, tool): | ||
158 | external_toolchain_bindir = d.expand('${EXTERNAL_TOOLCHAIN}${bindir_cross}') | ||
159 | target_prefix = d.expand('${TARGET_PREFIX}') | ||
160 | return os.path.join(external_toolchain_bindir, '%s%s' % (target_prefix, tool)) | ||
161 | |||
162 | def icc_get_tool(bb, d, tool): | ||
163 | if icc_is_native(bb, d): | ||
164 | return os.popen("which %s" % tool).read()[:-1] | ||
165 | elif icc_is_kernel(bb, d): | ||
166 | return os.popen("which %s" % get_cross_kernel_cc(bb, d)).read()[:-1] | ||
167 | else: | ||
168 | ice_dir = d.expand('${STAGING_BINDIR_TOOLCHAIN}') | ||
169 | target_sys = d.expand('${TARGET_SYS}') | ||
170 | tool_bin = os.path.join(ice_dir, "%s-%s" % (target_sys, tool)) | ||
171 | if os.path.isfile(tool_bin): | ||
172 | return tool_bin | ||
173 | else: | ||
174 | external_tool_bin = icc_get_external_tool(bb, d, tool) | ||
175 | if os.path.isfile(external_tool_bin): | ||
176 | return external_tool_bin | ||
177 | else: | ||
178 | return "" | ||
179 | |||
180 | def icc_get_and_check_tool(bb, d, tool): | ||
181 | # Check that g++ or gcc is not a symbolic link to icecc binary in | ||
182 | # PATH or icecc-create-env script will silently create an invalid | ||
183 | # compiler environment package. | ||
184 | t = icc_get_tool(bb, d, tool) | ||
185 | if t and os.popen("readlink -f %s" % t).read()[:-1] == get_icecc(d): | ||
186 | bb.error("%s is a symlink to %s in PATH and this prevents icecc from working" % (t, get_icecc(d))) | ||
187 | return "" | ||
188 | else: | ||
189 | return t | ||
190 | |||
191 | set_icecc_env() { | ||
192 | if [ "x${ICECC_DISABLED}" != "x" ] | ||
193 | then | ||
194 | return | ||
195 | fi | ||
196 | ICECC_VERSION="${@icc_version(bb, d)}" | ||
197 | if [ "x${ICECC_VERSION}" = "x" ] | ||
198 | then | ||
199 | return | ||
200 | fi | ||
201 | |||
202 | ICE_PATH="${@icc_path(bb, d)}" | ||
203 | if [ "x${ICE_PATH}" = "x" ] | ||
204 | then | ||
205 | return | ||
206 | fi | ||
207 | |||
208 | ICECC_CC="${@icc_get_and_check_tool(bb, d, "gcc")}" | ||
209 | ICECC_CXX="${@icc_get_and_check_tool(bb, d, "g++")}" | ||
210 | if [ ! -x "${ICECC_CC}" -o ! -x "${ICECC_CXX}" ] | ||
211 | then | ||
212 | return | ||
213 | fi | ||
214 | |||
215 | ICE_VERSION=`$ICECC_CC -dumpversion` | ||
216 | ICECC_VERSION=`echo ${ICECC_VERSION} | sed -e "s/@VERSION@/$ICE_VERSION/g"` | ||
217 | if [ ! -x "${ICECC_ENV_EXEC}" ] | ||
218 | then | ||
219 | return | ||
220 | fi | ||
221 | |||
222 | ICECC_AS="`${ICECC_CC} -print-prog-name=as`" | ||
223 | if [ "`dirname "${ICECC_AS}"`" = "." ] | ||
224 | then | ||
225 | ICECC_AS="`which as`" | ||
226 | fi | ||
227 | |||
228 | if [ ! -r "${ICECC_VERSION}" ] | ||
229 | then | ||
230 | mkdir -p "`dirname "${ICECC_VERSION}"`" | ||
231 | ${ICECC_ENV_EXEC} "${ICECC_CC}" "${ICECC_CXX}" "${ICECC_AS}" "${ICECC_VERSION}" | ||
232 | fi | ||
233 | |||
234 | export ICECC_VERSION ICECC_CC ICECC_CXX | ||
235 | export PATH="$ICE_PATH:$PATH" | ||
236 | export CCACHE_PATH="$PATH" | ||
237 | |||
238 | bbnote "Using icecc" | ||
239 | } | ||
240 | |||
241 | do_configure_prepend() { | ||
242 | set_icecc_env | ||
243 | } | ||
244 | |||
245 | do_compile_prepend() { | ||
246 | set_icecc_env | ||
247 | } | ||
248 | |||
249 | do_compile_kernelmodules_prepend() { | ||
250 | set_icecc_env | ||
251 | } | ||
252 | |||
253 | #do_install_prepend() { | ||
254 | # set_icecc_env | ||
255 | #} | ||