Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ocp-index locate returns the wrong location #167

Open
mlemerre opened this issue Jan 27, 2024 · 1 comment
Open

ocp-index locate returns the wrong location #167

mlemerre opened this issue Jan 27, 2024 · 1 comment

Comments

@mlemerre
Copy link

Hi,

First, thank you for ocp-index. I don't know why I did not know the tool before, it should definitively be part of the tools officially recommended!

One issue though is that it does not return the correct locations. If I type:

$ ocp-index locate Z.one
/home/matthieu/.opam/4.14.1+BER/.opam-switch/build/zarith.1.13/z.mli:62:0

this is incorrect.

If I look at the doc, the location where z.mli is looked up is obtained by opam var lib, whose value is

/home/matthieu/.opam/4.14.1+BER/lib

in my case.

And indeed, if I do

$ ocp-index locate Z.one --no-opamlib

Then there is no result.

So my guess is that there is some changes in the path done by ocp-index, which should return instead

./lib/zarith/z.mli

or

./.opam-switch/sources/zarith.1.13/z.mli

Is there something wrong in my setup? I only did opam install ocp-index.

Thanks
Matthieu

@lthls
Copy link
Contributor

lthls commented Jan 27, 2024

It is, unfortunately, the expected result.
To resolve Z.one, ocp-index looks up the .cmt and .cmti files available in the current setting that match the query. It finds /path/to/opam/switch/lib/zarith/z.cmti, which is more or less a marshalled version of the typed AST for z.mli, including locations. But since z.cmti was generated during installation of zarith, by compiling the file z.mli in the temporary build folder /path/to/opam/switch/.opam-switch/build/zarith.version/, that is the location stored in the AST, and the only one that ocp_index can report.
Note that ocp-index does not try to read or find source files, so the existence of a z.mli file in the library directory has no impact on what the tool will report.

One possible workaround is to keep build directories when installing opam packages (either by passing the -b or --keep-build-dir flag, or setting the environment variable OPAMKEEPBUILDDIR to 'true'). This will ensure that the locations stored inside the installed cmti files still exist.

Finally, if you have a copy of the zarith sources somewhere (through opam source, for example) you can ask opam to install the zarith package from these sources and use the source directory to build, which will increase the chance of ocp-index finding the right source files. The command would look like (cd /path/to/zarith/sources && opam install . --inplace-build).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants