public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
From: "Maxim Yu. Osipov" <mosipov@ilbers.de>
To: Cedric Hombourger <Cedric_Hombourger@mentor.com>,
	isar-users@googlegroups.com
Subject: Re: [PATCH v2] wic-img: import support for .wks.in files from oe-core
Date: Fri, 15 Feb 2019 18:43:28 +0100	[thread overview]
Message-ID: <c941888a-4f60-62cc-a2e1-b76f46fd3321@ilbers.de> (raw)
In-Reply-To: <1549653186-1216-1-git-send-email-Cedric_Hombourger@mentor.com>

On 2/8/19 8:13 PM, Cedric Hombourger wrote:
> OpenEmbedded supports use of variables in wks files if they are
> suffixed with .wks.in (instead of .wks). Use of this suffix adds
> a task to the build process to expand variables to their values
> when known or to the empty string when they are not. The result
> of the evaluation is placed in a regular .wks file placed in the
> build folder.
> 
> The .wks file for the de0-nano-soc machine was modified to show
> use of this feature and get it regularly tested as part of our
> regular Isar builds.

Applied to the 'next',

Thanks,
Maxim.

> Signed-off-by: Cedric Hombourger <Cedric_Hombourger@mentor.com>
> ---
>   doc/user_manual.md                                 |  2 +
>   meta-isar/conf/machine/de0-nano-soc.conf           |  2 +-
>   .../{de0-nano-soc.wks => de0-nano-soc.wks.in}      |  2 +-
>   meta/classes/wic-img.bbclass                       | 53 +++++++++++++++++++++-
>   4 files changed, 55 insertions(+), 4 deletions(-)
>   rename meta-isar/scripts/lib/wic/canned-wks/{de0-nano-soc.wks => de0-nano-soc.wks.in} (63%)
> 
> diff --git a/doc/user_manual.md b/doc/user_manual.md
> index ebc31c6..252d2ef 100644
> --- a/doc/user_manual.md
> +++ b/doc/user_manual.md
> @@ -197,6 +197,8 @@ A bootable disk image is generated if you set IMAGE_TYPE to 'wic-img'. Behind th
>    $ bitbake multiconfig:qemuamd64-stretch:isar-image-base
>   ```
>   
> +Variables may be used in `.wks.in` files; Isar will expand them and generate a regular `.wks` file before generating the disk image using `wic`.
> +
>   In order to run the EFI images with `qemu`, an EFI firmware is required and available at the following address:
>   https://github.com/tianocore/edk2/tree/3858b4a1ff09d3243fea8d07bd135478237cb8f7
>   
> diff --git a/meta-isar/conf/machine/de0-nano-soc.conf b/meta-isar/conf/machine/de0-nano-soc.conf
> index 63b2cfb..3a2c009 100644
> --- a/meta-isar/conf/machine/de0-nano-soc.conf
> +++ b/meta-isar/conf/machine/de0-nano-soc.conf
> @@ -11,7 +11,7 @@ U_BOOT_CONFIG_de0-nano-soc = "socfpga_de0_nano_soc_defconfig"
>   U_BOOT_BIN_de0-nano-soc = "u-boot-with-spl.sfp"
>   
>   IMAGE_TYPE ?= "wic-img"
> -WKS_FILE ?= "de0-nano-soc"
> +WKS_FILE ?= "de0-nano-soc.wks.in"
>   IMAGER_INSTALL += "u-boot-de0-nano-soc"
>   IMAGER_BUILD_DEPS += "u-boot-de0-nano-soc"
>   
> diff --git a/meta-isar/scripts/lib/wic/canned-wks/de0-nano-soc.wks b/meta-isar/scripts/lib/wic/canned-wks/de0-nano-soc.wks.in
> similarity index 63%
> rename from meta-isar/scripts/lib/wic/canned-wks/de0-nano-soc.wks
> rename to meta-isar/scripts/lib/wic/canned-wks/de0-nano-soc.wks.in
> index 184474d..05ce61b 100644
> --- a/meta-isar/scripts/lib/wic/canned-wks/de0-nano-soc.wks
> +++ b/meta-isar/scripts/lib/wic/canned-wks/de0-nano-soc.wks.in
> @@ -3,7 +3,7 @@
>   #
>   # SPDX-License-Identifier: MIT
>   
> -part --source rawcopy --sourceparams "file=/usr/lib/u-boot/de0-nano-soc/u-boot-with-spl.sfp" --system-id 0xa2 --align 1
> +part --source rawcopy --sourceparams "file=/usr/lib/u-boot/${MACHINE}/${U_BOOT_BIN}" --system-id 0xa2 --align 1
>   
>   part / --source rootfs-u-boot --ondisk mmcblk0 --fstype ext4 --label platform --align 1024 --active
>   
> diff --git a/meta/classes/wic-img.bbclass b/meta/classes/wic-img.bbclass
> index 76602d8..c9d90a9 100644
> --- a/meta/classes/wic-img.bbclass
> +++ b/meta/classes/wic-img.bbclass
> @@ -4,13 +4,36 @@
>   # this class is heavily inspired by OEs ./meta/classes/image_types_wic.bbclass
>   #
>   
> +WKS_FILE_CHECKSUM = "${@'${WKS_FULL_PATH}:%s' % os.path.exists('${WKS_FULL_PATH}')}"
> +
> +python do_write_wks_template () {
> +    """Write out expanded template contents to WKS_FULL_PATH."""
> +    import re
> +
> +    template_body = d.getVar('_WKS_TEMPLATE')
> +
> +    # Remove any remnant variable references left behind by the expansion
> +    # due to undefined variables
> +    expand_var_regexp = re.compile(r"\${[^{}@\n\t :]+}")
> +    while True:
> +        new_body = re.sub(expand_var_regexp, '', template_body)
> +        if new_body == template_body:
> +            break
> +        else:
> +            template_body = new_body
> +
> +    wks_file = d.getVar('WKS_FULL_PATH')
> +    with open(wks_file, 'w') as f:
> +        f.write(template_body)
> +}
> +
>   python () {
>       wks_full_path = None
>   
>       wks_file = d.getVar('WKS_FILE', True)
>       if not wks_file:
>           bb.fatal("WKS_FILE must be set")
> -    if not wks_file.endswith('.wks'):
> +    if not wks_file.endswith('.wks') and not wks_file.endswith('.wks.in'):
>           wks_file += '.wks'
>   
>       if os.path.isabs(wks_file):
> @@ -28,6 +51,32 @@ python () {
>           bb.fatal("WKS_FILE '%s' not found" % wks_file)
>   
>       d.setVar('WKS_FULL_PATH', wks_full_path)
> +
> +    wks_file_u = wks_full_path
> +    wks_file = wks_full_path
> +    base, ext = os.path.splitext(wks_file)
> +    if ext == '.in' and os.path.exists(wks_file):
> +        wks_out_file = os.path.join(d.getVar('WORKDIR'), os.path.basename(base))
> +        d.setVar('WKS_FULL_PATH', wks_out_file)
> +        d.setVar('WKS_TEMPLATE_PATH', wks_file_u)
> +        d.setVar('WKS_FILE_CHECKSUM', '${WKS_TEMPLATE_PATH}:True')
> +
> +        # We need to re-parse each time the file changes, and bitbake
> +        # needs to be told about that explicitly.
> +        bb.parse.mark_dependency(d, wks_file)
> +
> +        try:
> +            with open(wks_file, 'r') as f:
> +                body = f.read()
> +        except (IOError, OSError) as exc:
> +            pass
> +        else:
> +            # Previously, I used expandWithRefs to get the dependency list
> +            # and add it to WICVARS, but there's no point re-parsing the
> +            # file in process_wks_template as well, so just put it in
> +            # a variable and let the metadata deal with the deps.
> +            d.setVar('_WKS_TEMPLATE', body)
> +            bb.build.addtask('do_write_wks_template', 'do_wic_image', None, d)
>   }
>   
>   inherit buildchroot
> @@ -108,7 +157,7 @@ do_wic_image() {
>       cp -f $(ls -t -1 ${BUILDCHROOT_DIR}/tmp/${IMAGE_FULLNAME}.wic/*.direct | head -1) ${WIC_IMAGE_FILE}
>   }
>   
> -do_wic_image[file-checksums] += "${WKS_FULL_PATH}:True"
> +do_wic_image[file-checksums] += "${WKS_FILE_CHECKSUM}"
>   do_wic_image[depends] = "buildchroot-target:do_build"
>   
>   addtask wic_image before do_build after do_install_imager_deps
> 


-- 
Maxim Osipov
ilbers GmbH
Maria-Merian-Str. 8
85521 Ottobrunn
Germany
+49 (151) 6517 6917
mosipov@ilbers.de
http://ilbers.de/
Commercial register Munich, HRB 214197
General Manager: Baurzhan Ismagulov

  reply	other threads:[~2019-02-15 17:43 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-08  7:02 [PATCH] wic-img: handle variables in .wks files Cedric Hombourger
2019-02-08  7:42 ` Jan Kiszka
2019-02-08  7:44   ` Hombourger, Cedric
2019-02-08  7:48     ` Jan Kiszka
2019-02-08  7:53       ` Jan Kiszka
2019-02-08  7:55         ` Hombourger, Cedric
2019-02-08 11:32         ` Hombourger, Cedric
2019-02-08 13:50         ` Hombourger, Cedric
2019-02-08 19:13           ` [PATCH v2] wic-img: import support for .wks.in files from oe-core Cedric Hombourger
2019-02-15 17:43             ` Maxim Yu. Osipov [this message]
2019-02-08 14:28 ` [PATCH] wic-img: handle variables in .wks files Henning Schild
2019-02-08 14:31   ` Hombourger, Cedric
2019-02-08 14:31   ` Jan Kiszka
2019-02-08 16:27     ` Henning Schild

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c941888a-4f60-62cc-a2e1-b76f46fd3321@ilbers.de \
    --to=mosipov@ilbers.de \
    --cc=Cedric_Hombourger@mentor.com \
    --cc=isar-users@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox