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

u-boot: check the produced platform_install.sh (created from functions like write_uboot_platform) for shellcheck errors #7509

Conversation

rpardini
Copy link
Member

u-boot: check the produced platform_install.sh (created from functions like write_uboot_platform) for shellcheck errors

  • u-boot: check the produced platform_install.sh (created from functions like write_uboot_platform) for shellcheck errors
    • we've some smelly stuff in write_uboot_platform for some families that we'd rather catch early
    • implement small syntax fixes in setup_write_uboot_platform

@github-actions github-actions bot added size/medium PR with more then 50 and less then 250 lines Needs review Seeking for review Hardware Hardware related like kernel, U-Boot, ... Framework Framework components labels Nov 23, 2024
@rpardini rpardini marked this pull request as ready for review November 23, 2024 09:34
@rpardini rpardini requested review from a team and igorpecovnik as code owners November 23, 2024 09:34
Copy link
Member

@igorpecovnik igorpecovnik left a comment

Choose a reason for hiding this comment

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

why is using local not good?

@igorpecovnik igorpecovnik added Ready to merge Reviewed, tested and ready for merge and removed Needs review Seeking for review labels Dec 4, 2024
@rpardini
Copy link
Member Author

rpardini commented Dec 5, 2024

why is using local not good?

unclear what you're asking here? what local, what good?

@EvilOlaf
Copy link
Member

EvilOlaf commented Dec 5, 2024

I assume the question was about why local has been removed in a few places like https://github.com/armbian/build/pull/7509/files#diff-97ee188e57fa0d1ae8bc10a822bcb1bf7ec9fd3e66697c3a6c385f045513dce3R309

@igorpecovnik
Copy link
Member

Yes, local variable in function vs global. Probably makes no diff. just asking if there is a reasoning for this.

@rpardini
Copy link
Member Author

rpardini commented Dec 7, 2024

I assume the question was about why local has been removed in a few places like #7509 (files)

local variable in function vs global

That's not about local vs global. That's about the logic and specially the error control flow.

A statement with local x=1 does two things: 1) set the value of that variable and 2) declare a local variable. Those two things can fail, but in that specific order.

The return value ("success") of the local x=1 statement will be always true, because no matter if setting the value worked or not, declaring the variable as local always works. (Well not really, but for now lets say so).

Now for such simple (local x=1) statement that makes little difference. Let's take the case @EvilOlaf pointed out, despite that being horrible code:

local part=$(findfs PARTUUID=$tmp 2> /dev/null) # always works, even if findfs failed

So here, if findfs fails, we want to fail. But also here, local part will alway succeed, thus swallowing the error and driving people insane.

Thus one can separate the declaration of the variable scope in a statement, and the assignment in another, so the errors are not hidden.

local part # always works
part=$(findfs PARTUUID=$tmp 2> /dev/null) # will fail if findfs fails

I just realized I wrote a bad version of https://www.shellcheck.net/wiki/SC2155 so go read that instead.


Finally, why sometimes local and sometimes declare? That's a bit of bashism, I think, but declare also allows for extra modifiers (eg -r, -g, -A, -a and others).

…ons like write_uboot_platform) for shellcheck errors

- we've some smelly stuff in write_uboot_platform for some families that we'd rather catch early
- implement small syntax fixes in setup_write_uboot_platform
@rpardini rpardini force-pushed the pr/u-boot-check-the-produced-platforminstallsh-created-from-functions-like-writeubootplatform-for-shellcheck-errors branch from 7b785cc to d03771d Compare December 7, 2024 06:33
@github-actions github-actions bot added Needs review Seeking for review and removed Ready to merge Reviewed, tested and ready for merge labels Dec 7, 2024
@The-going
Copy link
Contributor

Has a full check of this code been done?
I mean, to assemble an image and run it on the device.

@rpardini
Copy link
Member Author

rpardini commented Dec 8, 2024

on the device.

Which device? I've tested the ones I have (rockchip64 and meson64).

@igorpecovnik igorpecovnik added the Ready to merge Reviewed, tested and ready for merge label Dec 9, 2024
@igorpecovnik igorpecovnik merged commit a55c8bf into armbian:main Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Framework Framework components Hardware Hardware related like kernel, U-Boot, ... Needs review Seeking for review Ready to merge Reviewed, tested and ready for merge size/medium PR with more then 50 and less then 250 lines
Development

Successfully merging this pull request may close these issues.

4 participants