Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | inherit meta |
| 2 | |
| 3 | # Wildcards specifying complementary packages to install for every package that has been explicitly |
| 4 | # installed into the rootfs |
| 5 | COMPLEMENTARY_GLOB[dev-pkgs] = '*-dev' |
| 6 | COMPLEMENTARY_GLOB[staticdev-pkgs] = '*-staticdev' |
| 7 | COMPLEMENTARY_GLOB[doc-pkgs] = '*-doc' |
| 8 | COMPLEMENTARY_GLOB[dbg-pkgs] = '*-dbg' |
| 9 | COMPLEMENTARY_GLOB[ptest-pkgs] = '*-ptest' |
| 10 | |
| 11 | def 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 | |
| 20 | SDKIMAGE_FEATURES ??= "dev-pkgs dbg-pkgs" |
| 21 | SDKIMAGE_INSTALL_COMPLEMENTARY = '${@complementary_globs("SDKIMAGE_FEATURES", d)}' |
| 22 | |
| 23 | inherit rootfs_${IMAGE_PKGTYPE} |
| 24 | |
| 25 | SDK_DIR = "${WORKDIR}/sdk" |
| 26 | SDK_OUTPUT = "${SDK_DIR}/image" |
| 27 | SDK_DEPLOY = "${DEPLOY_DIR}/sdk" |
| 28 | |
| 29 | B_task-populate-sdk = "${SDK_DIR}" |
| 30 | |
| 31 | SDKTARGETSYSROOT = "${SDKPATH}/sysroots/${REAL_MULTIMACH_TARGET_SYS}" |
| 32 | |
| 33 | TOOLCHAIN_HOST_TASK ?= "nativesdk-packagegroup-sdk-host packagegroup-cross-canadian-${MACHINE}" |
| 34 | TOOLCHAIN_HOST_TASK_ATTEMPTONLY ?= "" |
| 35 | TOOLCHAIN_TARGET_TASK ?= " \ |
| 36 | ${@multilib_pkg_extend(d, 'packagegroup-core-standalone-sdk-target')} \ |
| 37 | ${@multilib_pkg_extend(d, 'packagegroup-core-standalone-sdk-target-dbg')} \ |
| 38 | " |
| 39 | TOOLCHAIN_TARGET_TASK_ATTEMPTONLY ?= "" |
| 40 | TOOLCHAIN_OUTPUTNAME ?= "${SDK_NAME}-toolchain-${SDK_VERSION}" |
| 41 | |
| 42 | SDK_RDEPENDS = "${TOOLCHAIN_TARGET_TASK} ${TOOLCHAIN_HOST_TASK}" |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 43 | SDK_DEPENDS = "virtual/fakeroot-native pixz-native" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 44 | |
| 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 |
| 47 | REAL_MULTIMACH_TARGET_SYS = "${TUNE_PKGARCH}${TARGET_VENDOR}-${TARGET_OS}" |
| 48 | |
| 49 | PID = "${@os.getpid()}" |
| 50 | |
| 51 | EXCLUDE_FROM_WORLD = "1" |
| 52 | |
| 53 | SDK_PACKAGING_FUNC ?= "create_shar" |
| 54 | SDK_PRE_INSTALL_COMMAND ?= "" |
| 55 | SDK_POST_INSTALL_COMMAND ?= "" |
| 56 | SDK_RELOCATE_AFTER_INSTALL ?= "1" |
| 57 | |
| 58 | SDKEXTPATH ?= "~/${@d.getVar('DISTRO', True)}_sdk" |
| 59 | SDK_TITLE ?= "${@d.getVar('DISTRO_NAME', True) or d.getVar('DISTRO', True)} SDK" |
| 60 | |
| 61 | SDK_TARGET_MANIFEST = "${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.target.manifest" |
| 62 | SDK_HOST_MANIFEST = "${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.host.manifest" |
| 63 | python write_target_sdk_manifest () { |
| 64 | from oe.sdk import sdk_list_installed_packages |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 65 | from oe.utils import format_pkg_list |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 66 | sdkmanifestdir = os.path.dirname(d.getVar("SDK_TARGET_MANIFEST", True)) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 67 | pkgs = sdk_list_installed_packages(d, True) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 68 | if not os.path.exists(sdkmanifestdir): |
| 69 | bb.utils.mkdirhier(sdkmanifestdir) |
| 70 | with open(d.getVar('SDK_TARGET_MANIFEST', True), 'w') as output: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 71 | output.write(format_pkg_list(pkgs, 'ver')) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | python write_host_sdk_manifest () { |
| 75 | from oe.sdk import sdk_list_installed_packages |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 76 | from oe.utils import format_pkg_list |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 77 | sdkmanifestdir = os.path.dirname(d.getVar("SDK_HOST_MANIFEST", True)) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 78 | pkgs = sdk_list_installed_packages(d, False) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 79 | if not os.path.exists(sdkmanifestdir): |
| 80 | bb.utils.mkdirhier(sdkmanifestdir) |
| 81 | with open(d.getVar('SDK_HOST_MANIFEST', True), 'w') as output: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 82 | output.write(format_pkg_list(pkgs, 'ver')) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | POPULATE_SDK_POST_TARGET_COMMAND_append = " write_target_sdk_manifest ; " |
| 86 | POPULATE_SDK_POST_HOST_COMMAND_append = " write_host_sdk_manifest; " |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 87 | SDK_PACKAGING_COMMAND = "${@'${SDK_PACKAGING_FUNC};' if '${SDK_PACKAGING_FUNC}' else ''}" |
| 88 | SDK_POSTPROCESS_COMMAND = " create_sdk_files; check_sdk_sysroots; tar_sdk; ${SDK_PACKAGING_COMMAND} " |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 89 | |
| 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. |
| 93 | SDK_OLDEST_KERNEL = "2.6.32" |
| 94 | |
| 95 | fakeroot 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | fakeroot 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 Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 128 | python 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 179 | SDKTAROPTS = "--owner=root --group=root" |
| 180 | |
| 181 | fakeroot tar_sdk() { |
| 182 | # Package it up |
| 183 | mkdir -p ${SDK_DEPLOY} |
| 184 | cd ${SDK_OUTPUT}/${SDKPATH} |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 185 | tar ${SDKTAROPTS} -cf - . | pixz > ${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.tar.xz |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | fakeroot 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} |
| 199 | EOF |
| 200 | |
| 201 | cat << "EOF" >> ${T}/post_install_command |
| 202 | ${SDK_POST_INSTALL_COMMAND} |
| 203 | EOF |
| 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 Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 224 | cat ${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.tar.xz >> ${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.sh |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 225 | |
| 226 | # delete the old tarball, we don't need it anymore |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 227 | rm ${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.tar.xz |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | populate_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 Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 247 | def 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 | |
| 251 | def 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 | |
| 258 | do_populate_sdk[vardeps] += "${@sdk_variables(d)}" |
| 259 | |
| 260 | do_populate_sdk[file-checksums] += "${COREBASE}/meta/files/toolchain-shar-relocate.sh:True \ |
| 261 | ${COREBASE}/meta/files/toolchain-shar-extract.sh:True" |
| 262 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 263 | do_populate_sdk[dirs] = "${PKGDATA_DIR} ${TOPDIR}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 264 | do_populate_sdk[depends] += "${@' '.join([x + ':do_populate_sysroot' for x in d.getVar('SDK_DEPENDS', True).split()])} ${@d.getVarFlag('do_rootfs', 'depends', False)}" |
| 265 | do_populate_sdk[rdepends] = "${@' '.join([x + ':do_populate_sysroot' for x in d.getVar('SDK_RDEPENDS', True).split()])}" |
| 266 | do_populate_sdk[recrdeptask] += "do_packagedata do_package_write_rpm do_package_write_ipk do_package_write_deb" |
| 267 | addtask populate_sdk |