populate_sdk_ext.bbclass 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853
  1. #
  2. # Copyright OpenEmbedded Contributors
  3. #
  4. # SPDX-License-Identifier: MIT
  5. #
  6. # Extensible SDK
  7. inherit populate_sdk_base
  8. # Used to override TOOLCHAIN_HOST_TASK in the eSDK case
  9. TOOLCHAIN_HOST_TASK_ESDK = " \
  10. meta-environment-extsdk-${MACHINE} \
  11. "
  12. SDK_RELOCATE_AFTER_INSTALL:task-populate-sdk-ext = "0"
  13. SDK_EXT = ""
  14. SDK_EXT:task-populate-sdk-ext = "-ext"
  15. # Options are full or minimal
  16. SDK_EXT_TYPE ?= "full"
  17. SDK_INCLUDE_PKGDATA ?= "0"
  18. SDK_INCLUDE_TOOLCHAIN ?= "${@'1' if d.getVar('SDK_EXT_TYPE') == 'full' else '0'}"
  19. SDK_INCLUDE_NATIVESDK ?= "0"
  20. SDK_INCLUDE_BUILDTOOLS ?= '1'
  21. SDK_RECRDEP_TASKS ?= ""
  22. SDK_CUSTOM_TEMPLATECONF ?= "0"
  23. ESDK_LOCALCONF_ALLOW ?= ""
  24. ESDK_LOCALCONF_REMOVE ?= "CONF_VERSION \
  25. BB_NUMBER_THREADS \
  26. BB_NUMBER_PARSE_THREADS \
  27. PARALLEL_MAKE \
  28. PRSERV_HOST \
  29. SSTATE_MIRRORS \
  30. DL_DIR \
  31. SSTATE_DIR \
  32. TMPDIR \
  33. BB_SERVER_TIMEOUT \
  34. "
  35. ESDK_CLASS_INHERIT_DISABLE ?= "buildhistory"
  36. SDK_UPDATE_URL ?= ""
  37. SDK_TARGETS ?= "${PN}"
  38. def get_sdk_install_targets(d, images_only=False):
  39. sdk_install_targets = ''
  40. if images_only or d.getVar('SDK_EXT_TYPE') != 'minimal':
  41. sdk_install_targets = d.getVar('SDK_TARGETS')
  42. depd = d.getVar('BB_TASKDEPDATA', False)
  43. tasklist = bb.build.tasksbetween('do_image_complete', 'do_build', d)
  44. tasklist.remove('do_build')
  45. for v in depd.values():
  46. if v[1] in tasklist:
  47. if v[0] not in sdk_install_targets:
  48. sdk_install_targets += ' {}'.format(v[0])
  49. if not images_only:
  50. if d.getVar('SDK_INCLUDE_PKGDATA') == '1':
  51. sdk_install_targets += ' meta-world-pkgdata:do_allpackagedata'
  52. if d.getVar('SDK_INCLUDE_TOOLCHAIN') == '1':
  53. sdk_install_targets += ' meta-extsdk-toolchain:do_populate_sysroot'
  54. return sdk_install_targets
  55. get_sdk_install_targets[vardepsexclude] = "BB_TASKDEPDATA"
  56. OE_INIT_ENV_SCRIPT ?= "oe-init-build-env"
  57. # The files from COREBASE that you want preserved in the COREBASE copied
  58. # into the sdk. This allows someone to have their own setup scripts in
  59. # COREBASE be preserved as well as untracked files.
  60. COREBASE_FILES ?= " \
  61. oe-init-build-env \
  62. scripts \
  63. LICENSE \
  64. .templateconf \
  65. "
  66. SDK_DIR:task-populate-sdk-ext = "${WORKDIR}/sdk-ext"
  67. B:task-populate-sdk-ext = "${SDK_DIR}"
  68. TOOLCHAINEXT_OUTPUTNAME ?= "${SDK_NAME}-toolchain-ext-${SDK_VERSION}"
  69. TOOLCHAIN_OUTPUTNAME:task-populate-sdk-ext = "${TOOLCHAINEXT_OUTPUTNAME}"
  70. SDK_EXT_TARGET_MANIFEST = "${SDK_DEPLOY}/${TOOLCHAINEXT_OUTPUTNAME}.target.manifest"
  71. SDK_EXT_HOST_MANIFEST = "${SDK_DEPLOY}/${TOOLCHAINEXT_OUTPUTNAME}.host.manifest"
  72. python write_target_sdk_ext_manifest () {
  73. from oe.sdk import get_extra_sdkinfo
  74. sstate_dir = d.expand('${SDK_OUTPUT}/${SDKPATH}/sstate-cache')
  75. extra_info = get_extra_sdkinfo(sstate_dir)
  76. target = d.getVar('TARGET_SYS')
  77. target_multimach = d.getVar('MULTIMACH_TARGET_SYS')
  78. real_target_multimach = d.getVar('REAL_MULTIMACH_TARGET_SYS')
  79. pkgs = {}
  80. os.makedirs(os.path.dirname(d.getVar('SDK_EXT_TARGET_MANIFEST')), exist_ok=True)
  81. with open(d.getVar('SDK_EXT_TARGET_MANIFEST'), 'w') as f:
  82. for fn in extra_info['filesizes']:
  83. info = fn.split(':')
  84. if info[2] in (target, target_multimach, real_target_multimach) \
  85. or info[5] == 'allarch':
  86. if not info[1] in pkgs:
  87. f.write("%s %s %s\n" % (info[1], info[2], info[3]))
  88. pkgs[info[1]] = {}
  89. }
  90. python write_host_sdk_ext_manifest () {
  91. from oe.sdk import get_extra_sdkinfo
  92. sstate_dir = d.expand('${SDK_OUTPUT}/${SDKPATH}/sstate-cache')
  93. extra_info = get_extra_sdkinfo(sstate_dir)
  94. host = d.getVar('BUILD_SYS')
  95. with open(d.getVar('SDK_EXT_HOST_MANIFEST'), 'w') as f:
  96. for fn in extra_info['filesizes']:
  97. info = fn.split(':')
  98. if info[2] == host:
  99. f.write("%s %s %s\n" % (info[1], info[2], info[3]))
  100. }
  101. SDK_POSTPROCESS_COMMAND:append:task-populate-sdk-ext = " write_target_sdk_ext_manifest write_host_sdk_ext_manifest"
  102. SDK_TITLE:task-populate-sdk-ext = "${@d.getVar('DISTRO_NAME') or d.getVar('DISTRO')} Extensible SDK"
  103. def clean_esdk_builddir(d, sdkbasepath):
  104. """Clean up traces of the fake build for create_filtered_tasklist()"""
  105. import shutil
  106. cleanpaths = ['cache', 'tmp']
  107. for pth in cleanpaths:
  108. fullpth = os.path.join(sdkbasepath, pth)
  109. if os.path.isdir(fullpth):
  110. shutil.rmtree(fullpth)
  111. elif os.path.isfile(fullpth):
  112. os.remove(fullpth)
  113. def create_filtered_tasklist(d, sdkbasepath, tasklistfile, conf_initpath):
  114. """
  115. Create a filtered list of tasks. Also double-checks that the build system
  116. within the SDK basically works and required sstate artifacts are available.
  117. """
  118. import tempfile
  119. import shutil
  120. import oe.copy_buildsystem
  121. # Create a temporary build directory that we can pass to the env setup script
  122. shutil.copyfile(sdkbasepath + '/conf/local.conf', sdkbasepath + '/conf/local.conf.bak')
  123. try:
  124. with open(sdkbasepath + '/conf/local.conf', 'a') as f:
  125. # Force the use of sstate from the build system
  126. f.write('\nSSTATE_DIR:forcevariable = "%s"\n' % d.getVar('SSTATE_DIR'))
  127. # Ensure TMPDIR is the default so that clean_esdk_builddir() can delete it
  128. f.write('TMPDIR:forcevariable = "${TOPDIR}/tmp"\n')
  129. # Drop uninative if the build isn't using it (or else NATIVELSBSTRING will
  130. # be different and we won't be able to find our native sstate)
  131. if not bb.data.inherits_class('uninative', d):
  132. f.write('INHERIT:remove = "uninative"\n')
  133. # Unfortunately the default SDKPATH (or even a custom value) may contain characters that bitbake
  134. # will not allow in its COREBASE path, so we need to rename the directory temporarily
  135. temp_sdkbasepath = d.getVar('SDK_OUTPUT') + '/tmp-renamed-sdk'
  136. # Delete any existing temp dir
  137. try:
  138. shutil.rmtree(temp_sdkbasepath)
  139. except FileNotFoundError:
  140. pass
  141. bb.utils.rename(sdkbasepath, temp_sdkbasepath)
  142. cmdprefix = '. %s .; ' % conf_initpath
  143. logfile = d.getVar('WORKDIR') + '/tasklist_bb_log.txt'
  144. try:
  145. oe.copy_buildsystem.check_sstate_task_list(d, get_sdk_install_targets(d), tasklistfile, cmdprefix=cmdprefix, cwd=temp_sdkbasepath, logfile=logfile)
  146. except bb.process.ExecutionError as e:
  147. msg = 'Failed to generate filtered task list for extensible SDK:\n%s' % e.stdout.rstrip()
  148. if 'attempted to execute unexpectedly and should have been setscened' in e.stdout:
  149. msg += '\n----------\n\nNOTE: "attempted to execute unexpectedly and should have been setscened" errors indicate this may be caused by missing sstate artifacts that were likely produced in earlier builds, but have been subsequently deleted for some reason.\n'
  150. bb.fatal(msg)
  151. bb.utils.rename(temp_sdkbasepath, sdkbasepath)
  152. # Clean out residue of running bitbake, which check_sstate_task_list()
  153. # will effectively do
  154. clean_esdk_builddir(d, sdkbasepath)
  155. finally:
  156. localconf = sdkbasepath + '/conf/local.conf'
  157. if os.path.exists(localconf + '.bak'):
  158. os.replace(localconf + '.bak', localconf)
  159. def copy_bitbake_and_layers(d, baseoutpath, derivative):
  160. oe_init_env_script = d.getVar('OE_INIT_ENV_SCRIPT')
  161. conf_bbpath = ''
  162. conf_initpath = ''
  163. core_meta_subdir = ''
  164. # Copy in all metadata layers + bitbake (as repositories)
  165. buildsystem = oe.copy_buildsystem.BuildSystem('extensible SDK', d)
  166. if derivative:
  167. workspace_name = 'orig-workspace'
  168. else:
  169. workspace_name = None
  170. corebase, sdkbblayers = buildsystem.copy_bitbake_and_layers(baseoutpath + '/layers', workspace_name)
  171. conf_bbpath = os.path.join('layers', corebase, 'bitbake')
  172. for path in os.listdir(baseoutpath + '/layers'):
  173. relpath = os.path.join('layers', path, oe_init_env_script)
  174. if os.path.exists(os.path.join(baseoutpath, relpath)):
  175. conf_initpath = relpath
  176. relpath = os.path.join('layers', path, 'scripts', 'esdk-tools', 'devtool')
  177. if os.path.exists(os.path.join(baseoutpath, relpath)):
  178. esdk_tools_path = os.path.dirname(relpath)
  179. relpath = os.path.join('layers', path, 'meta')
  180. if os.path.exists(os.path.join(baseoutpath, relpath, 'lib', 'oe')):
  181. core_meta_subdir = relpath
  182. d.setVar('oe_init_build_env_path', conf_initpath)
  183. d.setVar('esdk_tools_path', esdk_tools_path)
  184. return (conf_initpath, conf_bbpath, core_meta_subdir, sdkbblayers)
  185. def write_devtool_config(d, baseoutpath, conf_bbpath, conf_initpath, core_meta_subdir):
  186. # Write out config file for devtool
  187. import configparser
  188. config = configparser.ConfigParser()
  189. config.add_section('General')
  190. config.set('General', 'bitbake_subdir', conf_bbpath)
  191. config.set('General', 'init_path', conf_initpath)
  192. config.set('General', 'core_meta_subdir', core_meta_subdir)
  193. config.add_section('SDK')
  194. config.set('SDK', 'sdk_targets', d.getVar('SDK_TARGETS'))
  195. updateurl = d.getVar('SDK_UPDATE_URL')
  196. if updateurl:
  197. config.set('SDK', 'updateserver', updateurl)
  198. bb.utils.mkdirhier(os.path.join(baseoutpath, 'conf'))
  199. with open(os.path.join(baseoutpath, 'conf', 'devtool.conf'), 'w') as f:
  200. config.write(f)
  201. def write_unlocked_sigs(d, baseoutpath):
  202. unlockedsigs = os.path.join(baseoutpath, 'conf', 'unlocked-sigs.inc')
  203. with open(unlockedsigs, 'w') as f:
  204. pass
  205. def write_bblayers_conf(d, baseoutpath, sdkbblayers):
  206. # Create a layer for new recipes / appends
  207. bbpath = d.getVar('BBPATH')
  208. env = os.environ.copy()
  209. env['PYTHONDONTWRITEBYTECODE'] = '1'
  210. bb.process.run(['devtool', '--bbpath', bbpath, '--basepath', baseoutpath, 'create-workspace', '--layerseries', d.getVar("LAYERSERIES_CORENAMES"), '--create-only', os.path.join(baseoutpath, 'workspace')], env=env)
  211. # Create bblayers.conf
  212. bb.utils.mkdirhier(baseoutpath + '/conf')
  213. with open(baseoutpath + '/conf/bblayers.conf', 'w') as f:
  214. f.write('# WARNING: this configuration has been automatically generated and in\n')
  215. f.write('# most cases should not be edited. If you need more flexibility than\n')
  216. f.write('# this configuration provides, it is strongly suggested that you set\n')
  217. f.write('# up a proper instance of the full build system and use that instead.\n\n')
  218. # LCONF_VERSION may not be set, for example when using meta-poky
  219. # so don't error if it isn't found
  220. lconf_version = d.getVar('LCONF_VERSION', False)
  221. if lconf_version is not None:
  222. f.write('LCONF_VERSION = "%s"\n\n' % lconf_version)
  223. f.write('BBPATH = "$' + '{TOPDIR}"\n')
  224. f.write('SDKBASEMETAPATH = "$' + '{TOPDIR}"\n')
  225. f.write('BBLAYERS := " \\\n')
  226. for layerrelpath in sdkbblayers:
  227. f.write(' $' + '{SDKBASEMETAPATH}/layers/%s \\\n' % layerrelpath)
  228. f.write(' $' + '{SDKBASEMETAPATH}/workspace \\\n')
  229. f.write(' "\n')
  230. def copy_uninative(d, baseoutpath):
  231. import shutil
  232. uninative_checksum = None
  233. # Copy uninative tarball
  234. # For now this is where uninative.bbclass expects the tarball
  235. if bb.data.inherits_class('uninative', d):
  236. uninative_file = d.expand('${UNINATIVE_DLDIR}/' + d.getVarFlag("UNINATIVE_CHECKSUM", d.getVar("BUILD_ARCH")) + '/${UNINATIVE_TARBALL}')
  237. uninative_checksum = bb.utils.sha256_file(uninative_file)
  238. uninative_outdir = '%s/downloads/uninative/%s' % (baseoutpath, uninative_checksum)
  239. bb.utils.mkdirhier(uninative_outdir)
  240. shutil.copy(uninative_file, uninative_outdir)
  241. return uninative_checksum
  242. def write_local_conf(d, baseoutpath, derivative, core_meta_subdir, uninative_checksum):
  243. import shutil
  244. #check if custome templateconf path is set
  245. use_custom_templateconf = d.getVar('SDK_CUSTOM_TEMPLATECONF')
  246. env_passthrough = (d.getVar('BB_ENV_PASSTHROUGH_ADDITIONS') or '').split()
  247. env_passthrough_values = {}
  248. # Create local.conf
  249. builddir = d.getVar('TOPDIR')
  250. if derivative and os.path.exists(builddir + '/conf/site.conf'):
  251. shutil.copyfile(builddir + '/conf/site.conf', baseoutpath + '/conf/site.conf')
  252. if derivative and os.path.exists(builddir + '/conf/auto.conf'):
  253. shutil.copyfile(builddir + '/conf/auto.conf', baseoutpath + '/conf/auto.conf')
  254. if derivative:
  255. shutil.copyfile(builddir + '/conf/local.conf', baseoutpath + '/conf/local.conf')
  256. else:
  257. local_conf_allowed = (d.getVar('ESDK_LOCALCONF_ALLOW') or '').split()
  258. local_conf_remove = (d.getVar('ESDK_LOCALCONF_REMOVE') or '').split()
  259. def handle_var(varname, origvalue, op, newlines):
  260. if varname in local_conf_remove or (origvalue.strip().startswith('/') and not varname in local_conf_allowed):
  261. newlines.append('# Removed original setting of %s\n' % varname)
  262. return None, op, 0, True
  263. else:
  264. if varname in env_passthrough:
  265. env_passthrough_values[varname] = origvalue
  266. return origvalue, op, 0, True
  267. varlist = ['[^#=+ ]*']
  268. oldlines = []
  269. if os.path.exists(builddir + '/conf/site.conf'):
  270. with open(builddir + '/conf/site.conf', 'r') as f:
  271. oldlines += f.readlines()
  272. if os.path.exists(builddir + '/conf/auto.conf'):
  273. with open(builddir + '/conf/auto.conf', 'r') as f:
  274. oldlines += f.readlines()
  275. if os.path.exists(builddir + '/conf/local.conf'):
  276. with open(builddir + '/conf/local.conf', 'r') as f:
  277. oldlines += f.readlines()
  278. (updated, newlines) = bb.utils.edit_metadata(oldlines, varlist, handle_var)
  279. with open(baseoutpath + '/conf/local.conf', 'w') as f:
  280. f.write('# WARNING: this configuration has been automatically generated and in\n')
  281. f.write('# most cases should not be edited. If you need more flexibility than\n')
  282. f.write('# this configuration provides, it is strongly suggested that you set\n')
  283. f.write('# up a proper instance of the full build system and use that instead.\n\n')
  284. for line in newlines:
  285. if line.strip() and not line.startswith('#'):
  286. f.write(line)
  287. # Write a newline just in case there's none at the end of the original
  288. f.write('\n')
  289. f.write('TMPDIR = "${TOPDIR}/tmp"\n')
  290. f.write('DL_DIR = "${TOPDIR}/downloads"\n')
  291. if bb.data.inherits_class('uninative', d):
  292. f.write('INHERIT += "%s"\n' % 'uninative')
  293. f.write('UNINATIVE_CHECKSUM[%s] = "%s"\n\n' % (d.getVar('BUILD_ARCH'), uninative_checksum))
  294. f.write('CONF_VERSION = "%s"\n\n' % d.getVar('CONF_VERSION', False))
  295. # Some classes are not suitable for SDK, remove them from INHERIT
  296. f.write('INHERIT:remove = "%s"\n' % d.getVar('ESDK_CLASS_INHERIT_DISABLE', False))
  297. # Bypass the default connectivity check if any
  298. f.write('CONNECTIVITY_CHECK_URIS = ""\n\n')
  299. # This warning will come out if reverse dependencies for a task
  300. # don't have sstate as well as the task itself. We already know
  301. # this will be the case for the extensible sdk, so turn off the
  302. # warning.
  303. f.write('SIGGEN_LOCKEDSIGS_SSTATE_EXISTS_CHECK = "none"\n\n')
  304. # Warn if the sigs in the locked-signature file don't match
  305. # the sig computed from the metadata.
  306. f.write('SIGGEN_LOCKEDSIGS_TASKSIG_CHECK = "warn"\n\n')
  307. # We want to be able to set this without a full reparse
  308. f.write('BB_HASHCONFIG_IGNORE_VARS:append = " SIGGEN_UNLOCKED_RECIPES"\n\n')
  309. # Set up which tasks are ignored for run on install
  310. f.write('BB_SETSCENE_ENFORCE_IGNORE_TASKS = "%:* *:do_shared_workdir *:do_rm_work wic-tools:* *:do_addto_recipe_sysroot"\n\n')
  311. # Hide the config information from bitbake output (since it's fixed within the SDK)
  312. f.write('BUILDCFG_HEADER = ""\n\n')
  313. # Write METADATA_REVISION
  314. # Needs distro override so it can override the value set in the bbclass code (later than local.conf)
  315. f.write('METADATA_REVISION:%s = "%s"\n\n' % (d.getVar('DISTRO'), d.getVar('METADATA_REVISION')))
  316. f.write('# Provide a flag to indicate we are in the EXT_SDK Context\n')
  317. f.write('WITHIN_EXT_SDK = "1"\n\n')
  318. if d.getVar("PRSERV_HOST"):
  319. # Override this, we now include PR data, so it should only point ot the local database
  320. f.write('PRSERV_HOST = "localhost:0"\n\n')
  321. # Allow additional config through sdk-extra.conf
  322. fn = bb.cookerdata.findConfigFile('sdk-extra.conf', d)
  323. if fn:
  324. with open(fn, 'r') as xf:
  325. for line in xf:
  326. f.write(line)
  327. # If you define a sdk_extraconf() function then it can contain additional config
  328. # (Though this is awkward; sdk-extra.conf should probably be used instead)
  329. extraconf = (d.getVar('sdk_extraconf') or '').strip()
  330. if extraconf:
  331. # Strip off any leading / trailing spaces
  332. for line in extraconf.splitlines():
  333. f.write(line.strip() + '\n')
  334. f.write('require conf/locked-sigs.inc\n')
  335. f.write('require conf/unlocked-sigs.inc\n')
  336. # Copy multiple configurations if they exist in the users config directory
  337. if d.getVar('BBMULTICONFIG') is not None:
  338. bb.utils.mkdirhier(os.path.join(baseoutpath, 'conf', 'multiconfig'))
  339. for mc in d.getVar('BBMULTICONFIG').split():
  340. dest_stub = "/conf/multiconfig/%s.conf" % (mc,)
  341. if os.path.exists(builddir + dest_stub):
  342. shutil.copyfile(builddir + dest_stub, baseoutpath + dest_stub)
  343. # If PR Service is in use, we need to export this as well
  344. bb.note('Do we have a pr database?')
  345. if d.getVar("PRSERV_HOST"):
  346. bb.note('Writing PR database...')
  347. # Based on the code in classes/prexport.bbclass
  348. import oe.prservice
  349. #dump meta info of tables
  350. localdata = d.createCopy()
  351. localdata.setVar('PRSERV_DUMPOPT_COL', "1")
  352. localdata.setVar('PRSERV_DUMPDIR', os.path.join(baseoutpath, 'conf'))
  353. localdata.setVar('PRSERV_DUMPFILE', '${PRSERV_DUMPDIR}/prserv.inc')
  354. bb.note('PR Database write to %s' % (localdata.getVar('PRSERV_DUMPFILE')))
  355. retval = oe.prservice.prserv_dump_db(localdata)
  356. if not retval:
  357. bb.error("prexport_handler: export failed!")
  358. return
  359. (metainfo, datainfo) = retval
  360. oe.prservice.prserv_export_tofile(localdata, metainfo, datainfo, True)
  361. # Use templateconf.cfg file from builddir if exists
  362. if os.path.exists(builddir + '/conf/templateconf.cfg') and use_custom_templateconf == '1':
  363. shutil.copyfile(builddir + '/conf/templateconf.cfg', baseoutpath + '/conf/templateconf.cfg')
  364. else:
  365. # Write a templateconf.cfg
  366. with open(baseoutpath + '/conf/templateconf.cfg', 'w') as f:
  367. f.write('meta/conf/templates/default\n')
  368. os.makedirs(os.path.join(baseoutpath, core_meta_subdir, 'conf/templates/default'), exist_ok=True)
  369. # Ensure any variables set from the external environment (by way of
  370. # BB_ENV_PASSTHROUGH_ADDITIONS) are set in the SDK's configuration
  371. extralines = []
  372. for name, value in env_passthrough_values.items():
  373. actualvalue = d.getVar(name) or ''
  374. if value != actualvalue:
  375. extralines.append('%s = "%s"\n' % (name, actualvalue))
  376. if extralines:
  377. with open(baseoutpath + '/conf/local.conf', 'a') as f:
  378. f.write('\n')
  379. f.write('# Extra settings from environment:\n')
  380. for line in extralines:
  381. f.write(line)
  382. f.write('\n')
  383. def prepare_locked_cache(d, baseoutpath, derivative, conf_initpath):
  384. import shutil
  385. # Filter the locked signatures file to just the sstate tasks we are interested in
  386. excluded_targets = get_sdk_install_targets(d, images_only=True)
  387. sigfile = d.getVar('WORKDIR') + '/locked-sigs.inc'
  388. lockedsigs_pruned = baseoutpath + '/conf/locked-sigs.inc'
  389. #nativesdk-only sigfile to merge into locked-sigs.inc
  390. sdk_include_nativesdk = (d.getVar("SDK_INCLUDE_NATIVESDK") == '1')
  391. nativesigfile = d.getVar('WORKDIR') + '/locked-sigs_nativesdk.inc'
  392. nativesigfile_pruned = d.getVar('WORKDIR') + '/locked-sigs_nativesdk_pruned.inc'
  393. if sdk_include_nativesdk:
  394. oe.copy_buildsystem.prune_lockedsigs([],
  395. excluded_targets.split(),
  396. nativesigfile,
  397. True,
  398. nativesigfile_pruned)
  399. oe.copy_buildsystem.merge_lockedsigs([],
  400. sigfile,
  401. nativesigfile_pruned,
  402. sigfile)
  403. oe.copy_buildsystem.prune_lockedsigs([],
  404. excluded_targets.split(),
  405. sigfile,
  406. False,
  407. lockedsigs_pruned)
  408. sstate_out = baseoutpath + '/sstate-cache'
  409. bb.utils.remove(sstate_out, True)
  410. # uninative.bbclass sets NATIVELSBSTRING to 'universal'
  411. fixedlsbstring = "universal" if bb.data.inherits_class('uninative', d) else ""
  412. sdk_include_toolchain = (d.getVar('SDK_INCLUDE_TOOLCHAIN') == '1')
  413. sdk_ext_type = d.getVar('SDK_EXT_TYPE')
  414. if (sdk_ext_type != 'minimal' or sdk_include_toolchain or derivative) and not sdk_include_nativesdk:
  415. # Create the filtered task list used to generate the sstate cache shipped with the SDK
  416. tasklistfn = d.getVar('WORKDIR') + '/tasklist.txt'
  417. create_filtered_tasklist(d, baseoutpath, tasklistfn, conf_initpath)
  418. else:
  419. tasklistfn = None
  420. # Add packagedata if enabled
  421. if d.getVar('SDK_INCLUDE_PKGDATA') == '1':
  422. lockedsigs_base = d.getVar('WORKDIR') + '/locked-sigs-base.inc'
  423. lockedsigs_copy = d.getVar('WORKDIR') + '/locked-sigs-copy.inc'
  424. shutil.move(lockedsigs_pruned, lockedsigs_base)
  425. oe.copy_buildsystem.merge_lockedsigs(['do_packagedata'],
  426. lockedsigs_base,
  427. d.getVar('STAGING_DIR_HOST') + '/world-pkgdata/locked-sigs-pkgdata.inc',
  428. lockedsigs_pruned,
  429. lockedsigs_copy)
  430. if sdk_include_toolchain:
  431. lockedsigs_base = d.getVar('WORKDIR') + '/locked-sigs-base2.inc'
  432. lockedsigs_toolchain = d.expand("${STAGING_DIR}/${TUNE_PKGARCH}/meta-extsdk-toolchain/locked-sigs/locked-sigs-extsdk-toolchain.inc")
  433. shutil.move(lockedsigs_pruned, lockedsigs_base)
  434. oe.copy_buildsystem.merge_lockedsigs([],
  435. lockedsigs_base,
  436. lockedsigs_toolchain,
  437. lockedsigs_pruned)
  438. oe.copy_buildsystem.create_locked_sstate_cache(lockedsigs_toolchain,
  439. d.getVar('SSTATE_DIR'),
  440. sstate_out, d,
  441. fixedlsbstring,
  442. filterfile=tasklistfn)
  443. if sdk_ext_type == 'minimal':
  444. if derivative:
  445. # Assume the user is not going to set up an additional sstate
  446. # mirror, thus we need to copy the additional artifacts (from
  447. # workspace recipes) into the derivative SDK
  448. lockedsigs_orig = d.getVar('TOPDIR') + '/conf/locked-sigs.inc'
  449. if os.path.exists(lockedsigs_orig):
  450. lockedsigs_extra = d.getVar('WORKDIR') + '/locked-sigs-extra.inc'
  451. oe.copy_buildsystem.merge_lockedsigs(None,
  452. lockedsigs_orig,
  453. lockedsigs_pruned,
  454. None,
  455. lockedsigs_extra)
  456. oe.copy_buildsystem.create_locked_sstate_cache(lockedsigs_extra,
  457. d.getVar('SSTATE_DIR'),
  458. sstate_out, d,
  459. fixedlsbstring,
  460. filterfile=tasklistfn)
  461. else:
  462. oe.copy_buildsystem.create_locked_sstate_cache(lockedsigs_pruned,
  463. d.getVar('SSTATE_DIR'),
  464. sstate_out, d,
  465. fixedlsbstring,
  466. filterfile=tasklistfn)
  467. # We don't need sstate do_package files
  468. for root, dirs, files in os.walk(sstate_out):
  469. for name in files:
  470. if name.endswith("_package.tar.zst"):
  471. f = os.path.join(root, name)
  472. os.remove(f)
  473. def write_manifest(d, baseoutpath):
  474. import glob
  475. # Write manifest file
  476. # Note: at the moment we cannot include the env setup script here to keep
  477. # it updated, since it gets modified during SDK installation (see
  478. # sdk_ext_postinst() below) thus the checksum we take here would always
  479. # be different.
  480. manifest_file_list = ['conf/*']
  481. if d.getVar('BBMULTICONFIG') is not None:
  482. manifest_file_list.append('conf/multiconfig/*')
  483. esdk_manifest_excludes = (d.getVar('ESDK_MANIFEST_EXCLUDES') or '').split()
  484. esdk_manifest_excludes_list = []
  485. for exclude_item in esdk_manifest_excludes:
  486. esdk_manifest_excludes_list += glob.glob(os.path.join(baseoutpath, exclude_item))
  487. manifest_file = os.path.join(baseoutpath, 'conf', 'sdk-conf-manifest')
  488. with open(manifest_file, 'w') as f:
  489. for item in manifest_file_list:
  490. for fn in glob.glob(os.path.join(baseoutpath, item)):
  491. if fn == manifest_file or os.path.isdir(fn):
  492. continue
  493. if fn in esdk_manifest_excludes_list:
  494. continue
  495. chksum = bb.utils.sha256_file(fn)
  496. f.write('%s\t%s\n' % (chksum, os.path.relpath(fn, baseoutpath)))
  497. python copy_buildsystem () {
  498. import oe.copy_buildsystem
  499. baseoutpath = d.getVar('SDK_OUTPUT') + '/' + d.getVar('SDKPATH')
  500. # Determine if we're building a derivative extensible SDK (from devtool build-sdk)
  501. derivative = (d.getVar('SDK_DERIVATIVE') or '') == '1'
  502. conf_initpath, conf_bbpath, core_meta_subdir, sdkbblayers = copy_bitbake_and_layers(d, baseoutpath, derivative)
  503. write_devtool_config(d, baseoutpath, conf_bbpath, conf_initpath, core_meta_subdir)
  504. write_unlocked_sigs(d, baseoutpath)
  505. write_bblayers_conf(d, baseoutpath, sdkbblayers)
  506. uninative_checksum = copy_uninative(d, baseoutpath)
  507. write_local_conf(d, baseoutpath, derivative, core_meta_subdir, uninative_checksum)
  508. prepare_locked_cache(d, baseoutpath, derivative, conf_initpath)
  509. write_manifest(d, baseoutpath)
  510. }
  511. def get_current_buildtools(d):
  512. """Get the file name of the current buildtools installer"""
  513. import glob
  514. btfiles = glob.glob(os.path.join(d.getVar('SDK_DEPLOY'), '*-buildtools-nativesdk-standalone-*.sh'))
  515. btfiles.sort(key=os.path.getctime)
  516. return os.path.basename(btfiles[-1])
  517. def get_sdk_required_utilities(buildtools_fn, d):
  518. """Find required utilities that aren't provided by the buildtools"""
  519. sanity_required_utilities = (d.getVar('SANITY_REQUIRED_UTILITIES') or '').split()
  520. sanity_required_utilities.append(d.expand('${BUILD_PREFIX}gcc'))
  521. sanity_required_utilities.append(d.expand('${BUILD_PREFIX}g++'))
  522. if buildtools_fn:
  523. buildtools_installer = os.path.join(d.getVar('SDK_DEPLOY'), buildtools_fn)
  524. filelist, _ = bb.process.run('%s -l' % buildtools_installer)
  525. else:
  526. buildtools_installer = None
  527. filelist = ""
  528. localdata = bb.data.createCopy(d)
  529. localdata.setVar('SDKPATH', '.')
  530. sdkpathnative = localdata.getVar('SDKPATHNATIVE')
  531. sdkbindirs = [localdata.getVar('bindir_nativesdk'),
  532. localdata.getVar('sbindir_nativesdk'),
  533. localdata.getVar('base_bindir_nativesdk'),
  534. localdata.getVar('base_sbindir_nativesdk')]
  535. for line in filelist.splitlines():
  536. splitline = line.split()
  537. if len(splitline) > 5:
  538. fn = splitline[5]
  539. if not fn.startswith('./'):
  540. fn = './%s' % fn
  541. if fn.startswith(sdkpathnative):
  542. relpth = '/' + os.path.relpath(fn, sdkpathnative)
  543. for bindir in sdkbindirs:
  544. if relpth.startswith(bindir):
  545. relpth = os.path.relpath(relpth, bindir)
  546. if relpth in sanity_required_utilities:
  547. sanity_required_utilities.remove(relpth)
  548. break
  549. return ' '.join(sanity_required_utilities)
  550. install_tools() {
  551. touch ${SDK_OUTPUT}/${SDKPATH}/.devtoolbase
  552. # find latest buildtools-tarball and install it
  553. if [ -n "${SDK_BUILDTOOLS_INSTALLER}" ]; then
  554. install ${SDK_DEPLOY}/${SDK_BUILDTOOLS_INSTALLER} ${SDK_OUTPUT}/${SDKPATH}
  555. fi
  556. install -m 0644 ${COREBASE}/meta/files/ext-sdk-prepare.py ${SDK_OUTPUT}/${SDKPATH}
  557. }
  558. do_populate_sdk_ext[file-checksums] += "${COREBASE}/meta/files/ext-sdk-prepare.py:True"
  559. sdk_ext_preinst() {
  560. # Since bitbake won't run as root it doesn't make sense to try and install
  561. # the extensible sdk as root.
  562. if [ "`id -u`" = "0" ]; then
  563. echo "ERROR: The extensible sdk cannot be installed as root."
  564. exit 1
  565. fi
  566. if ! command -v locale > /dev/null; then
  567. echo "ERROR: The installer requires the locale command, please install it first"
  568. exit 1
  569. fi
  570. # Check setting of LC_ALL set above
  571. canonicalised_locale=`echo $LC_ALL | sed 's/UTF-8/utf8/'`
  572. if ! locale -a | grep -q $canonicalised_locale ; then
  573. echo "ERROR: the installer requires the $LC_ALL locale to be installed (but not selected), please install it first"
  574. exit 1
  575. fi
  576. # The relocation script used by buildtools installer requires python
  577. if ! command -v python3 > /dev/null; then
  578. echo "ERROR: The installer requires python3, please install it first"
  579. exit 1
  580. fi
  581. missing_utils=""
  582. for util in ${SDK_REQUIRED_UTILITIES}; do
  583. if ! command -v $util > /dev/null; then
  584. missing_utils="$missing_utils $util"
  585. fi
  586. done
  587. if [ -n "$missing_utils" ] ; then
  588. echo "ERROR: the SDK requires the following missing utilities, please install them: $missing_utils"
  589. exit 1
  590. fi
  591. SDK_EXTENSIBLE="1"
  592. if [ "$publish" = "1" ] && [ "${SDK_EXT_TYPE}" = "minimal" ] ; then
  593. EXTRA_TAR_OPTIONS="$EXTRA_TAR_OPTIONS --exclude=sstate-cache"
  594. fi
  595. }
  596. SDK_PRE_INSTALL_COMMAND:task-populate-sdk-ext = "${sdk_ext_preinst}"
  597. # FIXME this preparation should be done as part of the SDK construction
  598. sdk_ext_postinst() {
  599. printf "\nExtracting buildtools...\n"
  600. cd $target_sdk_dir
  601. env_setup_script="$target_sdk_dir/environment-setup-${REAL_MULTIMACH_TARGET_SYS}"
  602. if [ -n "${SDK_BUILDTOOLS_INSTALLER}" ]; then
  603. printf "buildtools\ny" | ./${SDK_BUILDTOOLS_INSTALLER} > buildtools.log || { printf 'ERROR: buildtools installation failed:\n' ; cat buildtools.log ; echo "printf 'ERROR: this SDK was not fully installed and needs reinstalling\n'" >> $env_setup_script ; exit 1 ; }
  604. # Delete the buildtools tar file since it won't be used again
  605. rm -f ./${SDK_BUILDTOOLS_INSTALLER}
  606. # We don't need the log either since it succeeded
  607. rm -f buildtools.log
  608. # Make sure when the user sets up the environment, they also get
  609. # the buildtools-tarball tools in their path.
  610. echo "# Save and reset OECORE_NATIVE_SYSROOT as buildtools may change it" >> $env_setup_script
  611. echo "SAVED=\"\$OECORE_NATIVE_SYSROOT\"" >> $env_setup_script
  612. echo ". $target_sdk_dir/buildtools/environment-setup*" >> $env_setup_script
  613. echo "export OECORE_NATIVE_SYSROOT=\"\$SAVED\"" >> $env_setup_script
  614. fi
  615. # Allow bitbake environment setup to be ran as part of this sdk.
  616. echo "export OE_SKIP_SDK_CHECK=1" >> $env_setup_script
  617. # Work around runqemu not knowing how to get this information within the eSDK
  618. echo "export DEPLOY_DIR_IMAGE=$target_sdk_dir/tmp/${@os.path.relpath(d.getVar('DEPLOY_DIR_IMAGE'), d.getVar('TMPDIR'))}" >> $env_setup_script
  619. # A bit of another hack, but we need this in the path only for devtool
  620. # so put it at the end of $PATH.
  621. echo "export PATH=\"$target_sdk_dir/${esdk_tools_path}:\$PATH\"" >> $env_setup_script
  622. echo "printf 'SDK environment now set up; additionally you may now run devtool to perform development tasks.\nRun devtool --help for further details.\n'" >> $env_setup_script
  623. # Warn if trying to use external bitbake and the ext SDK together
  624. echo "(which bitbake > /dev/null 2>&1 && echo 'WARNING: attempting to use the extensible SDK in an environment set up to run bitbake - this may lead to unexpected results. Please source this script in a new shell session instead.') || true" >> $env_setup_script
  625. if [ "$prepare_buildsystem" != "no" -a -n "${SDK_BUILDTOOLS_INSTALLER}" ]; then
  626. printf "Preparing build system...\n"
  627. # dash which is /bin/sh on Ubuntu will not preserve the
  628. # current working directory when first ran, nor will it set $1 when
  629. # sourcing a script. That is why this has to look so ugly.
  630. LOGFILE="$target_sdk_dir/preparing_build_system.log"
  631. sh -c ". buildtools/environment-setup* > $LOGFILE 2>&1 && cd $target_sdk_dir/`dirname ${oe_init_build_env_path}` && set $target_sdk_dir && . $target_sdk_dir/${oe_init_build_env_path} $target_sdk_dir >> $LOGFILE 2>&1 && python3 $target_sdk_dir/ext-sdk-prepare.py $LOGFILE '${SDK_INSTALL_TARGETS}'" || { echo "printf 'ERROR: this SDK was not fully installed and needs reinstalling\n'" >> $env_setup_script ; exit 1 ; }
  632. fi
  633. if [ -e $target_sdk_dir/ext-sdk-prepare.py ]; then
  634. rm $target_sdk_dir/ext-sdk-prepare.py
  635. fi
  636. echo done
  637. }
  638. SDK_POST_INSTALL_COMMAND:task-populate-sdk-ext = "${sdk_ext_postinst}"
  639. SDK_POSTPROCESS_COMMAND:prepend:task-populate-sdk-ext = "copy_buildsystem install_tools "
  640. SDK_INSTALL_TARGETS = ""
  641. fakeroot python do_populate_sdk_ext() {
  642. # FIXME hopefully we can remove this restriction at some point, but uninative
  643. # currently forces this upon us
  644. if d.getVar('SDK_ARCH') != d.getVar('BUILD_ARCH'):
  645. bb.fatal('The extensible SDK can currently only be built for the same architecture as the machine being built on - SDK_ARCH is set to %s (likely via setting SDKMACHINE) which is different from the architecture of the build machine (%s). Unable to continue.' % (d.getVar('SDK_ARCH'), d.getVar('BUILD_ARCH')))
  646. # FIXME hopefully we can remove this restriction at some point, but the eSDK
  647. # can only be built for the primary (default) multiconfig
  648. if d.getVar('BB_CURRENT_MC') != '':
  649. bb.fatal('The extensible SDK can currently only be built for the default multiconfig. Currently trying to build for %s.' % d.getVar('BB_CURRENT_MC'))
  650. # eSDK dependencies don't use the traditional variables and things don't work properly if they are set
  651. d.setVar("TOOLCHAIN_HOST_TASK", "${TOOLCHAIN_HOST_TASK_ESDK}")
  652. d.setVar("TOOLCHAIN_TARGET_TASK", "")
  653. d.setVar('SDK_INSTALL_TARGETS', get_sdk_install_targets(d))
  654. if d.getVar('SDK_INCLUDE_BUILDTOOLS') == '1':
  655. buildtools_fn = get_current_buildtools(d)
  656. else:
  657. buildtools_fn = None
  658. d.setVar('SDK_REQUIRED_UTILITIES', get_sdk_required_utilities(buildtools_fn, d))
  659. d.setVar('SDK_BUILDTOOLS_INSTALLER', buildtools_fn)
  660. d.setVar('SDKDEPLOYDIR', '${SDKEXTDEPLOYDIR}')
  661. # ESDKs have a libc from the buildtools so ensure we don't ship linguas twice
  662. d.delVar('SDKIMAGE_LINGUAS')
  663. if d.getVar("SDK_INCLUDE_NATIVESDK") == '1':
  664. generate_nativesdk_lockedsigs(d)
  665. populate_sdk_common(d)
  666. }
  667. def generate_nativesdk_lockedsigs(d):
  668. import oe.copy_buildsystem
  669. sigfile = d.getVar('WORKDIR') + '/locked-sigs_nativesdk.inc'
  670. oe.copy_buildsystem.generate_locked_sigs(sigfile, d)
  671. def get_ext_sdk_depends(d):
  672. # Note: the deps varflag is a list not a string, so we need to specify expand=False
  673. deps = d.getVarFlag('do_image_complete', 'deps', False)
  674. pn = d.getVar('PN')
  675. deplist = ['%s:%s' % (pn, dep) for dep in deps]
  676. tasklist = bb.build.tasksbetween('do_image_complete', 'do_build', d)
  677. tasklist.append('do_rootfs')
  678. for task in tasklist:
  679. deplist.extend((d.getVarFlag(task, 'depends') or '').split())
  680. return ' '.join(deplist)
  681. python do_sdk_depends() {
  682. # We have to do this separately in its own task so we avoid recursing into
  683. # dependencies we don't need to (e.g. buildtools-tarball) and bringing those
  684. # into the SDK's sstate-cache
  685. import oe.copy_buildsystem
  686. sigfile = d.getVar('WORKDIR') + '/locked-sigs.inc'
  687. oe.copy_buildsystem.generate_locked_sigs(sigfile, d)
  688. }
  689. addtask sdk_depends
  690. do_sdk_depends[dirs] = "${WORKDIR}"
  691. do_sdk_depends[depends] = "${@get_ext_sdk_depends(d)} meta-extsdk-toolchain:do_populate_sysroot"
  692. do_sdk_depends[recrdeptask] = "${@d.getVarFlag('do_populate_sdk', 'recrdeptask', False)}"
  693. do_sdk_depends[recrdeptask] += "do_populate_lic do_package_qa do_populate_sysroot do_deploy ${SDK_RECRDEP_TASKS}"
  694. do_sdk_depends[rdepends] = "${@' '.join([x + ':do_package_write_${IMAGE_PKGTYPE} ' + x + ':do_packagedata' for x in d.getVar('TOOLCHAIN_HOST_TASK_ESDK').split()])}"
  695. do_populate_sdk_ext[dirs] = "${@d.getVarFlag('do_populate_sdk', 'dirs', False)}"
  696. do_populate_sdk_ext[depends] = "${@d.getVarFlag('do_populate_sdk', 'depends', False)} \
  697. ${@'buildtools-tarball:do_populate_sdk' if d.getVar('SDK_INCLUDE_BUILDTOOLS') == '1' else ''} \
  698. ${@'meta-world-pkgdata:do_collect_packagedata' if d.getVar('SDK_INCLUDE_PKGDATA') == '1' else ''} \
  699. ${@'meta-extsdk-toolchain:do_locked_sigs' if d.getVar('SDK_INCLUDE_TOOLCHAIN') == '1' else ''}"
  700. # We must avoid depending on do_build here if rm_work.bbclass is active,
  701. # because otherwise do_rm_work may run before do_populate_sdk_ext itself.
  702. # We can't mark do_populate_sdk_ext and do_sdk_depends as having to
  703. # run before do_rm_work, because then they would also run as part
  704. # of normal builds.
  705. do_populate_sdk_ext[rdepends] += "${@' '.join([x + ':' + (d.getVar('RM_WORK_BUILD_WITHOUT') or 'do_build') for x in d.getVar('SDK_TARGETS').split()])}"
  706. # Make sure code changes can result in rebuild
  707. do_populate_sdk_ext[vardeps] += "copy_buildsystem \
  708. sdk_ext_postinst"
  709. # Since any change in the metadata of any layer should cause a rebuild of the
  710. # sdk(since the layers are put in the sdk) set the task to nostamp so it
  711. # always runs.
  712. do_populate_sdk_ext[nostamp] = "1"
  713. SDKEXTDEPLOYDIR = "${WORKDIR}/deploy-${PN}-populate-sdk-ext"
  714. SSTATETASKS += "do_populate_sdk_ext"
  715. SSTATE_SKIP_CREATION:task-populate-sdk-ext = '1'
  716. do_populate_sdk_ext[cleandirs] = "${SDKEXTDEPLOYDIR}"
  717. do_populate_sdk_ext[sstate-inputdirs] = "${SDKEXTDEPLOYDIR}"
  718. do_populate_sdk_ext[sstate-outputdirs] = "${SDK_DEPLOY}"
  719. do_populate_sdk_ext[stamp-extra-info] = "${MACHINE_ARCH}"
  720. addtask populate_sdk_ext after do_sdk_depends