summaryrefslogtreecommitdiffstats
path: root/meta/classes/populate_sdk_base.bbclass
diff options
context:
space:
mode:
Diffstat (limited to 'meta/classes/populate_sdk_base.bbclass')
-rw-r--r--meta/classes/populate_sdk_base.bbclass337
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 0000000..10d04ed
--- /dev/null
+++ b/meta/classes/populate_sdk_base.bbclass
@@ -0,0 +1,337 @@
1inherit meta toolchain-scripts
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 populate_sdk_${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 ?= "packagegroup-core-standalone-sdk-target packagegroup-core-standalone-sdk-target-dbg"
36TOOLCHAIN_TARGET_TASK_ATTEMPTONLY ?= ""
37TOOLCHAIN_OUTPUTNAME ?= "${SDK_NAME}-toolchain-${SDK_VERSION}"
38
39SDK_RDEPENDS = "${TOOLCHAIN_TARGET_TASK} ${TOOLCHAIN_HOST_TASK}"
40SDK_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
44REAL_MULTIMACH_TARGET_SYS = "${TUNE_PKGARCH}${TARGET_VENDOR}-${TARGET_OS}"
45
46PID = "${@os.getpid()}"
47
48EXCLUDE_FROM_WORLD = "1"
49
50SDK_PACKAGING_FUNC ?= "create_shar"
51
52fakeroot 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
92fakeroot 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
109SDKTAROPTS = "--owner=root --group=root -j"
110
111fakeroot 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
118fakeroot create_shar() {
119 cat << "EOF" > ${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.sh
120#!/bin/bash
121
122INST_ARCH=$(uname -m | sed -e "s/i[3-6]86/ix86/" -e "s/x86[-_]64/x86_64/")
123SDK_ARCH=$(echo ${SDK_ARCH} | sed -e "s/i[3-6]86/ix86/" -e "s/x86[-_]64/x86_64/")
124
125if [ "$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
131fi
132
133DEFAULT_INSTALL_DIR="${SDKPATH}"
134SUDO_EXEC=""
135target_sdk_dir=""
136answer=""
137relocate=1
138savescripts=0
139verbose=0
140while 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
170done
171
172if [ $verbose = 1 ] ; then
173 set -x
174fi
175
176printf "Enter target directory for SDK (default: $DEFAULT_INSTALL_DIR): "
177if [ "$target_sdk_dir" = "" ]; then
178 read target_sdk_dir
179 [ "$target_sdk_dir" = "" ] && target_sdk_dir=$DEFAULT_INSTALL_DIR
180else
181 echo "$target_sdk_dir"
182fi
183
184eval target_sdk_dir=$(echo "$target_sdk_dir"|sed 's/ /\\ /g')
185if [ -d "$target_sdk_dir" ]; then
186 target_sdk_dir=$(cd "$target_sdk_dir"; pwd)
187else
188 target_sdk_dir=$(readlink -m "$target_sdk_dir")
189fi
190
191if [ -n "$(echo $target_sdk_dir|grep ' ')" ]; then
192 echo "The target directory path ($target_sdk_dir) contains spaces. Abort!"
193 exit 1
194fi
195
196if [ -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"
201else
202 printf "You are about to install the SDK to \"$target_sdk_dir\". Proceed[Y/n]?"
203
204 default_answer="y"
205fi
206
207if [ "$answer" = "" ]; then
208 read answer
209 [ "$answer" = "" ] && answer="$default_answer"
210else
211 echo $answer
212fi
213
214if [ "$answer" != "Y" -a "$answer" != "y" ]; then
215 echo "Installation aborted!"
216 exit 1
217fi
218
219# Try to create the directory (this will not succeed if user doesn't have rights)
220mkdir -p $target_sdk_dir >/dev/null 2>&1
221
222# if don't have the right to access dir, gain by sudo
223if [ ! -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
236fi
237
238payload_offset=$(($(grep -na -m1 "^MARKER:$" $0|cut -d':' -f1) + 1))
239
240printf "Extracting SDK..."
241tail -n +$payload_offset $0| $SUDO_EXEC tar xj -C $target_sdk_dir
242echo "done"
243
244printf "Setting it up..."
245# fix environment paths
246for 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
248done
249
250# fix dynamic loader paths in all ELF SDK binaries
251native_sysroot=$($SUDO_EXEC cat $env_setup_script |grep 'OECORE_NATIVE_SYSROOT='|cut -d'=' -f2|tr -d '"')
252dl_path=$($SUDO_EXEC find $native_sysroot/lib -name "ld-linux*")
253if [ "$dl_path" = "" ] ; then
254 echo "SDK could not be set up. Relocate script unable to find ld-linux.so. Abort!"
255 exit 1
256fi
257executable_files=$($SUDO_EXEC find $native_sysroot -type f -perm /111 -exec file '{}' \;| grep "\(executable\|dynamically linked\)" | cut -f 1 -d ':')
258
259tdir=`mktemp -d`
260if [ x$tdir = x ] ; then
261 echo "SDK relocate failed, could not create a temporary directory"
262 exit 1
263fi
264echo "#!/bin/bash" > $tdir/relocate_sdk.sh
265echo 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
268rm -rf $tdir
269if [ $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
275fi
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}
281for 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
283done
284
285# find out all perl scripts in $native_sysroot and modify them replacing the
286# host perl with SDK perl.
287for 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
290done
291
292echo 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
296if [ $savescripts = 0 ] ; then
297 $SUDO_EXEC rm ${env_setup_script%/*}/relocate_sdk.py ${env_setup_script%/*}/relocate_sdk.sh
298fi
299
300echo "SDK has been successfully set up and is ready to be used."
301
302exit 0
303
304MARKER:
305EOF
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
316populate_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
333do_populate_sdk[dirs] = "${TOPDIR}"
334do_populate_sdk[depends] += "${@' '.join([x + ':do_populate_sysroot' for x in d.getVar('SDK_DEPENDS', True).split()])}"
335do_populate_sdk[rdepends] = "${@' '.join([x + ':do_populate_sysroot' for x in d.getVar('SDK_RDEPENDS', True).split()])}"
336do_populate_sdk[recrdeptask] += "do_packagedata do_package_write_rpm do_package_write_ipk do_package_write_deb"
337addtask populate_sdk