sdk.py 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. #
  2. # Copyright OpenEmbedded Contributors
  3. #
  4. # SPDX-License-Identifier: GPL-2.0-only
  5. #
  6. from abc import ABCMeta, abstractmethod
  7. from oe.utils import execute_pre_post_process
  8. from oe.manifest import *
  9. from oe.package_manager import *
  10. import os
  11. import traceback
  12. class Sdk(object, metaclass=ABCMeta):
  13. def __init__(self, d, manifest_dir):
  14. self.d = d
  15. self.sdk_output = self.d.getVar('SDK_OUTPUT')
  16. self.sdk_native_path = self.d.getVar('SDKPATHNATIVE').strip('/')
  17. self.target_path = self.d.getVar('SDKTARGETSYSROOT').strip('/')
  18. self.sysconfdir = self.d.getVar('sysconfdir').strip('/')
  19. self.sdk_target_sysroot = os.path.join(self.sdk_output, self.target_path)
  20. self.sdk_host_sysroot = self.sdk_output
  21. if manifest_dir is None:
  22. self.manifest_dir = self.d.getVar("SDK_DIR")
  23. else:
  24. self.manifest_dir = manifest_dir
  25. self.remove(self.sdk_output, True)
  26. self.install_order = Manifest.INSTALL_ORDER
  27. @abstractmethod
  28. def _populate(self):
  29. pass
  30. def populate(self):
  31. self.mkdirhier(self.sdk_output)
  32. # call backend dependent implementation
  33. self._populate()
  34. # Don't ship any libGL in the SDK
  35. self.remove(os.path.join(self.sdk_output, self.sdk_native_path,
  36. self.d.getVar('libdir_nativesdk').strip('/'),
  37. "libGL*"))
  38. # Fix or remove broken .la files
  39. self.remove(os.path.join(self.sdk_output, self.sdk_native_path,
  40. self.d.getVar('libdir_nativesdk').strip('/'),
  41. "*.la"))
  42. # Link the ld.so.cache file into the hosts filesystem
  43. link_name = os.path.join(self.sdk_output, self.sdk_native_path,
  44. self.sysconfdir, "ld.so.cache")
  45. self.mkdirhier(os.path.dirname(link_name))
  46. os.symlink("/etc/ld.so.cache", link_name)
  47. execute_pre_post_process(self.d, self.d.getVar('SDK_POSTPROCESS_COMMAND'))
  48. def movefile(self, sourcefile, destdir):
  49. try:
  50. # FIXME: this check of movefile's return code to None should be
  51. # fixed within the function to use only exceptions to signal when
  52. # something goes wrong
  53. if (bb.utils.movefile(sourcefile, destdir) == None):
  54. raise OSError("moving %s to %s failed"
  55. %(sourcefile, destdir))
  56. #FIXME: using umbrella exc catching because bb.utils method raises it
  57. except Exception as e:
  58. bb.debug(1, "printing the stack trace\n %s" %traceback.format_exc())
  59. bb.fatal("unable to place %s in final SDK location" % sourcefile)
  60. def mkdirhier(self, dirpath):
  61. try:
  62. bb.utils.mkdirhier(dirpath)
  63. except OSError as e:
  64. bb.debug(1, "printing the stack trace\n %s" %traceback.format_exc())
  65. bb.fatal("cannot make dir for SDK: %s" % dirpath)
  66. def remove(self, path, recurse=False):
  67. try:
  68. bb.utils.remove(path, recurse)
  69. #FIXME: using umbrella exc catching because bb.utils method raises it
  70. except Exception as e:
  71. bb.debug(1, "printing the stack trace\n %s" %traceback.format_exc())
  72. bb.warn("cannot remove SDK dir: %s" % path)
  73. def install_locales(self, pm):
  74. linguas = self.d.getVar("SDKIMAGE_LINGUAS")
  75. if linguas:
  76. import fnmatch
  77. # Install the binary locales
  78. if linguas == "all":
  79. pm.install_glob("nativesdk-glibc-binary-localedata-*.utf-8", sdk=True)
  80. else:
  81. pm.install(["nativesdk-glibc-binary-localedata-%s.utf-8" % \
  82. lang for lang in linguas.split()])
  83. # Generate a locale archive of them
  84. target_arch = self.d.getVar('SDK_ARCH')
  85. rootfs = oe.path.join(self.sdk_host_sysroot, self.sdk_native_path)
  86. localedir = oe.path.join(rootfs, self.d.getVar("libdir_nativesdk"), "locale")
  87. generate_locale_archive(self.d, rootfs, target_arch, localedir)
  88. # And now delete the binary locales
  89. pkgs = fnmatch.filter(pm.list_installed(), "nativesdk-glibc-binary-localedata-*.utf-8")
  90. pm.remove(pkgs)
  91. else:
  92. # No linguas so do nothing
  93. pass
  94. def sdk_list_installed_packages(d, target, rootfs_dir=None):
  95. if rootfs_dir is None:
  96. sdk_output = d.getVar('SDK_OUTPUT')
  97. target_path = d.getVar('SDKTARGETSYSROOT').strip('/')
  98. rootfs_dir = [sdk_output, os.path.join(sdk_output, target_path)][target is True]
  99. if target is False:
  100. ipkgconf_sdk_target = d.getVar("IPKGCONF_SDK")
  101. d.setVar("IPKGCONF_TARGET", ipkgconf_sdk_target)
  102. img_type = d.getVar('IMAGE_PKGTYPE')
  103. import importlib
  104. cls = importlib.import_module('oe.package_manager.' + img_type)
  105. return cls.PMPkgsList(d, rootfs_dir).list_pkgs()
  106. def populate_sdk(d, manifest_dir=None):
  107. env_bkp = os.environ.copy()
  108. img_type = d.getVar('IMAGE_PKGTYPE')
  109. import importlib
  110. cls = importlib.import_module('oe.package_manager.' + img_type + '.sdk')
  111. cls.PkgSdk(d, manifest_dir).populate()
  112. os.environ.clear()
  113. os.environ.update(env_bkp)
  114. def get_extra_sdkinfo(sstate_dir):
  115. """
  116. This function is going to be used for generating the target and host manifest files packages of eSDK.
  117. """
  118. import math
  119. extra_info = {}
  120. extra_info['tasksizes'] = {}
  121. extra_info['filesizes'] = {}
  122. for root, _, files in os.walk(sstate_dir):
  123. for fn in files:
  124. if fn.endswith('.tgz'):
  125. fsize = int(math.ceil(float(os.path.getsize(os.path.join(root, fn))) / 1024))
  126. task = fn.rsplit(':',1)[1].split('_',1)[1].split(',')[0]
  127. origtotal = extra_info['tasksizes'].get(task, 0)
  128. extra_info['tasksizes'][task] = origtotal + fsize
  129. extra_info['filesizes'][fn] = fsize
  130. return extra_info