Message ID | 20221110124503.274124-5-Quirin.Gylstorff@siemens.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | SWUpdate abort on installing indentical image | expand |
On 10.11.22 13:45, Quirin Gylstorff wrote: > From: Quirin Gylstorff <quirin.gylstorff@siemens.com> > > This writes the target_image_uuid to the Variable TARGET_IMAGE_UUID > which can be used to validate a update against the root file system. > > Signed-off-by: Quirin Gylstorff <quirin.gylstorff@siemens.com> > --- > classes/image_uuid.bbclass | 19 +++++++++++++++++++ > 1 file changed, 19 insertions(+) > > diff --git a/classes/image_uuid.bbclass b/classes/image_uuid.bbclass > index 277941b..3e2e3de 100644 > --- a/classes/image_uuid.bbclass > +++ b/classes/image_uuid.bbclass > @@ -13,6 +13,8 @@ > inherit rootfs > inherit image > > +# Generate the uuid from BB_TASKHASH to ensure a new > +# hash on each rebuild > def generate_image_uuid(d): > import uuid > > @@ -23,6 +25,23 @@ def generate_image_uuid(d): > > IMAGE_UUID ?= "${@generate_image_uuid(d)}" > > +def read_target_image_uuid(d): > + import os.path > + > + deploy_dir = d.getVar("DEPLOY_DIR_IMAGE") > + image_full_name = d.getVar("IMAGE_FULLNAME") > + uuid_file = f"{deploy_dir}/{image_full_name}.uuid.env" > + if not os.path.isfile(uuid_file): > + return None > + > + target_image_uuid = None > + with open(uuid_file, "r") as f: > + uuid_file_content = f.read() > + target_image_uuid = uuid_file_content.split('=')[1].strip(' \t\n\r').strip('\"') > + return target_image_uuid > + > +TARGET_IMAGE_UUID = "${@read_target_image_uuid(d)}" When is this evaluated by bitbake? Only on every access, inside a task context? Because the file it reads from only exists after do_generate_image_uuid, obviously. Jan > + > do_generate_image_uuid[vardeps] += "IMAGE_UUID" > do_generate_image_uuid[depends] = "buildchroot-target:do_build" > do_generate_image_uuid[dirs] = "${DEPLOY_DIR_IMAGE}"
On 11/10/22 14:56, Jan Kiszka wrote: > On 10.11.22 13:45, Quirin Gylstorff wrote: >> From: Quirin Gylstorff <quirin.gylstorff@siemens.com> >> >> This writes the target_image_uuid to the Variable TARGET_IMAGE_UUID >> which can be used to validate a update against the root file system. >> >> Signed-off-by: Quirin Gylstorff <quirin.gylstorff@siemens.com> >> --- >> classes/image_uuid.bbclass | 19 +++++++++++++++++++ >> 1 file changed, 19 insertions(+) >> >> diff --git a/classes/image_uuid.bbclass b/classes/image_uuid.bbclass >> index 277941b..3e2e3de 100644 >> --- a/classes/image_uuid.bbclass >> +++ b/classes/image_uuid.bbclass >> @@ -13,6 +13,8 @@ >> inherit rootfs >> inherit image >> >> +# Generate the uuid from BB_TASKHASH to ensure a new >> +# hash on each rebuild >> def generate_image_uuid(d): >> import uuid >> >> @@ -23,6 +25,23 @@ def generate_image_uuid(d): >> >> IMAGE_UUID ?= "${@generate_image_uuid(d)}" >> >> +def read_target_image_uuid(d): >> + import os.path >> + >> + deploy_dir = d.getVar("DEPLOY_DIR_IMAGE") >> + image_full_name = d.getVar("IMAGE_FULLNAME") >> + uuid_file = f"{deploy_dir}/{image_full_name}.uuid.env" >> + if not os.path.isfile(uuid_file): >> + return None >> + >> + target_image_uuid = None >> + with open(uuid_file, "r") as f: >> + uuid_file_content = f.read() >> + target_image_uuid = uuid_file_content.split('=')[1].strip(' \t\n\r').strip('\"') >> + return target_image_uuid >> + >> +TARGET_IMAGE_UUID = "${@read_target_image_uuid(d)}" > > When is this evaluated by bitbake? Only on every access, inside a task > context? Because the file it reads from only exists after > do_generate_image_uuid, obviously. > > Jan The variable will be evaluated on access from my testing. I tried to set the variable during do_generate_image_uuid which let to a empty variable in the followup tasks. Quirin > >> + >> do_generate_image_uuid[vardeps] += "IMAGE_UUID" >> do_generate_image_uuid[depends] = "buildchroot-target:do_build" >> do_generate_image_uuid[dirs] = "${DEPLOY_DIR_IMAGE}" >
diff --git a/classes/image_uuid.bbclass b/classes/image_uuid.bbclass index 277941b..3e2e3de 100644 --- a/classes/image_uuid.bbclass +++ b/classes/image_uuid.bbclass @@ -13,6 +13,8 @@ inherit rootfs inherit image +# Generate the uuid from BB_TASKHASH to ensure a new +# hash on each rebuild def generate_image_uuid(d): import uuid @@ -23,6 +25,23 @@ def generate_image_uuid(d): IMAGE_UUID ?= "${@generate_image_uuid(d)}" +def read_target_image_uuid(d): + import os.path + + deploy_dir = d.getVar("DEPLOY_DIR_IMAGE") + image_full_name = d.getVar("IMAGE_FULLNAME") + uuid_file = f"{deploy_dir}/{image_full_name}.uuid.env" + if not os.path.isfile(uuid_file): + return None + + target_image_uuid = None + with open(uuid_file, "r") as f: + uuid_file_content = f.read() + target_image_uuid = uuid_file_content.split('=')[1].strip(' \t\n\r').strip('\"') + return target_image_uuid + +TARGET_IMAGE_UUID = "${@read_target_image_uuid(d)}" + do_generate_image_uuid[vardeps] += "IMAGE_UUID" do_generate_image_uuid[depends] = "buildchroot-target:do_build" do_generate_image_uuid[dirs] = "${DEPLOY_DIR_IMAGE}"