danstiner / hfmt

Format Haskell programs. Inspired by the gofmt utility.
MIT License
125 stars 14 forks source link

Configuration files aren't installed with `cabal copy` (and I'm guessing `cabal install` too) #44

Closed magthe closed 4 years ago

magthe commented 5 years ago

After packaging hfmt with the help of cabal copy I have a package with the following files:

hfmt /usr/
hfmt /usr/bin/
hfmt /usr/bin/hfmt
hfmt /usr/share/
hfmt /usr/share/doc/
hfmt /usr/share/doc/hfmt/
hfmt /usr/share/doc/hfmt/LICENSE

Unfortunately that isn't all files needed to actually run hfmt:

$ hfmt app/Main.hs 
hfmt: user error (Failed to find requested hint files:
  /usr/bin/data/hlint.yaml
)

I'm not sure this usage is prioritised, but it would be nice if it were easier to package hfmt.

danstiner commented 5 years ago

I honestly don't know how cabal copy works or why this would be failing. Could you give more detailed steps to help me reproduce?

magthe commented 5 years ago

The steps I use aren't the simplest, I think, but they should at least allow you to reproduce:

  stack build --dependencies-only
  stack \
        exec ghc-pkg -- list | grep pkgdb | awk '{print "--package-db=" $0}' > db-paths
  stack \
        exec --no-ghc-package-path cabal -- configure \
        $(cat db-paths) \
        --prefix=/usr --docdir="/usr/share/doc/${pkgname}"
  stack \
        exec --no-ghc-package-path cabal -- build
  stack \
        exec --no-ghc-package-path cabal -- copy \
        --destdir="${destdir}"

You end up with the result of the copy in destdir, and it's those contents that's then package up into a distro package.

danstiner commented 5 years ago

I ran those commands and the resulting executable worked fine (at least on the same machine). Do you maybe have custom hlint config that is causing this? Does the normal hfmt exe resulting from stack install work when run from the same working directory?

magthe commented 5 years ago

Here's how I manage to reproduce it on a clean system (a system with only stack and cabal installed)

mkdir hfmt-destdir
cabal get hfmt
cd hfmt-0.2.3.1
stack build --dependencies-only
stack exec ghc-pkg -- list | grep pkgdb | awk '{print "--package-db=" $0}' > db-paths
stack exec --no-ghc-package-path cabal -- configure $(cat db-paths) --prefix=/usr --docdir="/usr/share/doc/hfmt"
stack exec --no-ghc-package-path cabal -- build
stack exec --no-ghc-package-path cabal -- copy --destdir="../hfmt-destdir"
cd ..
rm -fr hfmt-0.2.3.1
rm -fr ~/.stack
echo 'main = putStrLn "Hello, World!"' > main.hs
./hfmt-destdir/usr/bin/hfmt main.hs

on my system this results in

hfmt: user error (Failed to find requested hint files:
  /home/magnus/Private/tmp/hfmt-destdir/usr/bin/data/hlint.yaml
)

and if I move the binary to /usr/local/bin I can see that it looks for the file relative to the location of the binary.

It also looks for the file in the location where stack caches the hlint library (under ~/.stack/snapshots/...).

I think a good solution would be to:

danstiner commented 5 years ago

Thanks, the comment about looking where hlint is installed by stack really helped me understand. The issue seems to be that a library I rely on (hlint) has hlint.yaml declared as a data file and expects it to get copied. I assumed cabal would copy any required data files from dependencies but it seems it will not. The fix should be as simple as copy in data/hlint.yaml from that project and add a data-files directive to the cabal file so it gets copied.

My personal laptop is in for repairs so I'm not sure when I'll have access to a machine to make the fix, but I'lll try to find a way.

magthe commented 5 years ago

Oh, take your time, I'm in no hurry :)