Update drivers
[vuplus_openembedded] / classes / icecc.bbclass
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 enviroment 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
30 def icc_determine_gcc_version(gcc):
31     """
32     Hack to determine the version of GCC
33
34     'i686-apple-darwin8-gcc-4.0.1 (GCC) 4.0.1 (Apple Computer, Inc. build 5363)'
35     """
36     return os.popen("%s --version" % gcc ).readline().split()[2]
37
38 def create_cross_env(bb,d):
39     """
40     Create a tar.bz2 of the current toolchain
41     """
42     # Constin native-native compilation no environment needed if
43     # host prefix is empty (let us duplicate the query for ease)
44     prefix = bb.data.expand('${HOST_PREFIX}', d)
45     if len(prefix) == 0:
46         return ""
47
48     import tarfile, socket, time
49     ice_dir = bb.data.expand('${CROSS_DIR}', d)
50     prefix  = bb.data.expand('${HOST_PREFIX}' , d)
51     distro  = bb.data.expand('${DISTRO}', d)
52     target_sys = bb.data.expand('${TARGET_SYS}',  d)
53     target_prefix = bb.data.expand('${TARGET_PREFIX}',  d)
54     float   = bb.data.getVar('TARGET_FPU', d) or "hard"
55     name    = socket.gethostname()
56
57     # Stupid check to determine if we have built a libc and a cross
58     # compiler.
59     try:
60         os.stat(os.path.join(ice_dir, target_sys, 'lib', 'libstdc++.so'))
61         os.stat(os.path.join(ice_dir, target_sys, 'bin', 'g++'))
62     except: # no cross compiler built yet
63         return ""
64
65     VERSION = icc_determine_gcc_version( os.path.join(ice_dir,target_sys,"bin","g++") )
66     cross_name = prefix + distro + "-" + target_sys + "-" + float + "-" + VERSION + "-" + name
67     tar_file = os.path.join(ice_dir, 'ice', cross_name + '.tar.gz')
68
69     try:
70         os.stat(tar_file)
71         # tar file already exists
72         return tar_file
73     except: 
74         try:
75             os.makedirs(os.path.join(ice_dir,'ice'))
76         except:
77             # directory already exists, continue
78             pass
79
80
81     #check if user has specified a specific icecc-create-env script
82     #if not use the OE provided one
83     cr_env_script = bb.data.expand('${ICECC_ENV_EXEC}',  d)
84     if cr_env_script == "${ICECC_ENV_EXEC}":
85         cr_env_script = 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,
88            "--silent",
89            os.path.join(ice_dir, 'bin', "%s-gcc" % target_sys),
90            os.path.join(ice_dir, 'bin', "%s-g++" % target_sys),
91            os.path.join(ice_dir, 'bin', "%s-as" % target_sys),
92            os.path.join(ice_dir,"ice",cross_name) ) )
93     return tar_file
94
95
96 def create_native_env(bb,d):
97     import tarfile, socket, time
98     ice_dir = bb.data.expand('${CROSS_DIR}', d)
99     prefix  = bb.data.expand('${HOST_PREFIX}' , d)
100     distro  = bb.data.expand('${DISTRO}', d)
101     target_sys = bb.data.expand('${TARGET_SYS}',  d)
102     target_prefix = bb.data.expand('${TARGET_PREFIX}',  d)
103     float   = bb.data.getVar('TARGET_FPU', d) or "hard"
104     name    = socket.gethostname()
105
106     archive_name = "local-host-env" + "-" + name
107     tar_file = os.path.join(ice_dir, 'ice', archive_name + '.tar.gz')
108
109     try:
110         os.stat(tar_file)
111         # tar file already exists
112         return tar_file
113     except: 
114         try:
115             #os.makedirs(os.path.join(ice_dir))
116             os.makedirs(os.path.join(ice_dir,'ice'))
117         except:
118             # directory already exists, continue
119             pass
120
121     #check if user has specified a specific icecc-create-env script
122     #if not use the OE provided one
123     cr_env_script = bb.data.expand('${ICECC_ENV_EXEC}',  d)
124     if cr_env_script == "${ICECC_ENV_EXEC}":
125         cr_env_script = bb.data.expand('${STAGING_DIR}', d)+"/ice/icecc-create-env"
126     result=os.popen("%s %s %s %s %s %s" %(cr_env_script,
127            "--silent",
128            os.popen("%s gcc" % "which").read()[:-1],
129            os.popen("%s g++" % "which").read()[:-1],
130            os.popen("%s as" % "which").read()[:-1],
131            os.path.join(ice_dir,"ice",archive_name) ) )
132     return tar_file
133
134
135 def get_cross_kernel_cc(bb,d):
136     kernel_cc = bb.data.expand('${KERNEL_CC}', d)
137     kernel_cc = kernel_cc.replace('ccache', '').strip()
138     kernel_cc = kernel_cc.split(' ')[0]
139     kernel_cc = kernel_cc.strip()
140     return kernel_cc
141
142
143 def create_cross_kernel_env(bb,d):
144     import tarfile, socket, time
145     ice_dir = bb.data.expand('${CROSS_DIR}', d)
146     prefix  = bb.data.expand('${HOST_PREFIX}' , d)
147     distro  = bb.data.expand('${DISTRO}', d)
148     target_sys = bb.data.expand('${TARGET_SYS}',  d)
149     target_prefix = bb.data.expand('${TARGET_PREFIX}',  d)
150     float   = bb.data.getVar('TARGET_FPU', d) or "hard"
151     name    = socket.gethostname()
152     kernel_cc = get_cross_kernel_cc(bb, d)
153
154     # Stupid check to determine if we have built a libc and a cross
155     # compiler.
156     try:
157         os.stat(os.path.join(ice_dir, 'bin', kernel_cc))
158     except: # no cross compiler built yet
159         return ""
160
161     VERSION = icc_determine_gcc_version( os.path.join(ice_dir,"bin",kernel_cc) )
162     cross_name = prefix + distro + "-" + target_sys + "-" + float + "-" + VERSION + "-" + name
163     tar_file = os.path.join(ice_dir, 'ice', cross_name + '.tar.gz')
164
165     try:
166         os.stat(tar_file)
167         # tar file already exists
168         return tar_file
169     except: 
170         try:
171             os.makedirs(os.path.join(ice_dir,'ice'))
172         except:
173             # directory already exists, continue
174             pass
175
176
177     #check if user has specified a specific icecc-create-env script
178     #if not use the OE provided one
179     cr_env_script = bb.data.getVar('ICECC_ENV_EXEC',  d) or  bb.data.expand('${STAGING_DIR}', d)+"/ice/icecc-create-env"
180     result=os.popen("%s %s %s %s %s %s" %(cr_env_script,
181            "--silent",
182            os.path.join(ice_dir, 'bin', kernel_cc),
183            os.path.join(ice_dir, 'bin', "%s-g++" % target_sys),
184            os.path.join(ice_dir, 'bin', "%s-as" % target_sys),
185            os.path.join(ice_dir, "ice", cross_name) ) )
186     return tar_file
187
188
189 def create_env(bb,d):
190
191         #return create_cross_kernel_env(bb,d) 
192
193         if bb.data.inherits_class("native", d):
194           return create_native_env(bb,d)
195         elif bb.data.inherits_class("kernel", d):
196           return create_cross_kernel_env(bb,d)
197         elif bb.data.inherits_class("cross", d):
198           return create_native_env(bb,d)
199         elif bb.data.inherits_class("sdk", d):
200           return create_native_env(bb,d)
201         else:  
202           return create_cross_env(bb,d)
203
204
205 def create_path(compilers, type, bb, d):
206     """
207     Create Symlinks for the icecc in the staging directory
208     """
209     staging = os.path.join(bb.data.expand('${STAGING_DIR}', d), "ice", type)
210
211     #check if the icecc path is set by the user
212     icecc   = bb.data.getVar('ICECC_PATH', d) or os.popen("%s icecc" % "which").read()[:-1]
213
214     # Create the dir if necessary
215     try:
216         os.stat(staging)
217     except:
218         os.makedirs(staging)
219
220     for compiler in compilers:
221         gcc_path = os.path.join(staging, compiler)
222         try:
223             os.stat(gcc_path)
224         except:
225             os.symlink(icecc, gcc_path)
226
227     return staging + ":"
228
229
230 def use_icc_version(bb,d):
231       icecc_ver = "yes"
232       system_class_blacklist = [ "none" ] 
233
234       for black in system_class_blacklist:
235            if bb.data.inherits_class(black, d):
236               icecc_ver = "no"
237
238       user_class_blacklist =  bb.data.getVar('ICECC_USER_CLASS_BL', d) or "none"
239       user_class_blacklist = user_class_blacklist.split()
240
241       for black in user_class_blacklist:
242            if bb.data.inherits_class(black, d):
243               icecc_ver = "no"
244
245       return icecc_ver
246
247
248 def icc_path(bb,d):
249     package_tmp = bb.data.expand('${PN}', d)
250
251     #"system" package blacklist contains a list of packages that can not distribute compile tasks
252     #for one reason or the other
253     system_package_blacklist = [ "uclibc", "glibc", "gcc", "qemu", "bind", "u-boot", "dhcp-forwarder", "enchant", "connman" ]
254     user_package_blacklist = (bb.data.getVar('ICECC_USER_PACKAGE_BL', d) or "").split()
255     package_blacklist = system_package_blacklist + user_package_blacklist
256
257     for black in package_blacklist:
258         if black in package_tmp:
259             bb.note(package_tmp, ' found in blacklist, disable icecc')
260             fallback_parallel = bb.data.getVar('ICECC_FALLBACK_PARALLEL', d) or ""
261             bb.data.setVar("PARALLEL_MAKE", fallback_parallel, d)
262             return ""
263
264     prefix = bb.data.expand('${HOST_PREFIX}', d)
265
266     if bb.data.inherits_class("cross", d):
267         return create_path( ["gcc", "g++"], "native", bb, d)
268
269     elif bb.data.inherits_class("native", d):
270         return create_path( ["gcc", "g++"], "native", bb, d)
271
272     elif bb.data.inherits_class("kernel", d):
273         return create_path( [get_cross_kernel_cc(bb,d), ], "cross-kernel", bb, d)
274
275     elif len(prefix) == 0:
276         return create_path( ["gcc", "g++"], "native", bb, d)
277
278     else:
279         return create_path( [prefix+"gcc", prefix+"g++"], "cross", bb, d)      
280
281
282 def icc_version(bb,d):
283     return create_env(bb,d)
284
285
286 def check_for_kernel(bb,d):     
287     if  bb.data.inherits_class("kernel", d):
288          return "yes"
289     return "no"
290
291
292 set_icecc_env() {
293     ICE_PATH=${@icc_path(bb,d)}
294     if test x${ICE_PATH} != x; then
295         export PATH=${ICE_PATH}$PATH
296         export CCACHE_PATH=$PATH
297         #check if we are building a kernel and select gcc-cross-kernel
298         if [ "${@check_for_kernel(bb,d)}" = "yes" ]; then
299             export ICECC_CC="${@get_cross_kernel_cc(bb,d)}"
300             export ICECC_CXX="${HOST_PREFIX}g++"
301         else
302             export ICECC_CC="${HOST_PREFIX}gcc"
303             export ICECC_CXX="${HOST_PREFIX}g++"
304         fi
305
306         if [ "${@use_icc_version(bb,d)}" = "yes" ]; then
307             export ICECC_VERSION="${@icc_version(bb,d)}"
308         else
309             export -n ICECC_VERSION
310         fi
311         oenote "set the icecream environment variables: PATH=$PATH, CCACHE_PATH=$CCACHE_PATH, ICECC_CC=$ICECC_CC, ICECC_CXX=$ICECC_CXX, ICECC_VERSION=$ICECC_VERSION"
312     fi
313 }
314
315 do_configure_prepend() {
316     set_icecc_env
317 }
318
319 do_compile_prepend() {
320     set_icecc_env
321 }