manifest.py 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. #
  2. # SPDX-License-Identifier: GPL-2.0-only
  3. #
  4. from abc import ABCMeta, abstractmethod
  5. import os
  6. import re
  7. import bb
  8. class Manifest(object, metaclass=ABCMeta):
  9. """
  10. This is an abstract class. Do not instantiate this directly.
  11. """
  12. PKG_TYPE_MUST_INSTALL = "mip"
  13. PKG_TYPE_MULTILIB = "mlp"
  14. PKG_TYPE_LANGUAGE = "lgp"
  15. PKG_TYPE_ATTEMPT_ONLY = "aop"
  16. MANIFEST_TYPE_IMAGE = "image"
  17. MANIFEST_TYPE_SDK_HOST = "sdk_host"
  18. MANIFEST_TYPE_SDK_TARGET = "sdk_target"
  19. var_maps = {
  20. MANIFEST_TYPE_IMAGE: {
  21. "PACKAGE_INSTALL": PKG_TYPE_MUST_INSTALL,
  22. "PACKAGE_INSTALL_ATTEMPTONLY": PKG_TYPE_ATTEMPT_ONLY,
  23. "LINGUAS_INSTALL": PKG_TYPE_LANGUAGE
  24. },
  25. MANIFEST_TYPE_SDK_HOST: {
  26. "TOOLCHAIN_HOST_TASK": PKG_TYPE_MUST_INSTALL,
  27. "TOOLCHAIN_HOST_TASK_ATTEMPTONLY": PKG_TYPE_ATTEMPT_ONLY
  28. },
  29. MANIFEST_TYPE_SDK_TARGET: {
  30. "TOOLCHAIN_TARGET_TASK": PKG_TYPE_MUST_INSTALL,
  31. "TOOLCHAIN_TARGET_TASK_ATTEMPTONLY": PKG_TYPE_ATTEMPT_ONLY
  32. }
  33. }
  34. INSTALL_ORDER = [
  35. PKG_TYPE_LANGUAGE,
  36. PKG_TYPE_MUST_INSTALL,
  37. PKG_TYPE_ATTEMPT_ONLY,
  38. PKG_TYPE_MULTILIB
  39. ]
  40. initial_manifest_file_header = \
  41. "# This file was generated automatically and contains the packages\n" \
  42. "# passed on to the package manager in order to create the rootfs.\n\n" \
  43. "# Format:\n" \
  44. "# <package_type>,<package_name>\n" \
  45. "# where:\n" \
  46. "# <package_type> can be:\n" \
  47. "# 'mip' = must install package\n" \
  48. "# 'aop' = attempt only package\n" \
  49. "# 'mlp' = multilib package\n" \
  50. "# 'lgp' = language package\n\n"
  51. def __init__(self, d, manifest_dir=None, manifest_type=MANIFEST_TYPE_IMAGE):
  52. self.d = d
  53. self.manifest_type = manifest_type
  54. if manifest_dir is None:
  55. if manifest_type != self.MANIFEST_TYPE_IMAGE:
  56. self.manifest_dir = self.d.getVar('SDK_DIR')
  57. else:
  58. self.manifest_dir = self.d.getVar('WORKDIR')
  59. else:
  60. self.manifest_dir = manifest_dir
  61. bb.utils.mkdirhier(self.manifest_dir)
  62. self.initial_manifest = os.path.join(self.manifest_dir, "%s_initial_manifest" % manifest_type)
  63. self.final_manifest = os.path.join(self.manifest_dir, "%s_final_manifest" % manifest_type)
  64. self.full_manifest = os.path.join(self.manifest_dir, "%s_full_manifest" % manifest_type)
  65. # packages in the following vars will be split in 'must install' and
  66. # 'multilib'
  67. self.vars_to_split = ["PACKAGE_INSTALL",
  68. "TOOLCHAIN_HOST_TASK",
  69. "TOOLCHAIN_TARGET_TASK"]
  70. """
  71. This creates a standard initial manifest for core-image-(minimal|sato|sato-sdk).
  72. This will be used for testing until the class is implemented properly!
  73. """
  74. def _create_dummy_initial(self):
  75. image_rootfs = self.d.getVar('IMAGE_ROOTFS')
  76. pkg_list = dict()
  77. if image_rootfs.find("core-image-sato-sdk") > 0:
  78. pkg_list[self.PKG_TYPE_MUST_INSTALL] = \
  79. "packagegroup-core-x11-sato-games packagegroup-base-extended " \
  80. "packagegroup-core-x11-sato packagegroup-core-x11-base " \
  81. "packagegroup-core-sdk packagegroup-core-tools-debug " \
  82. "packagegroup-core-boot packagegroup-core-tools-testapps " \
  83. "packagegroup-core-eclipse-debug packagegroup-core-qt-demoapps " \
  84. "apt packagegroup-core-tools-profile psplash " \
  85. "packagegroup-core-standalone-sdk-target " \
  86. "packagegroup-core-ssh-openssh dpkg kernel-dev"
  87. pkg_list[self.PKG_TYPE_LANGUAGE] = \
  88. "locale-base-en-us locale-base-en-gb"
  89. elif image_rootfs.find("core-image-sato") > 0:
  90. pkg_list[self.PKG_TYPE_MUST_INSTALL] = \
  91. "packagegroup-core-ssh-dropbear packagegroup-core-x11-sato-games " \
  92. "packagegroup-core-x11-base psplash apt dpkg packagegroup-base-extended " \
  93. "packagegroup-core-x11-sato packagegroup-core-boot"
  94. pkg_list['lgp'] = \
  95. "locale-base-en-us locale-base-en-gb"
  96. elif image_rootfs.find("core-image-minimal") > 0:
  97. pkg_list[self.PKG_TYPE_MUST_INSTALL] = "packagegroup-core-boot"
  98. with open(self.initial_manifest, "w+") as manifest:
  99. manifest.write(self.initial_manifest_file_header)
  100. for pkg_type in pkg_list:
  101. for pkg in pkg_list[pkg_type].split():
  102. manifest.write("%s,%s\n" % (pkg_type, pkg))
  103. """
  104. This will create the initial manifest which will be used by Rootfs class to
  105. generate the rootfs
  106. """
  107. @abstractmethod
  108. def create_initial(self):
  109. pass
  110. """
  111. This creates the manifest after everything has been installed.
  112. """
  113. @abstractmethod
  114. def create_final(self):
  115. pass
  116. """
  117. This creates the manifest after the package in initial manifest has been
  118. dummy installed. It lists all *to be installed* packages. There is no real
  119. installation, just a test.
  120. """
  121. @abstractmethod
  122. def create_full(self, pm):
  123. pass
  124. """
  125. The following function parses an initial manifest and returns a dictionary
  126. object with the must install, attempt only, multilib and language packages.
  127. """
  128. def parse_initial_manifest(self):
  129. pkgs = dict()
  130. with open(self.initial_manifest) as manifest:
  131. for line in manifest.read().split('\n'):
  132. comment = re.match("^#.*", line)
  133. pattern = "^(%s|%s|%s|%s),(.*)$" % \
  134. (self.PKG_TYPE_MUST_INSTALL,
  135. self.PKG_TYPE_ATTEMPT_ONLY,
  136. self.PKG_TYPE_MULTILIB,
  137. self.PKG_TYPE_LANGUAGE)
  138. pkg = re.match(pattern, line)
  139. if comment is not None:
  140. continue
  141. if pkg is not None:
  142. pkg_type = pkg.group(1)
  143. pkg_name = pkg.group(2)
  144. if not pkg_type in pkgs:
  145. pkgs[pkg_type] = [pkg_name]
  146. else:
  147. pkgs[pkg_type].append(pkg_name)
  148. return pkgs
  149. '''
  150. This following function parses a full manifest and return a list
  151. object with packages.
  152. '''
  153. def parse_full_manifest(self):
  154. installed_pkgs = list()
  155. if not os.path.exists(self.full_manifest):
  156. bb.note('full manifest not exist')
  157. return installed_pkgs
  158. with open(self.full_manifest, 'r') as manifest:
  159. for pkg in manifest.read().split('\n'):
  160. installed_pkgs.append(pkg.strip())
  161. return installed_pkgs
  162. def create_manifest(d, final_manifest=False, manifest_dir=None,
  163. manifest_type=Manifest.MANIFEST_TYPE_IMAGE):
  164. from oe.package_manager.rpm.manifest import RpmManifest
  165. from oe.package_manager.ipk.manifest import OpkgManifest
  166. from oe.package_manager.deb.manifest import DpkgManifest
  167. manifest_map = {'rpm': RpmManifest,
  168. 'ipk': OpkgManifest,
  169. 'deb': DpkgManifest}
  170. manifest = manifest_map[d.getVar('IMAGE_PKGTYPE')](d, manifest_dir, manifest_type)
  171. if final_manifest:
  172. manifest.create_final()
  173. else:
  174. manifest.create_initial()
  175. if __name__ == "__main__":
  176. pass