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
14 #If ICECC_PATH is not set in local.conf then the class will try to locate it using 'which'
15 #but nothing is sure ;)
17 #If ICECC_ENV_EXEC is set in local.conf should point to the icecc-create-env script provided by the user
18 #or the default one provided by icecc-create-env.bb will be used
19 #(NOTE that this is a modified version of the script need it and *not the one that comes with icecc*
21 #User can specify if specific packages or packages belonging to class should not use icecc to distribute
22 #compile jobs to remote machines, but handled localy, by defining ICECC_USER_CLASS_BL and ICECC_PACKAGE_BL
23 #with the appropriate values in local.conf
24 #########################################################################################
25 #Error checking is kept to minimum so double check any parameters you pass to the class
26 ###########################################################################################
29 def icc_determine_gcc_version(gcc):
31 Hack to determine the version of GCC
33 'i686-apple-darwin8-gcc-4.0.1 (GCC) 4.0.1 (Apple Computer, Inc. build 5363)'
36 return os.popen("%s --version" % gcc ).readline().split()[2]
38 def create_cross_env(bb,d):
40 Create a tar.bz2 of the current toolchain
43 # Constin native-native compilation no environment needed if
44 # host prefix is empty (let us duplicate the query for ease)
45 prefix = bb.data.expand('${HOST_PREFIX}', d)
49 import tarfile, socket, time, os
50 ice_dir = bb.data.expand('${CROSS_DIR}', d)
51 prefix = bb.data.expand('${HOST_PREFIX}' , d)
52 distro = bb.data.expand('${DISTRO}', d)
53 target_sys = bb.data.expand('${TARGET_SYS}', d)
54 target_prefix = bb.data.expand('${TARGET_PREFIX}', d)
55 float = bb.data.getVar('TARGET_FPU', d) or "hard"
56 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', 'libc.so'))
63 os.stat(os.path.join(ice_dir, target_sys, 'bin', 'g++'))
64 except: # no cross compiler built yet
67 VERSION = icc_determine_gcc_version( os.path.join(ice_dir,target_sys,"bin","g++") )
68 cross_name = prefix + distro + "-" + target_sys + "-" + float + "-" + VERSION + "-" + name
69 tar_file = os.path.join(ice_dir, 'ice', cross_name + '.tar.gz')
73 # tar file already exists
77 os.makedirs(os.path.join(ice_dir,'ice'))
79 # directory already exists, continue
83 #check if user has specified a specific icecc-create-env script
84 #if not use the OE provided one
85 cr_env_script = bb.data.getVar('ICECC_ENV_EXEC', d) or bb.data.expand('${STAGING_DIR}', d)+"/ice/icecc-create-env"
86 #call the modified create-env script
87 result=os.popen("%s %s %s %s %s %s" %(cr_env_script,
89 os.path.join(ice_dir,target_sys,'bin','gcc'),
90 os.path.join(ice_dir,target_sys,'bin','g++'),
91 os.path.join(ice_dir,target_sys,'bin','as'),
92 os.path.join(ice_dir,"ice",cross_name) ) )
96 def create_native_env(bb,d):
98 import tarfile, socket, time, os
99 ice_dir = bb.data.expand('${CROSS_DIR}', d)
100 prefix = bb.data.expand('${HOST_PREFIX}' , d)
101 distro = bb.data.expand('${DISTRO}', d)
102 target_sys = bb.data.expand('${TARGET_SYS}', d)
103 target_prefix = bb.data.expand('${TARGET_PREFIX}', d)
104 float = bb.data.getVar('TARGET_FPU', d) or "hard"
105 name = socket.gethostname()
108 archive_name = "local-host-env" + "-" + name
109 tar_file = os.path.join(ice_dir, 'ice', archive_name + '.tar.gz')
113 # tar file already exists
117 #os.makedirs(os.path.join(ice_dir))
118 os.makedirs(os.path.join(ice_dir,'ice'))
120 # 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.getVar('ICECC_ENV_EXEC', d) or bb.data.expand('${STAGING_DIR}', d)+"/ice/icecc-create-env"
127 result=os.popen("%s %s %s %s %s %s" %(cr_env_script,
129 os.popen("%s gcc" % "which").read()[:-1],
130 os.popen("%s g++" % "which").read()[:-1],
131 os.popen("%s as" % "which").read()[:-1],
132 os.path.join(ice_dir,"ice",archive_name) ) )
137 def create_cross_kernel_env(bb,d):
139 import tarfile, socket, time, os
140 ice_dir = bb.data.expand('${CROSS_DIR}', d)
141 prefix = bb.data.expand('${HOST_PREFIX}' , d)
142 distro = bb.data.expand('${DISTRO}', d)
143 target_sys = bb.data.expand('${TARGET_SYS}', d)
144 target_prefix = bb.data.expand('${TARGET_PREFIX}', d)
145 float = bb.data.getVar('TARGET_FPU', d) or "hard"
146 name = socket.gethostname()
147 kernel_cc = bb.data.expand('${KERNEL_CC}', d)
148 kernel_cc = kernel_cc[:-1]
151 # Stupid check to determine if we have built a libc and a cross
154 os.stat(os.path.join(ice_dir, 'bin', kernel_cc))
155 except: # no cross compiler built yet
158 VERSION = icc_determine_gcc_version( os.path.join(ice_dir,"bin",kernel_cc) )
159 cross_name = prefix + distro + "-" + target_sys + "-" + float + "-" + VERSION + "-" + name
160 tar_file = os.path.join(ice_dir, 'ice', cross_name + '.tar.gz')
164 # tar file already exists
168 os.makedirs(os.path.join(ice_dir,'ice'))
170 # directory already exists, continue
174 #check if user has specified a specific icecc-create-env script
175 #if not use the OE provided one
176 cr_env_script = bb.data.getVar('ICECC_ENV_EXEC', d) or bb.data.expand('${STAGING_DIR}', d)+"/ice/icecc-create-env"
177 result=os.popen("%s %s %s %s %s %s" %(cr_env_script,
179 os.path.join(ice_dir,'bin',kernel_cc),
180 os.path.join(ice_dir,target_sys,'bin','g++'),
181 os.path.join(ice_dir,target_sys,'bin','as'),
182 os.path.join(ice_dir,"ice",cross_name) ) )
186 def create_env(bb,d):
188 #return create_cross_kernel_env(bb,d)
189 if bb.data.inherits_class("native", d):
190 return create_native_env(bb,d)
191 elif bb.data.inherits_class("kernel", d):
192 return create_cross_kernel_env(bb,d)
193 elif bb.data.inherits_class("cross", d):
194 return create_native_env(bb,d)
196 return create_cross_env(bb,d)
199 def create_path(compilers, type, bb, d):
201 Create Symlinks for the icecc in the staging directory
205 staging = os.path.join(bb.data.expand('${STAGING_DIR}', d), "ice", type)
207 #check if the icecc path is set by the user
208 icecc = bb.data.getVar('ICECC_PATH', d) or os.popen("%s icecc" % "which").read()[:-1]
211 # Create the dir if necessary
217 for compiler in compilers:
218 gcc_path = os.path.join(staging, compiler)
222 os.symlink(icecc, gcc_path)
230 def use_icc_version(bb,d):
233 system_class_blacklist = [ "none" ]
235 for black in system_class_blacklist:
236 if bb.data.inherits_class(black, d):
240 user_class_blacklist = bb.data.getVar('ICECC_USER_CLASS_BL', d) or "none"
241 user_class_blacklist = user_class_blacklist.split()
243 for black in user_class_blacklist:
244 if bb.data.inherits_class(black, d):
251 def icc_path(bb,d,compile):
252 package_tmp = bb.data.expand('${PN}', d)
254 #"system" package blacklist contains a list of packages that can not distribute compile tasks
255 #for one reason or the other
256 system_package_blacklist = [ "uclibc", "glibc-intermediate", "qemu" ]
258 for black in system_package_blacklist:
259 if black in package_tmp:
260 bb.data.setVar('PARALLEL_MAKE' , '', d)
263 #user defined exclusion list
264 user_package_blacklist = bb.data.getVar('ICECC_USER_PACKAGE_BL', d) or "none"
265 user_package_blacklist = user_package_blacklist.split()
267 for black in user_package_blacklist:
268 if black in package_tmp:
269 bb.data.setVar('PARALLEL_MAKE' , '', d)
273 prefix = bb.data.expand('${HOST_PREFIX}', d)
276 if compile and bb.data.inherits_class("cross", d):
277 return create_path( ["gcc", "g++"], "native", bb, d)
279 elif compile and bb.data.inherits_class("native", d):
280 return create_path( ["gcc", "g++"], "native", bb, d)
282 elif compile and bb.data.inherits_class("kernel", d):
283 #kernel_cc = bb.data.expand('${KERNEL_CC}', d)
284 return create_path( [get_cross_kernel_ver(bb,d), "foo"], "cross-kernel", bb, d)
286 elif not compile or len(prefix) == 0:
287 return create_path( ["gcc", "g++"], "native", bb, d)
290 return create_path( [prefix+"gcc", prefix+"g++"], "cross", bb, d)
295 def icc_version(bb,d):
296 return create_env(bb,d)
298 def check_for_kernel(bb,d):
299 if bb.data.inherits_class("kernel", d):
305 def get_cross_kernel_ver(bb,d):
307 return bb.data.expand('${KERNEL_CC}', d).strip() or "gcc"
309 # set the icecream environment variables
310 do_configure_prepend() {
311 export PATH=${@icc_path(bb,d,False)}$PATH
312 export ICECC_CC="gcc"
313 export ICECC_CXX="g++"
316 do_compile_prepend() {
318 export PATH=${@icc_path(bb,d,True)}$PATH
320 #check if we are building a kernel and select gcc-cross-kernel
321 if [ "${@check_for_kernel(bb,d)}" = "yes" ]; then
322 export ICECC_CC="${@get_cross_kernel_ver(bb,d)}"
323 export ICECC_CXX="${HOST_PREFIX}g++"
325 export ICECC_CC="${HOST_PREFIX}gcc"
326 export ICECC_CXX="${HOST_PREFIX}g++"
329 if [ "${@use_icc_version(bb,d)}" = "yes" ]; then
330 export ICECC_VERSION="${@icc_version(bb,d)}"
332 export ICECC_VERSION="NONE"