blob: 008bb577c4d66499bf473840ac994bc0381680a0 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001inherit meta
2
3# Wildcards specifying complementary packages to install for every package that has been explicitly
4# installed into the rootfs
5COMPLEMENTARY_GLOB[dev-pkgs] = '*-dev'
6COMPLEMENTARY_GLOB[staticdev-pkgs] = '*-staticdev'
7COMPLEMENTARY_GLOB[doc-pkgs] = '*-doc'
8COMPLEMENTARY_GLOB[dbg-pkgs] = '*-dbg'
9COMPLEMENTARY_GLOB[ptest-pkgs] = '*-ptest'
10
11def complementary_globs(featurevar, d):
12 all_globs = d.getVarFlags('COMPLEMENTARY_GLOB')
13 globs = []
14 features = set((d.getVar(featurevar, True) or '').split())
15 for name, glob in all_globs.items():
16 if name in features:
17 globs.append(glob)
18 return ' '.join(globs)
19
20SDKIMAGE_FEATURES ??= "dev-pkgs dbg-pkgs"
21SDKIMAGE_INSTALL_COMPLEMENTARY = '${@complementary_globs("SDKIMAGE_FEATURES", d)}'
22
23inherit rootfs_${IMAGE_PKGTYPE}
24
25SDK_DIR = "${WORKDIR}/sdk"
26SDK_OUTPUT = "${SDK_DIR}/image"
27SDK_DEPLOY = "${DEPLOY_DIR}/sdk"
28
29B_task-populate-sdk = "${SDK_DIR}"
30
31SDKTARGETSYSROOT = "${SDKPATH}/sysroots/${REAL_MULTIMACH_TARGET_SYS}"
32
33TOOLCHAIN_HOST_TASK ?= "nativesdk-packagegroup-sdk-host packagegroup-cross-canadian-${MACHINE}"
34TOOLCHAIN_HOST_TASK_ATTEMPTONLY ?= ""
35TOOLCHAIN_TARGET_TASK ?= " \
36 ${@multilib_pkg_extend(d, 'packagegroup-core-standalone-sdk-target')} \
37 ${@multilib_pkg_extend(d, 'packagegroup-core-standalone-sdk-target-dbg')} \
38 "
39TOOLCHAIN_TARGET_TASK_ATTEMPTONLY ?= ""
40TOOLCHAIN_OUTPUTNAME ?= "${SDK_NAME}-toolchain-${SDK_VERSION}"
41
42SDK_RDEPENDS = "${TOOLCHAIN_TARGET_TASK} ${TOOLCHAIN_HOST_TASK}"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050043SDK_DEPENDS = "virtual/fakeroot-native pixz-native"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050044
45# We want the MULTIARCH_TARGET_SYS to point to the TUNE_PKGARCH, not PACKAGE_ARCH as it
46# could be set to the MACHINE_ARCH
47REAL_MULTIMACH_TARGET_SYS = "${TUNE_PKGARCH}${TARGET_VENDOR}-${TARGET_OS}"
48
49PID = "${@os.getpid()}"
50
51EXCLUDE_FROM_WORLD = "1"
52
53SDK_PACKAGING_FUNC ?= "create_shar"
54SDK_PRE_INSTALL_COMMAND ?= ""
55SDK_POST_INSTALL_COMMAND ?= ""
56SDK_RELOCATE_AFTER_INSTALL ?= "1"
57
58SDKEXTPATH ?= "~/${@d.getVar('DISTRO', True)}_sdk"
59SDK_TITLE ?= "${@d.getVar('DISTRO_NAME', True) or d.getVar('DISTRO', True)} SDK"
60
61SDK_TARGET_MANIFEST = "${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.target.manifest"
62SDK_HOST_MANIFEST = "${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.host.manifest"
63python write_target_sdk_manifest () {
64 from oe.sdk import sdk_list_installed_packages
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050065 from oe.utils import format_pkg_list
Patrick Williamsc124f4f2015-09-15 14:41:29 -050066 sdkmanifestdir = os.path.dirname(d.getVar("SDK_TARGET_MANIFEST", True))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050067 pkgs = sdk_list_installed_packages(d, True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050068 if not os.path.exists(sdkmanifestdir):
69 bb.utils.mkdirhier(sdkmanifestdir)
70 with open(d.getVar('SDK_TARGET_MANIFEST', True), 'w') as output:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050071 output.write(format_pkg_list(pkgs, 'ver'))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050072}
73
74python write_host_sdk_manifest () {
75 from oe.sdk import sdk_list_installed_packages
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050076 from oe.utils import format_pkg_list
Patrick Williamsc124f4f2015-09-15 14:41:29 -050077 sdkmanifestdir = os.path.dirname(d.getVar("SDK_HOST_MANIFEST", True))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050078 pkgs = sdk_list_installed_packages(d, False)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050079 if not os.path.exists(sdkmanifestdir):
80 bb.utils.mkdirhier(sdkmanifestdir)
81 with open(d.getVar('SDK_HOST_MANIFEST', True), 'w') as output:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050082 output.write(format_pkg_list(pkgs, 'ver'))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050083}
84
85POPULATE_SDK_POST_TARGET_COMMAND_append = " write_target_sdk_manifest ; "
86POPULATE_SDK_POST_HOST_COMMAND_append = " write_host_sdk_manifest; "
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050087SDK_PACKAGING_COMMAND = "${@'${SDK_PACKAGING_FUNC};' if '${SDK_PACKAGING_FUNC}' else ''}"
88SDK_POSTPROCESS_COMMAND = " create_sdk_files; check_sdk_sysroots; tar_sdk; ${SDK_PACKAGING_COMMAND} "
Patrick Williamsc124f4f2015-09-15 14:41:29 -050089
90# Some archs override this, we need the nativesdk version
91# turns out this is hard to get from the datastore due to TRANSLATED_TARGET_ARCH
92# manipulation.
93SDK_OLDEST_KERNEL = "2.6.32"
94
95fakeroot python do_populate_sdk() {
96 from oe.sdk import populate_sdk
97 from oe.manifest import create_manifest, Manifest
98
99 pn = d.getVar('PN', True)
100 runtime_mapping_rename("TOOLCHAIN_TARGET_TASK", pn, d)
101 runtime_mapping_rename("TOOLCHAIN_TARGET_TASK_ATTEMPTONLY", pn, d)
102
103 ld = bb.data.createCopy(d)
104 ld.setVar("PKGDATA_DIR", "${STAGING_DIR}/${SDK_ARCH}-${SDKPKGSUFFIX}${SDK_VENDOR}-${SDK_OS}/pkgdata")
105 runtime_mapping_rename("TOOLCHAIN_HOST_TASK", pn, ld)
106 runtime_mapping_rename("TOOLCHAIN_HOST_TASK_ATTEMPTONLY", pn, ld)
107 d.setVar("TOOLCHAIN_HOST_TASK", ld.getVar("TOOLCHAIN_HOST_TASK", True))
108 d.setVar("TOOLCHAIN_HOST_TASK_ATTEMPTONLY", ld.getVar("TOOLCHAIN_HOST_TASK_ATTEMPTONLY", True))
109
110 # create target/host SDK manifests
111 create_manifest(d, manifest_dir=d.getVar('SDK_DIR', True),
112 manifest_type=Manifest.MANIFEST_TYPE_SDK_HOST)
113 create_manifest(d, manifest_dir=d.getVar('SDK_DIR', True),
114 manifest_type=Manifest.MANIFEST_TYPE_SDK_TARGET)
115
116 populate_sdk(d)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500117}
118
119fakeroot create_sdk_files() {
120 cp ${COREBASE}/scripts/relocate_sdk.py ${SDK_OUTPUT}/${SDKPATH}/
121
122 # Replace the ##DEFAULT_INSTALL_DIR## with the correct pattern.
123 # Escape special characters like '+' and '.' in the SDKPATH
124 escaped_sdkpath=$(echo ${SDKPATH} |sed -e "s:[\+\.]:\\\\\\\\\0:g")
125 sed -i -e "s:##DEFAULT_INSTALL_DIR##:$escaped_sdkpath:" ${SDK_OUTPUT}/${SDKPATH}/relocate_sdk.py
126}
127
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500128python check_sdk_sysroots() {
129 # Fails build if there are broken or dangling symlinks in SDK sysroots
130
131 if d.getVar('CHECK_SDK_SYSROOTS', True) != '1':
132 # disabled, bail out
133 return
134
135 def norm_path(path):
136 return os.path.abspath(path)
137
138 # Get scan root
139 SCAN_ROOT = norm_path("${SDK_OUTPUT}/${SDKPATH}/sysroots/")
140
141 bb.note('Checking SDK sysroots at ' + SCAN_ROOT)
142
143 def check_symlink(linkPath):
144 if not os.path.islink(linkPath):
145 return
146
147 linkDirPath = os.path.dirname(linkPath)
148
149 targetPath = os.readlink(linkPath)
150 if not os.path.isabs(targetPath):
151 targetPath = os.path.join(linkDirPath, targetPath)
152 targetPath = norm_path(targetPath)
153
154 if SCAN_ROOT != os.path.commonprefix( [SCAN_ROOT, targetPath] ):
155 bb.error("Escaping symlink {0!s} --> {1!s}".format(linkPath, targetPath))
156 return
157
158 if not os.path.exists(targetPath):
159 bb.error("Broken symlink {0!s} --> {1!s}".format(linkPath, targetPath))
160 return
161
162 if os.path.isdir(targetPath):
163 dir_walk(targetPath)
164
165 def walk_error_handler(e):
166 bb.error(str(e))
167
168 def dir_walk(rootDir):
169 for dirPath,subDirEntries,fileEntries in os.walk(rootDir, followlinks=False, onerror=walk_error_handler):
170 entries = subDirEntries + fileEntries
171 for e in entries:
172 ePath = os.path.join(dirPath, e)
173 check_symlink(ePath)
174
175 # start
176 dir_walk(SCAN_ROOT)
177}
178
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500179SDKTAROPTS = "--owner=root --group=root"
180
181fakeroot tar_sdk() {
182 # Package it up
183 mkdir -p ${SDK_DEPLOY}
184 cd ${SDK_OUTPUT}/${SDKPATH}
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500185 tar ${SDKTAROPTS} -cf - . | pixz > ${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.tar.xz
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500186}
187
188fakeroot create_shar() {
189 # copy in the template shar extractor script
190 cp ${COREBASE}/meta/files/toolchain-shar-extract.sh ${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.sh
191
192 rm -f ${T}/pre_install_command ${T}/post_install_command
193
194 if [ ${SDK_RELOCATE_AFTER_INSTALL} -eq 1 ] ; then
195 cp ${COREBASE}/meta/files/toolchain-shar-relocate.sh ${T}/post_install_command
196 fi
197 cat << "EOF" >> ${T}/pre_install_command
198${SDK_PRE_INSTALL_COMMAND}
199EOF
200
201 cat << "EOF" >> ${T}/post_install_command
202${SDK_POST_INSTALL_COMMAND}
203EOF
204 sed -i -e '/@SDK_PRE_INSTALL_COMMAND@/r ${T}/pre_install_command' \
205 -e '/@SDK_POST_INSTALL_COMMAND@/r ${T}/post_install_command' \
206 ${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.sh
207
208 # substitute variables
209 sed -i -e 's#@SDK_ARCH@#${SDK_ARCH}#g' \
210 -e 's#@SDKPATH@#${SDKPATH}#g' \
211 -e 's#@SDKEXTPATH@#${SDKEXTPATH}#g' \
212 -e 's#@OLDEST_KERNEL@#${SDK_OLDEST_KERNEL}#g' \
213 -e 's#@REAL_MULTIMACH_TARGET_SYS@#${REAL_MULTIMACH_TARGET_SYS}#g' \
214 -e 's#@SDK_TITLE@#${SDK_TITLE}#g' \
215 -e 's#@SDK_VERSION@#${SDK_VERSION}#g' \
216 -e '/@SDK_PRE_INSTALL_COMMAND@/d' \
217 -e '/@SDK_POST_INSTALL_COMMAND@/d' \
218 ${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.sh
219
220 # add execution permission
221 chmod +x ${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.sh
222
223 # append the SDK tarball
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500224 cat ${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.tar.xz >> ${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.sh
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500225
226 # delete the old tarball, we don't need it anymore
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500227 rm ${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.tar.xz
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500228}
229
230populate_sdk_log_check() {
231 for target in $*
232 do
233 lf_path="`dirname ${BB_LOGFILE}`/log.do_$target.${PID}"
234
235 echo "log_check: Using $lf_path as logfile"
236
237 if test -e "$lf_path"
238 then
239 ${IMAGE_PKGTYPE}_log_check $target $lf_path
240 else
241 echo "Cannot find logfile [$lf_path]"
242 fi
243 echo "Logfile is clean"
244 done
245}
246
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500247def sdk_command_variables(d):
248 return ['OPKG_PREPROCESS_COMMANDS','OPKG_POSTPROCESS_COMMANDS','POPULATE_SDK_POST_HOST_COMMAND','POPULATE_SDK_POST_TARGET_COMMAND','SDK_POSTPROCESS_COMMAND','RPM_PREPROCESS_COMMANDS',
249 'RPM_POSTPROCESS_COMMANDS']
250
251def sdk_variables(d):
252 variables = ['BUILD_IMAGES_FROM_FEEDS','SDK_OS','SDK_OUTPUT','SDKPATHNATIVE','SDKTARGETSYSROOT','SDK_DIR','SDK_VENDOR','SDKIMAGE_INSTALL_COMPLEMENTARY','SDK_PACKAGE_ARCHS','SDK_OUTPUT',
253 'SDKTARGETSYSROOT','MULTILIB_VARIANTS','MULTILIBS','ALL_MULTILIB_PACKAGE_ARCHS','MULTILIB_GLOBAL_VARIANTS','BAD_RECOMMENDATIONS','NO_RECOMMENDATIONS','PACKAGE_ARCHS',
254 'PACKAGE_CLASSES','TARGET_VENDOR','TARGET_VENDOR','TARGET_ARCH','TARGET_OS','BBEXTENDVARIANT','FEED_DEPLOYDIR_BASE_URI']
255 variables.extend(sdk_command_variables(d))
256 return " ".join(variables)
257
258do_populate_sdk[vardeps] += "${@sdk_variables(d)}"
259
260do_populate_sdk[file-checksums] += "${COREBASE}/meta/files/toolchain-shar-relocate.sh:True \
261 ${COREBASE}/meta/files/toolchain-shar-extract.sh:True"
262
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500263do_populate_sdk[dirs] = "${PKGDATA_DIR} ${TOPDIR}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500264do_populate_sdk[depends] += "${@' '.join([x + ':do_populate_sysroot' for x in d.getVar('SDK_DEPENDS', True).split()])} ${@d.getVarFlag('do_rootfs', 'depends', False)}"
265do_populate_sdk[rdepends] = "${@' '.join([x + ':do_populate_sysroot' for x in d.getVar('SDK_RDEPENDS', True).split()])}"
266do_populate_sdk[recrdeptask] += "do_packagedata do_package_write_rpm do_package_write_ipk do_package_write_deb"
267addtask populate_sdk