Skip to content

Binaries have package_datadir hardcoded to build directory, not path in Paths_hlint.hs #6234

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

Open
essandess opened this issue Sep 11, 2019 · 0 comments

Comments

@essandess
Copy link

I’m trying to port IHaskell to MacPorts. IHaskell uses hlint. The issue is that both stack and cabal builds create binaries with an hlint_datadir that points to the build directory in .stack or .cabal-sandbox, not the install directory with prefix, say, /opt/local/share/hlint. After the build, these temporary build directories are discarded, and neither ihaskell nor hlint binaries work.

This issue has been opened at ndmitchell/hlint#699 and IHaskell/IHaskell#1061, and we all agree that it's an upstream issue with cabal.

Before I get to the issue, please let me recap the background:

Now that we have a working fix to stack and cabal's data-files issues, I'd like to use it for the MacPorts port. I haven't gotten this working with ihaskell's more complicated build, including its dependencies like hlint.

Would you please help figure out an hlint (within ihaskell) build recipe that produces a relocatable, properly prefix-ed binary?

The src/Paths_*.hs approach works for the ihaskell binary, but not for hlint_datadir in either the ihaskell or hlint binaries. I’ve tried many things:

Nothing is working. ghc always finds the Paths_hlint.hs that Cabal generates, not the one I provided.

Would you all please indicate a Cabal build recipe that reads my version of Paths_hlint.hs—not Cabal's autogen version—so that we can get a properly DESTDIR-ed and PREFIXED-ed binary for a packaged install?

Cabal-based build recipe:

cabal update
cabal install cpphs happy
cabal sandbox init
cabal sandbox add-source . ./ghc-parser ./ipython-kernel
cabal install --only-dependencies
cabal configure --extra-lib-dir=/usr/lib
cabal install --extra-lib-dir=/usr/lib

Alternate stack-based build recipe:

rm -fr ~/.stack ./.stack-work stack.yaml.lock
stack setup
stack build

Here's aPaths_hlint.hs that should work. A successful build recipe will just stick this in a place where it will be found by ghc before the Cabal’s autogen Paths_*.hs file.

{- Cabal data-files hardcoded path in binary fix.

This file replaces the `Paths_hlint.hs` automatically created by Cabal.

See:
* https://github.com/commercialhaskell/stack/issues/848
* https://github.com/commercialhaskell/stack/issues/4857
* https://github.com/haskell/cabal/issues/462
* https://github.com/haskell/cabal/issues/3586

-}
        
{-# LANGUAGE CPP #-}
{-# LANGUAGE NoRebindableSyntax #-}
{-# OPTIONS_GHC -fno-warn-missing-import-lists #-}
module Paths_hlint (
    version,
    getBinDir, getLibDir, getDynLibDir, getDataDir, getLibexecDir,
    getDataFileName, getSysconfDir
  ) where

import qualified Control.Exception as Exception
import Data.Version (Version(..))
import System.Environment (getEnv)
import Prelude

#if defined(VERSION_base)

#if MIN_VERSION_base(4,0,0)
catchIO :: IO a -> (Exception.IOException -> IO a) -> IO a
#else
catchIO :: IO a -> (Exception.Exception -> IO a) -> IO a
#endif

#else
catchIO :: IO a -> (Exception.IOException -> IO a) -> IO a
#endif
catchIO = Exception.catch

version :: Version
version = Version [2,0,1] []
bindir, libdir, dynlibdir, datadir, libexecdir, sysconfdir :: FilePath

bindir     = "/opt/local/bin"
libdir     = "/opt/local/lib/ihaskell"
dynlibdir  = "/opt/local/lib/ihaskell"
datadir    = "/opt/local/share/ihaskell"
libexecdir = "/opt/local/lib/ihaskell"
sysconfdir = "/opt/local/etc"

getBinDir, getLibDir, getDynLibDir, getDataDir, getLibexecDir, getSysconfDir :: IO FilePath
getBinDir = catchIO (getEnv "hlint_bindir") (\_ -> return bindir)
getLibDir = catchIO (getEnv "hlint_libdir") (\_ -> return libdir)
getDynLibDir = catchIO (getEnv "hlint_dynlibdir") (\_ -> return dynlibdir)
getDataDir = catchIO (getEnv "hlint_datadir") (\_ -> return datadir)
getLibexecDir = catchIO (getEnv "hlint_libexecdir") (\_ -> return libexecdir)
getSysconfDir = catchIO (getEnv "hlint_sysconfdir") (\_ -> return sysconfdir)

getDataFileName :: FilePath -> IO FilePath
getDataFileName name = do
  dir <- getDataDir
  return (dir ++ "/" ++ name)
essandess added a commit to essandess/macports-ports that referenced this issue Sep 13, 2019
* Uses port:stack for build
* Uses Paths_ihaskell.hs for correct `${prefix}` of Cabal data-files path

Related: haskell/cabal#6234
Related: commercialhaskell/stack#5026
Related: https://trac.macports.org/ticket/50608
mf2k pushed a commit to macports/macports-ports that referenced this issue Sep 14, 2019
* Uses port:stack for build
* Uses Paths_ihaskell.hs for correct `${prefix}` of Cabal data-files path

Related: haskell/cabal#6234
Related: commercialhaskell/stack#5026
Related: https://trac.macports.org/ticket/50608
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants