diff options
author | Christopher Larson <chris_larson@mentor.com> | 2016-07-01 14:27:09 -0700 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-07-20 10:28:44 +0100 |
commit | 42e870c5ed4b01f7b79700373bd1f4b21b95028a (patch) | |
tree | e004bc14981c169bdfdc81111b880d8fdac3eb8a /meta | |
parent | be90c3ec5cabc64a63488b9e1bf1879155b43a6a (diff) | |
download | poky-42e870c5ed4b01f7b79700373bd1f4b21b95028a.tar.gz |
image_types.bbclass: support template .wks.in files for wic
These files are treated as the contents of a bitbake variable, so usual
bitbake variable references are supported. I considered using another
templating mechanism, for example the one used by yocto-layer, but then we'd
end up largely mapping metadata variables to template fields anyway, which is
a pointless indirection. Let bitbake expand the variables directly instead.
This feature lets us, for example, reference ${APPEND} in --append, and avoid
hardcoding the serial console tty in the wks file, and let the user's changes
to APPEND affect wic the way they do the other image construction mechanisms.
The template is read in and set in a variable at parse time, so changes to the
variables referenced by the template will result in rebuilding the image.
(From OE-Core rev: 51cb21fe5f050874d52f5b05a8a1de79ea4ebf2f)
Signed-off-by: Christopher Larson <chris_larson@mentor.com>
Signed-off-by: Ross Burton <ross.burton@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta')
-rw-r--r-- | meta/classes/image_types.bbclass | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/meta/classes/image_types.bbclass b/meta/classes/image_types.bbclass index f7de756b71..2b97397a51 100644 --- a/meta/classes/image_types.bbclass +++ b/meta/classes/image_types.bbclass | |||
@@ -218,6 +218,52 @@ USING_WIC = "${@bb.utils.contains_any('IMAGE_FSTYPES', 'wic ' + ' '.join('wic.%s | |||
218 | WKS_FILE_CHECKSUM = "${@'${WKS_FULL_PATH}:%s' % os.path.exists('${WKS_FULL_PATH}') if '${USING_WIC}' else ''}" | 218 | WKS_FILE_CHECKSUM = "${@'${WKS_FULL_PATH}:%s' % os.path.exists('${WKS_FULL_PATH}') if '${USING_WIC}' else ''}" |
219 | do_image_wic[file-checksums] += "${WKS_FILE_CHECKSUM}" | 219 | do_image_wic[file-checksums] += "${WKS_FILE_CHECKSUM}" |
220 | 220 | ||
221 | python do_write_wks_template () { | ||
222 | """Write out expanded template contents to WKS_FULL_PATH.""" | ||
223 | import re | ||
224 | |||
225 | template_body = d.getVar('_WKS_TEMPLATE', True) | ||
226 | |||
227 | # Remove any remnant variable references left behind by the expansion | ||
228 | # due to undefined variables | ||
229 | expand_var_regexp = re.compile(r"\${[^{}@\n\t :]+}") | ||
230 | while True: | ||
231 | new_body = re.sub(expand_var_regexp, '', template_body) | ||
232 | if new_body == template_body: | ||
233 | break | ||
234 | else: | ||
235 | template_body = new_body | ||
236 | |||
237 | wks_file = d.getVar('WKS_FULL_PATH', True) | ||
238 | with open(wks_file, 'w') as f: | ||
239 | f.write(template_body) | ||
240 | } | ||
241 | |||
242 | python () { | ||
243 | if d.getVar('USING_WIC', True): | ||
244 | wks_file_u = d.getVar('WKS_FULL_PATH', False) | ||
245 | wks_file = d.expand(wks_file_u) | ||
246 | base, ext = os.path.splitext(wks_file) | ||
247 | if ext == '.in' and os.path.exists(wks_file): | ||
248 | wks_out_file = os.path.join(d.getVar('WORKDIR', True), os.path.basename(base)) | ||
249 | d.setVar('WKS_FULL_PATH', wks_out_file) | ||
250 | d.setVar('WKS_TEMPLATE_PATH', wks_file_u) | ||
251 | d.setVar('WKS_FILE_CHECKSUM', '${WKS_TEMPLATE_PATH}:True') | ||
252 | |||
253 | try: | ||
254 | with open(wks_file, 'r') as f: | ||
255 | body = f.read() | ||
256 | except (IOError, OSError) as exc: | ||
257 | pass | ||
258 | else: | ||
259 | # Previously, I used expandWithRefs to get the dependency list | ||
260 | # and add it to WICVARS, but there's no point re-parsing the | ||
261 | # file in process_wks_template as well, so just put it in | ||
262 | # a variable and let the metadata deal with the deps. | ||
263 | d.setVar('_WKS_TEMPLATE', body) | ||
264 | bb.build.addtask('do_write_wks_template', 'do_image_wic', None, d) | ||
265 | } | ||
266 | |||
221 | EXTRA_IMAGECMD = "" | 267 | EXTRA_IMAGECMD = "" |
222 | 268 | ||
223 | inherit siteinfo | 269 | inherit siteinfo |