Skip to content
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

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

Open
nh2 opened this issue Aug 8, 2019 · 2 comments
Open

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

nh2 opened this issue Aug 8, 2019 · 2 comments

Comments

@nh2
Copy link
Member

nh2 commented Aug 8, 2019

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 1b324a1, on Ubuntu 16.04.

Reason

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

The problem is in

elabProgramArgs = Map.fromList
[ (programId prog, args)
| prog <- configuredPrograms compilerprogdb
, let args = programOverrideArgs prog
, not (null args)
]
<> perPkgOptionMapMappend pkgid packageConfigProgramArgs

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

This is due to

perPkgOptionMapMappend pkgid f = getMapMappend (lookupPerPkgOption pkgid f)

which does

lookupPerPkgOption :: (Package pkg, Monoid m)
=> pkg -> (PackageConfig -> m) -> m
lookupPerPkgOption pkg f =
-- This is where we merge the options from the project config that
-- apply to all packages, all project local packages, and to specific
-- named packages
global `mappend` local `mappend` perpkg
where
global = f allPackagesConfig
local | isLocalToProject pkg
= f localPackagesConfig
| otherwise
= mempty
perpkg = maybe mempty f (Map.lookup (packageName pkg) perPackageConfig)

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, 20d0026, 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?

@nh2 nh2 mentioned this issue Aug 8, 2019
5 tasks
@23Skidoo
Copy link
Member

23Skidoo commented Aug 9, 2019

/cc @dcoutts

@jneira
Copy link
Member

jneira commented Aug 9, 2019

I've noted that behaviour trying to debug #5805 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants