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