ocaml / opam-repository

Main public package repository for opam, the source package manager of OCaml.
https://opam.ocaml.org
Creative Commons Zero v1.0 Universal
518 stars 1.14k forks source link

`opam install num` fails once on Mac with OCaml 4.06 #10857

Open djs55 opened 6 years ago

djs55 commented 6 years ago

There seems to be a problem with the "built-in" num library, but I'm not sure whether the problem is the metadata in this repo or somewhere else.

On a Mac with OCaml 4.06 from homebrew (brew install ocaml):

$ opam init
...
$ opam install ocamlfind -y
...
$ ocamlfind list
...
num                 (version: [distributed with Ocaml])
num-top             (version: 1.7.3)
num.core            (version: [internal])
...

but then if I

$ opam install num
The following actions will be performed:
  βˆ—  install num 1.1

=-=- Gathering sources =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=  🐫 
[default] https://opam.ocaml.org/archives/num.1.1+opam.tar.gz downloaded

=-=- Processing actions -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=  🐫 
[ERROR] The compilation of num failed at "make install".
Processing  1/1: [num: make uninstall]
#=== ERROR while installing num.1.1 ===========================================#
# opam-version 1.2.2
# os           darwin
# command      make install
# path         /Users/djs/.opam/system/build/num.1.1
# compiler     system (4.06.0)
# exit-code    2
# env-file     /Users/djs/.opam/system/build/num.1.1/num-86830-ad8886.env
# stdout-file  /Users/djs/.opam/system/build/num.1.1/num-86830-ad8886.out
# stderr-file  /Users/djs/.opam/system/build/num.1.1/num-86830-ad8886.err
### stdout ###
# /Applications/Xcode.app/Contents/Developer/usr/bin/make -C src install
# ocamlfind install num META
### stderr ###
# ocamlfind: Package num is already installed
#  - (file /Users/djs/.opam/system/lib/num/META already exists)
# make[1]: *** [install] Error 2
# make: *** [install] Error 2

I think as a clean up it executes ocamlfind remove num somewhere because now:

$ ocamlfind list | grep num
$ opam install num
The following actions will be performed:
  βˆ—  install num 1.1

=-=- Gathering sources =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=  🐫 
[num] Archive in cache

=-=- Processing actions -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=  🐫 
βˆ—  installed num.1.1
Done.
dbuenzli commented 6 years ago

I can't reproduce that (but I'm on opam v2.). Isn't that a case of missing eval $(opam config env) (though in practice I think it should not be needed for installs to work).

dbuenzli commented 6 years ago

@djs55 can you reproduce without starting from an opam init ? If that is the case a clear command sequence that leads to the issue would be nice to have. Thanks.

djs55 commented 6 years ago

Here's a full trace (still from opam init) after I deleted my ~/.opam and started a fresh shell:

Davids-MBP-2:~ djs$ set | grep opam
Davids-MBP-2:~ djs$ opam init
Checking for available remotes: rsync and local, git.
  - you won't be able to use mercurial repositories unless you install the hg
    command on your system.
  - you won't be able to use darcs repositories unless you install the darcs
    command on your system.

=-=- Fetching repository information =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[default] synchronized from https://opam.ocaml.org

=-=- Gathering sources =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

=-=- Processing actions -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-> installed base-bigarray.base
-> installed base-threads.base
-> installed base-unix.base
Done.

In normal operation, OPAM only alters files within ~/.opam.

During this initialisation, you can allow OPAM to add information to two
other files for best results. You can also make these additions manually
if you wish.

If you agree, OPAM will modify:

  - ~/.profile (or a file you specify) to set the right environment
    variables and to load the auto-completion scripts for your shell (bash)
    on startup. Specifically, it checks for and appends the following line:

    . /Users/djs/.opam/opam-init/init.sh > /dev/null 2> /dev/null || true

  - ~/.ocamlinit to ensure that non-system installations of `ocamlfind`
    (i.e. those installed by OPAM) will work correctly when running the
    OCaml toplevel. It does this by adding $OCAML_TOPLEVEL_PATH to the list
    of include directories.

If you choose to not configure your system now, you can either configure
OPAM manually (instructions will be displayed) or launch the automatic setup
later by running:

   opam config setup -a

Do you want OPAM to modify ~/.profile and ~/.ocamlinit?
(default is 'no', use 'f' to name a file other than ~/.profile)
    [N/y/f] 

Global configuration:
  Updating ~/.opam/opam-init/init.sh
  Updating ~/.opam/opam-init/init.zsh
  Updating ~/.opam/opam-init/init.csh
  Updating ~/.opam/opam-init/init.fish

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

1. To configure OPAM in the current shell session, you need to run:

      eval `opam config env`

2. To correctly configure OPAM for subsequent use, add the following
   line to your profile file (for instance ~/.profile):

      . /Users/djs/.opam/opam-init/init.sh > /dev/null 2> /dev/null || true

3. To avoid issues related to non-system installations of `ocamlfind`
   add the following lines to ~/.ocamlinit (create it if necessary):

      let () =
        try Topdirs.dir_directory (Sys.getenv "OCAML_TOPLEVEL_PATH")
        with Not_found -> ()
      ;;

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Davids-MBP-2:~ djs$ eval `opam config env`
Davids-MBP-2:~ djs$ opam install num
The following actions will be performed:
  βˆ—  install conf-m4   1                      [required by ocamlfind]
  βˆ—  install ocamlfind 1.7.3                  [required by num]
  βˆ—  install num       1.1  
===== βˆ—  3 =====
Do you want to continue ? [Y/n] y

=-=- Gathering sources =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=  🐫 
[default] https://opam.ocaml.org/archives/num.1.1+opam.tar.gz downloaded
[default] https://opam.ocaml.org/archives/ocamlfind.1.7.3+opam.tar.gz downloaded

=-=- Processing actions -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=  🐫 
βˆ—  installed conf-m4.1
βˆ—  installed ocamlfind.1.7.3
[ERROR] The compilation of num failed at "make install".
Processing  3/3: [num: make uninstall]
#=== ERROR while installing num.1.1 ===========================================#
# opam-version 1.2.2
# os           darwin
# command      make install
# path         /Users/djs/.opam/system/build/num.1.1
# compiler     system (4.06.0)
# exit-code    2
# env-file     /Users/djs/.opam/system/build/num.1.1/num-59008-48c407.env
# stdout-file  /Users/djs/.opam/system/build/num.1.1/num-59008-48c407.out
# stderr-file  /Users/djs/.opam/system/build/num.1.1/num-59008-48c407.err
### stdout ###
# /Applications/Xcode.app/Contents/Developer/usr/bin/make -C src install
# ocamlfind install num META
### stderr ###
# ocamlfind: Package num is already installed
#  - (file /Users/djs/.opam/system/lib/num/META already exists)
# make[1]: *** [install] Error 2
# make: *** [install] Error 2

=-=- Error report -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=  🐫 
The following actions failed
  βˆ—  install num 1.1
The following changes have been performed
  βˆ—  install conf-m4   1    
  βˆ—  install ocamlfind 1.7.3

The former state can be restored with:
    opam switch import "~/.opam/system/backup/state-20171106111352.export"
Davids-MBP-2:~ djs$ ocaml -version
The OCaml toplevel, version 4.06.0
Davids-MBP-2:~ djs$ opam --version
1.2.2
djs55 commented 6 years ago

I suspect it's something to do with the behaviour mentioned in this patch: https://github.com/ocaml/opam-repository/blob/master/packages/ocamlfind/ocamlfind.1.7.3/files/check-num-in-sitelib.patch

The configure of ocamlfind says:

- num: found

which is odd as 4.06 doesn't include num.cmi any more. Perhaps it's picking up a stale file somewhere?

djs55 commented 6 years ago

OK I think I know what's going on. opam install num (when it works):

- install -m 644 nums.cma libnums.a big_int.cmi nat.cmi num.cmi ratio.cmi arith_status.cmi big_int.mli nat.mli num.mli ratio.mli arith_status.mli big_int.cmti nat.cmti num.cmti ratio.cmti arith_status.cmti nums.cmxa nums.a big_int.cmx nat.cmx num.cmx ratio.cmx arith_status.cmx nums.cmxs /usr/local/lib/ocaml
- install dllnums.so /usr/local/lib/ocaml/stublibs

this is because it writes directly into the stdlib directory, not the opam switch: https://github.com/ocaml/num/blob/master/src/Makefile#L9

and then if I blow away my .opam and start again, these files persist, which cause ocamlfind to install a META file (because the library looks like it came with the compiler) and which causes the second opam install num to fail. The uninstall of num cleans up the files added on the first invocation.

djs55 commented 6 years ago

OK I'm pretty sure I at least know what's going on. I've made a proposed fix in the linked PR... although I'm not sure it's actually worth it (possible backwards compatibility issue versus irritating occasional glitch)

dbuenzli commented 6 years ago

@djs55 it seems upstream has a fix (@gerdstolpmann see https://github.com/ocaml/opam-repository/issues/10925#issuecomment-350302281) could you please try to test it so that we can move on this.

DestyNova commented 4 years ago

I'm having the same issue now (on Ubuntu 19.10). It might be due to having a relatively old .opam directory.

DestyNova commented 4 years ago

I tried manually executing ocamlfind remove num, which said:

Removed /home/omf/.opam/4.06.1/lib/num/META
Removed /home/omf/.opam/4.06.1/lib/num

However, when trying to install:

<><> Gathering sources ><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
[batteries.3.0.0] found in cache
[num.1.3] found in cache

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
[ERROR] The installation of num failed at "make install".

#=== ERROR while installing num.1.3 ===========================================#
# context     2.0.5 | linux/x86_64 | base-bigarray.base base-threads.base base-unix.base ocaml-base-compiler.4.06.1 | https://opam.ocaml.org#dd708a31
# path        ~/.opam/4.06.1/.opam-switch/build/num.1.3
# command     ~/.opam/opam-init/hooks/sandbox.sh install make install
# exit-code   2
# env-file    ~/.opam/log/num-21459-0a5907.env
# output-file ~/.opam/log/num-21459-0a5907.out
### output ###
# [...]
# install -d /home/omf/.opam/4.06.1/lib/ocaml/stublibs
# install dllnums.so /home/omf/.opam/4.06.1/lib/ocaml/stublibs
# make[1]: Leaving directory '/home/omf/.opam/4.06.1/.opam-switch/build/num.1.3/src' 
# make -C toplevel install
# make[1]: Entering directory '/home/omf/.opam/4.06.1/.opam-switch/build/num.1.3/toplevel'
# sed -e 's/%%VERSION%%/1.3/g' META.in > META
# ocamlfind install num-top META num_top.cma num_top.cmi num_top_printers.cmi
# ocamlfind: Package num-top is already installed
#  - (file /home/omf/.opam/4.06.1/lib/num-top/META already exists)
# make[1]: *** [Makefile:28: install] Error 2
# make[1]: Leaving directory '/home/omf/.opam/4.06.1/.opam-switch/build/num.1.3/toplevel'
# make: *** [Makefile:15: install] Error 2

I checked that file and:

$ ls -l /home/omf/.opam/4.06.1/lib/num-top/META
-rw-r--r-- 1 omf omf 123 Oct 13  2017 /home/omf/.opam/4.06.1/lib/num-top/META

Manually deleting it seems to have fixed the problem.

MiroFurtado commented 4 years ago

I am likewise getting this issue (MacOS)

[ERROR] It appears that the num library was previously installed to your system compiler's lib directory, probably by a faulty opam package. You will need to remove arith_flags., arith_status., big_int., int_misc., nat., num., ratio., nums., libnums. and stublibs/dllnums. from /usr/local/lib/ocaml.

However none of those files are present in /usr/local/lib/ocaml.

I solved it by executing ocamlfind remove num and then ocamlfind remove num-top followed by opam install num.

github-actions[bot] commented 4 years ago

This issue has been open 90 days with no activity. Consequently, it is being marked with the "stale" label. What this means is that the issue will be automatically closed in 30 days unless more comments are added or the "stale" label is removed. If you come across this issue in the future, you may also find it helpful to visit our forum at https://discuss.ocaml.org where queries related to OCaml package management are very welcome.

samoht commented 2 years ago

I just add this issue when creating a fresh switch:

#=== ERROR while installing num.1.4 =========================================#
# context     2.1.2 | macos/arm64 | ocaml.4.13.1 | https://opam.ocaml.org#27414071
# path        ~/git/mirage-www/_opam/.opam-switch/build/num.1.4
# command     ~/.opam/opam-init/hooks/sandbox.sh install make findlib-install
# exit-code   2
# env-file    ~/.opam/log/num-37410-01d092.env
# output-file ~/.opam/log/num-37410-01d092.out
### output ###
# /Library/Developer/CommandLineTools/usr/bin/make -C src findlib-install
# sed -e '/\^/d' -e 's/%%VERSION%%/1.4/g' META.in > META
# ocamlfind install num META nums.cma libnums.a big_int.cmi nat.cmi num.cmi ratio.cmi arith_status.cmi big_int.mli nat.mli num.mli ratio.mli arith_status.mli big_int.cmti nat.cmti num.cmti ratio.cmti arith_status.cmti nums.cmxa nums.a int_misc.cmx nat.cmx big_int.cmx arith_flags.cmx ratio.cmx num.cmx arith_status.cmx nums.cmxs dllnums.so
# ocamlfind: Package num is already installed
#  - (file /Users/thomas/git/mirage-www/_opam/lib/num/META already exists)
# make[1]: *** [findlib-install] Error 2
# make: *** [findlib-install] Error 2
github-actions[bot] commented 2 years ago

This issue has been open 90 days with no activity. Consequently, it is being marked with the "stale" label. What this means is that the issue will be automatically closed in 30 days unless more comments are added or the "stale" label is removed. If you come across this issue in the future, you may also find it helpful to visit our forum at https://discuss.ocaml.org where queries related to OCaml package management are very welcome.

github-actions[bot] commented 2 years ago

This issue has been open 90 days with no activity. Consequently, it is being marked with the "stale" label. What this means is that the issue will be automatically closed in 30 days unless more comments are added or the "stale" label is removed. If you come across this issue in the future, you may also find it helpful to visit our forum at https://discuss.ocaml.org where queries related to OCaml package management are very welcome.