AerithForge / the-ai-experiments

Repository for AI experiments
https://www.armbian.com
GNU General Public License v2.0
0 stars 0 forks source link

Sweep (map): Get rid of 'x-hack' such as [ “x$var” = “xval” ] from the code #2

Open Kreyren opened 11 months ago

Kreyren commented 11 months ago

x-hack is a shell/bash conditional using any letter (often 'x' thus the 'x-hack' name) followed by variable declaration ${var} and checking against the same letter followed by value such as:

# bash
[[ “x$var” == “xval” ]]

# POSIX shell
[ “x$var” = “xval” ]

This was done to ensure compatibility across different shells and systems many years ago, but today it's obsolete as the shells evolved enough to be more reliable.

That said the armbian codebase is still using them for some reason and it was agreed that these should be replaced so i want you to look through the codebase and fix all x-hacks.

Note that the declaration can also be written without quotes:

[[ x$var == xval ]]

Or even checking for a directory:

[[ x$var == xval/ ]]

Prefer to use e.g. [ -z "$var" ] over [ "$var" = "" ]

The following files alll have issues with x-hacks, try to address it

Break the following ~30 files into 6 issues editing 5 files each.

./packages/blobs/grub/09_linux_with_dtb.sh ./packages/bsp/nanopim4/nanopim4-pwm-fan.sh ./lib/tools/shellcheck.sh ./lib/functions/artifacts/artifact-armbian-bsp-cli.sh ./lib/functions/artifacts/artifact-firmware.sh ./lib/functions/rootfs/distro-specific.sh ./lib/functions/artifacts/artifacts-obtain.sh ./lib/functions/artifacts/artifacts-reversion.sh ./lib/functions/artifacts/artifact-uboot.sh ./lib/functions/artifacts/artifact-armbian-base-files.sh ./lib/functions/cli/entrypoint.sh ./lib/functions/artifacts/artifact-rootfs.sh ./lib/functions/artifacts/artifact-kernel.sh ./lib/functions/cli/commands.sh ./lib/functions/artifacts/artifact-full_firmware.sh ./lib/functions/cli/utils-cli.sh ./lib/functions/main/config-prepare.sh ./lib/functions/main/start-end.sh ./lib/functions/artifacts/artifact-fake-ubuntu-advantage-tools.sh ./lib/functions/cli/cli-patch.sh ./lib/functions/artifacts/artifact-armbian-zsh.sh ./lib/functions/rootfs/distro-agnostic.sh ./lib/functions/main/build-packages.sh ./lib/functions/artifacts/artifact-armbian-plymouth-theme.sh ./lib/functions/cli/cli-distccd.sh ./lib/functions/artifacts/artifact-armbian-desktop.sh ./lib/functions/cli/cli-configdump.sh ./lib/functions/artifacts/artifact-armbian-config.sh ./lib/functions/artifacts/artifact-armbian-bsp-desktop.sh ./lib/functions/logging/trap-logging.sh ./lib/functions/logging/traps.sh ./lib/functions/rootfs/create-cache.sh ./lib/functions/rootfs/rootfs-create.sh ./lib/functions/image/partitioning.sh ./lib/functions/image/initrd.sh ./lib/functions/image/rootfs-to-image.sh ./lib/functions/logging/runners.sh ./lib/functions/image/loop.sh ./lib/functions/logging/logging.sh ./lib/functions/logging/export-logs.sh ./lib/functions/logging/debug-dump.sh ./lib/functions/image/compress-checksum.sh ./lib/functions/logging/capture.sh ./lib/functions/host/host-utils.sh ./lib/functions/compilation/kernel-debs.sh ./extensions/grub-sbc-media.sh ./lib/functions/compilation/uboot.sh ./extensions/lsmod.sh ./extensions/nomod.sh ./extensions/nvidia.sh ./extensions/v4l2loopback-dkms.sh ./extensions/zfs.sh ./lib/functions/compilation/utils-compilation.sh ./lib/functions/compilation/kernel-make.sh ./lib/functions/compilation/kernel.sh ./extensions/grub.sh ./lib/functions/general/git-ref2info.sh ./lib/functions/general/apt-utils.sh ./extensions/gen-sample-extension-docs.sh ./lib/functions/general/shellcheck.sh ./lib/functions/general/python-tools.sh ./lib/functions/general/memoize-cached.sh ./lib/functions/general/oci-oras.sh ./lib/functions/compilation/patch/drivers-harness.sh ./lib/functions/general/hash-files.sh ./lib/functions/compilation/packages/utils-dpkgdeb.sh ./lib/functions/compilation/patch/patching.sh ./lib/functions/host/wsl2.sh ./lib/functions/compilation/distcc.sh ./lib/functions/host/prepare-host.sh ./lib/functions/compilation/crust.sh ./lib/functions/general/downloads.sh ./lib/functions/bsp/armbian-bsp-cli-deb.sh ./lib/functions/general/git.sh ./lib/functions/configuration/menu.sh ./lib/functions/host/docker.sh ./lib/functions/configuration/main-config.sh ./lib/functions/host/tmpfs-utils.sh ./lib/functions/host/mktemp-utils.sh ./lib/functions/compilation/atf.sh ./lib/functions/configuration/interactive.sh ./lib/functions/configuration/config-desktop.sh ./lib/functions/compilation/armbian-kernel.sh ./lib/functions/general/chroot-helpers.sh ./lib/functions/general/extensions.sh ./lib/functions/configuration/package-lists.sh


Checklist:

**Replace 'x-hack' conditionals in artifact-armbian-bsp-cli.sh and artifact-firmware.sh** * In lib/functions/artifacts/artifact-armbian-bsp-cli.sh, replace all 'x-hack' conditionals with modern conditionals. * In lib/functions/artifacts/artifact-firmware.sh, replace all 'x-hack' conditionals with modern conditionals.
**Replace 'x-hack' conditionals in artifact-armbian-base-files.sh and artifact-uboot.sh** * In lib/functions/artifacts/artifact-armbian-base-files.sh, replace all 'x-hack' conditionals with modern conditionals. * In lib/functions/artifacts/artifact-uboot.sh, replace all 'x-hack' conditionals with modern conditionals.
**Replace 'x-hack' conditionals in artifact-rootfs.sh and artifact-kernel.sh** * In lib/functions/artifacts/artifact-rootfs.sh, replace all 'x-hack' conditionals with modern conditionals. * In lib/functions/artifacts/artifact-kernel.sh, replace all 'x-hack' conditionals with modern conditionals.
**Replace 'x-hack' conditionals in artifact-full_firmware.sh and artifact-fake-ubuntu-advantage-tools.sh** * In lib/functions/artifacts/artifact-full_firmware.sh, replace all 'x-hack' conditionals with modern conditionals. * In lib/functions/artifacts/artifact-fake-ubuntu-advantage-tools.sh, replace all 'x-hack' conditionals with modern conditionals.
**Replace 'x-hack' conditionals in artifact-armbian-zsh.sh and artifact-armbian-plymouth-theme.sh** * In lib/functions/artifacts/artifact-armbian-zsh.sh, replace all 'x-hack' conditionals with modern conditionals. * In lib/functions/artifacts/artifact-armbian-plymouth-theme.sh, replace all 'x-hack' conditionals with modern conditionals.
**Replace 'x-hack' conditionals in artifact-armbian-config.sh and artifact-armbian-bsp-desktop.sh** * In lib/functions/artifacts/artifact-armbian-config.sh, replace all 'x-hack' conditionals with modern conditionals. * In lib/functions/artifacts/artifact-armbian-bsp-desktop.sh, replace all 'x-hack' conditionals with modern conditionals.
sweep-ai[bot] commented 11 months ago
Sweeping

100%
⚡ Sweep Free Trial: I'm creating this ticket using GPT-4. You have 4 GPT-4 tickets left for the month and 2 for the day. For more GPT-4 tickets, visit our payment portal.

Actions (click)


Step 1: 🔎 Searching

I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.

Some code snippets I looked at (click to expand). If some file is missing from here, you can mention the path in the ticket description. https://github.com/AerithForge/the-ai-experiments/blob/6f5112cdc8e23b172f8940601d9b1471b4bfd87d/lib/functions/artifacts/artifact-armbian-bsp-cli.sh#L205-L174 https://github.com/AerithForge/the-ai-experiments/blob/6f5112cdc8e23b172f8940601d9b1471b4bfd87d/lib/functions/artifacts/artifact-armbian-desktop.sh#L1-L108 https://github.com/AerithForge/the-ai-experiments/blob/6f5112cdc8e23b172f8940601d9b1471b4bfd87d/lib/functions/artifacts/artifact-armbian-bsp-desktop.sh#L1-L105 https://github.com/AerithForge/the-ai-experiments/blob/6f5112cdc8e23b172f8940601d9b1471b4bfd87d/lib/functions/artifacts/artifact-firmware.sh#L1-L96 https://github.com/AerithForge/the-ai-experiments/blob/6f5112cdc8e23b172f8940601d9b1471b4bfd87d/lib/functions/artifacts/artifact-full_firmware.sh#L1-L106

Step 2: ⌨️ Coding

I'm creating the following subissues:

Replace 'x-hack' conditionals in artifact-armbian-bsp-cli.sh and artifact-firmware.sh:

* In lib/functions/artifacts/artifact-armbian-bsp-cli.sh, replace all 'x-hack' conditionals with modern conditionals. * In lib/functions/artifacts/artifact-firmware.sh, replace all 'x-hack' conditionals with modern conditionals.

Replace 'x-hack' conditionals in artifact-armbian-base-files.sh and artifact-uboot.sh:

* In lib/functions/artifacts/artifact-armbian-base-files.sh, replace all 'x-hack' conditionals with modern conditionals. * In lib/functions/artifacts/artifact-uboot.sh, replace all 'x-hack' conditionals with modern conditionals.

Replace 'x-hack' conditionals in artifact-rootfs.sh and artifact-kernel.sh:

* In lib/functions/artifacts/artifact-rootfs.sh, replace all 'x-hack' conditionals with modern conditionals. * In lib/functions/artifacts/artifact-kernel.sh, replace all 'x-hack' conditionals with modern conditionals.

Replace 'x-hack' conditionals in artifact-full_firmware.sh and artifact-fake-ubuntu-advantage-tools.sh:

* In lib/functions/artifacts/artifact-full_firmware.sh, replace all 'x-hack' conditionals with modern conditionals. * In lib/functions/artifacts/artifact-fake-ubuntu-advantage-tools.sh, replace all 'x-hack' conditionals with modern conditionals.

Replace 'x-hack' conditionals in artifact-armbian-zsh.sh and artifact-armbian-plymouth-theme.sh:

* In lib/functions/artifacts/artifact-armbian-zsh.sh, replace all 'x-hack' conditionals with modern conditionals. * In lib/functions/artifacts/artifact-armbian-plymouth-theme.sh, replace all 'x-hack' conditionals with modern conditionals.

Replace 'x-hack' conditionals in artifact-armbian-config.sh and artifact-armbian-bsp-desktop.sh:

* In lib/functions/artifacts/artifact-armbian-config.sh, replace all 'x-hack' conditionals with modern conditionals. * In lib/functions/artifacts/artifact-armbian-bsp-desktop.sh, replace all 'x-hack' conditionals with modern conditionals.

Step 3: 🔁 Code Review

I finished creating the subissues! Track them at:


🎉 Latest improvements to Sweep:


💡 To recreate the pull request edit the issue title or description. To tweak the pull request, leave a comment on the pull request. Join Our Discord