haskell / haskell/cabal

--prog-option(s) (e.g. gcc-options) CLI flags get duplicated

Open
#6,183 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haskell
Stars
1.7k
Forks
750
Avg merge
4d 3h
Merged PRs (30d)
28

Description

Found in https://github.com/haskell/cabal/pull/5451/files#r310417490:

## Problem

When a flag like `--gcc-option` or the new `--ld-option` is given to `cabal build`, the eventual gcc/ld invocation will be given that flag *twice*.

For example, if you `cabal build --gcc-option=-v`, then `gcc -v -v` will be called.

You can verify this by passing `-v` to cabal and ghc, or using strace.

This is obviously problematic when giving a flag twice results in different behaviour from the tool than giving it once.

## Environment

Cabal version: `3.0.0.0` built from commit 1b324a1dfebb8a874ef29de408604b0981a737b6, on Ubuntu 16.04.

## Reason

I've spent a couple hours figuring out where this comes from.

The problem is in https://github.com/haskell/cabal/blob/1b324a1dfebb8a874ef29de408604b0981a737b6/cabal-install/Distribution/Client/ProjectPlanning.hs#L1851-L1857

In `elabProgramArgs`, the `<> perPkgOptionMapMappend pkgid packageConfigProgramArgs` is what contains the flags twice, for example `fromList [("ld",["-s","-s"])]`.

This is due to https://github.com/haskell/cabal/blob/1b324a1dfebb8a874ef29de408604b0981a737b6/cabal-install/Distribution/Client/ProjectPlanning.hs#L1899

which does https://github.com/haskell/cabal/blob/1b324a1dfebb8a874ef29de408604b0981a737b6/cabal-install/Distribution/Client/ProjectPlanning.hs#L1909-L1922

In ```global `mappend` local `mappend` perpkg```, **each `global` and `local`** contain `MapMappend {getMapMappend = fromList [("ld",["-s"])]}`.

This seems wrong.

The commit message of the commit that introduced this, https://github.com/haskell/cabal/commit/20d0026427d670158391885dcfa605d893c0903d, says

> Program options specified on the command line currently apply to all local packages, not just the targets of the command.

This suggests that such options should only be in `local`. How comes they are also in `global`?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.