blob: 64a4a58beff66e189a2074dc4e0b34d6bc7d3810 [file] [log] [blame]
Patrick Williams92b42cb2022-09-03 06:53:57 -05001#
2# Copyright OpenEmbedded Contributors
3#
4# SPDX-License-Identifier: MIT
5#
6
7PACKAGES = ""
8
9inherit image-postinst-intercepts image-artifact-names
10
11# Wildcards specifying complementary packages to install for every package that has been explicitly
12# installed into the rootfs
13COMPLEMENTARY_GLOB[dev-pkgs] = '*-dev'
14COMPLEMENTARY_GLOB[staticdev-pkgs] = '*-staticdev'
15COMPLEMENTARY_GLOB[doc-pkgs] = '*-doc'
16COMPLEMENTARY_GLOB[dbg-pkgs] = '*-dbg'
17COMPLEMENTARY_GLOB[src-pkgs] = '*-src'
Patrick Williams2390b1b2022-11-03 13:47:49 -050018COMPLEMENTARY_GLOB[ptest-pkgs] = '*-ptest ptest-runner'
Patrick Williams92b42cb2022-09-03 06:53:57 -050019COMPLEMENTARY_GLOB[bash-completion-pkgs] = '*-bash-completion'
20
21def complementary_globs(featurevar, d):
22 all_globs = d.getVarFlags('COMPLEMENTARY_GLOB')
23 globs = []
24 features = set((d.getVar(featurevar) or '').split())
25 for name, glob in all_globs.items():
26 if name in features:
27 globs.append(glob)
28 return ' '.join(globs)
29
30SDKIMAGE_FEATURES ??= "dev-pkgs dbg-pkgs src-pkgs ${@bb.utils.contains('DISTRO_FEATURES', 'api-documentation', 'doc-pkgs', '', d)}"
31SDKIMAGE_INSTALL_COMPLEMENTARY = '${@complementary_globs("SDKIMAGE_FEATURES", d)}'
32SDKIMAGE_INSTALL_COMPLEMENTARY[vardeps] += "SDKIMAGE_FEATURES"
33
34PACKAGE_ARCHS:append:task-populate-sdk = " sdk-provides-dummy-target"
35SDK_PACKAGE_ARCHS += "sdk-provides-dummy-${SDKPKGSUFFIX}"
36
37# List of locales to install, or "all" for all of them, or unset for none.
38SDKIMAGE_LINGUAS ?= "all"
39
40inherit rootfs_${IMAGE_PKGTYPE}
41
42SDK_DIR = "${WORKDIR}/sdk"
43SDK_OUTPUT = "${SDK_DIR}/image"
44SDK_DEPLOY = "${DEPLOY_DIR}/sdk"
45
46SDKDEPLOYDIR = "${WORKDIR}/${SDKMACHINE}-deploy-${PN}-populate-sdk"
47
48B:task-populate-sdk = "${SDK_DIR}"
49
50SDKTARGETSYSROOT = "${SDKPATH}/sysroots/${REAL_MULTIMACH_TARGET_SYS}"
51
52SDK_TOOLCHAIN_LANGS ??= ""
53SDK_TOOLCHAIN_LANGS:remove:sdkmingw32 = "rust"
54# libstd-rs doesn't build for mips n32 with compiler constraint errors
55SDK_TOOLCHAIN_LANGS:remove:mipsarchn32 = "rust"
56
57TOOLCHAIN_HOST_TASK ?= " \
58 nativesdk-packagegroup-sdk-host \
59 packagegroup-cross-canadian-${MACHINE} \
60 ${@bb.utils.contains('SDK_TOOLCHAIN_LANGS', 'go', 'packagegroup-go-cross-canadian-${MACHINE}', '', d)} \
61 ${@bb.utils.contains('SDK_TOOLCHAIN_LANGS', 'rust', 'packagegroup-rust-cross-canadian-${MACHINE}', '', d)} \
62"
63TOOLCHAIN_HOST_TASK_ATTEMPTONLY ?= ""
64TOOLCHAIN_TARGET_TASK ?= " \
65 ${@multilib_pkg_extend(d, 'packagegroup-core-standalone-sdk-target')} \
66 ${@bb.utils.contains('SDK_TOOLCHAIN_LANGS', 'go', multilib_pkg_extend(d, 'packagegroup-go-sdk-target'), '', d)} \
67 ${@bb.utils.contains('SDK_TOOLCHAIN_LANGS', 'rust', multilib_pkg_extend(d, 'libstd-rs'), '', d)} \
68 target-sdk-provides-dummy \
69"
70TOOLCHAIN_TARGET_TASK_ATTEMPTONLY ?= ""
71TOOLCHAIN_OUTPUTNAME ?= "${SDK_NAME}-toolchain-${SDK_VERSION}"
72
73# Default archived SDK's suffix
74SDK_ARCHIVE_TYPE ?= "tar.xz"
75SDK_XZ_COMPRESSION_LEVEL ?= "-9"
76SDK_XZ_OPTIONS ?= "${XZ_DEFAULTS} ${SDK_XZ_COMPRESSION_LEVEL}"
77
78# To support different sdk type according to SDK_ARCHIVE_TYPE, now support zip and tar.xz
79python () {
80 if d.getVar('SDK_ARCHIVE_TYPE') == 'zip':
81 d.setVar('SDK_ARCHIVE_DEPENDS', 'zip-native')
82 # SDK_ARCHIVE_CMD used to generate archived sdk ${TOOLCHAIN_OUTPUTNAME}.${SDK_ARCHIVE_TYPE} from input dir ${SDK_OUTPUT}/${SDKPATH} to output dir ${SDKDEPLOYDIR}
83 # recommand to cd into input dir first to avoid archive with buildpath
84 d.setVar('SDK_ARCHIVE_CMD', 'cd ${SDK_OUTPUT}/${SDKPATH}; zip -r -y ${SDKDEPLOYDIR}/${TOOLCHAIN_OUTPUTNAME}.${SDK_ARCHIVE_TYPE} .')
85 else:
86 d.setVar('SDK_ARCHIVE_DEPENDS', 'xz-native')
87 d.setVar('SDK_ARCHIVE_CMD', 'cd ${SDK_OUTPUT}/${SDKPATH}; tar ${SDKTAROPTS} -cf - . | xz ${SDK_XZ_OPTIONS} > ${SDKDEPLOYDIR}/${TOOLCHAIN_OUTPUTNAME}.${SDK_ARCHIVE_TYPE}')
88}
89
90SDK_RDEPENDS = "${TOOLCHAIN_TARGET_TASK} ${TOOLCHAIN_HOST_TASK}"
91SDK_DEPENDS = "virtual/fakeroot-native ${SDK_ARCHIVE_DEPENDS} cross-localedef-native nativesdk-qemuwrapper-cross ${@' '.join(["%s-qemuwrapper-cross" % m for m in d.getVar("MULTILIB_VARIANTS").split()])} qemuwrapper-cross"
92PATH:prepend = "${WORKDIR}/recipe-sysroot/${SDKPATHNATIVE}${bindir}/crossscripts:${@":".join(all_multilib_tune_values(d, 'STAGING_BINDIR_CROSS').split())}:"
93SDK_DEPENDS += "nativesdk-glibc-locale"
94
95# We want the MULTIARCH_TARGET_SYS to point to the TUNE_PKGARCH, not PACKAGE_ARCH as it
96# could be set to the MACHINE_ARCH
97REAL_MULTIMACH_TARGET_SYS = "${TUNE_PKGARCH}${TARGET_VENDOR}-${TARGET_OS}"
98
99PID = "${@os.getpid()}"
100
101EXCLUDE_FROM_WORLD = "1"
102
103SDK_PACKAGING_FUNC ?= "create_shar"
104SDK_PRE_INSTALL_COMMAND ?= ""
105SDK_POST_INSTALL_COMMAND ?= ""
106SDK_RELOCATE_AFTER_INSTALL ?= "1"
107
108SDKEXTPATH ??= "~/${@d.getVar('DISTRO')}_sdk"
109SDK_TITLE ??= "${@d.getVar('DISTRO_NAME') or d.getVar('DISTRO')} SDK"
110
111SDK_TARGET_MANIFEST = "${SDKDEPLOYDIR}/${TOOLCHAIN_OUTPUTNAME}.target.manifest"
112SDK_HOST_MANIFEST = "${SDKDEPLOYDIR}/${TOOLCHAIN_OUTPUTNAME}.host.manifest"
113SDK_EXT_TARGET_MANIFEST = "${SDK_DEPLOY}/${TOOLCHAINEXT_OUTPUTNAME}.target.manifest"
114SDK_EXT_HOST_MANIFEST = "${SDK_DEPLOY}/${TOOLCHAINEXT_OUTPUTNAME}.host.manifest"
115
116SDK_PRUNE_SYSROOT_DIRS ?= "/dev"
117
118python write_target_sdk_manifest () {
119 from oe.sdk import sdk_list_installed_packages
120 from oe.utils import format_pkg_list
121 sdkmanifestdir = os.path.dirname(d.getVar("SDK_TARGET_MANIFEST"))
122 pkgs = sdk_list_installed_packages(d, True)
123 if not os.path.exists(sdkmanifestdir):
124 bb.utils.mkdirhier(sdkmanifestdir)
125 with open(d.getVar('SDK_TARGET_MANIFEST'), 'w') as output:
126 output.write(format_pkg_list(pkgs, 'ver'))
127}
128
129sdk_prune_dirs () {
130 for d in ${SDK_PRUNE_SYSROOT_DIRS}; do
131 rm -rf ${SDK_OUTPUT}${SDKTARGETSYSROOT}$d
132 done
133}
134
135python write_sdk_test_data() {
136 from oe.data import export2json
137 testdata = "%s/%s.testdata.json" % (d.getVar('SDKDEPLOYDIR'), d.getVar('TOOLCHAIN_OUTPUTNAME'))
138 bb.utils.mkdirhier(os.path.dirname(testdata))
139 export2json(d, testdata)
140}
141
142python write_host_sdk_manifest () {
143 from oe.sdk import sdk_list_installed_packages
144 from oe.utils import format_pkg_list
145 sdkmanifestdir = os.path.dirname(d.getVar("SDK_HOST_MANIFEST"))
146 pkgs = sdk_list_installed_packages(d, False)
147 if not os.path.exists(sdkmanifestdir):
148 bb.utils.mkdirhier(sdkmanifestdir)
149 with open(d.getVar('SDK_HOST_MANIFEST'), 'w') as output:
150 output.write(format_pkg_list(pkgs, 'ver'))
151}
152
153POPULATE_SDK_POST_TARGET_COMMAND:append = " write_sdk_test_data ; "
154POPULATE_SDK_POST_TARGET_COMMAND:append:task-populate-sdk = " write_target_sdk_manifest; sdk_prune_dirs; "
155POPULATE_SDK_POST_HOST_COMMAND:append:task-populate-sdk = " write_host_sdk_manifest; "
156
157SDK_PACKAGING_COMMAND = "${@'${SDK_PACKAGING_FUNC};' if '${SDK_PACKAGING_FUNC}' else ''}"
158SDK_POSTPROCESS_COMMAND = " create_sdk_files; check_sdk_sysroots; archive_sdk; ${SDK_PACKAGING_COMMAND} "
159
160def populate_sdk_common(d):
161 from oe.sdk import populate_sdk
162 from oe.manifest import create_manifest, Manifest
163
164 # Handle package exclusions
165 excl_pkgs = (d.getVar("PACKAGE_EXCLUDE") or "").split()
166 inst_pkgs = (d.getVar("PACKAGE_INSTALL") or "").split()
167 inst_attempt_pkgs = (d.getVar("PACKAGE_INSTALL_ATTEMPTONLY") or "").split()
168
169 d.setVar('PACKAGE_INSTALL_ORIG', ' '.join(inst_pkgs))
170 d.setVar('PACKAGE_INSTALL_ATTEMPTONLY', ' '.join(inst_attempt_pkgs))
171
172 for pkg in excl_pkgs:
173 if pkg in inst_pkgs:
174 bb.warn("Package %s, set to be excluded, is in %s PACKAGE_INSTALL (%s). It will be removed from the list." % (pkg, d.getVar('PN'), inst_pkgs))
175 inst_pkgs.remove(pkg)
176
177 if pkg in inst_attempt_pkgs:
178 bb.warn("Package %s, set to be excluded, is in %s PACKAGE_INSTALL_ATTEMPTONLY (%s). It will be removed from the list." % (pkg, d.getVar('PN'), inst_pkgs))
179 inst_attempt_pkgs.remove(pkg)
180
181 d.setVar("PACKAGE_INSTALL", ' '.join(inst_pkgs))
182 d.setVar("PACKAGE_INSTALL_ATTEMPTONLY", ' '.join(inst_attempt_pkgs))
183
184 pn = d.getVar('PN')
185 runtime_mapping_rename("TOOLCHAIN_TARGET_TASK", pn, d)
186 runtime_mapping_rename("TOOLCHAIN_TARGET_TASK_ATTEMPTONLY", pn, d)
187
188 ld = bb.data.createCopy(d)
189 ld.setVar("PKGDATA_DIR", "${STAGING_DIR}/${SDK_ARCH}-${SDKPKGSUFFIX}${SDK_VENDOR}-${SDK_OS}/pkgdata")
190 runtime_mapping_rename("TOOLCHAIN_HOST_TASK", pn, ld)
191 runtime_mapping_rename("TOOLCHAIN_HOST_TASK_ATTEMPTONLY", pn, ld)
192 d.setVar("TOOLCHAIN_HOST_TASK", ld.getVar("TOOLCHAIN_HOST_TASK"))
193 d.setVar("TOOLCHAIN_HOST_TASK_ATTEMPTONLY", ld.getVar("TOOLCHAIN_HOST_TASK_ATTEMPTONLY"))
194
195 # create target/host SDK manifests
196 create_manifest(d, manifest_dir=d.getVar('SDK_DIR'),
197 manifest_type=Manifest.MANIFEST_TYPE_SDK_HOST)
198 create_manifest(d, manifest_dir=d.getVar('SDK_DIR'),
199 manifest_type=Manifest.MANIFEST_TYPE_SDK_TARGET)
200
201 populate_sdk(d)
202
203fakeroot python do_populate_sdk() {
204 populate_sdk_common(d)
205}
206SSTATETASKS += "do_populate_sdk"
207SSTATE_SKIP_CREATION:task-populate-sdk = '1'
208do_populate_sdk[cleandirs] = "${SDKDEPLOYDIR}"
209do_populate_sdk[sstate-inputdirs] = "${SDKDEPLOYDIR}"
210do_populate_sdk[sstate-outputdirs] = "${SDK_DEPLOY}"
211do_populate_sdk[stamp-extra-info] = "${MACHINE_ARCH}${SDKMACHINE}"
212python do_populate_sdk_setscene () {
213 sstate_setscene(d)
214}
215addtask do_populate_sdk_setscene
216
217PSEUDO_IGNORE_PATHS .= ",${SDKDEPLOYDIR},${WORKDIR}/oe-sdk-repo,${WORKDIR}/sstate-build-populate_sdk"
218
219fakeroot create_sdk_files() {
220 cp ${COREBASE}/scripts/relocate_sdk.py ${SDK_OUTPUT}/${SDKPATH}/
221
222 # Replace the ##DEFAULT_INSTALL_DIR## with the correct pattern.
223 # Escape special characters like '+' and '.' in the SDKPATH
224 escaped_sdkpath=$(echo ${SDKPATH} |sed -e "s:[\+\.]:\\\\\\\\\0:g")
225 sed -i -e "s:##DEFAULT_INSTALL_DIR##:$escaped_sdkpath:" ${SDK_OUTPUT}/${SDKPATH}/relocate_sdk.py
226
227 mkdir -p ${SDK_OUTPUT}/${SDKPATHNATIVE}${sysconfdir}/
228 echo '${SDKPATHNATIVE}${libdir_nativesdk}
229${SDKPATHNATIVE}${base_libdir_nativesdk}
230include /etc/ld.so.conf' > ${SDK_OUTPUT}/${SDKPATHNATIVE}${sysconfdir}/ld.so.conf
231}
232
233python check_sdk_sysroots() {
234 # Fails build if there are broken or dangling symlinks in SDK sysroots
235
236 if d.getVar('CHECK_SDK_SYSROOTS') != '1':
237 # disabled, bail out
238 return
239
240 def norm_path(path):
241 return os.path.abspath(path)
242
243 # Get scan root
244 SCAN_ROOT = norm_path("%s/%s/sysroots/" % (d.getVar('SDK_OUTPUT'),
245 d.getVar('SDKPATH')))
246
247 bb.note('Checking SDK sysroots at ' + SCAN_ROOT)
248
249 def check_symlink(linkPath):
250 if not os.path.islink(linkPath):
251 return
252
253 linkDirPath = os.path.dirname(linkPath)
254
255 targetPath = os.readlink(linkPath)
256 if not os.path.isabs(targetPath):
257 targetPath = os.path.join(linkDirPath, targetPath)
258 targetPath = norm_path(targetPath)
259
260 if SCAN_ROOT != os.path.commonprefix( [SCAN_ROOT, targetPath] ):
261 bb.error("Escaping symlink {0!s} --> {1!s}".format(linkPath, targetPath))
262 return
263
264 if not os.path.exists(targetPath):
265 bb.error("Broken symlink {0!s} --> {1!s}".format(linkPath, targetPath))
266 return
267
268 if os.path.isdir(targetPath):
269 dir_walk(targetPath)
270
271 def walk_error_handler(e):
272 bb.error(str(e))
273
274 def dir_walk(rootDir):
275 for dirPath,subDirEntries,fileEntries in os.walk(rootDir, followlinks=False, onerror=walk_error_handler):
276 entries = subDirEntries + fileEntries
277 for e in entries:
278 ePath = os.path.join(dirPath, e)
279 check_symlink(ePath)
280
281 # start
282 dir_walk(SCAN_ROOT)
283}
284
285SDKTAROPTS = "--owner=root --group=root"
286
287fakeroot archive_sdk() {
288 # Package it up
289 mkdir -p ${SDKDEPLOYDIR}
290 ${SDK_ARCHIVE_CMD}
291}
292
293TOOLCHAIN_SHAR_EXT_TMPL ?= "${COREBASE}/meta/files/toolchain-shar-extract.sh"
294TOOLCHAIN_SHAR_REL_TMPL ?= "${COREBASE}/meta/files/toolchain-shar-relocate.sh"
295
296fakeroot create_shar() {
297 # copy in the template shar extractor script
298 cp ${TOOLCHAIN_SHAR_EXT_TMPL} ${SDKDEPLOYDIR}/${TOOLCHAIN_OUTPUTNAME}.sh
299
300 rm -f ${T}/pre_install_command ${T}/post_install_command
301
302 if [ "${SDK_RELOCATE_AFTER_INSTALL}" = "1" ] ; then
303 cp ${TOOLCHAIN_SHAR_REL_TMPL} ${T}/post_install_command
304 fi
305 cat << "EOF" >> ${T}/pre_install_command
306${SDK_PRE_INSTALL_COMMAND}
307EOF
308
309 cat << "EOF" >> ${T}/post_install_command
310${SDK_POST_INSTALL_COMMAND}
311EOF
312 sed -i -e '/@SDK_PRE_INSTALL_COMMAND@/r ${T}/pre_install_command' \
313 -e '/@SDK_POST_INSTALL_COMMAND@/r ${T}/post_install_command' \
314 ${SDKDEPLOYDIR}/${TOOLCHAIN_OUTPUTNAME}.sh
315
316 # substitute variables
317 sed -i -e 's#@SDK_ARCH@#${SDK_ARCH}#g' \
318 -e 's#@SDKPATH@#${SDKPATH}#g' \
319 -e 's#@SDKPATHINSTALL@#${SDKPATHINSTALL}#g' \
320 -e 's#@SDKEXTPATH@#${SDKEXTPATH}#g' \
321 -e 's#@OLDEST_KERNEL@#${SDK_OLDEST_KERNEL}#g' \
322 -e 's#@REAL_MULTIMACH_TARGET_SYS@#${REAL_MULTIMACH_TARGET_SYS}#g' \
323 -e 's#@SDK_TITLE@#${@d.getVar("SDK_TITLE").replace('&', '\\&')}#g' \
324 -e 's#@SDK_VERSION@#${SDK_VERSION}#g' \
325 -e '/@SDK_PRE_INSTALL_COMMAND@/d' \
326 -e '/@SDK_POST_INSTALL_COMMAND@/d' \
327 -e 's#@SDK_GCC_VER@#${@oe.utils.host_gcc_version(d, taskcontextonly=True)}#g' \
328 -e 's#@SDK_ARCHIVE_TYPE@#${SDK_ARCHIVE_TYPE}#g' \
329 ${SDKDEPLOYDIR}/${TOOLCHAIN_OUTPUTNAME}.sh
330
331 # add execution permission
332 chmod +x ${SDKDEPLOYDIR}/${TOOLCHAIN_OUTPUTNAME}.sh
333
334 # append the SDK tarball
335 cat ${SDKDEPLOYDIR}/${TOOLCHAIN_OUTPUTNAME}.${SDK_ARCHIVE_TYPE} >> ${SDKDEPLOYDIR}/${TOOLCHAIN_OUTPUTNAME}.sh
336
337 # delete the old tarball, we don't need it anymore
338 rm ${SDKDEPLOYDIR}/${TOOLCHAIN_OUTPUTNAME}.${SDK_ARCHIVE_TYPE}
339}
340
341populate_sdk_log_check() {
342 for target in $*
343 do
344 lf_path="`dirname ${BB_LOGFILE}`/log.do_$target.${PID}"
345
346 echo "log_check: Using $lf_path as logfile"
347
348 if [ -e "$lf_path" ]; then
349 ${IMAGE_PKGTYPE}_log_check $target $lf_path
350 else
351 echo "Cannot find logfile [$lf_path]"
352 fi
353 echo "Logfile is clean"
354 done
355}
356
357def sdk_command_variables(d):
358 return ['OPKG_PREPROCESS_COMMANDS','OPKG_POSTPROCESS_COMMANDS','POPULATE_SDK_POST_HOST_COMMAND','POPULATE_SDK_PRE_TARGET_COMMAND','POPULATE_SDK_POST_TARGET_COMMAND','SDK_POSTPROCESS_COMMAND','RPM_PREPROCESS_COMMANDS','RPM_POSTPROCESS_COMMANDS']
359
360def sdk_variables(d):
361 variables = ['BUILD_IMAGES_FROM_FEEDS','SDK_OS','SDK_OUTPUT','SDKPATHNATIVE','SDKTARGETSYSROOT','SDK_DIR','SDK_VENDOR','SDKIMAGE_INSTALL_COMPLEMENTARY','SDK_PACKAGE_ARCHS','SDK_OUTPUT',
362 'SDKTARGETSYSROOT','MULTILIB_VARIANTS','MULTILIBS','ALL_MULTILIB_PACKAGE_ARCHS','MULTILIB_GLOBAL_VARIANTS','BAD_RECOMMENDATIONS','NO_RECOMMENDATIONS','PACKAGE_ARCHS',
363 'PACKAGE_CLASSES','TARGET_VENDOR','TARGET_VENDOR','TARGET_ARCH','TARGET_OS','BBEXTENDVARIANT','FEED_DEPLOYDIR_BASE_URI', 'PACKAGE_EXCLUDE_COMPLEMENTARY', 'IMAGE_INSTALL_DEBUGFS']
364 variables.extend(sdk_command_variables(d))
365 return " ".join(variables)
366
367do_populate_sdk[vardeps] += "${@sdk_variables(d)}"
368
369python () {
370 variables = sdk_command_variables(d)
371 for var in variables:
372 if d.getVar(var, False):
373 d.setVarFlag(var, 'func', '1')
374}
375
376do_populate_sdk[file-checksums] += "${TOOLCHAIN_SHAR_REL_TMPL}:True \
377 ${TOOLCHAIN_SHAR_EXT_TMPL}:True"
378
379do_populate_sdk[dirs] = "${PKGDATA_DIR} ${TOPDIR}"
380do_populate_sdk[depends] += "${@' '.join([x + ':do_populate_sysroot' for x in d.getVar('SDK_DEPENDS').split()])} ${@d.getVarFlag('do_rootfs', 'depends', False)}"
381do_populate_sdk[rdepends] = "${@' '.join([x + ':do_package_write_${IMAGE_PKGTYPE} ' + x + ':do_packagedata' for x in d.getVar('SDK_RDEPENDS').split()])}"
382do_populate_sdk[recrdeptask] += "do_packagedata do_package_write_rpm do_package_write_ipk do_package_write_deb"
383do_populate_sdk[file-checksums] += "${POSTINST_INTERCEPT_CHECKSUMS}"
384addtask populate_sdk