ocaml / ocaml-lsp

OCaml Language Server Protocol implementation
Other
771 stars 121 forks source link

Permission denied when installing #1029

Open Timmmm opened 1 year ago

Timmmm commented 1 year ago

I'm using the global opam switch (I think; I don't really know OCaml). If I run

ocaml install ocaml-lsp-server

It gives this output:

❯ opam install ocaml-lsp-server
The following actions will be performed:
  ∗ install dune-build-info     3.6.1   [required by ocaml-lsp-server]
  ∗ install dot-merlin-reader   4.5     [required by ocaml-lsp-server]
  ∗ install stdlib-shims        0.3.0   [required by ocaml-lsp-server]
  ∗ install ppx_yojson_conv_lib v0.15.0 [required by ocaml-lsp-server]
  ∗ install ocaml-lsp-server    1.4.1
===== ∗ 5 =====
Do you want to continue? [Y/n] Y

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
⬇ retrieved dune-build-info.3.6.1  (cached)
⬇ retrieved dot-merlin-reader.4.5  (https://opam.ocaml.org/cache)
⬇ retrieved ppx_yojson_conv_lib.v0.15.0  (https://opam.ocaml.org/cache)
⬇ retrieved stdlib-shims.0.3.0  (https://opam.ocaml.org/cache)
∗ installed dune-build-info.3.6.1
∗ installed ppx_yojson_conv_lib.v0.15.0
∗ installed stdlib-shims.0.3.0
∗ installed dot-merlin-reader.4.5
⬇ retrieved ocaml-lsp-server.1.4.1  (https://opam.ocaml.org/cache)
[ERROR] The compilation of ocaml-lsp-server.1.4.1 failed at "dune build -j 11 ocaml-lsp-server.install --release".

#=== ERROR while compiling ocaml-lsp-server.1.4.1 =============================#
# context     2.1.4 | linux/x86_64 | ocaml-base-compiler.4.08.0 | https://opam.ocaml.org#ff615534
# path        ~/.opam/4.08.0/.opam-switch/build/ocaml-lsp-server.1.4.1
# command     ~/.opam/opam-init/hooks/sandbox.sh build dune build -j 11 ocaml-lsp-server.install --release
# exit-code   1
# env-file    ~/.opam/log/ocaml-lsp-server-256070-7482d5.env
# output-file ~/.opam/log/ocaml-lsp-server-256070-7482d5.out
### output ###
# Error: /home/mycompany.com: Permission denied
# -> required by
#    _build/default/ocaml-lsp-server/src/.main.eobjs/build_info_data.ml-gen
# -> required by
#    _build/default/ocaml-lsp-server/src/.main.eobjs/native/build_info__Build_info_data.cmx
# -> required by _build/default/ocaml-lsp-server/src/main.exe
# -> required by _build/install/default/bin/ocamllsp
# -> required by _build/default/ocaml-lsp-server.install

<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
┌─ The following actions failed
│ λ build ocaml-lsp-server 1.4.1
└─ 
┌─ The following changes have been performed
│ ∗ install dot-merlin-reader   4.5
│ ∗ install dune-build-info     3.6.1
│ ∗ install ppx_yojson_conv_lib v0.15.0
│ ∗ install stdlib-shims        0.3.0
└─ 

The former state can be restored with:
    /usr/local/bin/opam switch import "/home/mycompany.com/timothy.hutt/.opam/4.08.0/.opam-switch/backup/state-20230127145351.export"

Bit weird. I guess it is due to the fact that my $HOME is /home/mycompany.com/timohty.hutt` and some code assumes that is impossible.

rgrinberg commented 1 year ago

=== ERROR while compiling ocaml-lsp-server.1.4.1 =============================

Can you try installing a newer version? This one is quite ancient.

Timmmm commented 1 year ago

Ah yeah a newer version worked. I was using an older version of OCaml because a project told me to use 4.08 or something, but I checked again and it actually said that was the minimum in a slightly ambiguous way.

Anyway it works. Carry on. :-)

Timmmm commented 1 year ago

Oh sorry, I don't know why I thought it had worked. It actually didn't. :-/

❯ opam install ocaml-lsp-server
The following actions will be performed:
  ↘ downgrade omd              2.0.0~alpha3 to 1.3.2 [required by ocaml-lsp-server]
  ∗ install   ocaml-lsp-server 1.15.1-5.0
===== ∗ 1   ↘ 1 =====
Do you want to continue? [Y/n] y

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
⬇ retrieved omd.1.3.2  (cached)
Processing  2/7: [ocaml-lsp-server.1.15.1-5.0: dl]
⬇ retrieved ocaml-lsp-server.1.15.1-5.0  (https://opam.ocaml.org/cache)
⊘ removed   omd.2.0.0~alpha3
∗ installed omd.1.3.2
[ERROR] The compilation of ocaml-lsp-server.1.15.1-5.0 failed at "dune build -j 11 ocaml-lsp-server.install --release".

#=== ERROR while compiling ocaml-lsp-server.1.15.1-5.0 ========================#
# context     2.1.4 | linux/x86_64 | ocaml.5.0.0 | https://opam.ocaml.org#a5e664bc
# path        ~/.opam/default/.opam-switch/build/ocaml-lsp-server.1.15.1-5.0
# command     ~/.opam/opam-init/hooks/sandbox.sh build dune build -j 11 ocaml-lsp-server.install --release
# exit-code   1
# env-file    ~/.opam/log/ocaml-lsp-server-45119-5ba721.env
# output-file ~/.opam/log/ocaml-lsp-server-45119-5ba721.out
### output ###
# [...]
# automatically added to the search path, but you should add -I +unix to the
# command-line to silence this alert (e.g. by adding unix to the list of
# libraries in your dune file, or adding use_unix to your _tags file for
# ocamlbuild, or using -package unix for ocamlfind).
# (cd _build/default && /home/mycompany.com/timothy.hutt/.opam/default/bin/ocamlopt.opt -w -40 -alert -unstable -g -I ocaml-lsp-server/src/.ocaml_lsp_server.objs/byte -I ocaml-lsp-server/src/.ocaml_lsp_server.objs/native -I /home/mycompany.com/timothy.hutt/.opam/default/lib/chrome-trace -I /home/mycompany.com/timothy.hutt/.opam/default/lib/csexp -I /home/mycompany.com/timothy.hutt/.opam/default/lib/dun[...]
# File "_none_", line 1:
# Alert ocaml_deprecated_auto_include: 
# OCaml's lib directory layout changed in 5.0. The unix subdirectory has been
# automatically added to the search path, but you should add -I +unix to the
# command-line to silence this alert (e.g. by adding unix to the list of
# libraries in your dune file, or adding use_unix to your _tags file for
# ocamlbuild, or using -package unix for ocamlfind).

<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
┌─ The following actions failed
│ λ build ocaml-lsp-server 1.15.1-5.0
└─ 
┌─ The following changes have been performed
│ ↘ downgrade omd 2.0.0~alpha3 to 1.3.2
└─ 

The former state can be restored with:
    /usr/local/bin/opam switch import "/home/mycompany.com/timothy.hutt/.opam/default/.opam-switch/backup/state-20230127195743.export"
Timmmm commented 1 year ago

The error is the same:

Error: /home/mycompany.com: Permission denied
-> required by
   _build/default/ocaml-lsp-server/bin/.main.eobjs/build_info_data.ml-gen
-> required by
   _build/default/ocaml-lsp-server/bin/.main.eobjs/native/build_info__Build_info_data.cmx
-> required by _build/default/ocaml-lsp-server/bin/main.exe
-> required by _build/install/default/bin/ocamllsp
-> required by _build/default/ocaml-lsp-server.install
Timmmm commented 1 year ago

I straced it and it turns out there is some thing scanning all parent directories:

262848 stat("/home/company.com/timothy.hutt/.cabal/bin/js_of_ocaml", 0x7ffcff76a530) = -1 ENOENT (No such file or directory)
262848 openat(AT_FDCWD, "/home/company.com/timothy.hutt/.opam/default/.opam-switch/build", O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_DIRECTORY) = 5
262848 fstat(5, {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
262848 getdents64(5, 0x29f9b70 /* 11 entries */, 32768) = 448
262848 getdents64(5, 0x29f9b70 /* 0 entries */, 32768) = 0
262848 close(5)                         = 0
262848 openat(AT_FDCWD, "/home/company.com/timothy.hutt/.opam/default/.opam-switch", O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_DIRECTORY) = 5
262848 fstat(5, {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
262848 getdents64(5, 0x29f9b70 /* 16 entries */, 32768) = 504
262848 getdents64(5, 0x29f9b70 /* 0 entries */, 32768) = 0
262848 close(5)                         = 0
262848 openat(AT_FDCWD, "/home/company.com/timothy.hutt/.opam/default", O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_DIRECTORY) = 5
262848 fstat(5, {st_mode=S_IFDIR|0755, st_size=95, ...}) = 0
262848 getdents64(5, 0x29f9b70 /* 9 entries */, 32768) = 232
262848 getdents64(5, 0x29f9b70 /* 0 entries */, 32768) = 0
262848 close(5)                         = 0
262848 openat(AT_FDCWD, "/home/company.com/timothy.hutt/.opam", O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_DIRECTORY) = 5
262848 fstat(5, {st_mode=S_IFDIR|0755, st_size=128, ...}) = 0
262848 getdents64(5, 0x29f9b70 /* 10 entries */, 32768) = 288
262848 getdents64(5, 0x29f9b70 /* 0 entries */, 32768) = 0
262848 close(5)                         = 0
262848 openat(AT_FDCWD, "/home/company.com/timothy.hutt", O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_DIRECTORY) = 5
262848 fstat(5, {st_mode=S_IFDIR|0700, st_size=4096, ...}) = 0
262848 getdents64(5, 0x29f9b70 /* 68 entries */, 32768) = 2176
262848 getdents64(5, 0x29f9b70 /* 0 entries */, 32768) = 0
262848 close(5)                         = 0
262848 openat(AT_FDCWD, "/home/company.com", O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_DIRECTORY) = -1 EACCES (Permission denied)
262848 stat("/home/company.com/timothy.hutt/.cabal/bin/cinaps", 0x7ffcff76a530) = -1 ENOENT (No such file or directory)
262848 stat("/home/company.com/timothy.hutt/.ghcup/bin/js_of_ocaml", 0x7ffcff76a530) = -1 ENOENT (No such file or directory)
262848 stat("/home/company.com/timothy.hutt/.ghcup/bin/cinaps", 0x7ffcff76a530) = -1 ENOENT (No such file or directory)

Maybe related to cinaps or js_of_ocaml whatever those are. Anyway it fails because /home/company.com is not accessible (don't ask my why it is set up like this!). I don't have time to wade through OCaml dependencies unfortunately so I just chmoded it and that works around the issue.

❯ ls -ld /home/company.com
drwx--x--x. 4 root root 46 Dec  8 13:47 /home/company.com

❯ sudo chmod go+r /home/company.com