dbuenzli / bos

Basic OS interaction for OCaml
http://erratique.ch/software/bos
ISC License
64 stars 16 forks source link

OS.Cmd.exists doesn't work on absolutely defined executables #67

Closed freuk closed 7 years ago

freuk commented 7 years ago

The OS.Cmd.must_exist always fails on NixOS, due to line 84 in bos_os_cmd.ml "let exists line" function failing.

Example:

$ls -lah /nix/store/yn142bzjxlngbvikkw5qgwzpy1ynbikj-bzip2-1.0.6.0.1-bin/bin/bzip2 
-r-xr-xr-x 1 root root 40K Jan  1  1970 /nix/store/yn142bzjxlngbvikkw5qgwzpy1ynbikj-bzip2-1.0.6.0.1-bin/bin/bzip2

$/nix/store/yn142bzjxlngbvikkw5qgwzpy1ynbikj-bzip2-1.0.6.0.1-bin/bin/bzip2
bzip2: I won't write compressed data to a terminal.
bzip2: For help, type: `bzip2 --help'.

$TOPKG_BZIP2="/nix/store/yn142bzjxlngbvikkw5qgwzpy1ynbikj-bzip2-1.0.6.0.1-bin/bin/bzip2" topkg distrib
topkg: [ERROR] /nix/store/yn142bzjxlngbvikkw5qgwzpy1ynbikj-bzip2-1.0.6.0.1-bin/bin/bzip2:
               no such command

Any idea? I'd like to use the dependent packages :-) Thank you very much.

dbuenzli commented 7 years ago

This seems related to #53 do you have which installed ?

dbuenzli commented 7 years ago

See this comment by @dsheets https://github.com/dbuenzli/bos/issues/52#issuecomment-222643618

freuk commented 7 years ago

I do have which installed, although It will not be found in /bin/ or /usr/bin:

$ which which
/run/current-system/sw/bin/which

$ ls -lah /run/current-system/sw/bin/which
lrwxrwxrwx 1 root root 64 Jan  1  1970 /run/current-system/sw/bin/which -> /nix/store/gi2qk4pimynjhvpjqa8fh2wi28fffk6g-which-2.21/bin/which
freuk commented 7 years ago

conf-which installs without issue.

dbuenzli commented 7 years ago

Could you make your topkg invocation with -v -v and post the result please.

dbuenzli commented 7 years ago

Hum I think this is the issue

> which /usr/bin/ls
> echo $?
1

So which with absolute paths exits with 1.

dbuenzli commented 7 years ago

So I guess that for absolute paths I should simply check the file's existence and if the exec bit is set (though at that point I should maybe simply implement #53).

dbuenzli commented 7 years ago

Hum I think this is the issue

which /usr/bin/ls echo $? 1 So which with absolute paths exits with 1.

Rubish... ls is in /bin/ls.

> which /bin/ls
/bin/ls
freuk commented 7 years ago
>topkg distrib -v -v                                                                                                                                          ~/sandbox/obandit
topkg: [INFO] topkg v0.8.1 running
topkg: [EXEC:15284] ["type"; "bzip2"]
topkg: [ERROR] bzip2: no such command
>which ls
/run/current-system/sw/bin/l
>secho $?
0
freuk commented 7 years ago
>TOPKG_BZIP2="/nix/store/yn142bzjxlngbvikkw5qgwzpy1ynbikj-bzip2-1.0.6.0.1-bin/bin/bzip2" topkg distrib -v -v                                                  ~/sandbox/obandit
topkg: [INFO] topkg v0.8.1 running
topkg: [EXEC:15520] ["type";
                     "/nix/store/yn142bzjxlngbvikkw5qgwzpy1ynbikj-bzip2-1.0.6.0.1-bin/bin/bzip2"]
topkg: [ERROR] /nix/store/yn142bzjxlngbvikkw5qgwzpy1ynbikj-bzip2-1.0.6.0.1-bin/bin/bzip2:
               no such command
dbuenzli commented 7 years ago

Ah topkg distrib is handled by topkg and not topkg-care and hence does not depend on bos. There's a minibos in topkg itself due to bootstrapping purposes.

So the problem lies here: https://github.com/dbuenzli/topkg/blob/master/src/topkg_os.ml#L226-L247

freuk commented 7 years ago

Ooooh sorry for misleading you..

dbuenzli commented 7 years ago

No problem. The system itself is a bit misleading.

dbuenzli commented 7 years ago

So type doesn't seem to work or nix or what ?

freuk commented 7 years ago

It's simply not there on my system.

which: no type in [...]
dbuenzli commented 7 years ago

I'm not sure there's a reason no to use which there. I opened https://github.com/dbuenzli/topkg/issues/99. Are you able to find a type to proceed ? If not tell me there I'll have a look at it today.

freuk commented 7 years ago

I've solved by putting

#!/bin/sh 
builtin type "$@"

in ~/.bin/ . Not a pleasant solution but.. it does the job. the executable is actually made like this on fedora systems, and in general this appears to be a shell builtin.

freuk commented 7 years ago

Thank you very much for your help @dbuenzli

dbuenzli commented 7 years ago

I've solved by putting

Ugh.

Not a pleasant solution but.. it does the job. the executable is actually made like this on fedora systems, and in general this appears to be a shell builtin.

But there's something I don't understand here. The topkg code is using OCaml's Sys.command so this should go through the shell.