sdk.py 6.5 KB

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