agda/hs-tags

hs-tags plainly calls `ghc` which might not work in all configurations

Closed this issue ยท 6 comments

Hello. I am having troubles generating tags in the agda repo.
When running the following command

find src/full/ -name "*.*hs" | xargs \
hs-tags --cabal Agda.cabal \
-i .stack-work/dist/x86_64-linux-tinfo6/Cabal-3.4.0.0/build/autogen/cabal_macros.h -e

I invariably get the following error:

hs-tags: user error (Pattern match failure in do expression at Main.hs:216:13-19)

I am using hs-tags 0.1.5. I compiled Agda from source using stack, and this project config file:

stack-9.0.1.yaml

Maybe am I just misusing hs-tags? If that's it, please excuse the inconvenience.

The error is raised here:

hs-tags/Main.hs

Line 216 in 5e5fca9

top : _ <- lines <$> runCmd "ghc --print-libdir"

Here, ghc is invoked in the following way:

$ ghc --print-libdir
/usr/local/lib/ghc-9.0.1

This may fail if you have no ghc in the PATH.

Maybe you can work around this by (1) installing ghc-9.0.1 so that it is in the PATH as ghc, and then (2) install with something like stack install --stack-yaml=stack-9.0.1 --system-ghc. Step (2) might not even be necessary.

Another work-around may be to wrap the call to hs-tags into stack exec, so that the ghc used by stack is available, e.g. (untested)

find src/full/ -name "*.*hs" | xargs \
stack exec --stack-yaml=stack-9.0.1 -- hs-tags --cabal Agda.cabal \
-i .stack-work/dist/x86_64-linux-tinfo6/Cabal-3.4.0.0/build/autogen/cabal_macros.h -e

We should give a proper error if ghc cannot be found.

The docs say (https://hackage.haskell.org/package/ghc-8.10.2/docs/GHC.html#v:initGhcMonad):

The first argument should point to the directory where GHC's library files reside. More precisely, this should be the output of ghc --print-libdir of the version of GHC the module using this API is compiled with. For portability, you should use the ghc-paths package, available at http://hackage.haskell.org/package/ghc-paths.

So maybe we should do that...

Meanwhile the stack exec workaround did the trick for me, thank you very much.

I pushed 791b1b8 implementing #3 (comment).
@antoinevanmuylder : Would you help me out, installing hs-tags from the latest master and testing whether it makes a difference for you?

Certainly. Will do that as soon as I get access to my machine.

It works:) For the record here is what I did @andreasabel

  1. delete old hs-tags binary
  2. install hs-tags master
    hs-tags --help gives me hs-tags version 0.1.6.
  3. run this command in agda repo (in the agda/ directory)
find src/full/ -name "*.*hs" | xargs \
-- hs-tags --cabal Agda.cabal \
-i .stack-work/dist/x86_64-linux-tinfo6/Cabal-3.4.0.0/build/autogen/cabal_macros.h \
--etags=./src/full/TAGS

Thanks