How to patch an opam package

On my system (Windows/Diskuv), cairo2 fails to compile. I have raised the issue which seems to be simple (just use variadic preprocessor arguments in the MSVC way), but if I modify the culprit file, opam install cairo2 gets the package back from the cache and compile the original version.

I have tried to copy the opam directory (cairo2.0.6.2) and launch opam install . thinking opam will install the package from the current directory, but the error message indicate it uses the directory from the opam\playground\.opam-switch\build directory, then I can’t build a customized version.

opam source --dev cairo2 && cd cairo2
...hack hack...
git add -p 
git commit -m "Fix MSVC"
opam pin add .

I have tried it. From a D:\DiskuvProjets\cairo2 directory, I type opam pin add . and get the error:

# C:\Users\frede\AppData\Local\opam\playground\.opam-switch\build\cairo2.0.6.2\_build\default\src\cairo_macros.h(178): error C2010: '.' : inattendu dans la liste de paramètres de macro

which indicates the cairo_macros.h is still compiled from the private opam directory.

Are you sure you commited changes to the repo ?

1 Like

It should be using your sources there, if you want to make sure, try opam pin add . --with-version 0.7, you should see the error appear with this new version instead. Also, make sure you have committed your changes before pinning.

1 Like

My bad… git commit -m 'a commit message' should be written git commit -m "a commit message" with a CMD prompt. Now, all is correct (excepted other issues which don’t deal with the current thread about opam).

Many thanks !


Thanks for the info I edited the post to make the instructions cross platform.

I’ve had similar problems before, and one of the maintainers (I think kit-y-kate ?) pointed out that I should always check that there’s no pre-existing pin – and if there is, to remove it. Once I did that, my problems seem to have disappeared. Just thought I’d note it. I also always do --working-dir just to be sure I didn’t forget to do a commit.

1 Like