blob: b9808bb8e3b02af7567bddef818a2d08d670ad08 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001# Extensible SDK
2
3inherit populate_sdk_base
4
5# NOTE: normally you cannot use task overrides for this kind of thing - this
6# only works because of get_sdk_ext_rdepends()
7
8TOOLCHAIN_HOST_TASK_task-populate-sdk-ext = " \
9 meta-environment-extsdk-${MACHINE} \
10 "
11
12TOOLCHAIN_TARGET_TASK_task-populate-sdk-ext = ""
13
14SDK_RDEPENDS_append_task-populate-sdk-ext = " ${SDK_TARGETS}"
15
16SDK_RELOCATE_AFTER_INSTALL_task-populate-sdk-ext = "0"
17
18SDK_LOCAL_CONF_WHITELIST ?= ""
19SDK_LOCAL_CONF_BLACKLIST ?= "CONF_VERSION BB_NUMBER_THREADS PARALLEL_MAKE PRSERV_HOST"
20SDK_INHERIT_BLACKLIST ?= "buildhistory icecc"
21SDK_UPDATE_URL ?= ""
22
23SDK_TARGETS ?= "${PN}"
24OE_INIT_ENV_SCRIPT ?= "oe-init-build-env"
25
26# The files from COREBASE that you want preserved in the COREBASE copied
27# into the sdk. This allows someone to have their own setup scripts in
28# COREBASE be preserved as well as untracked files.
29COREBASE_FILES ?= " \
30 oe-init-build-env \
31 oe-init-build-env-memres \
32 scripts \
33 LICENSE \
34 .templateconf \
35"
36
37SDK_DIR_task-populate-sdk-ext = "${WORKDIR}/sdk-ext"
38B_task-populate-sdk-ext = "${SDK_DIR}"
39TOOLCHAIN_OUTPUTNAME_task-populate-sdk-ext = "${SDK_NAME}-toolchain-ext-${SDK_VERSION}"
40
41SDK_TITLE_task-populate-sdk-ext = "${@d.getVar('DISTRO_NAME', True) or d.getVar('DISTRO', True)} Extensible SDK"
42
43python copy_buildsystem () {
44 import re
45 import oe.copy_buildsystem
46
47 oe_init_env_script = d.getVar('OE_INIT_ENV_SCRIPT', True)
48
49 conf_bbpath = ''
50 conf_initpath = ''
51 core_meta_subdir = ''
52
53 # Copy in all metadata layers + bitbake (as repositories)
Patrick Williamsf1e5d692016-03-30 15:21:19 -050054 buildsystem = oe.copy_buildsystem.BuildSystem('extensible SDK', d)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050055 baseoutpath = d.getVar('SDK_OUTPUT', True) + '/' + d.getVar('SDKPATH', True)
56 layers_copied = buildsystem.copy_bitbake_and_layers(baseoutpath + '/layers')
57
58 sdkbblayers = []
59 corebase = os.path.basename(d.getVar('COREBASE', True))
60 for layer in layers_copied:
61 if corebase == os.path.basename(layer):
62 conf_bbpath = os.path.join('layers', layer, 'bitbake')
63 else:
64 sdkbblayers.append(layer)
65
66 for path in os.listdir(baseoutpath + '/layers'):
67 relpath = os.path.join('layers', path, oe_init_env_script)
68 if os.path.exists(os.path.join(baseoutpath, relpath)):
69 conf_initpath = relpath
70
71 relpath = os.path.join('layers', path, 'scripts', 'devtool')
72 if os.path.exists(os.path.join(baseoutpath, relpath)):
73 scriptrelpath = os.path.dirname(relpath)
74
75 relpath = os.path.join('layers', path, 'meta')
76 if os.path.exists(os.path.join(baseoutpath, relpath, 'lib', 'oe')):
77 core_meta_subdir = relpath
78
79 d.setVar('oe_init_build_env_path', conf_initpath)
80 d.setVar('scriptrelpath', scriptrelpath)
81
82 # Write out config file for devtool
83 import ConfigParser
84 config = ConfigParser.SafeConfigParser()
85 config.add_section('General')
86 config.set('General', 'bitbake_subdir', conf_bbpath)
87 config.set('General', 'init_path', conf_initpath)
88 config.set('General', 'core_meta_subdir', core_meta_subdir)
89 config.add_section('SDK')
90 config.set('SDK', 'sdk_targets', d.getVar('SDK_TARGETS', True))
91 updateurl = d.getVar('SDK_UPDATE_URL', True)
92 if updateurl:
93 config.set('SDK', 'updateserver', updateurl)
94 bb.utils.mkdirhier(os.path.join(baseoutpath, 'conf'))
95 with open(os.path.join(baseoutpath, 'conf', 'devtool.conf'), 'w') as f:
96 config.write(f)
97
98 # Create a layer for new recipes / appends
99 bbpath = d.getVar('BBPATH', True)
100 bb.process.run(['devtool', '--bbpath', bbpath, '--basepath', baseoutpath, 'create-workspace', '--create-only', os.path.join(baseoutpath, 'workspace')])
101
102 # Create bblayers.conf
103 bb.utils.mkdirhier(baseoutpath + '/conf')
104 with open(baseoutpath + '/conf/bblayers.conf', 'w') as f:
105 f.write('# WARNING: this configuration has been automatically generated and in\n')
106 f.write('# most cases should not be edited. If you need more flexibility than\n')
107 f.write('# this configuration provides, it is strongly suggested that you set\n')
108 f.write('# up a proper instance of the full build system and use that instead.\n\n')
109
110 f.write('LCONF_VERSION = "%s"\n\n' % d.getVar('LCONF_VERSION', False))
111 f.write('BBPATH = "$' + '{TOPDIR}"\n')
112 f.write('SDKBASEMETAPATH = "$' + '{TOPDIR}"\n')
113 f.write('BBLAYERS := " \\\n')
114 for layerrelpath in sdkbblayers:
115 f.write(' $' + '{SDKBASEMETAPATH}/layers/%s \\\n' % layerrelpath)
116 f.write(' $' + '{SDKBASEMETAPATH}/workspace \\\n')
117 f.write(' "\n')
118
119 # Create local.conf
120 local_conf_whitelist = (d.getVar('SDK_LOCAL_CONF_WHITELIST', True) or '').split()
121 local_conf_blacklist = (d.getVar('SDK_LOCAL_CONF_BLACKLIST', True) or '').split()
122 def handle_var(varname, origvalue, op, newlines):
123 if varname in local_conf_blacklist or (origvalue.strip().startswith('/') and not varname in local_conf_whitelist):
124 newlines.append('# Removed original setting of %s\n' % varname)
125 return None, op, 0, True
126 else:
127 return origvalue, op, 0, True
128 varlist = ['[^#=+ ]*']
129 builddir = d.getVar('TOPDIR', True)
130 with open(builddir + '/conf/local.conf', 'r') as f:
131 oldlines = f.readlines()
132 (updated, newlines) = bb.utils.edit_metadata(oldlines, varlist, handle_var)
133
134 with open(baseoutpath + '/conf/local.conf', 'w') as f:
135 f.write('# WARNING: this configuration has been automatically generated and in\n')
136 f.write('# most cases should not be edited. If you need more flexibility than\n')
137 f.write('# this configuration provides, it is strongly suggested that you set\n')
138 f.write('# up a proper instance of the full build system and use that instead.\n\n')
139 for line in newlines:
140 if line.strip() and not line.startswith('#'):
141 f.write(line)
142
143 f.write('INHERIT += "%s"\n\n' % 'uninative')
144 f.write('CONF_VERSION = "%s"\n\n' % d.getVar('CONF_VERSION', False))
145
146 # Some classes are not suitable for SDK, remove them from INHERIT
147 f.write('INHERIT_remove = "%s"\n' % d.getVar('SDK_INHERIT_BLACKLIST'))
148
149 # Bypass the default connectivity check if any
150 f.write('CONNECTIVITY_CHECK_URIS = ""\n\n')
151
152 # Another hack, but we want the native part of sstate to be kept the same
153 # regardless of the host distro
154 fixedlsbstring = 'SDK-Fixed'
155 f.write('NATIVELSBSTRING_forcevariable = "%s"\n\n' % fixedlsbstring)
156
157 # Ensure locked sstate cache objects are re-used without error
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500158 f.write('SIGGEN_LOCKEDSIGS_CHECK_LEVEL = "none"\n\n')
159
160 # If you define a sdk_extraconf() function then it can contain additional config
161 extraconf = (d.getVar('sdk_extraconf', True) or '').strip()
162 if extraconf:
163 # Strip off any leading / trailing spaces
164 for line in extraconf.splitlines():
165 f.write(line.strip() + '\n')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500166
167 f.write('require conf/locked-sigs.inc\n')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500168
169 sigfile = d.getVar('WORKDIR', True) + '/locked-sigs.inc'
170 oe.copy_buildsystem.generate_locked_sigs(sigfile, d)
171
172 # Filter the locked signatures file to just the sstate tasks we are interested in
173 allowed_tasks = ['do_populate_lic', 'do_populate_sysroot', 'do_packagedata', 'do_package_write_ipk', 'do_package_write_rpm', 'do_package_write_deb', 'do_package_qa', 'do_deploy']
174 excluded_targets = d.getVar('SDK_TARGETS', True)
175 lockedsigs_pruned = baseoutpath + '/conf/locked-sigs.inc'
176 oe.copy_buildsystem.prune_lockedsigs(allowed_tasks,
177 excluded_targets,
178 sigfile,
179 lockedsigs_pruned)
180
181 sstate_out = baseoutpath + '/sstate-cache'
182 bb.utils.remove(sstate_out, True)
183 oe.copy_buildsystem.create_locked_sstate_cache(lockedsigs_pruned,
184 d.getVar('SSTATE_DIR', True),
185 sstate_out, d,
186 fixedlsbstring)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500187}
188
189def extsdk_get_buildtools_filename(d):
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500190 return '*-buildtools-nativesdk-standalone-*.sh'
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500191
192install_tools() {
193 install -d ${SDK_OUTPUT}/${SDKPATHNATIVE}${bindir_nativesdk}
194 lnr ${SDK_OUTPUT}/${SDKPATH}/${scriptrelpath}/devtool ${SDK_OUTPUT}/${SDKPATHNATIVE}${bindir_nativesdk}/devtool
195 lnr ${SDK_OUTPUT}/${SDKPATH}/${scriptrelpath}/recipetool ${SDK_OUTPUT}/${SDKPATHNATIVE}${bindir_nativesdk}/recipetool
196 touch ${SDK_OUTPUT}/${SDKPATH}/.devtoolbase
197
198 # find latest buildtools-tarball and install it
199 buildtools_path=`ls -t1 ${SDK_DEPLOY}/${@extsdk_get_buildtools_filename(d)} | head -n1`
200 install $buildtools_path ${SDK_OUTPUT}/${SDKPATH}
201
202 install ${SDK_DEPLOY}/${BUILD_ARCH}-nativesdk-libc.tar.bz2 ${SDK_OUTPUT}/${SDKPATH}
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500203
204 install -m 0755 ${COREBASE}/meta/files/ext-sdk-prepare.sh ${SDK_OUTPUT}/${SDKPATH}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500205}
206
207# Since bitbake won't run as root it doesn't make sense to try and install
208# the extensible sdk as root.
209sdk_ext_preinst() {
210 if [ "`id -u`" = "0" ]; then
211 echo "ERROR: The extensible sdk cannot be installed as root."
212 exit 1
213 fi
214 SDK_EXTENSIBLE="1"
215}
216SDK_PRE_INSTALL_COMMAND_task-populate-sdk-ext = "${sdk_ext_preinst}"
217
218# FIXME this preparation should be done as part of the SDK construction
219sdk_ext_postinst() {
220 printf "\nExtracting buildtools...\n"
221 cd $target_sdk_dir
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500222 printf "buildtools\ny" | ./*buildtools-nativesdk-standalone* > /dev/null || ( printf 'ERROR: buildtools installation failed\n' ; exit 1 )
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500223
224 # Make sure when the user sets up the environment, they also get
225 # the buildtools-tarball tools in their path.
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500226 env_setup_script="$target_sdk_dir/environment-setup-${REAL_MULTIMACH_TARGET_SYS}"
227 echo ". $target_sdk_dir/buildtools/environment-setup*" >> $env_setup_script
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500228
229 # Allow bitbake environment setup to be ran as part of this sdk.
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500230 echo "export OE_SKIP_SDK_CHECK=1" >> $env_setup_script
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500231
232 # A bit of another hack, but we need this in the path only for devtool
233 # so put it at the end of $PATH.
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500234 echo "export PATH=\$PATH:$target_sdk_dir/sysroots/${SDK_SYS}/${bindir_nativesdk}" >> $env_setup_script
235
236 echo "printf 'SDK environment now set up; additionally you may now run devtool to perform development tasks.\nRun devtool --help for further details.\n'" >> $env_setup_script
237
238 # Warn if trying to use external bitbake and the ext SDK together
239 echo "(which bitbake > /dev/null 2>&1 && echo 'WARNING: attempting to use the extensible SDK in an environment set up to run bitbake - this may lead to unexpected results. Please source this script in a new shell session instead.') || true" >> $env_setup_script
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500240
241 # For now this is where uninative.bbclass expects the tarball
242 mv *-nativesdk-libc.tar.* $target_sdk_dir/`dirname ${oe_init_build_env_path}`
243
244 if [ "$prepare_buildsystem" != "no" ]; then
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500245 printf "Preparing build system...\n"
246 # dash which is /bin/sh on Ubuntu will not preserve the
247 # current working directory when first ran, nor will it set $1 when
248 # sourcing a script. That is why this has to look so ugly.
249 LOGFILE="$target_sdk_dir/preparing_build_system.log"
250 sh -c ". buildtools/environment-setup* > $LOGFILE && cd $target_sdk_dir/`dirname ${oe_init_build_env_path}` && set $target_sdk_dir && . $target_sdk_dir/${oe_init_build_env_path} $target_sdk_dir >> $LOGFILE && $target_sdk_dir/ext-sdk-prepare.sh $target_sdk_dir '${SDK_TARGETS}' >> $LOGFILE 2>&1" || { echo "ERROR: SDK preparation failed: see $LOGFILE"; echo "printf 'ERROR: this SDK was not fully installed and needs reinstalling\n'" >> $env_setup_script ; exit 1 ; }
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500251 fi
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500252 rm -f $target_sdk_dir/ext-sdk-prepare.sh
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500253 echo done
254}
255
256SDK_POST_INSTALL_COMMAND_task-populate-sdk-ext = "${sdk_ext_postinst}"
257
258SDK_POSTPROCESS_COMMAND_prepend_task-populate-sdk-ext = "copy_buildsystem; install_tools; "
259
260fakeroot python do_populate_sdk_ext() {
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500261 # FIXME hopefully we can remove this restriction at some point, but uninative
262 # currently forces this upon us
263 if d.getVar('SDK_ARCH', True) != d.getVar('BUILD_ARCH', True):
264 bb.fatal('The extensible SDK can currently only be built for the same architecture as the machine being built on - SDK_ARCH is set to %s (likely via setting SDKMACHINE) which is different from the architecture of the build machine (%s). Unable to continue.' % (d.getVar('SDK_ARCH', True), d.getVar('BUILD_ARCH', True)))
265
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500266 bb.build.exec_func("do_populate_sdk", d)
267}
268
269def get_sdk_ext_rdepends(d):
270 localdata = d.createCopy()
271 localdata.appendVar('OVERRIDES', ':task-populate-sdk-ext')
272 bb.data.update_data(localdata)
273 return localdata.getVarFlag('do_populate_sdk', 'rdepends', True)
274
275do_populate_sdk_ext[dirs] = "${@d.getVarFlag('do_populate_sdk', 'dirs', False)}"
276do_populate_sdk_ext[depends] += "${@d.getVarFlag('do_populate_sdk', 'depends', False)}"
277do_populate_sdk_ext[rdepends] = "${@get_sdk_ext_rdepends(d)}"
278do_populate_sdk_ext[recrdeptask] += "${@d.getVarFlag('do_populate_sdk', 'recrdeptask', False)}"
279
280
281do_populate_sdk_ext[depends] += "buildtools-tarball:do_populate_sdk uninative-tarball:do_populate_sdk"
282
283do_populate_sdk_ext[rdepends] += "${@' '.join([x + ':do_build' for x in d.getVar('SDK_TARGETS', True).split()])}"
284do_populate_sdk_ext[recrdeptask] += "do_populate_lic do_package_qa do_populate_sysroot do_deploy"
285
286# Make sure codes change in copy_buildsystem can result in rebuilt
287do_populate_sdk_ext[vardeps] += "copy_buildsystem"
288
289addtask populate_sdk_ext