blob: 9fda1c9e78eabdf9fc87393686d3b40ea29b4ae2 [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"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050024
25SDK_RECRDEP_TASKS ?= ""
26
Patrick Williamsc124f4f2015-09-15 14:41:29 -050027SDK_LOCAL_CONF_WHITELIST ?= ""
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050028SDK_LOCAL_CONF_BLACKLIST ?= "CONF_VERSION \
29 BB_NUMBER_THREADS \
Patrick Williamsc0f7c042017-02-23 20:41:17 -060030 BB_NUMBER_PARSE_THREADS \
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050031 PARALLEL_MAKE \
32 PRSERV_HOST \
33 SSTATE_MIRRORS \
Patrick Williamsc0f7c042017-02-23 20:41:17 -060034 DL_DIR \
35 SSTATE_DIR \
36 TMPDIR \
Brad Bishopd7bf8c12018-02-25 22:55:05 -050037 BB_SERVER_TIMEOUT \
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050038 "
Patrick Williamsc124f4f2015-09-15 14:41:29 -050039SDK_INHERIT_BLACKLIST ?= "buildhistory icecc"
40SDK_UPDATE_URL ?= ""
41
42SDK_TARGETS ?= "${PN}"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050043
Patrick Williamsc0f7c042017-02-23 20:41:17 -060044def get_sdk_install_targets(d, images_only=False):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050045 sdk_install_targets = ''
Brad Bishop6e60e8b2018-02-01 10:27:11 -050046 if images_only or d.getVar('SDK_EXT_TYPE') != 'minimal':
47 sdk_install_targets = d.getVar('SDK_TARGETS')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050048
49 depd = d.getVar('BB_TASKDEPDATA', False)
Brad Bishop6e60e8b2018-02-01 10:27:11 -050050 tasklist = bb.build.tasksbetween('do_image_complete', 'do_build', d)
51 tasklist.remove('do_build')
Patrick Williamsc0f7c042017-02-23 20:41:17 -060052 for v in depd.values():
Brad Bishop6e60e8b2018-02-01 10:27:11 -050053 if v[1] in tasklist:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050054 if v[0] not in sdk_install_targets:
55 sdk_install_targets += ' {}'.format(v[0])
56
Patrick Williamsc0f7c042017-02-23 20:41:17 -060057 if not images_only:
Brad Bishop6e60e8b2018-02-01 10:27:11 -050058 if d.getVar('SDK_INCLUDE_PKGDATA') == '1':
Patrick Williamsc0f7c042017-02-23 20:41:17 -060059 sdk_install_targets += ' meta-world-pkgdata:do_allpackagedata'
Brad Bishop6e60e8b2018-02-01 10:27:11 -050060 if d.getVar('SDK_INCLUDE_TOOLCHAIN') == '1':
Patrick Williamsc0f7c042017-02-23 20:41:17 -060061 sdk_install_targets += ' meta-extsdk-toolchain:do_populate_sysroot'
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050062
63 return sdk_install_targets
64
65get_sdk_install_targets[vardepsexclude] = "BB_TASKDEPDATA"
66
Patrick Williamsc124f4f2015-09-15 14:41:29 -050067OE_INIT_ENV_SCRIPT ?= "oe-init-build-env"
68
69# The files from COREBASE that you want preserved in the COREBASE copied
70# into the sdk. This allows someone to have their own setup scripts in
71# COREBASE be preserved as well as untracked files.
72COREBASE_FILES ?= " \
73 oe-init-build-env \
Patrick Williamsc124f4f2015-09-15 14:41:29 -050074 scripts \
75 LICENSE \
76 .templateconf \
77"
78
79SDK_DIR_task-populate-sdk-ext = "${WORKDIR}/sdk-ext"
80B_task-populate-sdk-ext = "${SDK_DIR}"
Brad Bishop6e60e8b2018-02-01 10:27:11 -050081TOOLCHAINEXT_OUTPUTNAME ?= "${SDK_NAME}-toolchain-ext-${SDK_VERSION}"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050082TOOLCHAIN_OUTPUTNAME_task-populate-sdk-ext = "${TOOLCHAINEXT_OUTPUTNAME}"
83
84SDK_EXT_TARGET_MANIFEST = "${SDK_DEPLOY}/${TOOLCHAINEXT_OUTPUTNAME}.target.manifest"
85SDK_EXT_HOST_MANIFEST = "${SDK_DEPLOY}/${TOOLCHAINEXT_OUTPUTNAME}.host.manifest"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050086
Brad Bishopd7bf8c12018-02-25 22:55:05 -050087python write_target_sdk_ext_manifest () {
88 from oe.sdk import get_extra_sdkinfo
89 sstate_dir = d.expand('${SDK_OUTPUT}/${SDKPATH}/sstate-cache')
90 extra_info = get_extra_sdkinfo(sstate_dir)
91
92 target = d.getVar('TARGET_SYS')
93 target_multimach = d.getVar('MULTIMACH_TARGET_SYS')
94 real_target_multimach = d.getVar('REAL_MULTIMACH_TARGET_SYS')
95
96 pkgs = {}
97 with open(d.getVar('SDK_EXT_TARGET_MANIFEST'), 'w') as f:
98 for fn in extra_info['filesizes']:
99 info = fn.split(':')
100 if info[2] in (target, target_multimach, real_target_multimach) \
101 or info[5] == 'allarch':
102 if not info[1] in pkgs:
103 f.write("%s %s %s\n" % (info[1], info[2], info[3]))
104 pkgs[info[1]] = {}
105}
106python write_host_sdk_ext_manifest () {
107 from oe.sdk import get_extra_sdkinfo
108 sstate_dir = d.expand('${SDK_OUTPUT}/${SDKPATH}/sstate-cache')
109 extra_info = get_extra_sdkinfo(sstate_dir)
110 host = d.getVar('BUILD_SYS')
111 with open(d.getVar('SDK_EXT_HOST_MANIFEST'), 'w') as f:
112 for fn in extra_info['filesizes']:
113 info = fn.split(':')
114 if info[2] == host:
115 f.write("%s %s %s\n" % (info[1], info[2], info[3]))
116}
117
118SDK_POSTPROCESS_COMMAND_append_task-populate-sdk-ext = "write_target_sdk_ext_manifest; write_host_sdk_ext_manifest; "
119
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500120SDK_TITLE_task-populate-sdk-ext = "${@d.getVar('DISTRO_NAME') or d.getVar('DISTRO')} Extensible SDK"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500121
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600122def clean_esdk_builddir(d, sdkbasepath):
123 """Clean up traces of the fake build for create_filtered_tasklist()"""
124 import shutil
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500125 cleanpaths = 'cache conf/sanity_info tmp'.split()
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600126 for pth in cleanpaths:
127 fullpth = os.path.join(sdkbasepath, pth)
128 if os.path.isdir(fullpth):
129 shutil.rmtree(fullpth)
130 elif os.path.isfile(fullpth):
131 os.remove(fullpth)
132
133def create_filtered_tasklist(d, sdkbasepath, tasklistfile, conf_initpath):
134 """
135 Create a filtered list of tasks. Also double-checks that the build system
136 within the SDK basically works and required sstate artifacts are available.
137 """
138 import tempfile
139 import shutil
140 import oe.copy_buildsystem
141
142 # Create a temporary build directory that we can pass to the env setup script
143 shutil.copyfile(sdkbasepath + '/conf/local.conf', sdkbasepath + '/conf/local.conf.bak')
144 try:
145 with open(sdkbasepath + '/conf/local.conf', 'a') as f:
146 # Force the use of sstate from the build system
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500147 f.write('\nSSTATE_DIR_forcevariable = "%s"\n' % d.getVar('SSTATE_DIR'))
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500148 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 -0600149 # Ensure TMPDIR is the default so that clean_esdk_builddir() can delete it
150 f.write('TMPDIR_forcevariable = "${TOPDIR}/tmp"\n')
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500151 f.write('TCLIBCAPPEND_forcevariable = ""\n')
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600152 # Drop uninative if the build isn't using it (or else NATIVELSBSTRING will
153 # be different and we won't be able to find our native sstate)
154 if not bb.data.inherits_class('uninative', d):
155 f.write('INHERIT_remove = "uninative"\n')
156
157 # Unfortunately the default SDKPATH (or even a custom value) may contain characters that bitbake
158 # will not allow in its COREBASE path, so we need to rename the directory temporarily
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500159 temp_sdkbasepath = d.getVar('SDK_OUTPUT') + '/tmp-renamed-sdk'
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600160 # Delete any existing temp dir
161 try:
162 shutil.rmtree(temp_sdkbasepath)
163 except FileNotFoundError:
164 pass
165 os.rename(sdkbasepath, temp_sdkbasepath)
Brad Bishop316dfdd2018-06-25 12:45:53 -0400166 cmdprefix = '. %s .; ' % conf_initpath
167 logfile = d.getVar('WORKDIR') + '/tasklist_bb_log.txt'
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600168 try:
Brad Bishop316dfdd2018-06-25 12:45:53 -0400169 oe.copy_buildsystem.check_sstate_task_list(d, get_sdk_install_targets(d), tasklistfile, cmdprefix=cmdprefix, cwd=temp_sdkbasepath, logfile=logfile)
170 except bb.process.ExecutionError as e:
171 msg = 'Failed to generate filtered task list for extensible SDK:\n%s' % e.stdout.rstrip()
172 if 'attempted to execute unexpectedly and should have been setscened' in e.stdout:
173 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'
174 bb.fatal(msg)
175 os.rename(temp_sdkbasepath, sdkbasepath)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600176 # Clean out residue of running bitbake, which check_sstate_task_list()
177 # will effectively do
178 clean_esdk_builddir(d, sdkbasepath)
179 finally:
180 os.replace(sdkbasepath + '/conf/local.conf.bak', sdkbasepath + '/conf/local.conf')
181
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500182python copy_buildsystem () {
183 import re
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500184 import shutil
185 import glob
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500186 import oe.copy_buildsystem
187
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500188 oe_init_env_script = d.getVar('OE_INIT_ENV_SCRIPT')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500189
190 conf_bbpath = ''
191 conf_initpath = ''
192 core_meta_subdir = ''
193
194 # Copy in all metadata layers + bitbake (as repositories)
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500195 buildsystem = oe.copy_buildsystem.BuildSystem('extensible SDK', d)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500196 baseoutpath = d.getVar('SDK_OUTPUT') + '/' + d.getVar('SDKPATH')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500197
198 # Determine if we're building a derivative extensible SDK (from devtool build-sdk)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500199 derivative = (d.getVar('SDK_DERIVATIVE') or '') == '1'
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500200 if derivative:
201 workspace_name = 'orig-workspace'
202 else:
203 workspace_name = None
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500204
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800205 corebase, sdkbblayers = buildsystem.copy_bitbake_and_layers(baseoutpath + '/layers', workspace_name)
206 conf_bbpath = os.path.join('layers', corebase, 'bitbake')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500207
208 for path in os.listdir(baseoutpath + '/layers'):
209 relpath = os.path.join('layers', path, oe_init_env_script)
210 if os.path.exists(os.path.join(baseoutpath, relpath)):
211 conf_initpath = relpath
212
213 relpath = os.path.join('layers', path, 'scripts', 'devtool')
214 if os.path.exists(os.path.join(baseoutpath, relpath)):
215 scriptrelpath = os.path.dirname(relpath)
216
217 relpath = os.path.join('layers', path, 'meta')
218 if os.path.exists(os.path.join(baseoutpath, relpath, 'lib', 'oe')):
219 core_meta_subdir = relpath
220
221 d.setVar('oe_init_build_env_path', conf_initpath)
222 d.setVar('scriptrelpath', scriptrelpath)
223
224 # Write out config file for devtool
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600225 import configparser
226 config = configparser.SafeConfigParser()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500227 config.add_section('General')
228 config.set('General', 'bitbake_subdir', conf_bbpath)
229 config.set('General', 'init_path', conf_initpath)
230 config.set('General', 'core_meta_subdir', core_meta_subdir)
231 config.add_section('SDK')
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500232 config.set('SDK', 'sdk_targets', d.getVar('SDK_TARGETS'))
233 updateurl = d.getVar('SDK_UPDATE_URL')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500234 if updateurl:
235 config.set('SDK', 'updateserver', updateurl)
236 bb.utils.mkdirhier(os.path.join(baseoutpath, 'conf'))
237 with open(os.path.join(baseoutpath, 'conf', 'devtool.conf'), 'w') as f:
238 config.write(f)
239
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500240 unlockedsigs = os.path.join(baseoutpath, 'conf', 'unlocked-sigs.inc')
241 with open(unlockedsigs, 'w') as f:
242 pass
243
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500244 # Create a layer for new recipes / appends
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500245 bbpath = d.getVar('BBPATH')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500246 bb.process.run(['devtool', '--bbpath', bbpath, '--basepath', baseoutpath, 'create-workspace', '--create-only', os.path.join(baseoutpath, 'workspace')])
247
248 # Create bblayers.conf
249 bb.utils.mkdirhier(baseoutpath + '/conf')
250 with open(baseoutpath + '/conf/bblayers.conf', 'w') as f:
251 f.write('# WARNING: this configuration has been automatically generated and in\n')
252 f.write('# most cases should not be edited. If you need more flexibility than\n')
253 f.write('# this configuration provides, it is strongly suggested that you set\n')
254 f.write('# up a proper instance of the full build system and use that instead.\n\n')
255
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500256 # LCONF_VERSION may not be set, for example when using meta-poky
257 # so don't error if it isn't found
258 lconf_version = d.getVar('LCONF_VERSION', False)
259 if lconf_version is not None:
260 f.write('LCONF_VERSION = "%s"\n\n' % lconf_version)
261
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500262 f.write('BBPATH = "$' + '{TOPDIR}"\n')
263 f.write('SDKBASEMETAPATH = "$' + '{TOPDIR}"\n')
264 f.write('BBLAYERS := " \\\n')
265 for layerrelpath in sdkbblayers:
266 f.write(' $' + '{SDKBASEMETAPATH}/layers/%s \\\n' % layerrelpath)
267 f.write(' $' + '{SDKBASEMETAPATH}/workspace \\\n')
268 f.write(' "\n')
269
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600270 # Copy uninative tarball
271 # For now this is where uninative.bbclass expects the tarball
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500272 if bb.data.inherits_class('uninative', d):
273 uninative_file = d.expand('${UNINATIVE_DLDIR}/' + d.getVarFlag("UNINATIVE_CHECKSUM", d.getVar("BUILD_ARCH")) + '/${UNINATIVE_TARBALL}')
274 uninative_checksum = bb.utils.sha256_file(uninative_file)
275 uninative_outdir = '%s/downloads/uninative/%s' % (baseoutpath, uninative_checksum)
276 bb.utils.mkdirhier(uninative_outdir)
277 shutil.copy(uninative_file, uninative_outdir)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600278
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500279 env_whitelist = (d.getVar('BB_ENV_EXTRAWHITE') or '').split()
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500280 env_whitelist_values = {}
281
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500282 # Create local.conf
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500283 builddir = d.getVar('TOPDIR')
Brad Bishopa5c52ff2018-11-23 10:55:50 +1300284 if derivative and os.path.exists(builddir + '/conf/site.conf'):
285 shutil.copyfile(builddir + '/conf/site.conf', baseoutpath + '/conf/site.conf')
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500286 if derivative and os.path.exists(builddir + '/conf/auto.conf'):
287 shutil.copyfile(builddir + '/conf/auto.conf', baseoutpath + '/conf/auto.conf')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500288 if derivative:
289 shutil.copyfile(builddir + '/conf/local.conf', baseoutpath + '/conf/local.conf')
290 else:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500291 local_conf_whitelist = (d.getVar('SDK_LOCAL_CONF_WHITELIST') or '').split()
292 local_conf_blacklist = (d.getVar('SDK_LOCAL_CONF_BLACKLIST') or '').split()
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500293 def handle_var(varname, origvalue, op, newlines):
294 if varname in local_conf_blacklist or (origvalue.strip().startswith('/') and not varname in local_conf_whitelist):
295 newlines.append('# Removed original setting of %s\n' % varname)
296 return None, op, 0, True
297 else:
298 if varname in env_whitelist:
299 env_whitelist_values[varname] = origvalue
300 return origvalue, op, 0, True
301 varlist = ['[^#=+ ]*']
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500302 oldlines = []
Brad Bishopa5c52ff2018-11-23 10:55:50 +1300303 if os.path.exists(builddir + '/conf/site.conf'):
304 with open(builddir + '/conf/site.conf', 'r') as f:
305 oldlines += f.readlines()
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500306 if os.path.exists(builddir + '/conf/auto.conf'):
307 with open(builddir + '/conf/auto.conf', 'r') as f:
308 oldlines += f.readlines()
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500309 with open(builddir + '/conf/local.conf', 'r') as f:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500310 oldlines += f.readlines()
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500311 (updated, newlines) = bb.utils.edit_metadata(oldlines, varlist, handle_var)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500312
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500313 with open(baseoutpath + '/conf/local.conf', 'w') as f:
314 f.write('# WARNING: this configuration has been automatically generated and in\n')
315 f.write('# most cases should not be edited. If you need more flexibility than\n')
316 f.write('# this configuration provides, it is strongly suggested that you set\n')
317 f.write('# up a proper instance of the full build system and use that instead.\n\n')
318 for line in newlines:
319 if line.strip() and not line.startswith('#'):
320 f.write(line)
321 # Write a newline just in case there's none at the end of the original
322 f.write('\n')
323
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500324 f.write('TMPDIR = "${TOPDIR}/tmp"\n')
325 f.write('TCLIBCAPPEND = ""\n')
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600326 f.write('DL_DIR = "${TOPDIR}/downloads"\n')
327
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800328 if bb.data.inherits_class('uninative', d):
329 f.write('INHERIT += "%s"\n' % 'uninative')
330 f.write('UNINATIVE_CHECKSUM[%s] = "%s"\n\n' % (d.getVar('BUILD_ARCH'), uninative_checksum))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500331 f.write('CONF_VERSION = "%s"\n\n' % d.getVar('CONF_VERSION', False))
332
333 # Some classes are not suitable for SDK, remove them from INHERIT
334 f.write('INHERIT_remove = "%s"\n' % d.getVar('SDK_INHERIT_BLACKLIST', False))
335
336 # Bypass the default connectivity check if any
337 f.write('CONNECTIVITY_CHECK_URIS = ""\n\n')
338
339 # This warning will come out if reverse dependencies for a task
340 # don't have sstate as well as the task itself. We already know
341 # this will be the case for the extensible sdk, so turn off the
342 # warning.
343 f.write('SIGGEN_LOCKEDSIGS_SSTATE_EXISTS_CHECK = "none"\n\n')
344
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600345 # Warn if the sigs in the locked-signature file don't match
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500346 # the sig computed from the metadata.
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600347 f.write('SIGGEN_LOCKEDSIGS_TASKSIG_CHECK = "warn"\n\n')
348
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500349 # We want to be able to set this without a full reparse
350 f.write('BB_HASHCONFIG_WHITELIST_append = " SIGGEN_UNLOCKED_RECIPES"\n\n')
351
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600352 # Set up whitelist for run on install
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500353 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 -0500354
355 # Hide the config information from bitbake output (since it's fixed within the SDK)
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500356 f.write('BUILDCFG_HEADER = ""\n\n')
357
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500358 f.write('# Provide a flag to indicate we are in the EXT_SDK Context\n')
359 f.write('WITHIN_EXT_SDK = "1"\n\n')
360
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500361 # Map gcc-dependent uninative sstate cache for installer usage
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500362 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 -0500363
364 # Allow additional config through sdk-extra.conf
365 fn = bb.cookerdata.findConfigFile('sdk-extra.conf', d)
366 if fn:
367 with open(fn, 'r') as xf:
368 for line in xf:
369 f.write(line)
370
371 # If you define a sdk_extraconf() function then it can contain additional config
372 # (Though this is awkward; sdk-extra.conf should probably be used instead)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500373 extraconf = (d.getVar('sdk_extraconf') or '').strip()
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500374 if extraconf:
375 # Strip off any leading / trailing spaces
376 for line in extraconf.splitlines():
377 f.write(line.strip() + '\n')
378
379 f.write('require conf/locked-sigs.inc\n')
380 f.write('require conf/unlocked-sigs.inc\n')
381
Brad Bishop00e122a2019-10-05 11:10:57 -0400382 if os.path.exists(builddir + '/cache/bb_unihashes.dat'):
383 bb.parse.siggen.save_unitaskhashes()
384 bb.utils.mkdirhier(os.path.join(baseoutpath, 'cache'))
385 shutil.copyfile(builddir + '/cache/bb_unihashes.dat', baseoutpath + '/cache/bb_unihashes.dat')
386
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500387 # Write a templateconf.cfg
388 with open(baseoutpath + '/conf/templateconf.cfg', 'w') as f:
389 f.write('meta/conf\n')
390
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500391 # Ensure any variables set from the external environment (by way of
392 # BB_ENV_EXTRAWHITE) are set in the SDK's configuration
393 extralines = []
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600394 for name, value in env_whitelist_values.items():
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500395 actualvalue = d.getVar(name) or ''
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500396 if value != actualvalue:
397 extralines.append('%s = "%s"\n' % (name, actualvalue))
398 if extralines:
399 with open(baseoutpath + '/conf/local.conf', 'a') as f:
400 f.write('\n')
401 f.write('# Extra settings from environment:\n')
402 for line in extralines:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500403 f.write(line)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500404 f.write('\n')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500405
406 # Filter the locked signatures file to just the sstate tasks we are interested in
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600407 excluded_targets = get_sdk_install_targets(d, images_only=True)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500408 sigfile = d.getVar('WORKDIR') + '/locked-sigs.inc'
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500409 lockedsigs_pruned = baseoutpath + '/conf/locked-sigs.inc'
Brad Bishopa34c0302019-09-23 22:34:48 -0400410 #nativesdk-only sigfile to merge into locked-sigs.inc
411 sdk_include_nativesdk = (d.getVar("SDK_INCLUDE_NATIVESDK") == '1')
412 nativesigfile = d.getVar('WORKDIR') + '/locked-sigs_nativesdk.inc'
413 nativesigfile_pruned = d.getVar('WORKDIR') + '/locked-sigs_nativesdk_pruned.inc'
414
415 if sdk_include_nativesdk:
416 oe.copy_buildsystem.prune_lockedsigs([],
417 excluded_targets.split(),
418 nativesigfile,
419 True,
420 nativesigfile_pruned)
421
422 oe.copy_buildsystem.merge_lockedsigs([],
423 sigfile,
424 nativesigfile_pruned,
425 sigfile)
426
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500427 oe.copy_buildsystem.prune_lockedsigs([],
428 excluded_targets.split(),
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500429 sigfile,
Brad Bishopa34c0302019-09-23 22:34:48 -0400430 False,
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500431 lockedsigs_pruned)
432
433 sstate_out = baseoutpath + '/sstate-cache'
434 bb.utils.remove(sstate_out, True)
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500435
436 # uninative.bbclass sets NATIVELSBSTRING to 'universal%s' % oe.utils.host_gcc_version(d)
437 fixedlsbstring = "universal%s" % oe.utils.host_gcc_version(d)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500438
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500439 sdk_include_toolchain = (d.getVar('SDK_INCLUDE_TOOLCHAIN') == '1')
440 sdk_ext_type = d.getVar('SDK_EXT_TYPE')
Brad Bishopa34c0302019-09-23 22:34:48 -0400441 if (sdk_ext_type != 'minimal' or sdk_include_toolchain or derivative) and not sdk_include_nativesdk:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600442 # Create the filtered task list used to generate the sstate cache shipped with the SDK
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500443 tasklistfn = d.getVar('WORKDIR') + '/tasklist.txt'
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600444 create_filtered_tasklist(d, baseoutpath, tasklistfn, conf_initpath)
445 else:
446 tasklistfn = None
447
Brad Bishop00e122a2019-10-05 11:10:57 -0400448 if os.path.exists(builddir + '/cache/bb_unihashes.dat'):
449 bb.parse.siggen.save_unitaskhashes()
450 bb.utils.mkdirhier(os.path.join(baseoutpath, 'cache'))
451 shutil.copyfile(builddir + '/cache/bb_unihashes.dat', baseoutpath + '/cache/bb_unihashes.dat')
452
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500453 # Add packagedata if enabled
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500454 if d.getVar('SDK_INCLUDE_PKGDATA') == '1':
455 lockedsigs_base = d.getVar('WORKDIR') + '/locked-sigs-base.inc'
456 lockedsigs_copy = d.getVar('WORKDIR') + '/locked-sigs-copy.inc'
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500457 shutil.move(lockedsigs_pruned, lockedsigs_base)
458 oe.copy_buildsystem.merge_lockedsigs(['do_packagedata'],
459 lockedsigs_base,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500460 d.getVar('STAGING_DIR_HOST') + '/world-pkgdata/locked-sigs-pkgdata.inc',
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500461 lockedsigs_pruned,
462 lockedsigs_copy)
463
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600464 if sdk_include_toolchain:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500465 lockedsigs_base = d.getVar('WORKDIR') + '/locked-sigs-base2.inc'
466 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 -0600467 shutil.move(lockedsigs_pruned, lockedsigs_base)
468 oe.copy_buildsystem.merge_lockedsigs([],
469 lockedsigs_base,
470 lockedsigs_toolchain,
471 lockedsigs_pruned)
472 oe.copy_buildsystem.create_locked_sstate_cache(lockedsigs_toolchain,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500473 d.getVar('SSTATE_DIR'),
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600474 sstate_out, d,
475 fixedlsbstring,
476 filterfile=tasklistfn)
477
478 if sdk_ext_type == 'minimal':
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500479 if derivative:
480 # Assume the user is not going to set up an additional sstate
481 # mirror, thus we need to copy the additional artifacts (from
482 # workspace recipes) into the derivative SDK
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500483 lockedsigs_orig = d.getVar('TOPDIR') + '/conf/locked-sigs.inc'
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500484 if os.path.exists(lockedsigs_orig):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500485 lockedsigs_extra = d.getVar('WORKDIR') + '/locked-sigs-extra.inc'
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500486 oe.copy_buildsystem.merge_lockedsigs(None,
487 lockedsigs_orig,
488 lockedsigs_pruned,
489 None,
490 lockedsigs_extra)
491 oe.copy_buildsystem.create_locked_sstate_cache(lockedsigs_extra,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500492 d.getVar('SSTATE_DIR'),
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500493 sstate_out, d,
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600494 fixedlsbstring,
495 filterfile=tasklistfn)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500496 else:
497 oe.copy_buildsystem.create_locked_sstate_cache(lockedsigs_pruned,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500498 d.getVar('SSTATE_DIR'),
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500499 sstate_out, d,
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600500 fixedlsbstring,
501 filterfile=tasklistfn)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500502
503 # We don't need sstate do_package files
504 for root, dirs, files in os.walk(sstate_out):
505 for name in files:
506 if name.endswith("_package.tgz"):
507 f = os.path.join(root, name)
508 os.remove(f)
509
510 # Write manifest file
511 # Note: at the moment we cannot include the env setup script here to keep
512 # it updated, since it gets modified during SDK installation (see
513 # sdk_ext_postinst() below) thus the checksum we take here would always
514 # be different.
515 manifest_file_list = ['conf/*']
516 manifest_file = os.path.join(baseoutpath, 'conf', 'sdk-conf-manifest')
517 with open(manifest_file, 'w') as f:
518 for item in manifest_file_list:
519 for fn in glob.glob(os.path.join(baseoutpath, item)):
520 if fn == manifest_file:
521 continue
522 chksum = bb.utils.sha256_file(fn)
523 f.write('%s\t%s\n' % (chksum, os.path.relpath(fn, baseoutpath)))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500524}
525
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600526def get_current_buildtools(d):
527 """Get the file name of the current buildtools installer"""
528 import glob
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500529 btfiles = glob.glob(os.path.join(d.getVar('SDK_DEPLOY'), '*-buildtools-nativesdk-standalone-*.sh'))
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600530 btfiles.sort(key=os.path.getctime)
531 return os.path.basename(btfiles[-1])
532
533def get_sdk_required_utilities(buildtools_fn, d):
534 """Find required utilities that aren't provided by the buildtools"""
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500535 sanity_required_utilities = (d.getVar('SANITY_REQUIRED_UTILITIES') or '').split()
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600536 sanity_required_utilities.append(d.expand('${BUILD_PREFIX}gcc'))
537 sanity_required_utilities.append(d.expand('${BUILD_PREFIX}g++'))
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500538 buildtools_installer = os.path.join(d.getVar('SDK_DEPLOY'), buildtools_fn)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600539 filelist, _ = bb.process.run('%s -l' % buildtools_installer)
540 localdata = bb.data.createCopy(d)
541 localdata.setVar('SDKPATH', '.')
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500542 sdkpathnative = localdata.getVar('SDKPATHNATIVE')
543 sdkbindirs = [localdata.getVar('bindir_nativesdk'),
544 localdata.getVar('sbindir_nativesdk'),
545 localdata.getVar('base_bindir_nativesdk'),
546 localdata.getVar('base_sbindir_nativesdk')]
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600547 for line in filelist.splitlines():
548 splitline = line.split()
549 if len(splitline) > 5:
550 fn = splitline[5]
551 if not fn.startswith('./'):
552 fn = './%s' % fn
553 if fn.startswith(sdkpathnative):
554 relpth = '/' + os.path.relpath(fn, sdkpathnative)
555 for bindir in sdkbindirs:
556 if relpth.startswith(bindir):
557 relpth = os.path.relpath(relpth, bindir)
558 if relpth in sanity_required_utilities:
559 sanity_required_utilities.remove(relpth)
560 break
561 return ' '.join(sanity_required_utilities)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500562
563install_tools() {
564 install -d ${SDK_OUTPUT}/${SDKPATHNATIVE}${bindir_nativesdk}
Brad Bishop316dfdd2018-06-25 12:45:53 -0400565 scripts="devtool recipetool oe-find-native-sysroot runqemu* wic"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600566 for script in $scripts; do
567 for scriptfn in `find ${SDK_OUTPUT}/${SDKPATH}/${scriptrelpath} -maxdepth 1 -executable -name "$script"`; do
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800568 targetscriptfn="${SDK_OUTPUT}/${SDKPATHNATIVE}${bindir_nativesdk}/$(basename $scriptfn)"
569 test -e ${targetscriptfn} || lnr ${scriptfn} ${targetscriptfn}
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600570 done
571 done
572 # We can't use the same method as above because files in the sysroot won't exist at this point
573 # (they get populated from sstate on installation)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500574 unfsd_path="${SDK_OUTPUT}/${SDKPATHNATIVE}${bindir_nativesdk}/unfsd"
575 if [ "${SDK_INCLUDE_TOOLCHAIN}" = "1" -a ! -e $unfsd_path ] ; then
576 binrelpath=${@os.path.relpath(d.getVar('STAGING_BINDIR_NATIVE'), d.getVar('TMPDIR'))}
577 lnr ${SDK_OUTPUT}/${SDKPATH}/tmp/$binrelpath/unfsd $unfsd_path
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600578 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500579 touch ${SDK_OUTPUT}/${SDKPATH}/.devtoolbase
580
581 # find latest buildtools-tarball and install it
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600582 install ${SDK_DEPLOY}/${SDK_BUILDTOOLS_INSTALLER} ${SDK_OUTPUT}/${SDKPATH}
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500583
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500584 install -m 0644 ${COREBASE}/meta/files/ext-sdk-prepare.py ${SDK_OUTPUT}/${SDKPATH}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500585}
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500586do_populate_sdk_ext[file-checksums] += "${COREBASE}/meta/files/ext-sdk-prepare.py:True"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500587
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500588sdk_ext_preinst() {
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600589 # Since bitbake won't run as root it doesn't make sense to try and install
590 # the extensible sdk as root.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500591 if [ "`id -u`" = "0" ]; then
592 echo "ERROR: The extensible sdk cannot be installed as root."
593 exit 1
594 fi
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600595 if ! command -v locale > /dev/null; then
596 echo "ERROR: The installer requires the locale command, please install it first"
597 exit 1
598 fi
599 # Check setting of LC_ALL set above
600 canonicalised_locale=`echo $LC_ALL | sed 's/UTF-8/utf8/'`
601 if ! locale -a | grep -q $canonicalised_locale ; then
602 echo "ERROR: the installer requires the $LC_ALL locale to be installed (but not selected), please install it first"
603 exit 1
604 fi
605 # The relocation script used by buildtools installer requires python
606 if ! command -v python > /dev/null; then
607 echo "ERROR: The installer requires python, please install it first"
608 exit 1
609 fi
610 missing_utils=""
611 for util in ${SDK_REQUIRED_UTILITIES}; do
612 if ! command -v $util > /dev/null; then
613 missing_utils="$missing_utils $util"
614 fi
615 done
616 if [ -n "$missing_utils" ] ; then
617 echo "ERROR: the SDK requires the following missing utilities, please install them: $missing_utils"
618 exit 1
619 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500620 SDK_EXTENSIBLE="1"
Brad Bishop19323692019-04-05 15:28:33 -0400621 if [ "$publish" = "1" ] && [ "${SDK_EXT_TYPE}" = "minimal" ] ; then
622 EXTRA_TAR_OPTIONS="$EXTRA_TAR_OPTIONS --exclude=sstate-cache"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500623 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500624}
625SDK_PRE_INSTALL_COMMAND_task-populate-sdk-ext = "${sdk_ext_preinst}"
626
627# FIXME this preparation should be done as part of the SDK construction
628sdk_ext_postinst() {
629 printf "\nExtracting buildtools...\n"
630 cd $target_sdk_dir
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600631 env_setup_script="$target_sdk_dir/environment-setup-${REAL_MULTIMACH_TARGET_SYS}"
632 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 -0500633
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500634 # Delete the buildtools tar file since it won't be used again
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600635 rm -f ./${SDK_BUILDTOOLS_INSTALLER}
636 # We don't need the log either since it succeeded
637 rm -f buildtools.log
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500638
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500639 # Make sure when the user sets up the environment, they also get
640 # the buildtools-tarball tools in their path.
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500641 echo ". $target_sdk_dir/buildtools/environment-setup*" >> $env_setup_script
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500642
643 # Allow bitbake environment setup to be ran as part of this sdk.
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500644 echo "export OE_SKIP_SDK_CHECK=1" >> $env_setup_script
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500645 # Work around runqemu not knowing how to get this information within the eSDK
646 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 -0500647
648 # A bit of another hack, but we need this in the path only for devtool
649 # so put it at the end of $PATH.
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500650 echo "export PATH=$target_sdk_dir/sysroots/${SDK_SYS}${bindir_nativesdk}:\$PATH" >> $env_setup_script
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500651
652 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
653
654 # Warn if trying to use external bitbake and the ext SDK together
655 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 -0500656
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500657 if [ "$prepare_buildsystem" != "no" ]; then
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500658 printf "Preparing build system...\n"
659 # dash which is /bin/sh on Ubuntu will not preserve the
660 # current working directory when first ran, nor will it set $1 when
661 # sourcing a script. That is why this has to look so ugly.
662 LOGFILE="$target_sdk_dir/preparing_build_system.log"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600663 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 && python $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 -0400664 fi
665 if [ -e $target_sdk_dir/ext-sdk-prepare.py ]; then
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500666 rm $target_sdk_dir/ext-sdk-prepare.py
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500667 fi
668 echo done
669}
670
671SDK_POST_INSTALL_COMMAND_task-populate-sdk-ext = "${sdk_ext_postinst}"
672
673SDK_POSTPROCESS_COMMAND_prepend_task-populate-sdk-ext = "copy_buildsystem; install_tools; "
674
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500675SDK_INSTALL_TARGETS = ""
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500676fakeroot python do_populate_sdk_ext() {
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500677 # FIXME hopefully we can remove this restriction at some point, but uninative
678 # currently forces this upon us
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500679 if d.getVar('SDK_ARCH') != d.getVar('BUILD_ARCH'):
680 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 -0500681
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500682 d.setVar('SDK_INSTALL_TARGETS', get_sdk_install_targets(d))
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600683 buildtools_fn = get_current_buildtools(d)
684 d.setVar('SDK_REQUIRED_UTILITIES', get_sdk_required_utilities(buildtools_fn, d))
685 d.setVar('SDK_BUILDTOOLS_INSTALLER', buildtools_fn)
686 d.setVar('SDKDEPLOYDIR', '${SDKEXTDEPLOYDIR}')
Brad Bishop00111322018-04-01 22:23:53 -0400687 # ESDKs have a libc from the buildtools so ensure we don't ship linguas twice
688 d.delVar('SDKIMAGE_LINGUAS')
Brad Bishopa34c0302019-09-23 22:34:48 -0400689 if d.getVar("SDK_INCLUDE_NATIVESDK") == '1':
690 generate_nativesdk_lockedsigs(d)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600691 populate_sdk_common(d)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500692}
693
Brad Bishopa34c0302019-09-23 22:34:48 -0400694def generate_nativesdk_lockedsigs(d):
695 import oe.copy_buildsystem
696 sigfile = d.getVar('WORKDIR') + '/locked-sigs_nativesdk.inc'
697 oe.copy_buildsystem.generate_locked_sigs(sigfile, d)
698
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500699def get_ext_sdk_depends(d):
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600700 # Note: the deps varflag is a list not a string, so we need to specify expand=False
701 deps = d.getVarFlag('do_image_complete', 'deps', False)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500702 pn = d.getVar('PN')
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600703 deplist = ['%s:%s' % (pn, dep) for dep in deps]
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500704 tasklist = bb.build.tasksbetween('do_image_complete', 'do_build', d)
705 tasklist.append('do_rootfs')
706 for task in tasklist:
707 deplist.extend((d.getVarFlag(task, 'depends') or '').split())
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600708 return ' '.join(deplist)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500709
710python do_sdk_depends() {
711 # We have to do this separately in its own task so we avoid recursing into
712 # dependencies we don't need to (e.g. buildtools-tarball) and bringing those
713 # into the SDK's sstate-cache
714 import oe.copy_buildsystem
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500715 sigfile = d.getVar('WORKDIR') + '/locked-sigs.inc'
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500716 oe.copy_buildsystem.generate_locked_sigs(sigfile, d)
717}
718addtask sdk_depends
719
720do_sdk_depends[dirs] = "${WORKDIR}"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500721do_sdk_depends[depends] = "${@get_ext_sdk_depends(d)} meta-extsdk-toolchain:do_populate_sysroot"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500722do_sdk_depends[recrdeptask] = "${@d.getVarFlag('do_populate_sdk', 'recrdeptask', False)}"
723do_sdk_depends[recrdeptask] += "do_populate_lic do_package_qa do_populate_sysroot do_deploy ${SDK_RECRDEP_TASKS}"
724do_sdk_depends[rdepends] = "${@get_sdk_ext_rdepends(d)}"
725
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500726def get_sdk_ext_rdepends(d):
727 localdata = d.createCopy()
728 localdata.appendVar('OVERRIDES', ':task-populate-sdk-ext')
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500729 return localdata.getVarFlag('do_populate_sdk', 'rdepends')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500730
731do_populate_sdk_ext[dirs] = "${@d.getVarFlag('do_populate_sdk', 'dirs', False)}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500732
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500733do_populate_sdk_ext[depends] = "${@d.getVarFlag('do_populate_sdk', 'depends', False)} \
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500734 buildtools-tarball:do_populate_sdk \
735 ${@'meta-world-pkgdata:do_collect_packagedata' if d.getVar('SDK_INCLUDE_PKGDATA') == '1' else ''} \
736 ${@'meta-extsdk-toolchain:do_locked_sigs' if d.getVar('SDK_INCLUDE_TOOLCHAIN') == '1' else ''}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500737
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500738# We must avoid depending on do_build here if rm_work.bbclass is active,
739# because otherwise do_rm_work may run before do_populate_sdk_ext itself.
740# We can't mark do_populate_sdk_ext and do_sdk_depends as having to
741# run before do_rm_work, because then they would also run as part
742# of normal builds.
743do_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 -0500744
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500745# Make sure code changes can result in rebuild
746do_populate_sdk_ext[vardeps] += "copy_buildsystem \
747 sdk_ext_postinst"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500748
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500749# Since any change in the metadata of any layer should cause a rebuild of the
750# sdk(since the layers are put in the sdk) set the task to nostamp so it
751# always runs.
752do_populate_sdk_ext[nostamp] = "1"
753
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600754SDKEXTDEPLOYDIR = "${WORKDIR}/deploy-${PN}-populate-sdk-ext"
755
756SSTATETASKS += "do_populate_sdk_ext"
757SSTATE_SKIP_CREATION_task-populate-sdk-ext = '1'
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500758do_populate_sdk_ext[cleandirs] = "${SDKEXTDEPLOYDIR}"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600759do_populate_sdk_ext[sstate-inputdirs] = "${SDKEXTDEPLOYDIR}"
760do_populate_sdk_ext[sstate-outputdirs] = "${SDK_DEPLOY}"
Brad Bishop316dfdd2018-06-25 12:45:53 -0400761do_populate_sdk_ext[stamp-extra-info] = "${MACHINE_ARCH}"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600762
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500763addtask populate_sdk_ext after do_sdk_depends