phyver / GameShell

a game to learn (or teach) how to use standard commands in a Unix shell
GNU General Public License v3.0
2.17k stars 138 forks source link

macOS - Mission 28 is cancelled because some dependencies are not met. #79

Closed Photon9 closed 2 years ago

phyver commented 2 years ago

Without a C compiler, missions 28, 29 and 34 cannot be initialized and are thus skipped.

Can you check if one of the commands clang, gcc, c99 or cc exists on your system?

Maybe I should actually give the missing dependency in the message, instead of just saying "some dependency"!

Photon9 commented 2 years ago

I do have clang and gcc installed.

I reinstalled the game and got this message for 28 and 29 (34 still gives only one message):

compilation failed Process names should be equal to the corresponding filename for mission processes/02_ps_kill_signal/deps.sh. Error: mission 28 is cancelled because some dependencies are not met. Process names should be equal to the corresponding filename for mission processes/03_pstree_kill/deps.sh. Error: mission 29 is cancelled because some dependencies are not met.

Thinking about it it's also the case that this is an M1 Mac.

phyver commented 2 years ago

OK, there are 2 problems.

For mission 34 (and 28, 29) GameShell will try compiling small programs. It seems to fail for mission 34. If the compiler is here, it could be that some library is missing. Can you run GameShell in debug mode. There should be more verbose messages:

$ bash ./gameshell.sh -Dq
... plenty of messages ...
[mission 01] $ gsh goto 34
???

For missions 27, 28 and 29, processes run with a shebang need to get their name from the filename. Can you try running, not necessarily from inside GameShell?

$ uname -a
$ echo '#!/bin/sh' > test
$ echo 'sleep 100' >> test
$ chmod +x test
$ ./test &
$ ps
????   is there a process called "test"?
$ ps -o pid,ppid,comm
????   is there a process called "test"?
$ ps -c
????   is there  process called "test"?
Photon9 commented 2 years ago
cc -I/usr/local/include/ -L/usr/local/lib /Users/harrisonmorrow/gameshell/missions/stdin_stdout_stderr/05_stdout_stderr_redirection_merlin/merlin.c -lintl -lpthread -o /Users/harrisonmorrow/gameshell/.tmp/merlin
/Users/harrisonmorrow/gameshell/missions/stdin_stdout_stderr/05_stdout_stderr_redirection_merlin/merlin.c:2:10: fatal error:
      'libintl.h' file not found
#include <libintl.h>
         ^~~~~~~~~~~
1 error generated.
compilation failed
Error: mission 34 is cancelled because some dependencies are not met.
    GSH: sourcing $GSH_ROOT/missions/permissions/01_chmod_x_dir_king_quarter/static.sh
    GSH: sourcing $GSH_ROOT/missions/permissions/01_chmod_x_dir_king_quarter/init.sh

So, it's something to do with gettext (I think).

This also led me to this stack overflow answer:

https://stackoverflow.com/a/21233420

Modifying the fix to match how homebrew on M1 works to be:

ln -s /opt/homebrew/Cellar/gettext/0.21/lib/libintl.* /opt/homebrew/lib/

Returned:

ln: /opt/homebrew/lib//libintl.8.dylib: File exists ln: /opt/homebrew/lib//libintl.a: File exists ln: /opt/homebrew/lib//libintl.dylib: File exists

So, more investigation necessary. I will run the other tests and look into this one more later today.

Photon9 commented 2 years ago

Creating and running the test script worked. it turned up in ps

phyver commented 2 years ago

This also led me to this stack overflow answer:

https://stackoverflow.com/a/21233420

Have you tried one the other alleged fix:

$ brew reinstall gettext
$ brew unlink gettext && brew link gettext --force

which has the advantage of letting brew deal with everything.

Photon9 commented 2 years ago

Apologies, I tried that first.

phyver commented 2 years ago

Creating and running the test script worked. it turned up in ps

But does it have the name test (under header CMD or COMMAND) rather than sh or sh test or some other thing? And if so, for which invocation of ps?

Photon9 commented 2 years ago

Ah sorry the output from each commands, of course.

Run in bash just so I can paste the whole output but the only difference is my prompt.

Darwin Ogma.local 21.4.0 Darwin Kernel Version 21.4.0: Fri Mar 18 00:47:26 PDT 2022; root:xnu-8020.101.4~15/RELEASE_ARM64_T8101 arm64

bash-5.1$ ./test &
[3] 26208
bash-5.1$ ps
  PID TTY           TIME CMD
26185 ttys003    0:00.03 bash
26198 ttys003    0:00.01 /bin/sh ./test
26199 ttys003    0:00.00 sleep 100
26208 ttys003    0:00.01 /bin/sh ./test
26209 ttys003    0:00.00 sleep 100
95326 ttys003    0:03.36 -zsh
bash-5.1$ ps -o pid,ppid,comm
  PID  PPID COMM
26185 95326 bash
26198 26185 /bin/sh
26199 26198 sleep
26208 26185 /bin/sh
26209 26208 sleep
95326 95325 -zsh
bash-5.1$ ps -c
  PID TTY           TIME CMD
26185 ttys003    0:00.04 bash
26198 ttys003    0:00.01 sh
26199 ttys003    0:00.00 sleep
26208 ttys003    0:00.01 sh
26209 ttys003    0:00.00 sleep
95326 ttys003    0:03.36 -zsh
bash-5.1$
phyver commented 2 years ago

Apologies, I tried that first.

OK. I cannot really test anything on this architecture, so tell me about anything you find.

Can you try defining the variable GSH_NO_GETTEXT to 1 before starting mission 28? It should try compiling spell.c without internationalization support. (That should work with missions 28 and 29, but not for mission 34. (I'll add that to my TODO list.) This variable is automatically defined when the gettext utility isn't found. If that solves your problem, I can try defining it when libintl.h isn't found, or at least add an option to gameshell.sh.

Photon9 commented 2 years ago

okay... so exams are done and I have a flight in 10 hours but I have been doing my homework on c, glibc, and macOS.

libintl.h = part of glibc

glibc doesn't work on macOS from what I have seen homebrew says it requires linux.

macOS uses a version of BSDlibc

In this old fork of gnu's glibc there are the lines:

#include <locale.h>
#if (defined __APPLE__ && defined __MACH__) && 0 //@HAVE_NEWLOCALE@
# include <xlocale.h>
#endif

Perhaps getting the program that's compiled to include on macOS might help.

There are also some interesting comments in there about how while some of this stuff is standardised across posix but not c libraries.

I will continue my investigation on both issues.

phyver commented 2 years ago

Not thoroughly tested, but generating an archive (utils/archive.sh) with the option -E should only keep the English language and disable gettext entirely. It might be a work-around.

Do not hesitate to re-open the issue if you've discovered a better way to make those missions works on your version of macOS.