Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reproducible build #240

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft

Reproducible build #240

wants to merge 2 commits into from

Conversation

PLangowski
Copy link
Collaborator

No description provided.

@PLangowski PLangowski marked this pull request as draft February 17, 2025 13:15
@@ -0,0 +1,3 @@
FILESEXTRAPATHS:prepend := "${THISDIR}/lshw:"

SRC_URI:append = " file://0001-src-Makefile-Use-gzip-with-n-option.patch"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there no way to pass flags without patches?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried EXTRA_OEMAKE += "GZIP='gzip -9 -n'", but got this:

| gzip -9 -n -c pci.ids > pci.ids.gz
| gzip -9 -n -c usb.ids > usb.ids.gz
| gzip -9 -n -c oui.txt > oui.txt.gz
| gzip -9 -n -c manuf.txt > manuf.txt.gz
| gzip: gzip: gzip: abort: cannot provide files in GZIP environment variableabort: cannot provide files in GZIP environment variableabort: cannot provide files in GZIP environment variable

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try:

EXTRA_OEMAKE += "GZIP='-9 -n'"

do_image_wic:prepend() {
WKS_FILE="${WORKDIR}/usb-stick-dts.wks"
UUID="${@'$(echo ${LAYER_COMMIT_SHA} | cut -c1-8)-$(echo ${LAYER_COMMIT_SHA} | cut -c9-12)-4$(echo ${LAYER_COMMIT_SHA} | cut -c13-15)-$(echo ${LAYER_COMMIT_SHA} | cut -c16-19)-$(echo ${LAYER_COMMIT_SHA} | cut -c20-31)'}"
sed -i "s/--use-uuid/--uuid $UUID/" $WKS_FILE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with this is the following:
We need to evaluate a bash command to create a uuid based on the commit SHA. I tried defining the UUIDs in this recipe and passing them to WICVARS

 ROOT_UUID="${@'$(echo ${LAYER_COMMIT_SHA} | sha256sum | cut -c1-8)-$(echo ${LAYER_COMMIT_SHA} | sha256sum | cut -c9-12)-4$(echo ${LAYER_COMMIT_SHA} | sha256sum | cut -c13-15)-$(echo ${LAYER_COMMIT_SHA} | sha256sum | cut -c16-19)-$(echo ${LAYER_COMMIT_SHA} | sha256sum | cut -c20-31)'}"
BOOT_UUID="${@'$(echo "boot-${LAYER_COMMIT_SHA}" | sha256sum | cut -c1-8)-$(echo "boot-${LAYER_COMMIT_SHA}" | sha256sum | cut -c9-12)-4$(echo "boot-${LAYER_COMMIT_SHA}" | sha256sum | cut -c13-15)-$(echo "boot-${LAYER_COMMIT_SHA}" | sha256sum | cut -c16-19)-$(echo "boot-${LAYER_COMMIT_SHA}" | sha256sum | cut -c20-31)'}"

WICVARS += "ROOT_UUID BOOT_UUID "

but the commands were not evaluated, so the variables were passed to wks in the form of commands. I'm not sure how else I could pass them aside from the original idea. Unless we want to set fixed UUIDs, then it becomes a simple matter.

Copy link
Contributor

@m-iwanicki m-iwanicki Feb 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look at how every other recipe does this. Usually with python. I'm not sure if sh evaluation works:
https://docs.yoctoproject.org/bitbake/2.2/bitbake-user-manual/bitbake-user-manual-metadata.html#inline-python-variable-expansion

You could just define task and set value of this variable there: https://docs.yoctoproject.org/bitbake/2.2/bitbake-user-manual/bitbake-user-manual-metadata.html#exporting-variables-to-the-environment

You might write python task to begin with: https://docs.yoctoproject.org/bitbake/2.2/bitbake-user-manual/bitbake-user-manual-metadata.html#bitbake-style-python-functions
or just use this: https://docs.yoctoproject.org/bitbake/2.2/bitbake-user-manual/bitbake-user-manual-metadata.html#python-functions

BOOT_UUID="${@get_uuid('boot')}"
ROOT_UUID="${@get_uuid('root')}"

def get_uuid(string):
    import hashlib, uuid
    return str(uuid.UUID(hashlib.md5(f"{commit}{string}".encode()).hexdigest()))

you need to somehow get commit in python func. Not tested so there probably are mistakes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found do_rootfs_wicenv: https://git.yoctoproject.org/poky/plain/meta/classes-recipe/image_types_wic.bbclass
Maybe I can append the evaluated variables to the .env file there

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I can append the evaluated variables to the .env file there

why?

but the commands were not evaluated, so the variables were passed to wks in the form of commands

I think the problem was that you used wrong format. You can also use immediate variable expansion to make sure.
I think you tried to use bash script in python evaluation ('@'). Not only that but it's possible that it's because of ' in ${@'. It's possible that everything between '' was treated as string

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You forgot to include commit sha. I think it should be something like:

BOOT_UUID="${@get_uuid('boot' + d.getVar('LAYER_COMMIT_SHA'))}"
ROOT_UUID="${@get_uuid('root' + d.getVar('LAYER_COMMIT_SHA'))}"

Check if it works (and check if LAYER_COMMIT_SHA is evaluated correctly)

@PLangowski PLangowski force-pushed the reproducible-build branch 2 times, most recently from 1fc2090 to d66533a Compare February 21, 2025 09:05
@@ -32,3 +34,17 @@ local_autologin () {
}

ROOTFS_POSTPROCESS_COMMAND += "local_autologin; "

python do_rootfs_wicenv:append() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My previous suggestions didn't work? Because it's way more complicated and error prone

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I said, if done outside a task, they variables will not be evaluated before passed to the env

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I didn't see your comment above. I will try that

@@ -21,6 +21,17 @@ IMAGE_INSTALL:append = " \
lshw \
"

LAYER_COMMIT_SHA := "`cd ${LAYERDIR} && git rev-parse HEAD`"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use ` for shell evaluation

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Signed-off-by: Pawel Langowski <pawel.langowski@3mdeb.com>
Signed-off-by: Pawel Langowski <pawel.langowski@3mdeb.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants