ToyKeeper / anduril

Anduril 2 Flashlight Firmware and FSM UI Toolkit
GNU General Public License v3.0
232 stars 57 forks source link

./make anduril - No such file or directory #13

Closed GarikFirst closed 11 months ago

GarikFirst commented 11 months ago

I’m running GNU bash, version 5.2.15(1)-release (aarch64-apple-darwin22.1.0) from homebrew on macOS Sonoma 14.1, globstar option is on:

MacBook-Pro14-username:anduril username$ shopt globstar
globstar        on

But all builds failing with invalid shell option name and of course No such file or directory

MacBook-Pro14-username:anduril username $ ./make anduril
./make: line 11: shopt: globstar: invalid shell option name
===== anduril : fireflies-e01- =====
ui/anduril/anduril.c:45:23: fatal error: hw/fireflies/e01: No such file or directory
   45 | #include incfile(CFG_H)
      |                       ^
compilation terminated.
ERROR: build failed
===== anduril : fireflies-pl47--219 =====
ui/anduril/anduril.c:45:23: fatal error: hw/fireflies/pl47: No such file or directory
   45 | #include incfile(CFG_H)
      |                       ^
compilation terminated.
ERROR: build failed
SiteRelEnby commented 11 months ago

Relevant: https://github.com/ToyKeeper/anduril/pull/15

MacOS doing MacOS things, I guess.

ToyKeeper commented 11 months ago

Can you use zsh?

I prefer zsh, but tried to write the script using only bash-isms because I thought it would already be installed and was unlikely to break. But I guess the feature I wanted to use isn't as reliable as I thought. Switching to zsh should fix it, but at the expense of adding a build dependency which is less likely to be pre-installed.

ToyKeeper commented 11 months ago

... or is this just a matter of finding the correct bash executable? Like, would using "env bash" fix it? (i.e. system bash is too barebones, but brew bash works fine)

gretel commented 11 months ago

this is not a macos issue, but a portability one.

i.e. linting the file gives quite some output. personally i would suggest to go the Makefile way cause trying to solve portability issues on the shell is like reinventing wheels.

$ shellcheck make

In make line 53:
    -h|--help|help|/?|/h|/help)
                   ^-- SC2221 (warning): This pattern always overrides a later one on line 53.
                      ^-- SC2222 (warning): This pattern never matches because of a previous pattern on line 53.

In make line 58:
      rm -vf **/*~ hex/*.hex ui/**/*.elf ui/**/*.o ui/**/*.cpp
             ^-- SC2035 (info): Use ./*glob* or -- *glob* so names with dashes won't become options.

In make line 79:
      grep -E 'TODO:|FIXME:' **/*.[ch]
                             ^-- SC2035 (info): Use ./*glob* or -- *glob* so names with dashes won't become options.

In make line 90:
    html=$(echo "$md" | sed 's/.md$/.html/')
           ^-- SC2001 (style): See if you can use ${variable//search/replace} instead.

In make line 96:
BASEDIR=$(dirname $0)
                  ^-- SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean:
BASEDIR=$(dirname "$0")

In make line 97:
cd "$BASEDIR"
^-----------^ SC2164 (warning): Use 'cd ... || exit' or 'cd ... || return' in case cd fails.

Did you mean:
cd "$BASEDIR" || exit
$ shellcheck bin/build-all.sh

In bin/build-all.sh line 9:
if [ ! -z "$1" ]; then
     ^-- SC2236 (style): Use -n instead of ! -z.

In bin/build-all.sh line 11:
  SEARCH=$@
         ^-- SC2124 (warning): Assigning an array to a string! Assign as array, or use * instead of @ to concatenate.

In bin/build-all.sh line 29:
for TARGET in $( find hw/*/*/ -name "$UI".h ) ; do
              ^-----------------------------^ SC2044 (warning): For loops over find output are fragile. Use find -exec or a while read loop.

In bin/build-all.sh line 36:
  if [ ! -z "$SEARCH" ]; then
       ^-- SC2236 (style): Use -n instead of ! -z.

In bin/build-all.sh line 39:
        if [ 0 != $? ]; then SKIP=1 ; fi
                  ^-- SC2181 (style): Check exit code directly with e.g. 'if ! mycmd;', not indirectly with $?.

In bin/build-all.sh line 51:
  if [ 0 = $? ] ; then
           ^-- SC2181 (style): Check exit code directly with e.g. 'if mycmd;', not indirectly with $?.

In bin/build-all.sh line 52:
    mv -f "ui/$UI/$UI".hex hex/"$UI".$NAME.hex
                                     ^---^ SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean:
    mv -f "ui/$UI/$UI".hex hex/"$UI"."$NAME".hex

In bin/build-all.sh line 54:
    PASS=$(($PASS + 1))
            ^---^ SC2004 (style): $/${} is unnecessary on arithmetic variables.

In bin/build-all.sh line 58:
    FAIL=$(($FAIL + 1))
            ^---^ SC2004 (style): $/${} is unnecessary on arithmetic variables.
SiteRelEnby commented 11 months ago

@ToyKeeper using /usr/bin/env bash should fix it. I think that bash is a better option than zsh as it will actually be available everywhere as well as being much better understood for scripting - MacOS just by default attempts to force zsh.

ToyKeeper commented 11 months ago

I almost always write scripts in zsh unless I have a specific reason to use something else, because it has a lot of really useful features. So I'm not as familiar with bashisms. However, I don't mind using bash, since it has a nice set of features too. Using plain /bin/sh (i.e. dash) makes a lot of simple operations unnecessarily complicated though, so I don't want to strip things down that far.

Anyway, I'll switch to env and try to fix the lint warnings... and hopefully that'll fix things on MacOS?

gretel commented 11 months ago

Anyway, I'll switch to env and try to fix the lint warnings... and hopefully that'll fix things on MacOS?

sounds good to me. the lowest common denominator is sh, tho.

maybe have a look at elv.sh 😆

SiteRelEnby commented 11 months ago

Yeah, POSIX sh is just an exercise in writing boilerplate and triple-checking everything. dash is somewhere between the two but doesn't have the same cross-platform compatibility.

Can confirm via work laptop that switching to /usr/bin/env bash works fine (something I tend to always do automatically, I guess).

See https://github.com/ToyKeeper/anduril/pull/15

ToyKeeper commented 11 months ago

MacOS build fixed in bbdb68a04efb20b0c772b847706560d1b550e61b, I think.

Lint checks fixed in 96bb6aeb178182c95558c5157b6ddfaecfceb785, aside from a couple places where shellcheck was wrong.

gretel commented 11 months ago

Lint checks fixed in 96bb6ae, aside from a couple places where shellcheck was wrong.

cool, there also is bashate which has a fun name and does similar but different 🔪 💻