blob: d58b2ba5d0d32a6804b7ce0a468c9826af89f677 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001# Extensible SDK
2
3inherit populate_sdk_base
4
Patrick Williams213cb262021-08-07 19:21:33 -05005# Used to override TOOLCHAIN_HOST_TASK in the eSDK case
6TOOLCHAIN_HOST_TASK_ESDK = " \
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007 meta-environment-extsdk-${MACHINE} \
8 "
9
Patrick Williams213cb262021-08-07 19:21:33 -050010SDK_RELOCATE_AFTER_INSTALL:task-populate-sdk-ext = "0"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050012SDK_EXT = ""
Patrick Williams213cb262021-08-07 19:21:33 -050013SDK_EXT:task-populate-sdk-ext = "-ext"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050014
15# Options are full or minimal
16SDK_EXT_TYPE ?= "full"
Patrick Williamsc0f7c042017-02-23 20:41:17 -060017SDK_INCLUDE_PKGDATA ?= "0"
Brad Bishop6e60e8b2018-02-01 10:27:11 -050018SDK_INCLUDE_TOOLCHAIN ?= "${@'1' if d.getVar('SDK_EXT_TYPE') == 'full' else '0'}"
Brad Bishopa34c0302019-09-23 22:34:48 -040019SDK_INCLUDE_NATIVESDK ?= "0"
Brad Bishop1d80a2e2019-11-15 16:35:03 -050020SDK_INCLUDE_BUILDTOOLS ?= '1'
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050021
22SDK_RECRDEP_TASKS ?= ""
Andrew Geissler09209ee2020-12-13 08:44:15 -060023SDK_CUSTOM_TEMPLATECONF ?= "0"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050024
Andrew Geissler7e0e3c02022-02-25 20:34:39 +000025ESDK_LOCALCONF_ALLOW ?= ""
26ESDK_LOCALCONF_REMOVE ?= "CONF_VERSION \
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050027 BB_NUMBER_THREADS \
Patrick Williamsc0f7c042017-02-23 20:41:17 -060028 BB_NUMBER_PARSE_THREADS \
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050029 PARALLEL_MAKE \
30 PRSERV_HOST \
31 SSTATE_MIRRORS \
Patrick Williamsc0f7c042017-02-23 20:41:17 -060032 DL_DIR \
33 SSTATE_DIR \
34 TMPDIR \
Brad Bishopd7bf8c12018-02-25 22:55:05 -050035 BB_SERVER_TIMEOUT \
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050036 "
Andrew Geissler7e0e3c02022-02-25 20:34:39 +000037ESDK_CLASS_INHERIT_DISABLE ?= "buildhistory icecc"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050038SDK_UPDATE_URL ?= ""
39
40SDK_TARGETS ?= "${PN}"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050041
Patrick Williamsc0f7c042017-02-23 20:41:17 -060042def get_sdk_install_targets(d, images_only=False):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050043 sdk_install_targets = ''
Brad Bishop6e60e8b2018-02-01 10:27:11 -050044 if images_only or d.getVar('SDK_EXT_TYPE') != 'minimal':
45 sdk_install_targets = d.getVar('SDK_TARGETS')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050046
47 depd = d.getVar('BB_TASKDEPDATA', False)
Brad Bishop6e60e8b2018-02-01 10:27:11 -050048 tasklist = bb.build.tasksbetween('do_image_complete', 'do_build', d)
49 tasklist.remove('do_build')
Patrick Williamsc0f7c042017-02-23 20:41:17 -060050 for v in depd.values():
Brad Bishop6e60e8b2018-02-01 10:27:11 -050051 if v[1] in tasklist:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050052 if v[0] not in sdk_install_targets:
53 sdk_install_targets += ' {}'.format(v[0])
54
Patrick Williamsc0f7c042017-02-23 20:41:17 -060055 if not images_only:
Brad Bishop6e60e8b2018-02-01 10:27:11 -050056 if d.getVar('SDK_INCLUDE_PKGDATA') == '1':
Patrick Williamsc0f7c042017-02-23 20:41:17 -060057 sdk_install_targets += ' meta-world-pkgdata:do_allpackagedata'
Brad Bishop6e60e8b2018-02-01 10:27:11 -050058 if d.getVar('SDK_INCLUDE_TOOLCHAIN') == '1':
Patrick Williamsc0f7c042017-02-23 20:41:17 -060059 sdk_install_targets += ' meta-extsdk-toolchain:do_populate_sysroot'
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050060
61 return sdk_install_targets
62
63get_sdk_install_targets[vardepsexclude] = "BB_TASKDEPDATA"
64
Patrick Williamsc124f4f2015-09-15 14:41:29 -050065OE_INIT_ENV_SCRIPT ?= "oe-init-build-env"
66
67# The files from COREBASE that you want preserved in the COREBASE copied
68# into the sdk. This allows someone to have their own setup scripts in
69# COREBASE be preserved as well as untracked files.
70COREBASE_FILES ?= " \
71 oe-init-build-env \
Patrick Williamsc124f4f2015-09-15 14:41:29 -050072 scripts \
73 LICENSE \
74 .templateconf \
75"
76
Patrick Williams213cb262021-08-07 19:21:33 -050077SDK_DIR:task-populate-sdk-ext = "${WORKDIR}/sdk-ext"
78B:task-populate-sdk-ext = "${SDK_DIR}"
Brad Bishop6e60e8b2018-02-01 10:27:11 -050079TOOLCHAINEXT_OUTPUTNAME ?= "${SDK_NAME}-toolchain-ext-${SDK_VERSION}"
Patrick Williams213cb262021-08-07 19:21:33 -050080TOOLCHAIN_OUTPUTNAME:task-populate-sdk-ext = "${TOOLCHAINEXT_OUTPUTNAME}"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050081
82SDK_EXT_TARGET_MANIFEST = "${SDK_DEPLOY}/${TOOLCHAINEXT_OUTPUTNAME}.target.manifest"
83SDK_EXT_HOST_MANIFEST = "${SDK_DEPLOY}/${TOOLCHAINEXT_OUTPUTNAME}.host.manifest"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050084
Brad Bishopd7bf8c12018-02-25 22:55:05 -050085python write_target_sdk_ext_manifest () {
86 from oe.sdk import get_extra_sdkinfo
87 sstate_dir = d.expand('${SDK_OUTPUT}/${SDKPATH}/sstate-cache')
88 extra_info = get_extra_sdkinfo(sstate_dir)
89
90 target = d.getVar('TARGET_SYS')
91 target_multimach = d.getVar('MULTIMACH_TARGET_SYS')
92 real_target_multimach = d.getVar('REAL_MULTIMACH_TARGET_SYS')
93
94 pkgs = {}
Brad Bishop1d80a2e2019-11-15 16:35:03 -050095 os.makedirs(os.path.dirname(d.getVar('SDK_EXT_TARGET_MANIFEST')), exist_ok=True)
Brad Bishopd7bf8c12018-02-25 22:55:05 -050096 with open(d.getVar('SDK_EXT_TARGET_MANIFEST'), 'w') as f:
97 for fn in extra_info['filesizes']:
98 info = fn.split(':')
99 if info[2] in (target, target_multimach, real_target_multimach) \
100 or info[5] == 'allarch':
101 if not info[1] in pkgs:
102 f.write("%s %s %s\n" % (info[1], info[2], info[3]))
103 pkgs[info[1]] = {}
104}
105python write_host_sdk_ext_manifest () {
106 from oe.sdk import get_extra_sdkinfo
107 sstate_dir = d.expand('${SDK_OUTPUT}/${SDKPATH}/sstate-cache')
108 extra_info = get_extra_sdkinfo(sstate_dir)
109 host = d.getVar('BUILD_SYS')
110 with open(d.getVar('SDK_EXT_HOST_MANIFEST'), 'w') as f:
111 for fn in extra_info['filesizes']:
112 info = fn.split(':')
113 if info[2] == host:
114 f.write("%s %s %s\n" % (info[1], info[2], info[3]))
115}
116
Patrick Williams213cb262021-08-07 19:21:33 -0500117SDK_POSTPROCESS_COMMAND:append:task-populate-sdk-ext = "write_target_sdk_ext_manifest; write_host_sdk_ext_manifest; "
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500118
Patrick Williams213cb262021-08-07 19:21:33 -0500119SDK_TITLE:task-populate-sdk-ext = "${@d.getVar('DISTRO_NAME') or d.getVar('DISTRO')} Extensible SDK"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500120
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600121def clean_esdk_builddir(d, sdkbasepath):
122 """Clean up traces of the fake build for create_filtered_tasklist()"""
123 import shutil
Andrew Geissler82c905d2020-04-13 13:39:40 -0500124 cleanpaths = ['cache', 'tmp']
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600125 for pth in cleanpaths:
126 fullpth = os.path.join(sdkbasepath, pth)
127 if os.path.isdir(fullpth):
128 shutil.rmtree(fullpth)
129 elif os.path.isfile(fullpth):
130 os.remove(fullpth)
131
132def create_filtered_tasklist(d, sdkbasepath, tasklistfile, conf_initpath):
133 """
134 Create a filtered list of tasks. Also double-checks that the build system
135 within the SDK basically works and required sstate artifacts are available.
136 """
137 import tempfile
138 import shutil
139 import oe.copy_buildsystem
140
141 # Create a temporary build directory that we can pass to the env setup script
142 shutil.copyfile(sdkbasepath + '/conf/local.conf', sdkbasepath + '/conf/local.conf.bak')
143 try:
144 with open(sdkbasepath + '/conf/local.conf', 'a') as f:
145 # Force the use of sstate from the build system
Patrick Williams213cb262021-08-07 19:21:33 -0500146 f.write('\nSSTATE_DIR:forcevariable = "%s"\n' % d.getVar('SSTATE_DIR'))
147 f.write('SSTATE_MIRRORS:forcevariable = "file://universal/(.*) file://universal-4.9/\\1 file://universal-4.9/(.*) file://universal-4.8/\\1"\n')
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600148 # Ensure TMPDIR is the default so that clean_esdk_builddir() can delete it
Patrick Williams213cb262021-08-07 19:21:33 -0500149 f.write('TMPDIR:forcevariable = "${TOPDIR}/tmp"\n')
150 f.write('TCLIBCAPPEND:forcevariable = ""\n')
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600151 # Drop uninative if the build isn't using it (or else NATIVELSBSTRING will
152 # be different and we won't be able to find our native sstate)
153 if not bb.data.inherits_class('uninative', d):
Patrick Williams213cb262021-08-07 19:21:33 -0500154 f.write('INHERIT:remove = "uninative"\n')
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600155
156 # Unfortunately the default SDKPATH (or even a custom value) may contain characters that bitbake
157 # will not allow in its COREBASE path, so we need to rename the directory temporarily
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500158 temp_sdkbasepath = d.getVar('SDK_OUTPUT') + '/tmp-renamed-sdk'
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600159 # Delete any existing temp dir
160 try:
161 shutil.rmtree(temp_sdkbasepath)
162 except FileNotFoundError:
163 pass
Andrew Geisslerc926e172021-05-07 16:11:35 -0500164 bb.utils.rename(sdkbasepath, temp_sdkbasepath)
Brad Bishop316dfdd2018-06-25 12:45:53 -0400165 cmdprefix = '. %s .; ' % conf_initpath
166 logfile = d.getVar('WORKDIR') + '/tasklist_bb_log.txt'
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600167 try:
Brad Bishop316dfdd2018-06-25 12:45:53 -0400168 oe.copy_buildsystem.check_sstate_task_list(d, get_sdk_install_targets(d), tasklistfile, cmdprefix=cmdprefix, cwd=temp_sdkbasepath, logfile=logfile)
169 except bb.process.ExecutionError as e:
170 msg = 'Failed to generate filtered task list for extensible SDK:\n%s' % e.stdout.rstrip()
171 if 'attempted to execute unexpectedly and should have been setscened' in e.stdout:
172 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'
173 bb.fatal(msg)
Andrew Geisslerc926e172021-05-07 16:11:35 -0500174 bb.utils.rename(temp_sdkbasepath, sdkbasepath)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600175 # Clean out residue of running bitbake, which check_sstate_task_list()
176 # will effectively do
177 clean_esdk_builddir(d, sdkbasepath)
178 finally:
Andrew Geissler82c905d2020-04-13 13:39:40 -0500179 localconf = sdkbasepath + '/conf/local.conf'
180 if os.path.exists(localconf + '.bak'):
181 os.replace(localconf + '.bak', localconf)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600182
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500183python copy_buildsystem () {
184 import re
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500185 import shutil
186 import glob
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500187 import oe.copy_buildsystem
188
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500189 oe_init_env_script = d.getVar('OE_INIT_ENV_SCRIPT')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500190
191 conf_bbpath = ''
192 conf_initpath = ''
193 core_meta_subdir = ''
194
195 # Copy in all metadata layers + bitbake (as repositories)
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500196 buildsystem = oe.copy_buildsystem.BuildSystem('extensible SDK', d)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500197 baseoutpath = d.getVar('SDK_OUTPUT') + '/' + d.getVar('SDKPATH')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500198
Andrew Geissler09209ee2020-12-13 08:44:15 -0600199 #check if custome templateconf path is set
200 use_custom_templateconf = d.getVar('SDK_CUSTOM_TEMPLATECONF')
201
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500202 # Determine if we're building a derivative extensible SDK (from devtool build-sdk)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500203 derivative = (d.getVar('SDK_DERIVATIVE') or '') == '1'
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500204 if derivative:
205 workspace_name = 'orig-workspace'
206 else:
207 workspace_name = None
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500208
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800209 corebase, sdkbblayers = buildsystem.copy_bitbake_and_layers(baseoutpath + '/layers', workspace_name)
210 conf_bbpath = os.path.join('layers', corebase, 'bitbake')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500211
212 for path in os.listdir(baseoutpath + '/layers'):
213 relpath = os.path.join('layers', path, oe_init_env_script)
214 if os.path.exists(os.path.join(baseoutpath, relpath)):
215 conf_initpath = relpath
216
217 relpath = os.path.join('layers', path, 'scripts', 'devtool')
218 if os.path.exists(os.path.join(baseoutpath, relpath)):
219 scriptrelpath = os.path.dirname(relpath)
220
221 relpath = os.path.join('layers', path, 'meta')
222 if os.path.exists(os.path.join(baseoutpath, relpath, 'lib', 'oe')):
223 core_meta_subdir = relpath
224
225 d.setVar('oe_init_build_env_path', conf_initpath)
226 d.setVar('scriptrelpath', scriptrelpath)
227
228 # Write out config file for devtool
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600229 import configparser
230 config = configparser.SafeConfigParser()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500231 config.add_section('General')
232 config.set('General', 'bitbake_subdir', conf_bbpath)
233 config.set('General', 'init_path', conf_initpath)
234 config.set('General', 'core_meta_subdir', core_meta_subdir)
235 config.add_section('SDK')
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500236 config.set('SDK', 'sdk_targets', d.getVar('SDK_TARGETS'))
237 updateurl = d.getVar('SDK_UPDATE_URL')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500238 if updateurl:
239 config.set('SDK', 'updateserver', updateurl)
240 bb.utils.mkdirhier(os.path.join(baseoutpath, 'conf'))
241 with open(os.path.join(baseoutpath, 'conf', 'devtool.conf'), 'w') as f:
242 config.write(f)
243
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500244 unlockedsigs = os.path.join(baseoutpath, 'conf', 'unlocked-sigs.inc')
245 with open(unlockedsigs, 'w') as f:
246 pass
247
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500248 # Create a layer for new recipes / appends
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500249 bbpath = d.getVar('BBPATH')
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500250 env = os.environ.copy()
251 env['PYTHONDONTWRITEBYTECODE'] = '1'
252 bb.process.run(['devtool', '--bbpath', bbpath, '--basepath', baseoutpath, 'create-workspace', '--create-only', os.path.join(baseoutpath, 'workspace')], env=env)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500253
254 # Create bblayers.conf
255 bb.utils.mkdirhier(baseoutpath + '/conf')
256 with open(baseoutpath + '/conf/bblayers.conf', 'w') as f:
257 f.write('# WARNING: this configuration has been automatically generated and in\n')
258 f.write('# most cases should not be edited. If you need more flexibility than\n')
259 f.write('# this configuration provides, it is strongly suggested that you set\n')
260 f.write('# up a proper instance of the full build system and use that instead.\n\n')
261
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500262 # LCONF_VERSION may not be set, for example when using meta-poky
263 # so don't error if it isn't found
264 lconf_version = d.getVar('LCONF_VERSION', False)
265 if lconf_version is not None:
266 f.write('LCONF_VERSION = "%s"\n\n' % lconf_version)
267
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500268 f.write('BBPATH = "$' + '{TOPDIR}"\n')
269 f.write('SDKBASEMETAPATH = "$' + '{TOPDIR}"\n')
270 f.write('BBLAYERS := " \\\n')
271 for layerrelpath in sdkbblayers:
272 f.write(' $' + '{SDKBASEMETAPATH}/layers/%s \\\n' % layerrelpath)
273 f.write(' $' + '{SDKBASEMETAPATH}/workspace \\\n')
274 f.write(' "\n')
275
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600276 # Copy uninative tarball
277 # For now this is where uninative.bbclass expects the tarball
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500278 if bb.data.inherits_class('uninative', d):
279 uninative_file = d.expand('${UNINATIVE_DLDIR}/' + d.getVarFlag("UNINATIVE_CHECKSUM", d.getVar("BUILD_ARCH")) + '/${UNINATIVE_TARBALL}')
280 uninative_checksum = bb.utils.sha256_file(uninative_file)
281 uninative_outdir = '%s/downloads/uninative/%s' % (baseoutpath, uninative_checksum)
282 bb.utils.mkdirhier(uninative_outdir)
283 shutil.copy(uninative_file, uninative_outdir)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600284
Andrew Geissler9aee5002022-03-30 16:27:02 +0000285 env_passthrough = (d.getVar('BB_ENV_PASSTHROUGH_ADDITIONS') or '').split()
286 env_passthrough_values = {}
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500287
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500288 # Create local.conf
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500289 builddir = d.getVar('TOPDIR')
Brad Bishopa5c52ff2018-11-23 10:55:50 +1300290 if derivative and os.path.exists(builddir + '/conf/site.conf'):
291 shutil.copyfile(builddir + '/conf/site.conf', baseoutpath + '/conf/site.conf')
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500292 if derivative and os.path.exists(builddir + '/conf/auto.conf'):
293 shutil.copyfile(builddir + '/conf/auto.conf', baseoutpath + '/conf/auto.conf')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500294 if derivative:
295 shutil.copyfile(builddir + '/conf/local.conf', baseoutpath + '/conf/local.conf')
296 else:
Andrew Geissler9aee5002022-03-30 16:27:02 +0000297 local_conf_allowed = (d.getVar('ESDK_LOCALCONF_ALLOW') or '').split()
298 local_conf_remove = (d.getVar('ESDK_LOCALCONF_REMOVE') or '').split()
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500299 def handle_var(varname, origvalue, op, newlines):
Andrew Geissler9aee5002022-03-30 16:27:02 +0000300 if varname in local_conf_remove or (origvalue.strip().startswith('/') and not varname in local_conf_allowed):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500301 newlines.append('# Removed original setting of %s\n' % varname)
302 return None, op, 0, True
303 else:
Andrew Geissler9aee5002022-03-30 16:27:02 +0000304 if varname in env_passthrough:
305 env_passthrough_values[varname] = origvalue
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500306 return origvalue, op, 0, True
307 varlist = ['[^#=+ ]*']
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500308 oldlines = []
Brad Bishopa5c52ff2018-11-23 10:55:50 +1300309 if os.path.exists(builddir + '/conf/site.conf'):
310 with open(builddir + '/conf/site.conf', 'r') as f:
311 oldlines += f.readlines()
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500312 if os.path.exists(builddir + '/conf/auto.conf'):
313 with open(builddir + '/conf/auto.conf', 'r') as f:
314 oldlines += f.readlines()
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500315 if os.path.exists(builddir + '/conf/local.conf'):
316 with open(builddir + '/conf/local.conf', 'r') as f:
317 oldlines += f.readlines()
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500318 (updated, newlines) = bb.utils.edit_metadata(oldlines, varlist, handle_var)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500319
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500320 with open(baseoutpath + '/conf/local.conf', 'w') as f:
321 f.write('# WARNING: this configuration has been automatically generated and in\n')
322 f.write('# most cases should not be edited. If you need more flexibility than\n')
323 f.write('# this configuration provides, it is strongly suggested that you set\n')
324 f.write('# up a proper instance of the full build system and use that instead.\n\n')
325 for line in newlines:
326 if line.strip() and not line.startswith('#'):
327 f.write(line)
328 # Write a newline just in case there's none at the end of the original
329 f.write('\n')
330
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500331 f.write('TMPDIR = "${TOPDIR}/tmp"\n')
332 f.write('TCLIBCAPPEND = ""\n')
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600333 f.write('DL_DIR = "${TOPDIR}/downloads"\n')
334
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800335 if bb.data.inherits_class('uninative', d):
336 f.write('INHERIT += "%s"\n' % 'uninative')
337 f.write('UNINATIVE_CHECKSUM[%s] = "%s"\n\n' % (d.getVar('BUILD_ARCH'), uninative_checksum))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500338 f.write('CONF_VERSION = "%s"\n\n' % d.getVar('CONF_VERSION', False))
339
340 # Some classes are not suitable for SDK, remove them from INHERIT
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000341 f.write('INHERIT:remove = "%s"\n' % d.getVar('ESDK_CLASS_INHERIT_DISABLE', False))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500342
343 # Bypass the default connectivity check if any
344 f.write('CONNECTIVITY_CHECK_URIS = ""\n\n')
345
346 # This warning will come out if reverse dependencies for a task
347 # don't have sstate as well as the task itself. We already know
348 # this will be the case for the extensible sdk, so turn off the
349 # warning.
350 f.write('SIGGEN_LOCKEDSIGS_SSTATE_EXISTS_CHECK = "none"\n\n')
351
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600352 # Warn if the sigs in the locked-signature file don't match
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500353 # the sig computed from the metadata.
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600354 f.write('SIGGEN_LOCKEDSIGS_TASKSIG_CHECK = "warn"\n\n')
355
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500356 # We want to be able to set this without a full reparse
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000357 f.write('BB_HASHCONFIG_IGNORE_VARS:append = " SIGGEN_UNLOCKED_RECIPES"\n\n')
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500358
Andrew Geissler9aee5002022-03-30 16:27:02 +0000359 # Set up which tasks are ignored for run on install
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000360 f.write('BB_SETSCENE_ENFORCE_IGNORE_TASKS = "%:* *:do_shared_workdir *:do_rm_work wic-tools:* *:do_addto_recipe_sysroot"\n\n')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500361
362 # Hide the config information from bitbake output (since it's fixed within the SDK)
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500363 f.write('BUILDCFG_HEADER = ""\n\n')
364
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500365 # Write METADATA_REVISION
366 f.write('METADATA_REVISION = "%s"\n\n' % d.getVar('METADATA_REVISION'))
367
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500368 f.write('# Provide a flag to indicate we are in the EXT_SDK Context\n')
369 f.write('WITHIN_EXT_SDK = "1"\n\n')
370
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500371 # Map gcc-dependent uninative sstate cache for installer usage
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500372 f.write('SSTATE_MIRRORS += " file://universal/(.*) file://universal-4.9/\\1 file://universal-4.9/(.*) file://universal-4.8/\\1"\n\n')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500373
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500374 if d.getVar("PRSERV_HOST"):
375 # Override this, we now include PR data, so it should only point ot the local database
376 f.write('PRSERV_HOST = "localhost:0"\n\n')
377
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500378 # Allow additional config through sdk-extra.conf
379 fn = bb.cookerdata.findConfigFile('sdk-extra.conf', d)
380 if fn:
381 with open(fn, 'r') as xf:
382 for line in xf:
383 f.write(line)
384
385 # If you define a sdk_extraconf() function then it can contain additional config
386 # (Though this is awkward; sdk-extra.conf should probably be used instead)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500387 extraconf = (d.getVar('sdk_extraconf') or '').strip()
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500388 if extraconf:
389 # Strip off any leading / trailing spaces
390 for line in extraconf.splitlines():
391 f.write(line.strip() + '\n')
392
393 f.write('require conf/locked-sigs.inc\n')
394 f.write('require conf/unlocked-sigs.inc\n')
395
Andrew Geissler09036742021-06-25 14:25:14 -0500396 # Copy multiple configurations if they exist in the users config directory
397 if d.getVar('BBMULTICONFIG') is not None:
398 bb.utils.mkdirhier(os.path.join(baseoutpath, 'conf', 'multiconfig'))
399 for mc in d.getVar('BBMULTICONFIG').split():
400 dest_stub = "/conf/multiconfig/%s.conf" % (mc,)
401 if os.path.exists(builddir + dest_stub):
402 shutil.copyfile(builddir + dest_stub, baseoutpath + dest_stub)
403
Andrew Geissler78b72792022-06-14 06:47:25 -0500404 cachedir = os.path.join(baseoutpath, 'cache')
405 bb.utils.mkdirhier(cachedir)
406 bb.parse.siggen.copy_unitaskhashes(cachedir)
Brad Bishop00e122a2019-10-05 11:10:57 -0400407
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500408 # If PR Service is in use, we need to export this as well
409 bb.note('Do we have a pr database?')
410 if d.getVar("PRSERV_HOST"):
411 bb.note('Writing PR database...')
412 # Based on the code in classes/prexport.bbclass
413 import oe.prservice
414 #dump meta info of tables
415 localdata = d.createCopy()
416 localdata.setVar('PRSERV_DUMPOPT_COL', "1")
417 localdata.setVar('PRSERV_DUMPDIR', os.path.join(baseoutpath, 'conf'))
418 localdata.setVar('PRSERV_DUMPFILE', '${PRSERV_DUMPDIR}/prserv.inc')
419
420 bb.note('PR Database write to %s' % (localdata.getVar('PRSERV_DUMPFILE')))
421
422 retval = oe.prservice.prserv_dump_db(localdata)
423 if not retval:
424 bb.error("prexport_handler: export failed!")
425 return
426 (metainfo, datainfo) = retval
427 oe.prservice.prserv_export_tofile(localdata, metainfo, datainfo, True)
428
Andrew Geissler82c905d2020-04-13 13:39:40 -0500429 # Use templateconf.cfg file from builddir if exists
Andrew Geissler09209ee2020-12-13 08:44:15 -0600430 if os.path.exists(builddir + '/conf/templateconf.cfg') and use_custom_templateconf == '1':
Andrew Geissler82c905d2020-04-13 13:39:40 -0500431 shutil.copyfile(builddir + '/conf/templateconf.cfg', baseoutpath + '/conf/templateconf.cfg')
432 else:
433 # Write a templateconf.cfg
434 with open(baseoutpath + '/conf/templateconf.cfg', 'w') as f:
435 f.write('meta/conf\n')
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500436
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500437 # Ensure any variables set from the external environment (by way of
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000438 # BB_ENV_PASSTHROUGH_ADDITIONS) are set in the SDK's configuration
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500439 extralines = []
Andrew Geissler9aee5002022-03-30 16:27:02 +0000440 for name, value in env_passthrough_values.items():
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500441 actualvalue = d.getVar(name) or ''
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500442 if value != actualvalue:
443 extralines.append('%s = "%s"\n' % (name, actualvalue))
444 if extralines:
445 with open(baseoutpath + '/conf/local.conf', 'a') as f:
446 f.write('\n')
447 f.write('# Extra settings from environment:\n')
448 for line in extralines:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500449 f.write(line)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500450 f.write('\n')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500451
452 # Filter the locked signatures file to just the sstate tasks we are interested in
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600453 excluded_targets = get_sdk_install_targets(d, images_only=True)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500454 sigfile = d.getVar('WORKDIR') + '/locked-sigs.inc'
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500455 lockedsigs_pruned = baseoutpath + '/conf/locked-sigs.inc'
Brad Bishopa34c0302019-09-23 22:34:48 -0400456 #nativesdk-only sigfile to merge into locked-sigs.inc
457 sdk_include_nativesdk = (d.getVar("SDK_INCLUDE_NATIVESDK") == '1')
458 nativesigfile = d.getVar('WORKDIR') + '/locked-sigs_nativesdk.inc'
459 nativesigfile_pruned = d.getVar('WORKDIR') + '/locked-sigs_nativesdk_pruned.inc'
460
461 if sdk_include_nativesdk:
462 oe.copy_buildsystem.prune_lockedsigs([],
463 excluded_targets.split(),
464 nativesigfile,
465 True,
466 nativesigfile_pruned)
467
468 oe.copy_buildsystem.merge_lockedsigs([],
469 sigfile,
470 nativesigfile_pruned,
471 sigfile)
472
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500473 oe.copy_buildsystem.prune_lockedsigs([],
474 excluded_targets.split(),
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500475 sigfile,
Brad Bishopa34c0302019-09-23 22:34:48 -0400476 False,
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500477 lockedsigs_pruned)
478
479 sstate_out = baseoutpath + '/sstate-cache'
480 bb.utils.remove(sstate_out, True)
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500481
482 # uninative.bbclass sets NATIVELSBSTRING to 'universal%s' % oe.utils.host_gcc_version(d)
483 fixedlsbstring = "universal%s" % oe.utils.host_gcc_version(d)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500484
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500485 sdk_include_toolchain = (d.getVar('SDK_INCLUDE_TOOLCHAIN') == '1')
486 sdk_ext_type = d.getVar('SDK_EXT_TYPE')
Brad Bishopa34c0302019-09-23 22:34:48 -0400487 if (sdk_ext_type != 'minimal' or sdk_include_toolchain or derivative) and not sdk_include_nativesdk:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600488 # Create the filtered task list used to generate the sstate cache shipped with the SDK
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500489 tasklistfn = d.getVar('WORKDIR') + '/tasklist.txt'
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600490 create_filtered_tasklist(d, baseoutpath, tasklistfn, conf_initpath)
491 else:
492 tasklistfn = None
493
Andrew Geissler78b72792022-06-14 06:47:25 -0500494
495 cachedir = os.path.join(baseoutpath, 'cache')
496 bb.utils.mkdirhier(cachedir)
497 bb.parse.siggen.copy_unitaskhashes(cachedir)
Brad Bishop00e122a2019-10-05 11:10:57 -0400498
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500499 # Add packagedata if enabled
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500500 if d.getVar('SDK_INCLUDE_PKGDATA') == '1':
501 lockedsigs_base = d.getVar('WORKDIR') + '/locked-sigs-base.inc'
502 lockedsigs_copy = d.getVar('WORKDIR') + '/locked-sigs-copy.inc'
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500503 shutil.move(lockedsigs_pruned, lockedsigs_base)
504 oe.copy_buildsystem.merge_lockedsigs(['do_packagedata'],
505 lockedsigs_base,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500506 d.getVar('STAGING_DIR_HOST') + '/world-pkgdata/locked-sigs-pkgdata.inc',
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500507 lockedsigs_pruned,
508 lockedsigs_copy)
509
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600510 if sdk_include_toolchain:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500511 lockedsigs_base = d.getVar('WORKDIR') + '/locked-sigs-base2.inc'
512 lockedsigs_toolchain = d.expand("${STAGING_DIR}/${TUNE_PKGARCH}/meta-extsdk-toolchain/locked-sigs/locked-sigs-extsdk-toolchain.inc")
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600513 shutil.move(lockedsigs_pruned, lockedsigs_base)
514 oe.copy_buildsystem.merge_lockedsigs([],
515 lockedsigs_base,
516 lockedsigs_toolchain,
517 lockedsigs_pruned)
518 oe.copy_buildsystem.create_locked_sstate_cache(lockedsigs_toolchain,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500519 d.getVar('SSTATE_DIR'),
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600520 sstate_out, d,
521 fixedlsbstring,
522 filterfile=tasklistfn)
523
524 if sdk_ext_type == 'minimal':
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500525 if derivative:
526 # Assume the user is not going to set up an additional sstate
527 # mirror, thus we need to copy the additional artifacts (from
528 # workspace recipes) into the derivative SDK
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500529 lockedsigs_orig = d.getVar('TOPDIR') + '/conf/locked-sigs.inc'
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500530 if os.path.exists(lockedsigs_orig):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500531 lockedsigs_extra = d.getVar('WORKDIR') + '/locked-sigs-extra.inc'
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500532 oe.copy_buildsystem.merge_lockedsigs(None,
533 lockedsigs_orig,
534 lockedsigs_pruned,
535 None,
536 lockedsigs_extra)
537 oe.copy_buildsystem.create_locked_sstate_cache(lockedsigs_extra,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500538 d.getVar('SSTATE_DIR'),
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500539 sstate_out, d,
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600540 fixedlsbstring,
541 filterfile=tasklistfn)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500542 else:
543 oe.copy_buildsystem.create_locked_sstate_cache(lockedsigs_pruned,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500544 d.getVar('SSTATE_DIR'),
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500545 sstate_out, d,
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600546 fixedlsbstring,
547 filterfile=tasklistfn)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500548
549 # We don't need sstate do_package files
550 for root, dirs, files in os.walk(sstate_out):
551 for name in files:
Andrew Geisslereff27472021-10-29 15:35:00 -0500552 if name.endswith("_package.tar.zst"):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500553 f = os.path.join(root, name)
554 os.remove(f)
555
556 # Write manifest file
557 # Note: at the moment we cannot include the env setup script here to keep
558 # it updated, since it gets modified during SDK installation (see
559 # sdk_ext_postinst() below) thus the checksum we take here would always
560 # be different.
561 manifest_file_list = ['conf/*']
Andrew Geissler09036742021-06-25 14:25:14 -0500562 if d.getVar('BBMULTICONFIG') is not None:
563 manifest_file_list.append('conf/multiconfig/*')
564
Andrew Geisslerc3d88e42020-10-02 09:45:00 -0500565 esdk_manifest_excludes = (d.getVar('ESDK_MANIFEST_EXCLUDES') or '').split()
566 esdk_manifest_excludes_list = []
567 for exclude_item in esdk_manifest_excludes:
568 esdk_manifest_excludes_list += glob.glob(os.path.join(baseoutpath, exclude_item))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500569 manifest_file = os.path.join(baseoutpath, 'conf', 'sdk-conf-manifest')
570 with open(manifest_file, 'w') as f:
571 for item in manifest_file_list:
572 for fn in glob.glob(os.path.join(baseoutpath, item)):
Andrew Geissler09036742021-06-25 14:25:14 -0500573 if fn == manifest_file or os.path.isdir(fn):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500574 continue
Andrew Geisslerc3d88e42020-10-02 09:45:00 -0500575 if fn in esdk_manifest_excludes_list:
576 continue
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500577 chksum = bb.utils.sha256_file(fn)
578 f.write('%s\t%s\n' % (chksum, os.path.relpath(fn, baseoutpath)))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500579}
580
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600581def get_current_buildtools(d):
582 """Get the file name of the current buildtools installer"""
583 import glob
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500584 btfiles = glob.glob(os.path.join(d.getVar('SDK_DEPLOY'), '*-buildtools-nativesdk-standalone-*.sh'))
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600585 btfiles.sort(key=os.path.getctime)
586 return os.path.basename(btfiles[-1])
587
588def get_sdk_required_utilities(buildtools_fn, d):
589 """Find required utilities that aren't provided by the buildtools"""
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500590 sanity_required_utilities = (d.getVar('SANITY_REQUIRED_UTILITIES') or '').split()
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600591 sanity_required_utilities.append(d.expand('${BUILD_PREFIX}gcc'))
592 sanity_required_utilities.append(d.expand('${BUILD_PREFIX}g++'))
Brad Bishop1d80a2e2019-11-15 16:35:03 -0500593 if buildtools_fn:
594 buildtools_installer = os.path.join(d.getVar('SDK_DEPLOY'), buildtools_fn)
595 filelist, _ = bb.process.run('%s -l' % buildtools_installer)
596 else:
597 buildtools_installer = None
598 filelist = ""
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600599 localdata = bb.data.createCopy(d)
600 localdata.setVar('SDKPATH', '.')
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500601 sdkpathnative = localdata.getVar('SDKPATHNATIVE')
602 sdkbindirs = [localdata.getVar('bindir_nativesdk'),
603 localdata.getVar('sbindir_nativesdk'),
604 localdata.getVar('base_bindir_nativesdk'),
605 localdata.getVar('base_sbindir_nativesdk')]
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600606 for line in filelist.splitlines():
607 splitline = line.split()
608 if len(splitline) > 5:
609 fn = splitline[5]
610 if not fn.startswith('./'):
611 fn = './%s' % fn
612 if fn.startswith(sdkpathnative):
613 relpth = '/' + os.path.relpath(fn, sdkpathnative)
614 for bindir in sdkbindirs:
615 if relpth.startswith(bindir):
616 relpth = os.path.relpath(relpth, bindir)
617 if relpth in sanity_required_utilities:
618 sanity_required_utilities.remove(relpth)
619 break
620 return ' '.join(sanity_required_utilities)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500621
622install_tools() {
623 install -d ${SDK_OUTPUT}/${SDKPATHNATIVE}${bindir_nativesdk}
Brad Bishop316dfdd2018-06-25 12:45:53 -0400624 scripts="devtool recipetool oe-find-native-sysroot runqemu* wic"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600625 for script in $scripts; do
626 for scriptfn in `find ${SDK_OUTPUT}/${SDKPATH}/${scriptrelpath} -maxdepth 1 -executable -name "$script"`; do
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800627 targetscriptfn="${SDK_OUTPUT}/${SDKPATHNATIVE}${bindir_nativesdk}/$(basename $scriptfn)"
Andrew Geissler595f6302022-01-24 19:11:47 +0000628 test -e ${targetscriptfn} || ln -rs ${scriptfn} ${targetscriptfn}
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600629 done
630 done
631 # We can't use the same method as above because files in the sysroot won't exist at this point
632 # (they get populated from sstate on installation)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500633 unfsd_path="${SDK_OUTPUT}/${SDKPATHNATIVE}${bindir_nativesdk}/unfsd"
634 if [ "${SDK_INCLUDE_TOOLCHAIN}" = "1" -a ! -e $unfsd_path ] ; then
635 binrelpath=${@os.path.relpath(d.getVar('STAGING_BINDIR_NATIVE'), d.getVar('TMPDIR'))}
Andrew Geissler595f6302022-01-24 19:11:47 +0000636 ln -rs ${SDK_OUTPUT}/${SDKPATH}/tmp/$binrelpath/unfsd $unfsd_path
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600637 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500638 touch ${SDK_OUTPUT}/${SDKPATH}/.devtoolbase
639
640 # find latest buildtools-tarball and install it
Brad Bishop1d80a2e2019-11-15 16:35:03 -0500641 if [ -n "${SDK_BUILDTOOLS_INSTALLER}" ]; then
642 install ${SDK_DEPLOY}/${SDK_BUILDTOOLS_INSTALLER} ${SDK_OUTPUT}/${SDKPATH}
643 fi
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500644
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500645 install -m 0644 ${COREBASE}/meta/files/ext-sdk-prepare.py ${SDK_OUTPUT}/${SDKPATH}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500646}
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500647do_populate_sdk_ext[file-checksums] += "${COREBASE}/meta/files/ext-sdk-prepare.py:True"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500648
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500649sdk_ext_preinst() {
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600650 # Since bitbake won't run as root it doesn't make sense to try and install
651 # the extensible sdk as root.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500652 if [ "`id -u`" = "0" ]; then
653 echo "ERROR: The extensible sdk cannot be installed as root."
654 exit 1
655 fi
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600656 if ! command -v locale > /dev/null; then
657 echo "ERROR: The installer requires the locale command, please install it first"
658 exit 1
659 fi
660 # Check setting of LC_ALL set above
661 canonicalised_locale=`echo $LC_ALL | sed 's/UTF-8/utf8/'`
662 if ! locale -a | grep -q $canonicalised_locale ; then
663 echo "ERROR: the installer requires the $LC_ALL locale to be installed (but not selected), please install it first"
664 exit 1
665 fi
666 # The relocation script used by buildtools installer requires python
Andrew Geissler82c905d2020-04-13 13:39:40 -0500667 if ! command -v python3 > /dev/null; then
668 echo "ERROR: The installer requires python3, please install it first"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600669 exit 1
670 fi
671 missing_utils=""
672 for util in ${SDK_REQUIRED_UTILITIES}; do
673 if ! command -v $util > /dev/null; then
674 missing_utils="$missing_utils $util"
675 fi
676 done
677 if [ -n "$missing_utils" ] ; then
678 echo "ERROR: the SDK requires the following missing utilities, please install them: $missing_utils"
679 exit 1
680 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500681 SDK_EXTENSIBLE="1"
Brad Bishop19323692019-04-05 15:28:33 -0400682 if [ "$publish" = "1" ] && [ "${SDK_EXT_TYPE}" = "minimal" ] ; then
683 EXTRA_TAR_OPTIONS="$EXTRA_TAR_OPTIONS --exclude=sstate-cache"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500684 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500685}
Patrick Williams213cb262021-08-07 19:21:33 -0500686SDK_PRE_INSTALL_COMMAND:task-populate-sdk-ext = "${sdk_ext_preinst}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500687
688# FIXME this preparation should be done as part of the SDK construction
689sdk_ext_postinst() {
690 printf "\nExtracting buildtools...\n"
691 cd $target_sdk_dir
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600692 env_setup_script="$target_sdk_dir/environment-setup-${REAL_MULTIMACH_TARGET_SYS}"
Brad Bishop1d80a2e2019-11-15 16:35:03 -0500693 if [ -n "${SDK_BUILDTOOLS_INSTALLER}" ]; then
694 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 ; }
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500695
Brad Bishop1d80a2e2019-11-15 16:35:03 -0500696 # Delete the buildtools tar file since it won't be used again
697 rm -f ./${SDK_BUILDTOOLS_INSTALLER}
698 # We don't need the log either since it succeeded
699 rm -f buildtools.log
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500700
Brad Bishop1d80a2e2019-11-15 16:35:03 -0500701 # Make sure when the user sets up the environment, they also get
702 # the buildtools-tarball tools in their path.
Andrew Geissler635e0e42020-08-21 15:58:33 -0500703 echo "# Save and reset OECORE_NATIVE_SYSROOT as buildtools may change it" >> $env_setup_script
704 echo "SAVED=\"\$OECORE_NATIVE_SYSROOT\"" >> $env_setup_script
Brad Bishop1d80a2e2019-11-15 16:35:03 -0500705 echo ". $target_sdk_dir/buildtools/environment-setup*" >> $env_setup_script
Andrew Geissler635e0e42020-08-21 15:58:33 -0500706 echo "OECORE_NATIVE_SYSROOT=\"\$SAVED\"" >> $env_setup_script
Brad Bishop1d80a2e2019-11-15 16:35:03 -0500707 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500708
709 # Allow bitbake environment setup to be ran as part of this sdk.
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500710 echo "export OE_SKIP_SDK_CHECK=1" >> $env_setup_script
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500711 # Work around runqemu not knowing how to get this information within the eSDK
712 echo "export DEPLOY_DIR_IMAGE=$target_sdk_dir/tmp/${@os.path.relpath(d.getVar('DEPLOY_DIR_IMAGE'), d.getVar('TMPDIR'))}" >> $env_setup_script
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500713
714 # A bit of another hack, but we need this in the path only for devtool
715 # so put it at the end of $PATH.
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500716 echo "export PATH=$target_sdk_dir/sysroots/${SDK_SYS}${bindir_nativesdk}:\$PATH" >> $env_setup_script
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500717
718 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
719
720 # Warn if trying to use external bitbake and the ext SDK together
721 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
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500722
Brad Bishop1d80a2e2019-11-15 16:35:03 -0500723 if [ "$prepare_buildsystem" != "no" -a -n "${SDK_BUILDTOOLS_INSTALLER}" ]; then
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500724 printf "Preparing build system...\n"
725 # dash which is /bin/sh on Ubuntu will not preserve the
726 # current working directory when first ran, nor will it set $1 when
727 # sourcing a script. That is why this has to look so ugly.
728 LOGFILE="$target_sdk_dir/preparing_build_system.log"
Andrew Geissler475cb722020-07-10 16:00:51 -0500729 sh -c ". buildtools/environment-setup* > $LOGFILE && 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 && 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 ; }
Brad Bishop19323692019-04-05 15:28:33 -0400730 fi
731 if [ -e $target_sdk_dir/ext-sdk-prepare.py ]; then
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500732 rm $target_sdk_dir/ext-sdk-prepare.py
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500733 fi
734 echo done
735}
736
Patrick Williams213cb262021-08-07 19:21:33 -0500737SDK_POST_INSTALL_COMMAND:task-populate-sdk-ext = "${sdk_ext_postinst}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500738
Patrick Williams213cb262021-08-07 19:21:33 -0500739SDK_POSTPROCESS_COMMAND:prepend:task-populate-sdk-ext = "copy_buildsystem; install_tools; "
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500740
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500741SDK_INSTALL_TARGETS = ""
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500742fakeroot python do_populate_sdk_ext() {
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500743 # FIXME hopefully we can remove this restriction at some point, but uninative
744 # currently forces this upon us
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500745 if d.getVar('SDK_ARCH') != d.getVar('BUILD_ARCH'):
746 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')))
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500747
Andrew Geissler5f350902021-07-23 13:09:54 -0400748 # FIXME hopefully we can remove this restriction at some point, but the eSDK
749 # can only be built for the primary (default) multiconfig
750 if d.getVar('BB_CURRENT_MC') != 'default':
751 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'))
752
Patrick Williams213cb262021-08-07 19:21:33 -0500753 # eSDK dependencies don't use the traditional variables and things don't work properly if they are set
754 d.setVar("TOOLCHAIN_HOST_TASK", "${TOOLCHAIN_HOST_TASK_ESDK}")
755 d.setVar("TOOLCHAIN_TARGET_TASK", "")
756
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500757 d.setVar('SDK_INSTALL_TARGETS', get_sdk_install_targets(d))
Brad Bishop1d80a2e2019-11-15 16:35:03 -0500758 if d.getVar('SDK_INCLUDE_BUILDTOOLS') == '1':
759 buildtools_fn = get_current_buildtools(d)
760 else:
761 buildtools_fn = None
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600762 d.setVar('SDK_REQUIRED_UTILITIES', get_sdk_required_utilities(buildtools_fn, d))
763 d.setVar('SDK_BUILDTOOLS_INSTALLER', buildtools_fn)
764 d.setVar('SDKDEPLOYDIR', '${SDKEXTDEPLOYDIR}')
Brad Bishop00111322018-04-01 22:23:53 -0400765 # ESDKs have a libc from the buildtools so ensure we don't ship linguas twice
766 d.delVar('SDKIMAGE_LINGUAS')
Brad Bishopa34c0302019-09-23 22:34:48 -0400767 if d.getVar("SDK_INCLUDE_NATIVESDK") == '1':
768 generate_nativesdk_lockedsigs(d)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600769 populate_sdk_common(d)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500770}
771
Brad Bishopa34c0302019-09-23 22:34:48 -0400772def generate_nativesdk_lockedsigs(d):
773 import oe.copy_buildsystem
774 sigfile = d.getVar('WORKDIR') + '/locked-sigs_nativesdk.inc'
775 oe.copy_buildsystem.generate_locked_sigs(sigfile, d)
776
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500777def get_ext_sdk_depends(d):
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600778 # Note: the deps varflag is a list not a string, so we need to specify expand=False
779 deps = d.getVarFlag('do_image_complete', 'deps', False)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500780 pn = d.getVar('PN')
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600781 deplist = ['%s:%s' % (pn, dep) for dep in deps]
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500782 tasklist = bb.build.tasksbetween('do_image_complete', 'do_build', d)
783 tasklist.append('do_rootfs')
784 for task in tasklist:
785 deplist.extend((d.getVarFlag(task, 'depends') or '').split())
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600786 return ' '.join(deplist)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500787
788python do_sdk_depends() {
789 # We have to do this separately in its own task so we avoid recursing into
790 # dependencies we don't need to (e.g. buildtools-tarball) and bringing those
791 # into the SDK's sstate-cache
792 import oe.copy_buildsystem
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500793 sigfile = d.getVar('WORKDIR') + '/locked-sigs.inc'
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500794 oe.copy_buildsystem.generate_locked_sigs(sigfile, d)
795}
796addtask sdk_depends
797
798do_sdk_depends[dirs] = "${WORKDIR}"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500799do_sdk_depends[depends] = "${@get_ext_sdk_depends(d)} meta-extsdk-toolchain:do_populate_sysroot"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500800do_sdk_depends[recrdeptask] = "${@d.getVarFlag('do_populate_sdk', 'recrdeptask', False)}"
801do_sdk_depends[recrdeptask] += "do_populate_lic do_package_qa do_populate_sysroot do_deploy ${SDK_RECRDEP_TASKS}"
Patrick Williams213cb262021-08-07 19:21:33 -0500802do_sdk_depends[rdepends] = "${@' '.join([x + ':do_package_write_${IMAGE_PKGTYPE} ' + x + ':do_packagedata' for x in d.getVar('TOOLCHAIN_HOST_TASK_ESDK').split()])}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500803
804do_populate_sdk_ext[dirs] = "${@d.getVarFlag('do_populate_sdk', 'dirs', False)}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500805
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500806do_populate_sdk_ext[depends] = "${@d.getVarFlag('do_populate_sdk', 'depends', False)} \
Brad Bishop1d80a2e2019-11-15 16:35:03 -0500807 ${@'buildtools-tarball:do_populate_sdk' if d.getVar('SDK_INCLUDE_BUILDTOOLS') == '1' else ''} \
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500808 ${@'meta-world-pkgdata:do_collect_packagedata' if d.getVar('SDK_INCLUDE_PKGDATA') == '1' else ''} \
809 ${@'meta-extsdk-toolchain:do_locked_sigs' if d.getVar('SDK_INCLUDE_TOOLCHAIN') == '1' else ''}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500810
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500811# We must avoid depending on do_build here if rm_work.bbclass is active,
812# because otherwise do_rm_work may run before do_populate_sdk_ext itself.
813# We can't mark do_populate_sdk_ext and do_sdk_depends as having to
814# run before do_rm_work, because then they would also run as part
815# of normal builds.
816do_populate_sdk_ext[rdepends] += "${@' '.join([x + ':' + (d.getVar('RM_WORK_BUILD_WITHOUT') or 'do_build') for x in d.getVar('SDK_TARGETS').split()])}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500817
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500818# Make sure code changes can result in rebuild
819do_populate_sdk_ext[vardeps] += "copy_buildsystem \
820 sdk_ext_postinst"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500821
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500822# Since any change in the metadata of any layer should cause a rebuild of the
823# sdk(since the layers are put in the sdk) set the task to nostamp so it
824# always runs.
825do_populate_sdk_ext[nostamp] = "1"
826
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600827SDKEXTDEPLOYDIR = "${WORKDIR}/deploy-${PN}-populate-sdk-ext"
828
829SSTATETASKS += "do_populate_sdk_ext"
Patrick Williams213cb262021-08-07 19:21:33 -0500830SSTATE_SKIP_CREATION:task-populate-sdk-ext = '1'
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500831do_populate_sdk_ext[cleandirs] = "${SDKEXTDEPLOYDIR}"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600832do_populate_sdk_ext[sstate-inputdirs] = "${SDKEXTDEPLOYDIR}"
833do_populate_sdk_ext[sstate-outputdirs] = "${SDK_DEPLOY}"
Brad Bishop316dfdd2018-06-25 12:45:53 -0400834do_populate_sdk_ext[stamp-extra-info] = "${MACHINE_ARCH}"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600835
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500836addtask populate_sdk_ext after do_sdk_depends