[OE-core] [PATCH RFC 01/18] fs-uuid.bbclass: rewrite get_fs_uuid function
Martin Hundebøll
mnhu at prevas.dk
Wed Dec 20 08:00:32 UTC 2017
Hi,
On 2017-12-19 23:58, California Sullivan wrote:
> I couldn't find anywhere it was being used, and in trying to use it it
> just spit out an error.
>
> It now generates a random UUID and puts it in the deploy dir for
> consumption.
>
> Also use DISK_SIGNATURE_UUID for the replacement function, since that
> is user-overridable.
>
> Signed-off-by: California Sullivan <california.l.sullivan at intel.com>
> ---
> meta/classes/fs-uuid.bbclass | 32 ++++++++++++++++++++++----------
> 1 file changed, 22 insertions(+), 10 deletions(-)
>
> diff --git a/meta/classes/fs-uuid.bbclass b/meta/classes/fs-uuid.bbclass
> index 9b53dfba7ab..5a96054294e 100644
> --- a/meta/classes/fs-uuid.bbclass
> +++ b/meta/classes/fs-uuid.bbclass
> @@ -1,16 +1,26 @@
> +inherit deploy
> +
> # Extract UUID from ${ROOTFS}, which must have been built
> # by the time that this function gets called. Only works
> # on ext file systems and depends on tune2fs.
> def get_rootfs_uuid(d):
> - import subprocess
> - rootfs = d.getVar('ROOTFS')
> - output = subprocess.check_output(['tune2fs', '-l', rootfs])
> - for line in output.split('\n'):
> - if line.startswith('Filesystem UUID:'):
> - uuid = line.split()[-1]
> - bb.note('UUID of %s: %s' % (rootfs, uuid))
> - return uuid
> - bb.fatal('Could not determine filesystem UUID of %s' % rootfs)
> + import os
> + import uuid
> + deploydir = d.getVar('DEPLOY_DIR_IMAGE')
> + bootfs_uuid_file = deploydir + "/bootfs-uuid"
Maybe use a default assigned class variable here instead of the
hard-coded "bootfs-uuid". The class is named "get_rootfs_uuid", so I
would expect it to handle multiple cases.
> + uuid_str = "deadbeef-dead-beef-dead-beefdeadbeef"
> + if d.getVar('BUILD_REPRODUCIBLE_BINARIES', True) != "1":
> + if os.path.exists(bootfs_uuid_file):
> + with open(bootfs_uuid_file, "r+") as file:
> + uuid_str = file.read()
> + else:
> + # deploydir might not exist yet...creating it here could be bad?
> + if not os.path.exists(deploydir):
> + os.makedirs(deploydir)
> + uuid_str = str(uuid.uuid4())
> + with open(bootfs_uuid_file, "w") as file:
> + file.write(uuid_str)
> + return uuid_str
>
> # Replace the special <<uuid-of-rootfs>> inside a string (like the
> # root= APPEND string in a syslinux.cfg or systemd-boot entry) with the
> @@ -19,6 +29,8 @@ def get_rootfs_uuid(d):
> def replace_rootfs_uuid(d, string):
> UUID_PLACEHOLDER = '<<uuid-of-rootfs>>'
> if UUID_PLACEHOLDER in string:
> - uuid = get_rootfs_uuid(d)
> + uuid = d.getVar('DISK_SIGNATURE_UUID', True)
> string = string.replace(UUID_PLACEHOLDER, uuid)
> return string
> +
> +DISK_SIGNATURE_UUID ?= "${@get_rootfs_uuid(d)}"
>
--
MARTIN HUNDEBØLL, Prevas A/S
Software Developer
Hedeager 3, DK-8200 Aarhus N
Phone +45 87438070
Mobile +45 25562438
Martin.Hundeboll at prevas.dk
www.prevas.com
More information about the Openembedded-core
mailing list