Skip to content

Commit

Permalink
Merge pull request haskell#7973 from patrickdoc/local-ghc-options
Browse files Browse the repository at this point in the history
Remove local options from global program options
  • Loading branch information
mergify[bot] authored Feb 28, 2022
2 parents 9b300f3 + ab0c9c6 commit c46eb51
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ commandLineFlagsToProjectConfig globalFlags NixStyleFlags {..} clientInstallFlag
-- split the package config (from command line arguments) into
-- those applied to all packages and those to local only.
--
-- for now we will just copy over the ProgramPaths/Args/Extra into
-- for now we will just copy over the ProgramPaths/Extra into
-- the AllPackages. The LocalPackages do not inherit them from
-- AllPackages, and as such need to retain them.
--
Expand All @@ -215,7 +215,6 @@ commandLineFlagsToProjectConfig globalFlags NixStyleFlags {..} clientInstallFlag
splitConfig :: PackageConfig -> (PackageConfig, PackageConfig)
splitConfig pc = (pc
, mempty { packageConfigProgramPaths = packageConfigProgramPaths pc
, packageConfigProgramArgs = packageConfigProgramArgs pc
, packageConfigProgramPathExtra = packageConfigProgramPathExtra pc
, packageConfigDocumentation = packageConfigDocumentation pc })

Expand Down
3 changes: 0 additions & 3 deletions cabal-install/src/Distribution/Client/ProjectPlanning.hs
Original file line number Diff line number Diff line change
Expand Up @@ -476,15 +476,13 @@ rebuildInstallPlan verbosity
},
projectConfigLocalPackages = PackageConfig {
packageConfigProgramPaths,
packageConfigProgramArgs,
packageConfigProgramPathExtra
}
} = do
progsearchpath <- liftIO $ getSystemSearchPath
rerunIfChanged verbosity fileMonitorCompiler
(hcFlavor, hcPath, hcPkg, progsearchpath,
packageConfigProgramPaths,
packageConfigProgramArgs,
packageConfigProgramPathExtra) $ do

liftIO $ info verbosity "Compiler settings changed, reconfiguring..."
Expand All @@ -508,7 +506,6 @@ rebuildInstallPlan verbosity
hcPkg = flagToMaybe projectConfigHcPkg
progdb =
userSpecifyPaths (Map.toList (getMapLast packageConfigProgramPaths))
. userSpecifyArgss (Map.toList (getMapMappend packageConfigProgramArgs))
. modifyProgramSearchPath
(++ [ ProgramSearchPathDir dir
| dir <- fromNubList packageConfigProgramPathExtra ])
Expand Down
93 changes: 93 additions & 0 deletions cabal-install/tests/IntegrationTests2.hs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ tests config =

, testGroup "Regression tests" $
[ testCase "issue #3324" (testRegressionIssue3324 config)
, testCase "program options scope all" (testProgramOptionsAll config)
, testCase "program options scope local" (testProgramOptionsLocal config)
, testCase "program options scope specific" (testProgramOptionsSpecific config)
]
]

Expand Down Expand Up @@ -1540,6 +1543,96 @@ testRegressionIssue3324 config = when (buildOS /= Windows) $ do
where
testdir = "regression/3324"

-- | Test global program options are propagated correctly
-- from ProjectConfig to ElaboratedInstallPlan
testProgramOptionsAll :: ProjectConfig -> Assertion
testProgramOptionsAll config0 = do
-- P is a tarball package, Q is a local dir package that depends on it.
(_, elaboratedPlan, _) <- planProject testdir config
let packages = filterConfiguredPackages $ InstallPlan.toList elaboratedPlan

assertEqual "q"
(Just [ghcFlag])
(getProgArgs packages "q")
assertEqual "p"
(Just [ghcFlag])
(getProgArgs packages "p")
where
testdir = "regression/program-options"
programArgs = MapMappend (Map.fromList [("ghc", [ghcFlag])])
ghcFlag = "-fno-full-laziness"

-- Insert flag into global config
config = config0 {
projectConfigAllPackages = (projectConfigAllPackages config0) {
packageConfigProgramArgs = programArgs
}
}

-- | Test local program options are propagated correctly
-- from ProjectConfig to ElaboratedInstallPlan
testProgramOptionsLocal :: ProjectConfig -> Assertion
testProgramOptionsLocal config0 = do
(_, elaboratedPlan, _) <- planProject testdir config
let localPackages = filterConfiguredPackages $ InstallPlan.toList elaboratedPlan

assertEqual "q"
(Just [ghcFlag])
(getProgArgs localPackages "q")
assertEqual "p"
Nothing
(getProgArgs localPackages "p")
where
testdir = "regression/program-options"
programArgs = MapMappend (Map.fromList [("ghc", [ghcFlag])])
ghcFlag = "-fno-full-laziness"

-- Insert flag into local config
config = config0 {
projectConfigLocalPackages = (projectConfigLocalPackages config0) {
packageConfigProgramArgs = programArgs
}
}

-- | Test package specific program options are propagated correctly
-- from ProjectConfig to ElaboratedInstallPlan
testProgramOptionsSpecific :: ProjectConfig -> Assertion
testProgramOptionsSpecific config0 = do
(_, elaboratedPlan, _) <- planProject testdir config
let packages = filterConfiguredPackages $ InstallPlan.toList elaboratedPlan

assertEqual "q"
(Nothing)
(getProgArgs packages "q")
assertEqual "p"
(Just [ghcFlag])
(getProgArgs packages "p")
where
testdir = "regression/program-options"
programArgs = MapMappend (Map.fromList [("ghc", [ghcFlag])])
ghcFlag = "-fno-full-laziness"

-- Insert flag into package "p" config
config = config0 {
projectConfigSpecificPackage = MapMappend (Map.fromList [(mkPackageName "p", configArgs)])
}
configArgs = mempty {
packageConfigProgramArgs = programArgs
}

filterConfiguredPackages :: [ElaboratedPlanPackage] -> [ElaboratedConfiguredPackage]
filterConfiguredPackages [] = []
filterConfiguredPackages (InstallPlan.PreExisting _ : pkgs) = filterConfiguredPackages pkgs
filterConfiguredPackages (InstallPlan.Installed elab : pkgs) = elab : filterConfiguredPackages pkgs
filterConfiguredPackages (InstallPlan.Configured elab : pkgs) = elab : filterConfiguredPackages pkgs

getProgArgs :: [ElaboratedConfiguredPackage] -> String -> Maybe [String]
getProgArgs [] _ = Nothing
getProgArgs (elab : pkgs) name
| pkgName (elabPkgSourceId elab) == mkPackageName name
= Map.lookup "ghc" (elabProgramArgs elab)
| otherwise
= getProgArgs pkgs name

---------------------------------
-- Test utils to plan and build
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
packages: p-0.1.tar.gz
q/
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Q where

import P

q = p ++ " world"
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: q
version: 0.1
build-type: Simple
cabal-version: >= 1.2

library
exposed-modules: Q
build-depends: base, p
22 changes: 22 additions & 0 deletions cabal-install/tests/UnitTests/Distribution/Client/Configure.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Distribution.Client.CmdConfigure
import Test.Tasty
import Test.Tasty.HUnit
import Control.Monad
import qualified Data.Map as Map
import System.Directory
import System.FilePath
import Distribution.Verbosity
Expand Down Expand Up @@ -94,6 +95,27 @@ configureTests = testGroup "Configure tests"

doesFileExist backup >>=
assertBool ("No file found, expected: " ++ backup)

, testCase "Local program options" $ do
let ghcFlags = ["-fno-full-laziness"]
flags = (defaultNixStyleFlags ())
{ configFlags = mempty
{ configVerbosity = Flag silent
, configProgramArgs = [("ghc", ghcFlags)]
}
, projectFlags = mempty
{ flagProjectFileName = Flag projectFile }
}
(_, ProjectConfig {..}) <- configureAction' flags [] defaultGlobalFlags


assertEqual "global"
Nothing
(Map.lookup "ghc" (getMapMappend (packageConfigProgramArgs projectConfigAllPackages)))

assertEqual "local"
(Just ghcFlags)
(Map.lookup "ghc" (getMapMappend (packageConfigProgramArgs projectConfigLocalPackages)))
]

projectFile :: FilePath
Expand Down
9 changes: 9 additions & 0 deletions changelog.d/pr-7973
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
synopsis: Apply local options only to local packages
packages: cabal-install
prs: #7973
issues: #7998

description: {
- Command-line `ghc-options` only applies to local packages
- `program-options` stanza only applies to local packages
}
17 changes: 7 additions & 10 deletions doc/cabal-project.rst
Original file line number Diff line number Diff line change
Expand Up @@ -643,16 +643,13 @@ an external dependency) should be built with ``-fno-state-hack``::
package bytestring
ghc-options: -fno-state-hack

``ghc-options`` is not specifically described in this documentation,
but is one of many fields for configuring programs. They take the form
``progname-options`` and ``progname-location``, and
can only be set inside package stanzas. (TODO: They are not supported
at top-level, see :issue:`3579`.)

At the moment, there is no way to specify an option to apply to all
external packages or all inplace packages. Additionally, it is only
possible to specify these options on the command line for all local
packages (there is no per-package command line interface.)
``ghc-options`` is not specifically described in this documentation, but is one
of many fields for configuring programs. They take the form
``progname-options`` and ``progname-location``, and can be set for all local
packages in a ``program-options`` stanza or under a package stanza.

On the command line, these options are applied to all local packages.
There is no per-package command line interface.

Some flags were added by more recent versions of the Cabal library. This
means that they are NOT supported by packages which use Custom setup
Expand Down

0 comments on commit c46eb51

Please sign in to comment.