haskell / haskell/cabal

Handling paths for include-dirs, extra-lib-dirs, and framework-dirs.

Open
#2,641 5 comments 1 reaction 0 assignees View on GitHub
Cabal: cmd/build Cabal: file format type: bug type: discussion type: enhancement
Dominant language
Haskell
Stars
1.7k
Forks
750
Avg merge
4d 3h
Merged PRs (30d)
28

Description

Sorry for writting a lengthy bug report, but while trying to fix #694 during ZuriHac 2015, I consulted with @kosmikus and @dcoutts, and we realised that there is no simple solution to this problem.
## Handling options in Cabal

Currently cabal treats options specified in global `~/.cabal/config` file, local `cabal.config` file, project's `.cabal` file, together with options passed on the command line in an uniform way, by merging them during the configure step and performing a single check. These options include paths that will be supplied to `ghc-pkg` when registering the package.
## Problem

`ghc-pkg` will complain and report an error when the following paths are relative:
- _include-dirs_, which is passed to `ghc-pkg` as fully expanded (prefixed with cwd if relative) and does not cause any `ghc-pkg` errors if _include-dirs_ is set to a relative path;
- _extra-lib-dirs_, which is passed to `ghc-pkg` as-it-is, and will cause a `ghc-pkg` error, if _extra-lib-dirs_ is set to a relative path;
- _framework-dirs_, which cannot be specified in project's `.cabal` file, is passed to `ghc-pkg` as-it-is, and will cause a `ghc-pkg` error, if _framework-dirs_ is set to a relative path;

Additionally, as @bos mentioned in #694, it would make little sense for some of these paths to be relative and lie outside of the project tree. Actually, there is a check in Cabal to determine if the absolute paths are outside of the project tree and produces a [`PackageBuildWarning`](https://github.com/haskell/cabal/blob/master/Cabal/Distribution/PackageDescription/Check.hs#l816), but I am not sure if it works correctly.
## Proposed solution

During configure step, Cabal should pick up any path that would cause a `ghc-pkg` error and produce a sensible warning message, that will clearly instruct the developer what to do.

Desirable handling of paths, as proposed by @dcoutts:
- allow relative _include-dirs_ in the project's `.cabal` file,
- require _extra-lib-dirs_ to be absolute in the project's `.cabal` file,
- allow relative paths on the command line or in a local `cabal.config` file (by expanding them to absolute paths).
- require paths specified in the global `~/.cabal/config` file to be absolute.

Currently, I am working on extending [`checkPaths`](https://github.com/haskell/cabal/blob/master/Cabal/Distribution/PackageDescription/Check.hs#l813) to check for paths that need to be absolute.
Any inputs and opinions are welcome.
## Related Issues

So far I found the folllowing issues related to this problem: #694, #1317, #1378

Contributor guide

Open the contributing guide

Research direction

Start with Cabal/Distribution/PackageDescription/Check.hs and the checkPaths function named in the issue. Compare its existing path checks with the proposed rules for .cabal, local cabal.config, global ~/.cabal/config, and command-line paths; done means configure-time warnings clearly identify paths that must be absolute.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.