1 # IceCream distributed compiling support
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
8 # For the cross compiler, creates a tar.gz of our toolchain and sets
9 # ICECC_VERSION accordingly.
11 #The class now handles all 3 different compile 'stages' (i.e native ,cross-kernel and target) creating the
12 #necessary enviroment tar.gz file to be used by the remote machines.
13 #It also supports meta-toolchain generation
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 ;)
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*
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 ###########################################################################################
30 def icc_determine_gcc_version(gcc):
32 Hack to determine the version of GCC
34 'i686-apple-darwin8-gcc-4.0.1 (GCC) 4.0.1 (Apple Computer, Inc. build 5363)'
37 return os.popen("%s --version" % gcc ).readline().split()[2]
40 def create_cross_env(bb,d):
42 Create a tar.bz2 of the current toolchain
44 # Constin native-native compilation no environment needed if
45 # host prefix is empty (let us duplicate the query for ease)
46 prefix = bb.data.expand('${HOST_PREFIX}', d)
50 import tarfile, socket, time, os
51 ice_dir = bb.data.expand('${CROSS_DIR}', d)
52 prefix = bb.data.expand('${HOST_PREFIX}' , d)
53 distro = bb.data.expand('${DISTRO}', d)
54 target_sys = bb.data.expand('${TARGET_SYS}', d)
55 target_prefix = bb.data.expand('${TARGET_PREFIX}', d)
56 float = bb.data.getVar('TARGET_FPU', d) or "hard"
57 name = socket.gethostname()
59 # Stupid check to determine if we have built a libc and a cross
62 os.stat(os.path.join(ice_dir, target_sys, 'lib', 'libstdc++.so'))
63 os.stat(os.path.join(ice_dir, target_sys, 'bin', 'g++'))
64 except: # no cross compiler built yet
65 bb.error('no cross compiler built yet?')
68 VERSION = icc_determine_gcc_version( os.path.join(ice_dir,target_sys,"bin","g++") )
69 cross_name = prefix + distro + "-" + target_sys + "-" + float + "-" + VERSION + "-" + name
70 tar_file = os.path.join(ice_dir, 'ice', cross_name + '.tar.gz')
74 # tar file already exists
78 os.makedirs(os.path.join(ice_dir,'ice'))
80 # directory already exists, continue
84 #check if user has specified a specific icecc-create-env script
85 #if not use the OE provided one
86 cr_env_script = bb.data.expand('${ICECC_ENV_EXEC}', d)
87 if cr_env_script == "${ICECC_ENV_EXEC}":
88 cr_env_script = bb.data.expand('${STAGING_DIR}', d)+"/ice/icecc-create-env"
89 #call the modified create-env script
90 result=os.popen("%s %s %s %s %s %s" %(cr_env_script,
92 os.path.join(ice_dir, 'bin', "%s-gcc" % target_sys),
93 os.path.join(ice_dir, 'bin', "%s-g++" % target_sys),
94 os.path.join(ice_dir, 'bin', "%s-as" % target_sys),
95 os.path.join(ice_dir,"ice",cross_name) ) )
99 def create_native_env(bb,d):
100 import tarfile, socket, time, os
101 ice_dir = bb.data.expand('${CROSS_DIR}', d)
102 prefix = bb.data.expand('${HOST_PREFIX}' , d)
103 distro = bb.data.expand('${DISTRO}', d)
104 target_sys = bb.data.expand('${TARGET_SYS}', d)
105 target_prefix = bb.data.expand('${TARGET_PREFIX}', d)
106 float = bb.data.getVar('TARGET_FPU', d) or "hard"
107 name = socket.gethostname()
109 archive_name = "local-host-env" + "-" + name
110 tar_file = os.path.join(ice_dir, 'ice', archive_name + '.tar.gz')
114 # tar file already exists
118 #os.makedirs(os.path.join(ice_dir))
119 os.makedirs(os.path.join(ice_dir,'ice'))
121 # directory already exists, continue
124 #check if user has specified a specific icecc-create-env script
125 #if not use the OE provided one
126 cr_env_script = bb.data.expand('${ICECC_ENV_EXEC}', d)
127 if cr_env_script == "${ICECC_ENV_EXEC}":
128 cr_env_script = bb.data.expand('${STAGING_DIR}', d)+"/ice/icecc-create-env"
129 result=os.popen("%s %s %s %s %s %s" %(cr_env_script,
131 os.popen("%s gcc" % "which").read()[:-1],
132 os.popen("%s g++" % "which").read()[:-1],
133 os.popen("%s as" % "which").read()[:-1],
134 os.path.join(ice_dir,"ice",archive_name) ) )
138 def get_cross_kernel_cc(bb,d):
139 kernel_cc = bb.data.expand('${KERNEL_CC}', d)
140 kernel_cc = kernel_cc.replace('ccache', '').strip()
141 kernel_cc = kernel_cc.split(' ')[0]
142 kernel_cc = kernel_cc.strip()
146 def create_cross_kernel_env(bb,d):
147 import tarfile, socket, time, os
148 ice_dir = bb.data.expand('${CROSS_DIR}', d)
149 prefix = bb.data.expand('${HOST_PREFIX}' , d)
150 distro = bb.data.expand('${DISTRO}', d)
151 target_sys = bb.data.expand('${TARGET_SYS}', d)
152 target_prefix = bb.data.expand('${TARGET_PREFIX}', d)
153 float = bb.data.getVar('TARGET_FPU', d) or "hard"
154 name = socket.gethostname()
155 kernel_cc = get_cross_kernel_cc(bb, d)
157 # Stupid check to determine if we have built a libc and a cross
160 os.stat(os.path.join(ice_dir, 'bin', kernel_cc))
161 except: # no cross compiler built yet
162 bb.error('no kernel cross compiler built yet')
165 VERSION = icc_determine_gcc_version( os.path.join(ice_dir,"bin",kernel_cc) )
166 cross_name = prefix + distro + "-" + target_sys + "-" + float + "-" + VERSION + "-" + name
167 tar_file = os.path.join(ice_dir, 'ice', cross_name + '.tar.gz')
171 # tar file already exists
175 os.makedirs(os.path.join(ice_dir,'ice'))
177 # directory already exists, continue
181 #check if user has specified a specific icecc-create-env script
182 #if not use the OE provided one
183 cr_env_script = bb.data.getVar('ICECC_ENV_EXEC', d) or bb.data.expand('${STAGING_DIR}', d)+"/ice/icecc-create-env"
184 result=os.popen("%s %s %s %s %s %s" %(cr_env_script,
186 os.path.join(ice_dir, 'bin', kernel_cc),
187 os.path.join(ice_dir, 'bin', "%s-g++" % target_sys),
188 os.path.join(ice_dir, 'bin', "%s-as" % target_sys),
189 os.path.join(ice_dir, "ice", cross_name) ) )
193 def create_env(bb,d):
195 #return create_cross_kernel_env(bb,d)
197 if bb.data.inherits_class("native", d):
198 return create_native_env(bb,d)
199 elif bb.data.inherits_class("kernel", d):
200 return create_cross_kernel_env(bb,d)
201 elif bb.data.inherits_class("cross", d):
202 return create_native_env(bb,d)
203 elif bb.data.inherits_class("sdk", d):
204 return create_native_env(bb,d)
206 return create_cross_env(bb,d)
209 def create_path(compilers, type, bb, d):
211 Create Symlinks for the icecc in the staging directory
215 staging = os.path.join(bb.data.expand('${STAGING_DIR}', d), "ice", type)
217 #check if the icecc path is set by the user
218 icecc = bb.data.getVar('ICECC_PATH', d) or os.popen("%s icecc" % "which").read()[:-1]
220 # Create the dir if necessary
226 for compiler in compilers:
227 gcc_path = os.path.join(staging, compiler)
231 os.symlink(icecc, gcc_path)
236 def use_icc_version(bb,d):
238 system_class_blacklist = [ "none" ]
240 for black in system_class_blacklist:
241 if bb.data.inherits_class(black, d):
244 user_class_blacklist = bb.data.getVar('ICECC_USER_CLASS_BL', d) or "none"
245 user_class_blacklist = user_class_blacklist.split()
247 for black in user_class_blacklist:
248 if bb.data.inherits_class(black, d):
255 package_tmp = bb.data.expand('${PN}', d)
257 #"system" package blacklist contains a list of packages that can not distribute compile tasks
258 #for one reason or the other
259 system_package_blacklist = [ "uclibc", "glibc", "gcc", "qemu", "bind", "u-boot", "dhcp-forwarder", "enchant", "connman" ]
260 user_package_blacklist = (bb.data.getVar('ICECC_USER_PACKAGE_BL', d) or "").split()
261 package_blacklist = system_package_blacklist + user_package_blacklist
263 for black in package_blacklist:
264 if black in package_tmp:
265 bb.note(package_tmp, ' found in blacklist, disable icecc')
266 bb.data.setVar("PARALLEL_MAKE" , "", d)
269 prefix = bb.data.expand('${HOST_PREFIX}', d)
271 if bb.data.inherits_class("cross", d):
272 return create_path( ["gcc", "g++"], "native", bb, d)
274 elif bb.data.inherits_class("native", d):
275 return create_path( ["gcc", "g++"], "native", bb, d)
277 elif bb.data.inherits_class("kernel", d):
278 return create_path( [get_cross_kernel_cc(bb,d), ], "cross-kernel", bb, d)
280 elif len(prefix) == 0:
281 return create_path( ["gcc", "g++"], "native", bb, d)
284 return create_path( [prefix+"gcc", prefix+"g++"], "cross", bb, d)
287 def icc_version(bb,d):
288 return create_env(bb,d)
291 def check_for_kernel(bb,d):
292 if bb.data.inherits_class("kernel", d):
298 ICE_PATH=${@icc_path(bb,d)}
299 if test x${ICE_PATH} != x; then
300 export PATH=${ICE_PATH}$PATH
301 export CCACHE_PATH=$PATH
302 #check if we are building a kernel and select gcc-cross-kernel
303 if [ "${@check_for_kernel(bb,d)}" = "yes" ]; then
304 export ICECC_CC="${@get_cross_kernel_cc(bb,d)}"
305 export ICECC_CXX="${HOST_PREFIX}g++"
307 export ICECC_CC="${HOST_PREFIX}gcc"
308 export ICECC_CXX="${HOST_PREFIX}g++"
311 if [ "${@use_icc_version(bb,d)}" = "yes" ]; then
312 export ICECC_VERSION="${@icc_version(bb,d)}"
314 export -n ICECC_VERSION
316 oenote "set the icecream environment variables: PATH=$PATH, CCACHE_PATH=$CCACHE_PATH, ICECC_CC=$ICECC_CC, ICECC_CXX=$ICECC_CXX, ICECC_VERSION=$ICECC_VERSION"
320 do_configure_prepend() {
324 do_compile_prepend() {