blob: 6f35b612c2cea899da878746916273d0765a399e [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001# Extensible SDK
2
3inherit populate_sdk_base
4
5# NOTE: normally you cannot use task overrides for this kind of thing - this
6# only works because of get_sdk_ext_rdepends()
7
8TOOLCHAIN_HOST_TASK_task-populate-sdk-ext = " \
9 meta-environment-extsdk-${MACHINE} \
10 "
11
12TOOLCHAIN_TARGET_TASK_task-populate-sdk-ext = ""
13
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014SDK_RELOCATE_AFTER_INSTALL_task-populate-sdk-ext = "0"
15
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050016SDK_EXT = ""
17SDK_EXT_task-populate-sdk-ext = "-ext"
18
19# Options are full or minimal
20SDK_EXT_TYPE ?= "full"
Patrick Williamsc0f7c042017-02-23 20:41:17 -060021SDK_INCLUDE_PKGDATA ?= "0"
Brad Bishop6e60e8b2018-02-01 10:27:11 -050022SDK_INCLUDE_TOOLCHAIN ?= "${@'1' if d.getVar('SDK_EXT_TYPE') == 'full' else '0'}"
Brad Bishopa34c0302019-09-23 22:34:48 -040023SDK_INCLUDE_NATIVESDK ?= "0"
Brad Bishop1d80a2e2019-11-15 16:35:03 -050024SDK_INCLUDE_BUILDTOOLS ?= '1'
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050025
26SDK_RECRDEP_TASKS ?= ""
27
Patrick Williamsc124f4f2015-09-15 14:41:29 -050028SDK_LOCAL_CONF_WHITELIST ?= ""
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050029SDK_LOCAL_CONF_BLACKLIST ?= "CONF_VERSION \
30 BB_NUMBER_THREADS \
Patrick Williamsc0f7c042017-02-23 20:41:17 -060031 BB_NUMBER_PARSE_THREADS \
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050032 PARALLEL_MAKE \
33 PRSERV_HOST \
34 SSTATE_MIRRORS \
Patrick Williamsc0f7c042017-02-23 20:41:17 -060035 DL_DIR \
36 SSTATE_DIR \
37 TMPDIR \
Brad Bishopd7bf8c12018-02-25 22:55:05 -050038 BB_SERVER_TIMEOUT \
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050039 "
Patrick Williamsc124f4f2015-09-15 14:41:29 -050040SDK_INHERIT_BLACKLIST ?= "buildhistory icecc"
41SDK_UPDATE_URL ?= ""
42
43SDK_TARGETS ?= "${PN}"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050044
Patrick Williamsc0f7c042017-02-23 20:41:17 -060045def get_sdk_install_targets(d, images_only=False):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050046 sdk_install_targets = ''
Brad Bishop6e60e8b2018-02-01 10:27:11 -050047 if images_only or d.getVar('SDK_EXT_TYPE') != 'minimal':
48 sdk_install_targets = d.getVar('SDK_TARGETS')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050049
50 depd = d.getVar('BB_TASKDEPDATA', False)
Brad Bishop6e60e8b2018-02-01 10:27:11 -050051 tasklist = bb.build.tasksbetween('do_image_complete', 'do_build', d)
52 tasklist.remove('do_build')
Patrick Williamsc0f7c042017-02-23 20:41:17 -060053 for v in depd.values():
Brad Bishop6e60e8b2018-02-01 10:27:11 -050054 if v[1] in tasklist:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050055 if v[0] not in sdk_install_targets:
56 sdk_install_targets += ' {}'.format(v[0])
57
Patrick Williamsc0f7c042017-02-23 20:41:17 -060058 if not images_only:
Brad Bishop6e60e8b2018-02-01 10:27:11 -050059 if d.getVar('SDK_INCLUDE_PKGDATA') == '1':
Patrick Williamsc0f7c042017-02-23 20:41:17 -060060 sdk_install_targets += ' meta-world-pkgdata:do_allpackagedata'
Brad Bishop6e60e8b2018-02-01 10:27:11 -050061 if d.getVar('SDK_INCLUDE_TOOLCHAIN') == '1':
Patrick Williamsc0f7c042017-02-23 20:41:17 -060062 sdk_install_targets += ' meta-extsdk-toolchain:do_populate_sysroot'
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050063
64 return sdk_install_targets
65
66get_sdk_install_targets[vardepsexclude] = "BB_TASKDEPDATA"
67
Patrick Williamsc124f4f2015-09-15 14:41:29 -050068OE_INIT_ENV_SCRIPT ?= "oe-init-build-env"
69
70# The files from COREBASE that you want preserved in the COREBASE copied
71# into the sdk. This allows someone to have their own setup scripts in
72# COREBASE be preserved as well as untracked files.
73COREBASE_FILES ?= " \
74 oe-init-build-env \
Patrick Williamsc124f4f2015-09-15 14:41:29 -050075 scripts \
76 LICENSE \
77 .templateconf \
78"
79
80SDK_DIR_task-populate-sdk-ext = "${WORKDIR}/sdk-ext"
81B_task-populate-sdk-ext = "${SDK_DIR}"
Brad Bishop6e60e8b2018-02-01 10:27:11 -050082TOOLCHAINEXT_OUTPUTNAME ?= "${SDK_NAME}-toolchain-ext-${SDK_VERSION}"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050083TOOLCHAIN_OUTPUTNAME_task-populate-sdk-ext = "${TOOLCHAINEXT_OUTPUTNAME}"
84
85SDK_EXT_TARGET_MANIFEST = "${SDK_DEPLOY}/${TOOLCHAINEXT_OUTPUTNAME}.target.manifest"
86SDK_EXT_HOST_MANIFEST = "${SDK_DEPLOY}/${TOOLCHAINEXT_OUTPUTNAME}.host.manifest"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050087
Brad Bishopd7bf8c12018-02-25 22:55:05 -050088python write_target_sdk_ext_manifest () {
89 from oe.sdk import get_extra_sdkinfo
90 sstate_dir = d.expand('${SDK_OUTPUT}/${SDKPATH}/sstate-cache')
91 extra_info = get_extra_sdkinfo(sstate_dir)
92
93 target = d.getVar('TARGET_SYS')
94 target_multimach = d.getVar('MULTIMACH_TARGET_SYS')
95 real_target_multimach = d.getVar('REAL_MULTIMACH_TARGET_SYS')
96
97 pkgs = {}
Brad Bishop1d80a2e2019-11-15 16:35:03 -050098 os.makedirs(os.path.dirname(d.getVar('SDK_EXT_TARGET_MANIFEST')), exist_ok=True)
Brad Bishopd7bf8c12018-02-25 22:55:05 -050099 with open(d.getVar('SDK_EXT_TARGET_MANIFEST'), 'w') as f:
100 for fn in extra_info['filesizes']:
101 info = fn.split(':')
102 if info[2] in (target, target_multimach, real_target_multimach) \
103 or info[5] == 'allarch':
104 if not info[1] in pkgs:
105 f.write("%s %s %s\n" % (info[1], info[2], info[3]))
106 pkgs[info[1]] = {}
107}
108python write_host_sdk_ext_manifest () {
109 from oe.sdk import get_extra_sdkinfo
110 sstate_dir = d.expand('${SDK_OUTPUT}/${SDKPATH}/sstate-cache')
111 extra_info = get_extra_sdkinfo(sstate_dir)
112 host = d.getVar('BUILD_SYS')
113 with open(d.getVar('SDK_EXT_HOST_MANIFEST'), 'w') as f:
114 for fn in extra_info['filesizes']:
115 info = fn.split(':')
116 if info[2] == host:
117 f.write("%s %s %s\n" % (info[1], info[2], info[3]))
118}
119
120SDK_POSTPROCESS_COMMAND_append_task-populate-sdk-ext = "write_target_sdk_ext_manifest; write_host_sdk_ext_manifest; "
121
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500122SDK_TITLE_task-populate-sdk-ext = "${@d.getVar('DISTRO_NAME') or d.getVar('DISTRO')} Extensible SDK"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500123
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600124def clean_esdk_builddir(d, sdkbasepath):
125 """Clean up traces of the fake build for create_filtered_tasklist()"""
126 import shutil
Andrew Geissler82c905d2020-04-13 13:39:40 -0500127 cleanpaths = ['cache', 'tmp']
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600128 for pth in cleanpaths:
129 fullpth = os.path.join(sdkbasepath, pth)
130 if os.path.isdir(fullpth):
131 shutil.rmtree(fullpth)
132 elif os.path.isfile(fullpth):
133 os.remove(fullpth)
134
135def create_filtered_tasklist(d, sdkbasepath, tasklistfile, conf_initpath):
136 """
137 Create a filtered list of tasks. Also double-checks that the build system
138 within the SDK basically works and required sstate artifacts are available.
139 """
140 import tempfile
141 import shutil
142 import oe.copy_buildsystem
143
144 # Create a temporary build directory that we can pass to the env setup script
145 shutil.copyfile(sdkbasepath + '/conf/local.conf', sdkbasepath + '/conf/local.conf.bak')
146 try:
147 with open(sdkbasepath + '/conf/local.conf', 'a') as f:
148 # Force the use of sstate from the build system
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500149 f.write('\nSSTATE_DIR_forcevariable = "%s"\n' % d.getVar('SSTATE_DIR'))
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500150 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 -0600151 # Ensure TMPDIR is the default so that clean_esdk_builddir() can delete it
152 f.write('TMPDIR_forcevariable = "${TOPDIR}/tmp"\n')
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500153 f.write('TCLIBCAPPEND_forcevariable = ""\n')
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600154 # Drop uninative if the build isn't using it (or else NATIVELSBSTRING will
155 # be different and we won't be able to find our native sstate)
156 if not bb.data.inherits_class('uninative', d):
157 f.write('INHERIT_remove = "uninative"\n')
158
159 # Unfortunately the default SDKPATH (or even a custom value) may contain characters that bitbake
160 # will not allow in its COREBASE path, so we need to rename the directory temporarily
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500161 temp_sdkbasepath = d.getVar('SDK_OUTPUT') + '/tmp-renamed-sdk'
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600162 # Delete any existing temp dir
163 try:
164 shutil.rmtree(temp_sdkbasepath)
165 except FileNotFoundError:
166 pass
167 os.rename(sdkbasepath, temp_sdkbasepath)
Brad Bishop316dfdd2018-06-25 12:45:53 -0400168 cmdprefix = '. %s .; ' % conf_initpath
169 logfile = d.getVar('WORKDIR') + '/tasklist_bb_log.txt'
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600170 try:
Brad Bishop316dfdd2018-06-25 12:45:53 -0400171 oe.copy_buildsystem.check_sstate_task_list(d, get_sdk_install_targets(d), tasklistfile, cmdprefix=cmdprefix, cwd=temp_sdkbasepath, logfile=logfile)
172 except bb.process.ExecutionError as e:
173 msg = 'Failed to generate filtered task list for extensible SDK:\n%s' % e.stdout.rstrip()
174 if 'attempted to execute unexpectedly and should have been setscened' in e.stdout:
175 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'
176 bb.fatal(msg)
177 os.rename(temp_sdkbasepath, sdkbasepath)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600178 # Clean out residue of running bitbake, which check_sstate_task_list()
179 # will effectively do
180 clean_esdk_builddir(d, sdkbasepath)
181 finally:
Andrew Geissler82c905d2020-04-13 13:39:40 -0500182 localconf = sdkbasepath + '/conf/local.conf'
183 if os.path.exists(localconf + '.bak'):
184 os.replace(localconf + '.bak', localconf)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600185
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500186python copy_buildsystem () {
187 import re
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500188 import shutil
189 import glob
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500190 import oe.copy_buildsystem
191
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500192 oe_init_env_script = d.getVar('OE_INIT_ENV_SCRIPT')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500193
194 conf_bbpath = ''
195 conf_initpath = ''
196 core_meta_subdir = ''
197
198 # Copy in all metadata layers + bitbake (as repositories)
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500199 buildsystem = oe.copy_buildsystem.BuildSystem('extensible SDK', d)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500200 baseoutpath = d.getVar('SDK_OUTPUT') + '/' + d.getVar('SDKPATH')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500201
202 # 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')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500250 bb.process.run(['devtool', '--bbpath', bbpath, '--basepath', baseoutpath, 'create-workspace', '--create-only', os.path.join(baseoutpath, 'workspace')])
251
252 # Create bblayers.conf
253 bb.utils.mkdirhier(baseoutpath + '/conf')
254 with open(baseoutpath + '/conf/bblayers.conf', 'w') as f:
255 f.write('# WARNING: this configuration has been automatically generated and in\n')
256 f.write('# most cases should not be edited. If you need more flexibility than\n')
257 f.write('# this configuration provides, it is strongly suggested that you set\n')
258 f.write('# up a proper instance of the full build system and use that instead.\n\n')
259
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500260 # LCONF_VERSION may not be set, for example when using meta-poky
261 # so don't error if it isn't found
262 lconf_version = d.getVar('LCONF_VERSION', False)
263 if lconf_version is not None:
264 f.write('LCONF_VERSION = "%s"\n\n' % lconf_version)
265
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500266 f.write('BBPATH = "$' + '{TOPDIR}"\n')
267 f.write('SDKBASEMETAPATH = "$' + '{TOPDIR}"\n')
268 f.write('BBLAYERS := " \\\n')
269 for layerrelpath in sdkbblayers:
270 f.write(' $' + '{SDKBASEMETAPATH}/layers/%s \\\n' % layerrelpath)
271 f.write(' $' + '{SDKBASEMETAPATH}/workspace \\\n')
272 f.write(' "\n')
273
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600274 # Copy uninative tarball
275 # For now this is where uninative.bbclass expects the tarball
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500276 if bb.data.inherits_class('uninative', d):
277 uninative_file = d.expand('${UNINATIVE_DLDIR}/' + d.getVarFlag("UNINATIVE_CHECKSUM", d.getVar("BUILD_ARCH")) + '/${UNINATIVE_TARBALL}')
278 uninative_checksum = bb.utils.sha256_file(uninative_file)
279 uninative_outdir = '%s/downloads/uninative/%s' % (baseoutpath, uninative_checksum)
280 bb.utils.mkdirhier(uninative_outdir)
281 shutil.copy(uninative_file, uninative_outdir)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600282
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500283 env_whitelist = (d.getVar('BB_ENV_EXTRAWHITE') or '').split()
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500284 env_whitelist_values = {}
285
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500286 # Create local.conf
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500287 builddir = d.getVar('TOPDIR')
Brad Bishopa5c52ff2018-11-23 10:55:50 +1300288 if derivative and os.path.exists(builddir + '/conf/site.conf'):
289 shutil.copyfile(builddir + '/conf/site.conf', baseoutpath + '/conf/site.conf')
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500290 if derivative and os.path.exists(builddir + '/conf/auto.conf'):
291 shutil.copyfile(builddir + '/conf/auto.conf', baseoutpath + '/conf/auto.conf')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500292 if derivative:
293 shutil.copyfile(builddir + '/conf/local.conf', baseoutpath + '/conf/local.conf')
294 else:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500295 local_conf_whitelist = (d.getVar('SDK_LOCAL_CONF_WHITELIST') or '').split()
296 local_conf_blacklist = (d.getVar('SDK_LOCAL_CONF_BLACKLIST') or '').split()
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500297 def handle_var(varname, origvalue, op, newlines):
298 if varname in local_conf_blacklist or (origvalue.strip().startswith('/') and not varname in local_conf_whitelist):
299 newlines.append('# Removed original setting of %s\n' % varname)
300 return None, op, 0, True
301 else:
302 if varname in env_whitelist:
303 env_whitelist_values[varname] = origvalue
304 return origvalue, op, 0, True
305 varlist = ['[^#=+ ]*']
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500306 oldlines = []
Brad Bishopa5c52ff2018-11-23 10:55:50 +1300307 if os.path.exists(builddir + '/conf/site.conf'):
308 with open(builddir + '/conf/site.conf', 'r') as f:
309 oldlines += f.readlines()
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500310 if os.path.exists(builddir + '/conf/auto.conf'):
311 with open(builddir + '/conf/auto.conf', 'r') as f:
312 oldlines += f.readlines()
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500313 if os.path.exists(builddir + '/conf/local.conf'):
314 with open(builddir + '/conf/local.conf', 'r') as f:
315 oldlines += f.readlines()
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500316 (updated, newlines) = bb.utils.edit_metadata(oldlines, varlist, handle_var)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500317
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500318 with open(baseoutpath + '/conf/local.conf', 'w') as f:
319 f.write('# WARNING: this configuration has been automatically generated and in\n')
320 f.write('# most cases should not be edited. If you need more flexibility than\n')
321 f.write('# this configuration provides, it is strongly suggested that you set\n')
322 f.write('# up a proper instance of the full build system and use that instead.\n\n')
323 for line in newlines:
324 if line.strip() and not line.startswith('#'):
325 f.write(line)
326 # Write a newline just in case there's none at the end of the original
327 f.write('\n')
328
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500329 f.write('TMPDIR = "${TOPDIR}/tmp"\n')
330 f.write('TCLIBCAPPEND = ""\n')
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600331 f.write('DL_DIR = "${TOPDIR}/downloads"\n')
332
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800333 if bb.data.inherits_class('uninative', d):
334 f.write('INHERIT += "%s"\n' % 'uninative')
335 f.write('UNINATIVE_CHECKSUM[%s] = "%s"\n\n' % (d.getVar('BUILD_ARCH'), uninative_checksum))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500336 f.write('CONF_VERSION = "%s"\n\n' % d.getVar('CONF_VERSION', False))
337
338 # Some classes are not suitable for SDK, remove them from INHERIT
339 f.write('INHERIT_remove = "%s"\n' % d.getVar('SDK_INHERIT_BLACKLIST', False))
340
341 # Bypass the default connectivity check if any
342 f.write('CONNECTIVITY_CHECK_URIS = ""\n\n')
343
344 # This warning will come out if reverse dependencies for a task
345 # don't have sstate as well as the task itself. We already know
346 # this will be the case for the extensible sdk, so turn off the
347 # warning.
348 f.write('SIGGEN_LOCKEDSIGS_SSTATE_EXISTS_CHECK = "none"\n\n')
349
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600350 # Warn if the sigs in the locked-signature file don't match
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500351 # the sig computed from the metadata.
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600352 f.write('SIGGEN_LOCKEDSIGS_TASKSIG_CHECK = "warn"\n\n')
353
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500354 # We want to be able to set this without a full reparse
355 f.write('BB_HASHCONFIG_WHITELIST_append = " SIGGEN_UNLOCKED_RECIPES"\n\n')
356
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600357 # Set up whitelist for run on install
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500358 f.write('BB_SETSCENE_ENFORCE_WHITELIST = "%:* *:do_shared_workdir *:do_rm_work wic-tools:* *:do_addto_recipe_sysroot"\n\n')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500359
360 # Hide the config information from bitbake output (since it's fixed within the SDK)
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500361 f.write('BUILDCFG_HEADER = ""\n\n')
362
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500363 f.write('# Provide a flag to indicate we are in the EXT_SDK Context\n')
364 f.write('WITHIN_EXT_SDK = "1"\n\n')
365
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500366 # Map gcc-dependent uninative sstate cache for installer usage
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500367 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 -0500368
369 # Allow additional config through sdk-extra.conf
370 fn = bb.cookerdata.findConfigFile('sdk-extra.conf', d)
371 if fn:
372 with open(fn, 'r') as xf:
373 for line in xf:
374 f.write(line)
375
376 # If you define a sdk_extraconf() function then it can contain additional config
377 # (Though this is awkward; sdk-extra.conf should probably be used instead)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500378 extraconf = (d.getVar('sdk_extraconf') or '').strip()
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500379 if extraconf:
380 # Strip off any leading / trailing spaces
381 for line in extraconf.splitlines():
382 f.write(line.strip() + '\n')
383
384 f.write('require conf/locked-sigs.inc\n')
385 f.write('require conf/unlocked-sigs.inc\n')
386
Brad Bishop00e122a2019-10-05 11:10:57 -0400387 if os.path.exists(builddir + '/cache/bb_unihashes.dat'):
388 bb.parse.siggen.save_unitaskhashes()
389 bb.utils.mkdirhier(os.path.join(baseoutpath, 'cache'))
390 shutil.copyfile(builddir + '/cache/bb_unihashes.dat', baseoutpath + '/cache/bb_unihashes.dat')
391
Andrew Geissler82c905d2020-04-13 13:39:40 -0500392 # Use templateconf.cfg file from builddir if exists
393 if os.path.exists(builddir + '/conf/templateconf.cfg'):
394 shutil.copyfile(builddir + '/conf/templateconf.cfg', baseoutpath + '/conf/templateconf.cfg')
395 else:
396 # Write a templateconf.cfg
397 with open(baseoutpath + '/conf/templateconf.cfg', 'w') as f:
398 f.write('meta/conf\n')
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500399
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500400 # Ensure any variables set from the external environment (by way of
401 # BB_ENV_EXTRAWHITE) are set in the SDK's configuration
402 extralines = []
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600403 for name, value in env_whitelist_values.items():
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500404 actualvalue = d.getVar(name) or ''
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500405 if value != actualvalue:
406 extralines.append('%s = "%s"\n' % (name, actualvalue))
407 if extralines:
408 with open(baseoutpath + '/conf/local.conf', 'a') as f:
409 f.write('\n')
410 f.write('# Extra settings from environment:\n')
411 for line in extralines:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500412 f.write(line)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500413 f.write('\n')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500414
415 # Filter the locked signatures file to just the sstate tasks we are interested in
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600416 excluded_targets = get_sdk_install_targets(d, images_only=True)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500417 sigfile = d.getVar('WORKDIR') + '/locked-sigs.inc'
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500418 lockedsigs_pruned = baseoutpath + '/conf/locked-sigs.inc'
Brad Bishopa34c0302019-09-23 22:34:48 -0400419 #nativesdk-only sigfile to merge into locked-sigs.inc
420 sdk_include_nativesdk = (d.getVar("SDK_INCLUDE_NATIVESDK") == '1')
421 nativesigfile = d.getVar('WORKDIR') + '/locked-sigs_nativesdk.inc'
422 nativesigfile_pruned = d.getVar('WORKDIR') + '/locked-sigs_nativesdk_pruned.inc'
423
424 if sdk_include_nativesdk:
425 oe.copy_buildsystem.prune_lockedsigs([],
426 excluded_targets.split(),
427 nativesigfile,
428 True,
429 nativesigfile_pruned)
430
431 oe.copy_buildsystem.merge_lockedsigs([],
432 sigfile,
433 nativesigfile_pruned,
434 sigfile)
435
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500436 oe.copy_buildsystem.prune_lockedsigs([],
437 excluded_targets.split(),
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500438 sigfile,
Brad Bishopa34c0302019-09-23 22:34:48 -0400439 False,
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500440 lockedsigs_pruned)
441
442 sstate_out = baseoutpath + '/sstate-cache'
443 bb.utils.remove(sstate_out, True)
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500444
445 # uninative.bbclass sets NATIVELSBSTRING to 'universal%s' % oe.utils.host_gcc_version(d)
446 fixedlsbstring = "universal%s" % oe.utils.host_gcc_version(d)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500447
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500448 sdk_include_toolchain = (d.getVar('SDK_INCLUDE_TOOLCHAIN') == '1')
449 sdk_ext_type = d.getVar('SDK_EXT_TYPE')
Brad Bishopa34c0302019-09-23 22:34:48 -0400450 if (sdk_ext_type != 'minimal' or sdk_include_toolchain or derivative) and not sdk_include_nativesdk:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600451 # Create the filtered task list used to generate the sstate cache shipped with the SDK
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500452 tasklistfn = d.getVar('WORKDIR') + '/tasklist.txt'
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600453 create_filtered_tasklist(d, baseoutpath, tasklistfn, conf_initpath)
454 else:
455 tasklistfn = None
456
Brad Bishop00e122a2019-10-05 11:10:57 -0400457 if os.path.exists(builddir + '/cache/bb_unihashes.dat'):
458 bb.parse.siggen.save_unitaskhashes()
459 bb.utils.mkdirhier(os.path.join(baseoutpath, 'cache'))
460 shutil.copyfile(builddir + '/cache/bb_unihashes.dat', baseoutpath + '/cache/bb_unihashes.dat')
461
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500462 # Add packagedata if enabled
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500463 if d.getVar('SDK_INCLUDE_PKGDATA') == '1':
464 lockedsigs_base = d.getVar('WORKDIR') + '/locked-sigs-base.inc'
465 lockedsigs_copy = d.getVar('WORKDIR') + '/locked-sigs-copy.inc'
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500466 shutil.move(lockedsigs_pruned, lockedsigs_base)
467 oe.copy_buildsystem.merge_lockedsigs(['do_packagedata'],
468 lockedsigs_base,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500469 d.getVar('STAGING_DIR_HOST') + '/world-pkgdata/locked-sigs-pkgdata.inc',
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500470 lockedsigs_pruned,
471 lockedsigs_copy)
472
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600473 if sdk_include_toolchain:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500474 lockedsigs_base = d.getVar('WORKDIR') + '/locked-sigs-base2.inc'
475 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 -0600476 shutil.move(lockedsigs_pruned, lockedsigs_base)
477 oe.copy_buildsystem.merge_lockedsigs([],
478 lockedsigs_base,
479 lockedsigs_toolchain,
480 lockedsigs_pruned)
481 oe.copy_buildsystem.create_locked_sstate_cache(lockedsigs_toolchain,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500482 d.getVar('SSTATE_DIR'),
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600483 sstate_out, d,
484 fixedlsbstring,
485 filterfile=tasklistfn)
486
487 if sdk_ext_type == 'minimal':
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500488 if derivative:
489 # Assume the user is not going to set up an additional sstate
490 # mirror, thus we need to copy the additional artifacts (from
491 # workspace recipes) into the derivative SDK
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500492 lockedsigs_orig = d.getVar('TOPDIR') + '/conf/locked-sigs.inc'
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500493 if os.path.exists(lockedsigs_orig):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500494 lockedsigs_extra = d.getVar('WORKDIR') + '/locked-sigs-extra.inc'
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500495 oe.copy_buildsystem.merge_lockedsigs(None,
496 lockedsigs_orig,
497 lockedsigs_pruned,
498 None,
499 lockedsigs_extra)
500 oe.copy_buildsystem.create_locked_sstate_cache(lockedsigs_extra,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500501 d.getVar('SSTATE_DIR'),
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500502 sstate_out, d,
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600503 fixedlsbstring,
504 filterfile=tasklistfn)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500505 else:
506 oe.copy_buildsystem.create_locked_sstate_cache(lockedsigs_pruned,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500507 d.getVar('SSTATE_DIR'),
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500508 sstate_out, d,
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600509 fixedlsbstring,
510 filterfile=tasklistfn)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500511
512 # We don't need sstate do_package files
513 for root, dirs, files in os.walk(sstate_out):
514 for name in files:
515 if name.endswith("_package.tgz"):
516 f = os.path.join(root, name)
517 os.remove(f)
518
519 # Write manifest file
520 # Note: at the moment we cannot include the env setup script here to keep
521 # it updated, since it gets modified during SDK installation (see
522 # sdk_ext_postinst() below) thus the checksum we take here would always
523 # be different.
524 manifest_file_list = ['conf/*']
Andrew Geisslerc3d88e42020-10-02 09:45:00 -0500525 esdk_manifest_excludes = (d.getVar('ESDK_MANIFEST_EXCLUDES') or '').split()
526 esdk_manifest_excludes_list = []
527 for exclude_item in esdk_manifest_excludes:
528 esdk_manifest_excludes_list += glob.glob(os.path.join(baseoutpath, exclude_item))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500529 manifest_file = os.path.join(baseoutpath, 'conf', 'sdk-conf-manifest')
530 with open(manifest_file, 'w') as f:
531 for item in manifest_file_list:
532 for fn in glob.glob(os.path.join(baseoutpath, item)):
533 if fn == manifest_file:
534 continue
Andrew Geisslerc3d88e42020-10-02 09:45:00 -0500535 if fn in esdk_manifest_excludes_list:
536 continue
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500537 chksum = bb.utils.sha256_file(fn)
538 f.write('%s\t%s\n' % (chksum, os.path.relpath(fn, baseoutpath)))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500539}
540
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600541def get_current_buildtools(d):
542 """Get the file name of the current buildtools installer"""
543 import glob
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500544 btfiles = glob.glob(os.path.join(d.getVar('SDK_DEPLOY'), '*-buildtools-nativesdk-standalone-*.sh'))
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600545 btfiles.sort(key=os.path.getctime)
546 return os.path.basename(btfiles[-1])
547
548def get_sdk_required_utilities(buildtools_fn, d):
549 """Find required utilities that aren't provided by the buildtools"""
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500550 sanity_required_utilities = (d.getVar('SANITY_REQUIRED_UTILITIES') or '').split()
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600551 sanity_required_utilities.append(d.expand('${BUILD_PREFIX}gcc'))
552 sanity_required_utilities.append(d.expand('${BUILD_PREFIX}g++'))
Brad Bishop1d80a2e2019-11-15 16:35:03 -0500553 if buildtools_fn:
554 buildtools_installer = os.path.join(d.getVar('SDK_DEPLOY'), buildtools_fn)
555 filelist, _ = bb.process.run('%s -l' % buildtools_installer)
556 else:
557 buildtools_installer = None
558 filelist = ""
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600559 localdata = bb.data.createCopy(d)
560 localdata.setVar('SDKPATH', '.')
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500561 sdkpathnative = localdata.getVar('SDKPATHNATIVE')
562 sdkbindirs = [localdata.getVar('bindir_nativesdk'),
563 localdata.getVar('sbindir_nativesdk'),
564 localdata.getVar('base_bindir_nativesdk'),
565 localdata.getVar('base_sbindir_nativesdk')]
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600566 for line in filelist.splitlines():
567 splitline = line.split()
568 if len(splitline) > 5:
569 fn = splitline[5]
570 if not fn.startswith('./'):
571 fn = './%s' % fn
572 if fn.startswith(sdkpathnative):
573 relpth = '/' + os.path.relpath(fn, sdkpathnative)
574 for bindir in sdkbindirs:
575 if relpth.startswith(bindir):
576 relpth = os.path.relpath(relpth, bindir)
577 if relpth in sanity_required_utilities:
578 sanity_required_utilities.remove(relpth)
579 break
580 return ' '.join(sanity_required_utilities)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500581
582install_tools() {
583 install -d ${SDK_OUTPUT}/${SDKPATHNATIVE}${bindir_nativesdk}
Brad Bishop316dfdd2018-06-25 12:45:53 -0400584 scripts="devtool recipetool oe-find-native-sysroot runqemu* wic"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600585 for script in $scripts; do
586 for scriptfn in `find ${SDK_OUTPUT}/${SDKPATH}/${scriptrelpath} -maxdepth 1 -executable -name "$script"`; do
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800587 targetscriptfn="${SDK_OUTPUT}/${SDKPATHNATIVE}${bindir_nativesdk}/$(basename $scriptfn)"
588 test -e ${targetscriptfn} || lnr ${scriptfn} ${targetscriptfn}
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600589 done
590 done
591 # We can't use the same method as above because files in the sysroot won't exist at this point
592 # (they get populated from sstate on installation)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500593 unfsd_path="${SDK_OUTPUT}/${SDKPATHNATIVE}${bindir_nativesdk}/unfsd"
594 if [ "${SDK_INCLUDE_TOOLCHAIN}" = "1" -a ! -e $unfsd_path ] ; then
595 binrelpath=${@os.path.relpath(d.getVar('STAGING_BINDIR_NATIVE'), d.getVar('TMPDIR'))}
596 lnr ${SDK_OUTPUT}/${SDKPATH}/tmp/$binrelpath/unfsd $unfsd_path
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600597 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500598 touch ${SDK_OUTPUT}/${SDKPATH}/.devtoolbase
599
600 # find latest buildtools-tarball and install it
Brad Bishop1d80a2e2019-11-15 16:35:03 -0500601 if [ -n "${SDK_BUILDTOOLS_INSTALLER}" ]; then
602 install ${SDK_DEPLOY}/${SDK_BUILDTOOLS_INSTALLER} ${SDK_OUTPUT}/${SDKPATH}
603 fi
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500604
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500605 install -m 0644 ${COREBASE}/meta/files/ext-sdk-prepare.py ${SDK_OUTPUT}/${SDKPATH}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500606}
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500607do_populate_sdk_ext[file-checksums] += "${COREBASE}/meta/files/ext-sdk-prepare.py:True"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500608
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500609sdk_ext_preinst() {
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600610 # Since bitbake won't run as root it doesn't make sense to try and install
611 # the extensible sdk as root.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500612 if [ "`id -u`" = "0" ]; then
613 echo "ERROR: The extensible sdk cannot be installed as root."
614 exit 1
615 fi
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600616 if ! command -v locale > /dev/null; then
617 echo "ERROR: The installer requires the locale command, please install it first"
618 exit 1
619 fi
620 # Check setting of LC_ALL set above
621 canonicalised_locale=`echo $LC_ALL | sed 's/UTF-8/utf8/'`
622 if ! locale -a | grep -q $canonicalised_locale ; then
623 echo "ERROR: the installer requires the $LC_ALL locale to be installed (but not selected), please install it first"
624 exit 1
625 fi
626 # The relocation script used by buildtools installer requires python
Andrew Geissler82c905d2020-04-13 13:39:40 -0500627 if ! command -v python3 > /dev/null; then
628 echo "ERROR: The installer requires python3, please install it first"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600629 exit 1
630 fi
631 missing_utils=""
632 for util in ${SDK_REQUIRED_UTILITIES}; do
633 if ! command -v $util > /dev/null; then
634 missing_utils="$missing_utils $util"
635 fi
636 done
637 if [ -n "$missing_utils" ] ; then
638 echo "ERROR: the SDK requires the following missing utilities, please install them: $missing_utils"
639 exit 1
640 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500641 SDK_EXTENSIBLE="1"
Brad Bishop19323692019-04-05 15:28:33 -0400642 if [ "$publish" = "1" ] && [ "${SDK_EXT_TYPE}" = "minimal" ] ; then
643 EXTRA_TAR_OPTIONS="$EXTRA_TAR_OPTIONS --exclude=sstate-cache"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500644 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500645}
646SDK_PRE_INSTALL_COMMAND_task-populate-sdk-ext = "${sdk_ext_preinst}"
647
648# FIXME this preparation should be done as part of the SDK construction
649sdk_ext_postinst() {
650 printf "\nExtracting buildtools...\n"
651 cd $target_sdk_dir
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600652 env_setup_script="$target_sdk_dir/environment-setup-${REAL_MULTIMACH_TARGET_SYS}"
Brad Bishop1d80a2e2019-11-15 16:35:03 -0500653 if [ -n "${SDK_BUILDTOOLS_INSTALLER}" ]; then
654 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 -0500655
Brad Bishop1d80a2e2019-11-15 16:35:03 -0500656 # Delete the buildtools tar file since it won't be used again
657 rm -f ./${SDK_BUILDTOOLS_INSTALLER}
658 # We don't need the log either since it succeeded
659 rm -f buildtools.log
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500660
Brad Bishop1d80a2e2019-11-15 16:35:03 -0500661 # Make sure when the user sets up the environment, they also get
662 # the buildtools-tarball tools in their path.
Andrew Geissler635e0e42020-08-21 15:58:33 -0500663 echo "# Save and reset OECORE_NATIVE_SYSROOT as buildtools may change it" >> $env_setup_script
664 echo "SAVED=\"\$OECORE_NATIVE_SYSROOT\"" >> $env_setup_script
Brad Bishop1d80a2e2019-11-15 16:35:03 -0500665 echo ". $target_sdk_dir/buildtools/environment-setup*" >> $env_setup_script
Andrew Geissler635e0e42020-08-21 15:58:33 -0500666 echo "OECORE_NATIVE_SYSROOT=\"\$SAVED\"" >> $env_setup_script
Brad Bishop1d80a2e2019-11-15 16:35:03 -0500667 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500668
669 # Allow bitbake environment setup to be ran as part of this sdk.
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500670 echo "export OE_SKIP_SDK_CHECK=1" >> $env_setup_script
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500671 # Work around runqemu not knowing how to get this information within the eSDK
672 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 -0500673
674 # A bit of another hack, but we need this in the path only for devtool
675 # so put it at the end of $PATH.
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500676 echo "export PATH=$target_sdk_dir/sysroots/${SDK_SYS}${bindir_nativesdk}:\$PATH" >> $env_setup_script
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500677
678 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
679
680 # Warn if trying to use external bitbake and the ext SDK together
681 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 -0500682
Brad Bishop1d80a2e2019-11-15 16:35:03 -0500683 if [ "$prepare_buildsystem" != "no" -a -n "${SDK_BUILDTOOLS_INSTALLER}" ]; then
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500684 printf "Preparing build system...\n"
685 # dash which is /bin/sh on Ubuntu will not preserve the
686 # current working directory when first ran, nor will it set $1 when
687 # sourcing a script. That is why this has to look so ugly.
688 LOGFILE="$target_sdk_dir/preparing_build_system.log"
Andrew Geissler475cb722020-07-10 16:00:51 -0500689 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 -0400690 fi
691 if [ -e $target_sdk_dir/ext-sdk-prepare.py ]; then
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500692 rm $target_sdk_dir/ext-sdk-prepare.py
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500693 fi
694 echo done
695}
696
697SDK_POST_INSTALL_COMMAND_task-populate-sdk-ext = "${sdk_ext_postinst}"
698
699SDK_POSTPROCESS_COMMAND_prepend_task-populate-sdk-ext = "copy_buildsystem; install_tools; "
700
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500701SDK_INSTALL_TARGETS = ""
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500702fakeroot python do_populate_sdk_ext() {
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500703 # FIXME hopefully we can remove this restriction at some point, but uninative
704 # currently forces this upon us
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500705 if d.getVar('SDK_ARCH') != d.getVar('BUILD_ARCH'):
706 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 -0500707
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500708 d.setVar('SDK_INSTALL_TARGETS', get_sdk_install_targets(d))
Brad Bishop1d80a2e2019-11-15 16:35:03 -0500709 if d.getVar('SDK_INCLUDE_BUILDTOOLS') == '1':
710 buildtools_fn = get_current_buildtools(d)
711 else:
712 buildtools_fn = None
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600713 d.setVar('SDK_REQUIRED_UTILITIES', get_sdk_required_utilities(buildtools_fn, d))
714 d.setVar('SDK_BUILDTOOLS_INSTALLER', buildtools_fn)
715 d.setVar('SDKDEPLOYDIR', '${SDKEXTDEPLOYDIR}')
Brad Bishop00111322018-04-01 22:23:53 -0400716 # ESDKs have a libc from the buildtools so ensure we don't ship linguas twice
717 d.delVar('SDKIMAGE_LINGUAS')
Brad Bishopa34c0302019-09-23 22:34:48 -0400718 if d.getVar("SDK_INCLUDE_NATIVESDK") == '1':
719 generate_nativesdk_lockedsigs(d)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600720 populate_sdk_common(d)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500721}
722
Brad Bishopa34c0302019-09-23 22:34:48 -0400723def generate_nativesdk_lockedsigs(d):
724 import oe.copy_buildsystem
725 sigfile = d.getVar('WORKDIR') + '/locked-sigs_nativesdk.inc'
726 oe.copy_buildsystem.generate_locked_sigs(sigfile, d)
727
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500728def get_ext_sdk_depends(d):
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600729 # Note: the deps varflag is a list not a string, so we need to specify expand=False
730 deps = d.getVarFlag('do_image_complete', 'deps', False)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500731 pn = d.getVar('PN')
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600732 deplist = ['%s:%s' % (pn, dep) for dep in deps]
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500733 tasklist = bb.build.tasksbetween('do_image_complete', 'do_build', d)
734 tasklist.append('do_rootfs')
735 for task in tasklist:
736 deplist.extend((d.getVarFlag(task, 'depends') or '').split())
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600737 return ' '.join(deplist)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500738
739python do_sdk_depends() {
740 # We have to do this separately in its own task so we avoid recursing into
741 # dependencies we don't need to (e.g. buildtools-tarball) and bringing those
742 # into the SDK's sstate-cache
743 import oe.copy_buildsystem
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500744 sigfile = d.getVar('WORKDIR') + '/locked-sigs.inc'
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500745 oe.copy_buildsystem.generate_locked_sigs(sigfile, d)
746}
747addtask sdk_depends
748
749do_sdk_depends[dirs] = "${WORKDIR}"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500750do_sdk_depends[depends] = "${@get_ext_sdk_depends(d)} meta-extsdk-toolchain:do_populate_sysroot"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500751do_sdk_depends[recrdeptask] = "${@d.getVarFlag('do_populate_sdk', 'recrdeptask', False)}"
752do_sdk_depends[recrdeptask] += "do_populate_lic do_package_qa do_populate_sysroot do_deploy ${SDK_RECRDEP_TASKS}"
753do_sdk_depends[rdepends] = "${@get_sdk_ext_rdepends(d)}"
754
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500755def get_sdk_ext_rdepends(d):
756 localdata = d.createCopy()
757 localdata.appendVar('OVERRIDES', ':task-populate-sdk-ext')
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500758 return localdata.getVarFlag('do_populate_sdk', 'rdepends')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500759
760do_populate_sdk_ext[dirs] = "${@d.getVarFlag('do_populate_sdk', 'dirs', False)}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500761
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500762do_populate_sdk_ext[depends] = "${@d.getVarFlag('do_populate_sdk', 'depends', False)} \
Brad Bishop1d80a2e2019-11-15 16:35:03 -0500763 ${@'buildtools-tarball:do_populate_sdk' if d.getVar('SDK_INCLUDE_BUILDTOOLS') == '1' else ''} \
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500764 ${@'meta-world-pkgdata:do_collect_packagedata' if d.getVar('SDK_INCLUDE_PKGDATA') == '1' else ''} \
765 ${@'meta-extsdk-toolchain:do_locked_sigs' if d.getVar('SDK_INCLUDE_TOOLCHAIN') == '1' else ''}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500766
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500767# We must avoid depending on do_build here if rm_work.bbclass is active,
768# because otherwise do_rm_work may run before do_populate_sdk_ext itself.
769# We can't mark do_populate_sdk_ext and do_sdk_depends as having to
770# run before do_rm_work, because then they would also run as part
771# of normal builds.
772do_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 -0500773
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500774# Make sure code changes can result in rebuild
775do_populate_sdk_ext[vardeps] += "copy_buildsystem \
776 sdk_ext_postinst"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500777
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500778# Since any change in the metadata of any layer should cause a rebuild of the
779# sdk(since the layers are put in the sdk) set the task to nostamp so it
780# always runs.
781do_populate_sdk_ext[nostamp] = "1"
782
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600783SDKEXTDEPLOYDIR = "${WORKDIR}/deploy-${PN}-populate-sdk-ext"
784
785SSTATETASKS += "do_populate_sdk_ext"
786SSTATE_SKIP_CREATION_task-populate-sdk-ext = '1'
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500787do_populate_sdk_ext[cleandirs] = "${SDKEXTDEPLOYDIR}"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600788do_populate_sdk_ext[sstate-inputdirs] = "${SDKEXTDEPLOYDIR}"
789do_populate_sdk_ext[sstate-outputdirs] = "${SDK_DEPLOY}"
Brad Bishop316dfdd2018-06-25 12:45:53 -0400790do_populate_sdk_ext[stamp-extra-info] = "${MACHINE_ARCH}"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600791
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500792addtask populate_sdk_ext after do_sdk_depends