icecc.bbclass 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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. ICECC_ENV_EXEC ?= "${STAGING_BINDIR_NATIVE}/icecc-create-env"
  29. def icecc_dep_prepend(d):
  30. # INHIBIT_DEFAULT_DEPS doesn't apply to the patch command. Whether or not
  31. # we need that built is the responsibility of the patch function / class, not
  32. # the application.
  33. if not d.getVar('INHIBIT_DEFAULT_DEPS'):
  34. return "icecc-create-env-native"
  35. return ""
  36. DEPENDS_prepend += "${@icecc_dep_prepend(d)} "
  37. def get_cross_kernel_cc(bb,d):
  38. kernel_cc = d.expand('${KERNEL_CC}')
  39. kernel_cc = kernel_cc.replace('ccache', '').strip()
  40. kernel_cc = kernel_cc.split(' ')[0]
  41. kernel_cc = kernel_cc.strip()
  42. return kernel_cc
  43. def create_path(compilers, bb, d):
  44. """
  45. Create Symlinks for the icecc in the staging directory
  46. """
  47. staging = os.path.join(d.expand('${STAGING_BINDIR}'), "ice")
  48. if icc_is_kernel(bb, d):
  49. staging += "-kernel"
  50. #check if the icecc path is set by the user
  51. icecc = d.getVar('ICECC_PATH') or os.popen("which icecc").read()[:-1]
  52. # Create the dir if necessary
  53. try:
  54. os.stat(staging)
  55. except:
  56. try:
  57. os.makedirs(staging)
  58. except:
  59. pass
  60. for compiler in compilers:
  61. gcc_path = os.path.join(staging, compiler)
  62. try:
  63. os.stat(gcc_path)
  64. except:
  65. try:
  66. os.symlink(icecc, gcc_path)
  67. except:
  68. pass
  69. return staging
  70. def use_icc(bb,d):
  71. package_tmp = d.expand('${PN}')
  72. system_class_blacklist = [ "none" ]
  73. user_class_blacklist = (d.getVar('ICECC_USER_CLASS_BL') or "none").split()
  74. package_class_blacklist = system_class_blacklist + user_class_blacklist
  75. for black in package_class_blacklist:
  76. if bb.data.inherits_class(black, d):
  77. #bb.note(package_tmp, ' class ', black, ' found in blacklist, disable icecc')
  78. return "no"
  79. #"system" package blacklist contains a list of packages that can not distribute compile tasks
  80. #for one reason or the other
  81. system_package_blacklist = [ "uclibc", "glibc", "gcc", "bind", "u-boot", "dhcp-forwarder", "enchant", "connman", "orbit2" ]
  82. user_package_blacklist = (d.getVar('ICECC_USER_PACKAGE_BL') or "").split()
  83. package_blacklist = system_package_blacklist + user_package_blacklist
  84. for black in package_blacklist:
  85. if black in package_tmp:
  86. #bb.note(package_tmp, ' found in blacklist, disable icecc')
  87. return "no"
  88. if d.getVar('PARALLEL_MAKE') == "":
  89. bb.note(package_tmp, " ", d.expand('${PV}'), " has empty PARALLEL_MAKE, disable icecc")
  90. return "no"
  91. return "yes"
  92. def icc_is_kernel(bb, d):
  93. return \
  94. bb.data.inherits_class("kernel", d);
  95. def icc_is_native(bb, d):
  96. return \
  97. bb.data.inherits_class("cross", d) or \
  98. bb.data.inherits_class("native", d);
  99. def icc_version(bb, d):
  100. if use_icc(bb, d) == "no":
  101. return ""
  102. parallel = d.getVar('ICECC_PARALLEL_MAKE') or ""
  103. d.setVar("PARALLEL_MAKE", parallel)
  104. if icc_is_native(bb, d):
  105. archive_name = "local-host-env"
  106. elif d.expand('${HOST_PREFIX}') == "":
  107. bb.fatal(d.expand("${PN}"), " NULL prefix")
  108. else:
  109. prefix = d.expand('${HOST_PREFIX}' )
  110. distro = d.expand('${DISTRO}')
  111. target_sys = d.expand('${TARGET_SYS}')
  112. float = d.getVar('TARGET_FPU') or "hard"
  113. archive_name = prefix + distro + "-" + target_sys + "-" + float
  114. if icc_is_kernel(bb, d):
  115. archive_name += "-kernel"
  116. import socket
  117. ice_dir = d.expand('${STAGING_DIR_NATIVE}${prefix_native}')
  118. tar_file = os.path.join(ice_dir, 'ice', archive_name + "-@VERSION@-" + socket.gethostname() + '.tar.gz')
  119. return tar_file
  120. def icc_path(bb,d):
  121. if icc_is_kernel(bb, d):
  122. return create_path( [get_cross_kernel_cc(bb,d), ], bb, d)
  123. else:
  124. prefix = d.expand('${HOST_PREFIX}')
  125. return create_path( [prefix+"gcc", prefix+"g++"], bb, d)
  126. def icc_get_tool(bb, d, tool):
  127. if icc_is_native(bb, d):
  128. return os.popen("which %s" % tool).read()[:-1]
  129. elif icc_is_kernel(bb, d):
  130. return os.popen("which %s" % get_cross_kernel_cc(bb, d)).read()[:-1]
  131. else:
  132. ice_dir = d.expand('${STAGING_BINDIR_TOOLCHAIN}')
  133. target_sys = d.expand('${TARGET_SYS}')
  134. return os.path.join(ice_dir, "%s-%s" % (target_sys, tool))
  135. set_icecc_env() {
  136. ICECC_VERSION="${@icc_version(bb, d)}"
  137. if [ "x${ICECC_VERSION}" = "x" ]
  138. then
  139. return
  140. fi
  141. ICE_PATH="${@icc_path(bb, d)}"
  142. if [ "x${ICE_PATH}" = "x" ]
  143. then
  144. return
  145. fi
  146. ICECC_CC="${@icc_get_tool(bb,d, "gcc")}"
  147. ICECC_CXX="${@icc_get_tool(bb,d, "g++")}"
  148. if [ ! -x "${ICECC_CC}" -o ! -x "${ICECC_CXX}" ]
  149. then
  150. return
  151. fi
  152. ICE_VERSION=`$ICECC_CC -dumpversion`
  153. ICECC_VERSION=`echo ${ICECC_VERSION} | sed -e "s/@VERSION@/$ICE_VERSION/g"`
  154. if [ ! -x "${ICECC_ENV_EXEC}" ]
  155. then
  156. return
  157. fi
  158. ICECC_AS="`${ICECC_CC} -print-prog-name=as`"
  159. if [ "`dirname "${ICECC_AS}"`" = "." ]
  160. then
  161. ICECC_AS="`which as`"
  162. fi
  163. if [ ! -r "${ICECC_VERSION}" ]
  164. then
  165. mkdir -p "`dirname "${ICECC_VERSION}"`"
  166. ${ICECC_ENV_EXEC} "${ICECC_CC}" "${ICECC_CXX}" "${ICECC_AS}" "${ICECC_VERSION}"
  167. fi
  168. export ICECC_VERSION ICECC_CC ICECC_CXX
  169. export PATH="$ICE_PATH:$PATH"
  170. export CCACHE_PATH="$PATH"
  171. }
  172. do_configure_prepend() {
  173. set_icecc_env
  174. }
  175. do_compile_prepend() {
  176. set_icecc_env
  177. }
  178. do_compile_kernelmodules_prepend() {
  179. set_icecc_env
  180. }
  181. #do_install_prepend() {
  182. # set_icecc_env
  183. #}