# IceCream distributed compiling support # # Stages directories with symlinks from gcc/g++ to icecc, for both # native and cross compilers. Depending on each configure or compile, # the directories are added at the head of the PATH list and ICECC_CXX # and ICEC_CC are set. # # For the cross compiler, creates a tar.gz of our toolchain and sets # ICECC_VERSION accordingly. # #To use this class you must set ICECC_PATH and ICECC_ENV_EXEC in the local.conf #ICECC_PATH should point to the icecc #If its not set it will try to find one, but nothing is sure ;) # #ICECC_ENV_EXEC should point to the icecc-create-env script #(NOTE that this is a modified version of the script need it and *not the one that comes with icecc* # #The class now handles all 3 different compile 'stages' (i.e native ,cross-kernel and target) creating the #necessary enviroment tar.gz file to be used by the remote machines # #Error checking is kept to minimum so double check any parameters you pass to the class def icc_determine_gcc_version(gcc): """ Hack to determine the version of GCC 'i686-apple-darwin8-gcc-4.0.1 (GCC) 4.0.1 (Apple Computer, Inc. build 5363)' """ import os return os.popen("%s --version" % gcc ).readline().split()[2] def create_cross_env(bb,d): """ Create a tar.bz2 of the current toolchain """ # Constin native-native compilation no environment needed if # host prefix is empty (let us duplicate the query for ease) prefix = bb.data.expand('${HOST_PREFIX}', d) if len(prefix) == 0: return "" import tarfile, socket, time, os ice_dir = bb.data.expand('${CROSS_DIR}', d) prefix = bb.data.expand('${HOST_PREFIX}' , d) distro = bb.data.expand('${DISTRO}', d) target_sys = bb.data.expand('${TARGET_SYS}', d) target_prefix = bb.data.expand('${TARGET_PREFIX}', d) float = bb.data.getVar('TARGET_FPU', d) or "hard" name = socket.gethostname() # Stupid check to determine if we have built a libc and a cross # compiler. try: os.stat(os.path.join(ice_dir, target_sys, 'lib', 'libc.so')) os.stat(os.path.join(ice_dir, target_sys, 'bin', 'g++')) except: # no cross compiler built yet return "" VERSION = icc_determine_gcc_version( os.path.join(ice_dir,target_sys,"bin","g++") ) cross_name = prefix + distro + "-" + target_sys + "-" + float + "-" + VERSION + "-" + name tar_file = os.path.join(ice_dir, 'ice', cross_name + '.tar.gz') try: os.stat(tar_file) # tar file already exists return tar_file except: try: os.makedirs(os.path.join(ice_dir,'ice')) except: # directory already exists, continue pass #call the modified create-env script cr_env_script = bb.data.getVar('ICECC_ENV_EXEC', d) #print ("CR_ENV_SCRIPT= %s" % cr_env_script) result=os.popen("%s %s %s %s %s %s" %(cr_env_script, "--silent", os.path.join(ice_dir,target_sys,'bin','gcc'), os.path.join(ice_dir,target_sys,'bin','g++'), os.path.join(ice_dir,target_sys,'bin','as'), os.path.join(ice_dir,"ice",cross_name) ) ) return tar_file def create_native_env(bb,d): import tarfile, socket, time, os ice_dir = bb.data.expand('${CROSS_DIR}', d) prefix = bb.data.expand('${HOST_PREFIX}' , d) distro = bb.data.expand('${DISTRO}', d) target_sys = bb.data.expand('${TARGET_SYS}', d) target_prefix = bb.data.expand('${TARGET_PREFIX}', d) float = bb.data.getVar('TARGET_FPU', d) or "hard" name = socket.gethostname() archive_name = "local-host-env" + "-" + name tar_file = os.path.join(ice_dir, 'ice', archive_name + '.tar.gz') try: os.stat(tar_file) # tar file already exists return tar_file except: try: #os.makedirs(os.path.join(ice_dir)) os.makedirs(os.path.join(ice_dir,'ice')) except: # directory already exists, continue pass #call the modified create-env script gcc1_i=os.popen("%s gcc" % "which").read()[:-1] gcc2_i=os.popen("%s g++" % "which").read()[:-1] gcc3_i=os.popen("%s as" % "which").read()[:-1] cr_env_script = bb.data.getVar('ICECC_ENV_EXEC', d) #print ("CR_ENV_SCRIPT= %s" % cr_env_script) result=os.popen("%s %s %s %s %s %s" %(cr_env_script, "--silent", gcc1_i, gcc2_i, gcc3_i, os.path.join(ice_dir,"ice",archive_name) ) ) return tar_file def create_cross_kernel_env(bb,d): import tarfile, socket, time, os ice_dir = bb.data.expand('${CROSS_DIR}', d) prefix = bb.data.expand('${HOST_PREFIX}' , d) distro = bb.data.expand('${DISTRO}', d) target_sys = bb.data.expand('${TARGET_SYS}', d) target_prefix = bb.data.expand('${TARGET_PREFIX}', d) float = bb.data.getVar('TARGET_FPU', d) or "hard" name = socket.gethostname() kernel_cc = bb.data.expand('${KERNEL_CC}', d) kernel_cc = kernel_cc[:-1] # Stupid check to determine if we have built a libc and a cross # compiler. try: os.stat(os.path.join(ice_dir, 'bin', kernel_cc)) except: # no cross compiler built yet return "" VERSION = icc_determine_gcc_version( os.path.join(ice_dir,"bin",kernel_cc) ) cross_name = prefix + distro + "-" + target_sys + "-" + float + "-" + VERSION + "-" + name tar_file = os.path.join(ice_dir, 'ice', cross_name + '.tar.gz') try: os.stat(tar_file) # tar file already exists return tar_file except: try: os.makedirs(os.path.join(ice_dir,'ice')) except: # directory already exists, continue pass #call the modified create-env script cr_env_script = bb.data.getVar('ICECC_ENV_EXEC', d) #print ("CR_ENV_SCRIPT= %s" % cr_env_script) result=os.popen("%s %s %s %s %s %s" %(cr_env_script, "--silent", os.path.join(ice_dir,'bin',kernel_cc), os.path.join(ice_dir,target_sys,'bin','g++'), os.path.join(ice_dir,target_sys,'bin','as'), os.path.join(ice_dir,"ice",cross_name) ) ) return tar_file def create_env(bb,d): #return create_cross_kernel_env(bb,d) if bb.data.inherits_class("native", d): return create_native_env(bb,d) elif bb.data.inherits_class("kernel", d): return create_cross_kernel_env(bb,d) elif bb.data.inherits_class("cross", d): return create_native_env(bb,d) else: return create_cross_env(bb,d) def create_path(compilers, type, bb, d): """ Create Symlinks for the icecc in the staging directory """ import os staging = os.path.join(bb.data.expand('${STAGING_DIR}', d), "ice", type) #check if the icecc path is set by the user icecc = bb.data.getVar('ICECC_PATH', d) or os.popen("%s icecc" % "which").read()[:-1] # Create the dir if necessary try: os.stat(staging) except: os.makedirs(staging) for compiler in compilers: gcc_path = os.path.join(staging, compiler) try: os.stat(gcc_path) except: os.symlink(icecc, gcc_path) return staging + ":" def use_icc_version(bb,d): # Constin native native #prefix = bb.data.expand('${HOST_PREFIX}', d) #if len(prefix) == 0: # return "no" section_blacklist = [ "none" ] for black in section_blacklist: if bb.data.inherits_class(black, d): return "no" return "yes" def icc_path(bb,d,compile): #native = bb.data.expand('${PN}', d) #blacklist = [ "ulibc", "glibc", "ncurses" ] #blacklist = [ "none" ] #for black in blacklist: # if black in native: # return "" #blacklist = [ "none" ] #for black in blacklist: # if bb.data.inherits_class(black, d): # compile = False prefix = bb.data.expand('${HOST_PREFIX}', d) if compile and bb.data.inherits_class("cross", d): return create_path( ["gcc", "g++"], "native", bb, d) elif compile and bb.data.inherits_class("native", d): return create_path( ["gcc", "g++"], "native", bb, d) elif compile and bb.data.inherits_class("kernel", d): #kernel_cc = bb.data.expand('${KERNEL_CC}', d) return create_path( [get_cross_kernel_ver(bb,d), "foo"], "cross-kernel", bb, d) elif not compile or len(prefix) == 0: return create_path( ["gcc", "g++"], "native", bb, d) else: return create_path( [prefix+"gcc", prefix+"g++"], "cross", bb, d) def icc_version(bb,d): return create_env(bb,d) def check_for_kernel(bb,d): if bb.data.inherits_class("kernel", d): return "yes" return "no" def get_cross_kernel_ver(bb,d): if bb.data.inherits_class("kernel", d): tmp_cc_ver = bb.data.expand('${KERNEL_CC}', d) kernel_cc_ver = tmp_cc_ver[:-1] return kernel_cc_ver else: kernel_cc_ver = "gcc" return kernel_cc_ver # set the icecream environment variables do_configure_prepend() { export PATH=${@icc_path(bb,d,False)}$PATH export ICECC_CC="gcc" export ICECC_CXX="g++" } do_compile_prepend() { export PATH=${@icc_path(bb,d,True)}$PATH #check if we are building a kernel and select gcc-cross-kernel if [ "${@check_for_kernel(bb,d)}" = "yes" ]; then export ICECC_CC="${@get_cross_kernel_ver(bb,d)}" export ICECC_CXX="${HOST_PREFIX}g++" else export ICECC_CC="${HOST_PREFIX}gcc" export ICECC_CXX="${HOST_PREFIX}g++" fi if [ "${@use_icc_version(bb,d)}" = "yes" ]; then #print ICECC_VERSION="${@icc_version(bb,d)}" export ICECC_VERSION="${@icc_version(bb,d)}" fi }