diff options
| author | Tudor Florea <tudor.florea@enea.com> | 2014-10-16 03:05:19 +0200 |
|---|---|---|
| committer | Tudor Florea <tudor.florea@enea.com> | 2014-10-16 03:05:19 +0200 |
| commit | c527fd1f14c27855a37f2e8ac5346ce8d940ced2 (patch) | |
| tree | bb002c1fdf011c41dbd2f0927bed23ecb5f83c97 /meta/classes/populate_sdk_base.bbclass | |
| download | poky-daisy-140929.tar.gz | |
initial commit for Enea Linux 4.0-140929daisy-140929
Migrated from the internal git server on the daisy-enea-point-release branch
Signed-off-by: Tudor Florea <tudor.florea@enea.com>
Diffstat (limited to 'meta/classes/populate_sdk_base.bbclass')
| -rw-r--r-- | meta/classes/populate_sdk_base.bbclass | 337 |
1 files changed, 337 insertions, 0 deletions
diff --git a/meta/classes/populate_sdk_base.bbclass b/meta/classes/populate_sdk_base.bbclass new file mode 100644 index 0000000000..10d04edc63 --- /dev/null +++ b/meta/classes/populate_sdk_base.bbclass | |||
| @@ -0,0 +1,337 @@ | |||
| 1 | inherit meta toolchain-scripts | ||
| 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 populate_sdk_${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 ?= "packagegroup-core-standalone-sdk-target packagegroup-core-standalone-sdk-target-dbg" | ||
| 36 | TOOLCHAIN_TARGET_TASK_ATTEMPTONLY ?= "" | ||
| 37 | TOOLCHAIN_OUTPUTNAME ?= "${SDK_NAME}-toolchain-${SDK_VERSION}" | ||
| 38 | |||
| 39 | SDK_RDEPENDS = "${TOOLCHAIN_TARGET_TASK} ${TOOLCHAIN_HOST_TASK}" | ||
| 40 | SDK_DEPENDS = "virtual/fakeroot-native sed-native" | ||
| 41 | |||
| 42 | # We want the MULTIARCH_TARGET_SYS to point to the TUNE_PKGARCH, not PACKAGE_ARCH as it | ||
| 43 | # could be set to the MACHINE_ARCH | ||
| 44 | REAL_MULTIMACH_TARGET_SYS = "${TUNE_PKGARCH}${TARGET_VENDOR}-${TARGET_OS}" | ||
| 45 | |||
| 46 | PID = "${@os.getpid()}" | ||
| 47 | |||
| 48 | EXCLUDE_FROM_WORLD = "1" | ||
| 49 | |||
| 50 | SDK_PACKAGING_FUNC ?= "create_shar" | ||
| 51 | |||
| 52 | fakeroot python do_populate_sdk() { | ||
| 53 | from oe.sdk import populate_sdk | ||
| 54 | from oe.manifest import create_manifest, Manifest | ||
| 55 | |||
| 56 | pn = d.getVar('PN', True) | ||
| 57 | runtime_mapping_rename("TOOLCHAIN_TARGET_TASK", pn, d) | ||
| 58 | |||
| 59 | # create target/host SDK manifests | ||
| 60 | create_manifest(d, manifest_dir=d.getVar('SDK_DIR', True), | ||
| 61 | manifest_type=Manifest.MANIFEST_TYPE_SDK_HOST) | ||
| 62 | create_manifest(d, manifest_dir=d.getVar('SDK_DIR', True), | ||
| 63 | manifest_type=Manifest.MANIFEST_TYPE_SDK_TARGET) | ||
| 64 | |||
| 65 | populate_sdk(d) | ||
| 66 | |||
| 67 | # Handle multilibs in the SDK environment, siteconfig, etc files... | ||
| 68 | localdata = bb.data.createCopy(d) | ||
| 69 | |||
| 70 | # make sure we only use the WORKDIR value from 'd', or it can change | ||
| 71 | localdata.setVar('WORKDIR', d.getVar('WORKDIR', True)) | ||
| 72 | |||
| 73 | # make sure we only use the SDKTARGETSYSROOT value from 'd' | ||
| 74 | localdata.setVar('SDKTARGETSYSROOT', d.getVar('SDKTARGETSYSROOT', True)) | ||
| 75 | |||
| 76 | # Process DEFAULTTUNE | ||
| 77 | bb.build.exec_func("create_sdk_files", localdata) | ||
| 78 | |||
| 79 | variants = d.getVar("MULTILIB_VARIANTS", True) or "" | ||
| 80 | for item in variants.split(): | ||
| 81 | # Load overrides from 'd' to avoid having to reset the value... | ||
| 82 | overrides = d.getVar("OVERRIDES", False) + ":virtclass-multilib-" + item | ||
| 83 | localdata.setVar("OVERRIDES", overrides) | ||
| 84 | bb.data.update_data(localdata) | ||
| 85 | bb.build.exec_func("create_sdk_files", localdata) | ||
| 86 | |||
| 87 | bb.build.exec_func("tar_sdk", d) | ||
| 88 | |||
| 89 | bb.build.exec_func(d.getVar("SDK_PACKAGING_FUNC", True), d) | ||
| 90 | } | ||
| 91 | |||
| 92 | fakeroot create_sdk_files() { | ||
| 93 | # Setup site file for external use | ||
| 94 | toolchain_create_sdk_siteconfig ${SDK_OUTPUT}/${SDKPATH}/site-config-${REAL_MULTIMACH_TARGET_SYS} | ||
| 95 | |||
| 96 | toolchain_create_sdk_env_script ${SDK_OUTPUT}/${SDKPATH}/environment-setup-${REAL_MULTIMACH_TARGET_SYS} | ||
| 97 | |||
| 98 | # Add version information | ||
| 99 | toolchain_create_sdk_version ${SDK_OUTPUT}/${SDKPATH}/version-${REAL_MULTIMACH_TARGET_SYS} | ||
| 100 | |||
| 101 | cp ${COREBASE}/scripts/relocate_sdk.py ${SDK_OUTPUT}/${SDKPATH}/ | ||
| 102 | |||
| 103 | # Replace the ##DEFAULT_INSTALL_DIR## with the correct pattern. | ||
| 104 | # Escape special characters like '+' and '.' in the SDKPATH | ||
| 105 | escaped_sdkpath=$(echo ${SDKPATH} |sed -e "s:[\+\.]:\\\\\\\\\0:g") | ||
| 106 | sed -i -e "s:##DEFAULT_INSTALL_DIR##:$escaped_sdkpath:" ${SDK_OUTPUT}/${SDKPATH}/relocate_sdk.py | ||
| 107 | } | ||
| 108 | |||
| 109 | SDKTAROPTS = "--owner=root --group=root -j" | ||
| 110 | |||
| 111 | fakeroot tar_sdk() { | ||
| 112 | # Package it up | ||
| 113 | mkdir -p ${SDK_DEPLOY} | ||
| 114 | cd ${SDK_OUTPUT}/${SDKPATH} | ||
| 115 | tar ${SDKTAROPTS} -c --file=${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.tar.bz2 . | ||
| 116 | } | ||
| 117 | |||
| 118 | fakeroot create_shar() { | ||
| 119 | cat << "EOF" > ${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.sh | ||
| 120 | #!/bin/bash | ||
| 121 | |||
| 122 | INST_ARCH=$(uname -m | sed -e "s/i[3-6]86/ix86/" -e "s/x86[-_]64/x86_64/") | ||
| 123 | SDK_ARCH=$(echo ${SDK_ARCH} | sed -e "s/i[3-6]86/ix86/" -e "s/x86[-_]64/x86_64/") | ||
| 124 | |||
| 125 | if [ "$INST_ARCH" != "$SDK_ARCH" ]; then | ||
| 126 | # Allow for installation of ix86 SDK on x86_64 host | ||
| 127 | if [ "$INST_ARCH" != x86_64 -o "$SDK_ARCH" != ix86 ]; then | ||
| 128 | echo "Error: Installation machine not supported!" | ||
| 129 | exit 1 | ||
| 130 | fi | ||
| 131 | fi | ||
| 132 | |||
| 133 | DEFAULT_INSTALL_DIR="${SDKPATH}" | ||
| 134 | SUDO_EXEC="" | ||
| 135 | target_sdk_dir="" | ||
| 136 | answer="" | ||
| 137 | relocate=1 | ||
| 138 | savescripts=0 | ||
| 139 | verbose=0 | ||
| 140 | while getopts ":yd:DRS" OPT; do | ||
| 141 | case $OPT in | ||
| 142 | y) | ||
| 143 | answer="Y" | ||
| 144 | [ "$target_sdk_dir" = "" ] && target_sdk_dir=$DEFAULT_INSTALL_DIR | ||
| 145 | ;; | ||
| 146 | d) | ||
| 147 | target_sdk_dir=$OPTARG | ||
| 148 | ;; | ||
| 149 | D) | ||
| 150 | verbose=1 | ||
| 151 | ;; | ||
| 152 | R) | ||
| 153 | relocate=0 | ||
| 154 | savescripts=1 | ||
| 155 | ;; | ||
| 156 | S) | ||
| 157 | savescripts=1 | ||
| 158 | ;; | ||
| 159 | *) | ||
| 160 | echo "Usage: $(basename $0) [-y] [-d <dir>]" | ||
| 161 | echo " -y Automatic yes to all prompts" | ||
| 162 | echo " -d <dir> Install the SDK to <dir>" | ||
| 163 | echo "======== Advanced DEBUGGING ONLY OPTIONS ========" | ||
| 164 | echo " -S Save relocation scripts" | ||
| 165 | echo " -R Do not relocate executables" | ||
| 166 | echo " -D use set -x to see what is going on" | ||
| 167 | exit 1 | ||
| 168 | ;; | ||
| 169 | esac | ||
| 170 | done | ||
| 171 | |||
| 172 | if [ $verbose = 1 ] ; then | ||
| 173 | set -x | ||
| 174 | fi | ||
| 175 | |||
| 176 | printf "Enter target directory for SDK (default: $DEFAULT_INSTALL_DIR): " | ||
| 177 | if [ "$target_sdk_dir" = "" ]; then | ||
| 178 | read target_sdk_dir | ||
| 179 | [ "$target_sdk_dir" = "" ] && target_sdk_dir=$DEFAULT_INSTALL_DIR | ||
| 180 | else | ||
| 181 | echo "$target_sdk_dir" | ||
| 182 | fi | ||
| 183 | |||
| 184 | eval target_sdk_dir=$(echo "$target_sdk_dir"|sed 's/ /\\ /g') | ||
| 185 | if [ -d "$target_sdk_dir" ]; then | ||
| 186 | target_sdk_dir=$(cd "$target_sdk_dir"; pwd) | ||
| 187 | else | ||
| 188 | target_sdk_dir=$(readlink -m "$target_sdk_dir") | ||
| 189 | fi | ||
| 190 | |||
| 191 | if [ -n "$(echo $target_sdk_dir|grep ' ')" ]; then | ||
| 192 | echo "The target directory path ($target_sdk_dir) contains spaces. Abort!" | ||
| 193 | exit 1 | ||
| 194 | fi | ||
| 195 | |||
| 196 | if [ -e "$target_sdk_dir/environment-setup-${REAL_MULTIMACH_TARGET_SYS}" ]; then | ||
| 197 | echo "The directory \"$target_sdk_dir\" already contains a SDK for this architecture." | ||
| 198 | printf "If you continue, existing files will be overwritten! Proceed[y/N]?" | ||
| 199 | |||
| 200 | default_answer="n" | ||
| 201 | else | ||
| 202 | printf "You are about to install the SDK to \"$target_sdk_dir\". Proceed[Y/n]?" | ||
| 203 | |||
| 204 | default_answer="y" | ||
| 205 | fi | ||
| 206 | |||
| 207 | if [ "$answer" = "" ]; then | ||
| 208 | read answer | ||
| 209 | [ "$answer" = "" ] && answer="$default_answer" | ||
| 210 | else | ||
| 211 | echo $answer | ||
| 212 | fi | ||
| 213 | |||
| 214 | if [ "$answer" != "Y" -a "$answer" != "y" ]; then | ||
| 215 | echo "Installation aborted!" | ||
| 216 | exit 1 | ||
| 217 | fi | ||
| 218 | |||
| 219 | # Try to create the directory (this will not succeed if user doesn't have rights) | ||
| 220 | mkdir -p $target_sdk_dir >/dev/null 2>&1 | ||
| 221 | |||
| 222 | # if don't have the right to access dir, gain by sudo | ||
| 223 | if [ ! -x $target_sdk_dir -o ! -w $target_sdk_dir -o ! -r $target_sdk_dir ]; then | ||
| 224 | SUDO_EXEC=$(which "sudo") | ||
| 225 | if [ -z $SUDO_EXEC ]; then | ||
| 226 | echo "No command 'sudo' found, please install sudo first. Abort!" | ||
| 227 | exit 1 | ||
| 228 | fi | ||
| 229 | |||
| 230 | # test sudo could gain root right | ||
| 231 | $SUDO_EXEC pwd >/dev/null 2>&1 | ||
| 232 | [ $? -ne 0 ] && echo "Sorry, you are not allowed to execute as root." && exit 1 | ||
| 233 | |||
| 234 | # now that we have sudo rights, create the directory | ||
| 235 | $SUDO_EXEC mkdir -p $target_sdk_dir >/dev/null 2>&1 | ||
| 236 | fi | ||
| 237 | |||
| 238 | payload_offset=$(($(grep -na -m1 "^MARKER:$" $0|cut -d':' -f1) + 1)) | ||
| 239 | |||
| 240 | printf "Extracting SDK..." | ||
| 241 | tail -n +$payload_offset $0| $SUDO_EXEC tar xj -C $target_sdk_dir | ||
| 242 | echo "done" | ||
| 243 | |||
| 244 | printf "Setting it up..." | ||
| 245 | # fix environment paths | ||
| 246 | for env_setup_script in `ls $target_sdk_dir/environment-setup-*`; do | ||
| 247 | $SUDO_EXEC sed -e "s:$DEFAULT_INSTALL_DIR:$target_sdk_dir:g" -i $env_setup_script | ||
| 248 | done | ||
| 249 | |||
| 250 | # fix dynamic loader paths in all ELF SDK binaries | ||
| 251 | native_sysroot=$($SUDO_EXEC cat $env_setup_script |grep 'OECORE_NATIVE_SYSROOT='|cut -d'=' -f2|tr -d '"') | ||
| 252 | dl_path=$($SUDO_EXEC find $native_sysroot/lib -name "ld-linux*") | ||
| 253 | if [ "$dl_path" = "" ] ; then | ||
| 254 | echo "SDK could not be set up. Relocate script unable to find ld-linux.so. Abort!" | ||
| 255 | exit 1 | ||
| 256 | fi | ||
| 257 | executable_files=$($SUDO_EXEC find $native_sysroot -type f -perm /111 -exec file '{}' \;| grep "\(executable\|dynamically linked\)" | cut -f 1 -d ':') | ||
| 258 | |||
| 259 | tdir=`mktemp -d` | ||
| 260 | if [ x$tdir = x ] ; then | ||
| 261 | echo "SDK relocate failed, could not create a temporary directory" | ||
| 262 | exit 1 | ||
| 263 | fi | ||
| 264 | echo "#!/bin/bash" > $tdir/relocate_sdk.sh | ||
| 265 | echo exec ${env_setup_script%/*}/relocate_sdk.py $target_sdk_dir $dl_path $executable_files >> $tdir/relocate_sdk.sh | ||
| 266 | $SUDO_EXEC mv $tdir/relocate_sdk.sh ${env_setup_script%/*}/relocate_sdk.sh | ||
| 267 | $SUDO_EXEC chmod 755 ${env_setup_script%/*}/relocate_sdk.sh | ||
| 268 | rm -rf $tdir | ||
| 269 | if [ $relocate = 1 ] ; then | ||
| 270 | $SUDO_EXEC ${env_setup_script%/*}/relocate_sdk.sh | ||
| 271 | if [ $? -ne 0 ]; then | ||
| 272 | echo "SDK could not be set up. Relocate script failed. Abort!" | ||
| 273 | exit 1 | ||
| 274 | fi | ||
| 275 | fi | ||
| 276 | |||
| 277 | # replace ${SDKPATH} with the new prefix in all text files: configs/scripts/etc | ||
| 278 | $SUDO_EXEC find $native_sysroot -type f -exec file '{}' \;|grep ":.*\(ASCII\|script\|source\).*text"|cut -d':' -f1|$SUDO_EXEC xargs sed -i -e "s:$DEFAULT_INSTALL_DIR:$target_sdk_dir:g" | ||
| 279 | |||
| 280 | # change all symlinks pointing to ${SDKPATH} | ||
| 281 | for l in $($SUDO_EXEC find $native_sysroot -type l); do | ||
| 282 | $SUDO_EXEC ln -sfn $(readlink $l|$SUDO_EXEC sed -e "s:$DEFAULT_INSTALL_DIR:$target_sdk_dir:") $l | ||
| 283 | done | ||
| 284 | |||
| 285 | # find out all perl scripts in $native_sysroot and modify them replacing the | ||
| 286 | # host perl with SDK perl. | ||
| 287 | for perl_script in $($SUDO_EXEC grep "^#!.*perl" -rl $native_sysroot); do | ||
| 288 | $SUDO_EXEC sed -i -e "s:^#! */usr/bin/perl.*:#! /usr/bin/env perl:g" -e \ | ||
| 289 | "s: /usr/bin/perl: /usr/bin/env perl:g" $perl_script | ||
| 290 | done | ||
| 291 | |||
| 292 | echo done | ||
| 293 | |||
| 294 | # delete the relocating script, so that user is forced to re-run the installer | ||
| 295 | # if he/she wants another location for the sdk | ||
| 296 | if [ $savescripts = 0 ] ; then | ||
| 297 | $SUDO_EXEC rm ${env_setup_script%/*}/relocate_sdk.py ${env_setup_script%/*}/relocate_sdk.sh | ||
| 298 | fi | ||
| 299 | |||
| 300 | echo "SDK has been successfully set up and is ready to be used." | ||
| 301 | |||
| 302 | exit 0 | ||
| 303 | |||
| 304 | MARKER: | ||
| 305 | EOF | ||
| 306 | # add execution permission | ||
| 307 | chmod +x ${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.sh | ||
| 308 | |||
| 309 | # append the SDK tarball | ||
| 310 | cat ${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.tar.bz2 >> ${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.sh | ||
| 311 | |||
| 312 | # delete the old tarball, we don't need it anymore | ||
| 313 | rm ${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.tar.bz2 | ||
| 314 | } | ||
| 315 | |||
| 316 | populate_sdk_log_check() { | ||
| 317 | for target in $* | ||
| 318 | do | ||
| 319 | lf_path="`dirname ${BB_LOGFILE}`/log.do_$target.${PID}" | ||
| 320 | |||
| 321 | echo "log_check: Using $lf_path as logfile" | ||
| 322 | |||
| 323 | if test -e "$lf_path" | ||
| 324 | then | ||
| 325 | ${IMAGE_PKGTYPE}_log_check $target $lf_path | ||
| 326 | else | ||
| 327 | echo "Cannot find logfile [$lf_path]" | ||
| 328 | fi | ||
| 329 | echo "Logfile is clean" | ||
| 330 | done | ||
| 331 | } | ||
| 332 | |||
| 333 | do_populate_sdk[dirs] = "${TOPDIR}" | ||
| 334 | do_populate_sdk[depends] += "${@' '.join([x + ':do_populate_sysroot' for x in d.getVar('SDK_DEPENDS', True).split()])}" | ||
| 335 | do_populate_sdk[rdepends] = "${@' '.join([x + ':do_populate_sysroot' for x in d.getVar('SDK_RDEPENDS', True).split()])}" | ||
| 336 | do_populate_sdk[recrdeptask] += "do_packagedata do_package_write_rpm do_package_write_ipk do_package_write_deb" | ||
| 337 | addtask populate_sdk | ||
