Skip to content

Commit c46eb51

Browse files
authored
Merge pull request #7973 from patrickdoc/local-ghc-options
Remove local options from global program options
2 parents 9b300f3 + ab0c9c6 commit c46eb51

File tree

10 files changed

+147
-15
lines changed

10 files changed

+147
-15
lines changed

cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ commandLineFlagsToProjectConfig globalFlags NixStyleFlags {..} clientInstallFlag
198198
-- split the package config (from command line arguments) into
199199
-- those applied to all packages and those to local only.
200200
--
201-
-- for now we will just copy over the ProgramPaths/Args/Extra into
201+
-- for now we will just copy over the ProgramPaths/Extra into
202202
-- the AllPackages. The LocalPackages do not inherit them from
203203
-- AllPackages, and as such need to retain them.
204204
--
@@ -215,7 +215,6 @@ commandLineFlagsToProjectConfig globalFlags NixStyleFlags {..} clientInstallFlag
215215
splitConfig :: PackageConfig -> (PackageConfig, PackageConfig)
216216
splitConfig pc = (pc
217217
, mempty { packageConfigProgramPaths = packageConfigProgramPaths pc
218-
, packageConfigProgramArgs = packageConfigProgramArgs pc
219218
, packageConfigProgramPathExtra = packageConfigProgramPathExtra pc
220219
, packageConfigDocumentation = packageConfigDocumentation pc })
221220

cabal-install/src/Distribution/Client/ProjectPlanning.hs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -476,15 +476,13 @@ rebuildInstallPlan verbosity
476476
},
477477
projectConfigLocalPackages = PackageConfig {
478478
packageConfigProgramPaths,
479-
packageConfigProgramArgs,
480479
packageConfigProgramPathExtra
481480
}
482481
} = do
483482
progsearchpath <- liftIO $ getSystemSearchPath
484483
rerunIfChanged verbosity fileMonitorCompiler
485484
(hcFlavor, hcPath, hcPkg, progsearchpath,
486485
packageConfigProgramPaths,
487-
packageConfigProgramArgs,
488486
packageConfigProgramPathExtra) $ do
489487

490488
liftIO $ info verbosity "Compiler settings changed, reconfiguring..."
@@ -508,7 +506,6 @@ rebuildInstallPlan verbosity
508506
hcPkg = flagToMaybe projectConfigHcPkg
509507
progdb =
510508
userSpecifyPaths (Map.toList (getMapLast packageConfigProgramPaths))
511-
. userSpecifyArgss (Map.toList (getMapMappend packageConfigProgramArgs))
512509
. modifyProgramSearchPath
513510
(++ [ ProgramSearchPathDir dir
514511
| dir <- fromNubList packageConfigProgramPathExtra ])

cabal-install/tests/IntegrationTests2.hs

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ tests config =
135135

136136
, testGroup "Regression tests" $
137137
[ testCase "issue #3324" (testRegressionIssue3324 config)
138+
, testCase "program options scope all" (testProgramOptionsAll config)
139+
, testCase "program options scope local" (testProgramOptionsLocal config)
140+
, testCase "program options scope specific" (testProgramOptionsSpecific config)
138141
]
139142
]
140143

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

1546+
-- | Test global program options are propagated correctly
1547+
-- from ProjectConfig to ElaboratedInstallPlan
1548+
testProgramOptionsAll :: ProjectConfig -> Assertion
1549+
testProgramOptionsAll config0 = do
1550+
-- P is a tarball package, Q is a local dir package that depends on it.
1551+
(_, elaboratedPlan, _) <- planProject testdir config
1552+
let packages = filterConfiguredPackages $ InstallPlan.toList elaboratedPlan
1553+
1554+
assertEqual "q"
1555+
(Just [ghcFlag])
1556+
(getProgArgs packages "q")
1557+
assertEqual "p"
1558+
(Just [ghcFlag])
1559+
(getProgArgs packages "p")
1560+
where
1561+
testdir = "regression/program-options"
1562+
programArgs = MapMappend (Map.fromList [("ghc", [ghcFlag])])
1563+
ghcFlag = "-fno-full-laziness"
1564+
1565+
-- Insert flag into global config
1566+
config = config0 {
1567+
projectConfigAllPackages = (projectConfigAllPackages config0) {
1568+
packageConfigProgramArgs = programArgs
1569+
}
1570+
}
1571+
1572+
-- | Test local program options are propagated correctly
1573+
-- from ProjectConfig to ElaboratedInstallPlan
1574+
testProgramOptionsLocal :: ProjectConfig -> Assertion
1575+
testProgramOptionsLocal config0 = do
1576+
(_, elaboratedPlan, _) <- planProject testdir config
1577+
let localPackages = filterConfiguredPackages $ InstallPlan.toList elaboratedPlan
1578+
1579+
assertEqual "q"
1580+
(Just [ghcFlag])
1581+
(getProgArgs localPackages "q")
1582+
assertEqual "p"
1583+
Nothing
1584+
(getProgArgs localPackages "p")
1585+
where
1586+
testdir = "regression/program-options"
1587+
programArgs = MapMappend (Map.fromList [("ghc", [ghcFlag])])
1588+
ghcFlag = "-fno-full-laziness"
1589+
1590+
-- Insert flag into local config
1591+
config = config0 {
1592+
projectConfigLocalPackages = (projectConfigLocalPackages config0) {
1593+
packageConfigProgramArgs = programArgs
1594+
}
1595+
}
1596+
1597+
-- | Test package specific program options are propagated correctly
1598+
-- from ProjectConfig to ElaboratedInstallPlan
1599+
testProgramOptionsSpecific :: ProjectConfig -> Assertion
1600+
testProgramOptionsSpecific config0 = do
1601+
(_, elaboratedPlan, _) <- planProject testdir config
1602+
let packages = filterConfiguredPackages $ InstallPlan.toList elaboratedPlan
1603+
1604+
assertEqual "q"
1605+
(Nothing)
1606+
(getProgArgs packages "q")
1607+
assertEqual "p"
1608+
(Just [ghcFlag])
1609+
(getProgArgs packages "p")
1610+
where
1611+
testdir = "regression/program-options"
1612+
programArgs = MapMappend (Map.fromList [("ghc", [ghcFlag])])
1613+
ghcFlag = "-fno-full-laziness"
1614+
1615+
-- Insert flag into package "p" config
1616+
config = config0 {
1617+
projectConfigSpecificPackage = MapMappend (Map.fromList [(mkPackageName "p", configArgs)])
1618+
}
1619+
configArgs = mempty {
1620+
packageConfigProgramArgs = programArgs
1621+
}
1622+
1623+
filterConfiguredPackages :: [ElaboratedPlanPackage] -> [ElaboratedConfiguredPackage]
1624+
filterConfiguredPackages [] = []
1625+
filterConfiguredPackages (InstallPlan.PreExisting _ : pkgs) = filterConfiguredPackages pkgs
1626+
filterConfiguredPackages (InstallPlan.Installed elab : pkgs) = elab : filterConfiguredPackages pkgs
1627+
filterConfiguredPackages (InstallPlan.Configured elab : pkgs) = elab : filterConfiguredPackages pkgs
1628+
1629+
getProgArgs :: [ElaboratedConfiguredPackage] -> String -> Maybe [String]
1630+
getProgArgs [] _ = Nothing
1631+
getProgArgs (elab : pkgs) name
1632+
| pkgName (elabPkgSourceId elab) == mkPackageName name
1633+
= Map.lookup "ghc" (elabProgramArgs elab)
1634+
| otherwise
1635+
= getProgArgs pkgs name
15431636

15441637
---------------------------------
15451638
-- Test utils to plan and build
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
packages: p-0.1.tar.gz
2+
q/
319 Bytes
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module Q where
2+
3+
import P
4+
5+
q = p ++ " world"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name: q
2+
version: 0.1
3+
build-type: Simple
4+
cabal-version: >= 1.2
5+
6+
library
7+
exposed-modules: Q
8+
build-depends: base, p

cabal-install/tests/UnitTests/Distribution/Client/Configure.hs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Distribution.Client.CmdConfigure
66
import Test.Tasty
77
import Test.Tasty.HUnit
88
import Control.Monad
9+
import qualified Data.Map as Map
910
import System.Directory
1011
import System.FilePath
1112
import Distribution.Verbosity
@@ -94,6 +95,27 @@ configureTests = testGroup "Configure tests"
9495

9596
doesFileExist backup >>=
9697
assertBool ("No file found, expected: " ++ backup)
98+
99+
, testCase "Local program options" $ do
100+
let ghcFlags = ["-fno-full-laziness"]
101+
flags = (defaultNixStyleFlags ())
102+
{ configFlags = mempty
103+
{ configVerbosity = Flag silent
104+
, configProgramArgs = [("ghc", ghcFlags)]
105+
}
106+
, projectFlags = mempty
107+
{ flagProjectFileName = Flag projectFile }
108+
}
109+
(_, ProjectConfig {..}) <- configureAction' flags [] defaultGlobalFlags
110+
111+
112+
assertEqual "global"
113+
Nothing
114+
(Map.lookup "ghc" (getMapMappend (packageConfigProgramArgs projectConfigAllPackages)))
115+
116+
assertEqual "local"
117+
(Just ghcFlags)
118+
(Map.lookup "ghc" (getMapMappend (packageConfigProgramArgs projectConfigLocalPackages)))
97119
]
98120

99121
projectFile :: FilePath

changelog.d/pr-7973

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
synopsis: Apply local options only to local packages
2+
packages: cabal-install
3+
prs: #7973
4+
issues: #7998
5+
6+
description: {
7+
- Command-line `ghc-options` only applies to local packages
8+
- `program-options` stanza only applies to local packages
9+
}

doc/cabal-project.rst

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -643,16 +643,13 @@ an external dependency) should be built with ``-fno-state-hack``::
643643
package bytestring
644644
ghc-options: -fno-state-hack
645645

646-
``ghc-options`` is not specifically described in this documentation,
647-
but is one of many fields for configuring programs. They take the form
648-
``progname-options`` and ``progname-location``, and
649-
can only be set inside package stanzas. (TODO: They are not supported
650-
at top-level, see :issue:`3579`.)
651-
652-
At the moment, there is no way to specify an option to apply to all
653-
external packages or all inplace packages. Additionally, it is only
654-
possible to specify these options on the command line for all local
655-
packages (there is no per-package command line interface.)
646+
``ghc-options`` is not specifically described in this documentation, but is one
647+
of many fields for configuring programs. They take the form
648+
``progname-options`` and ``progname-location``, and can be set for all local
649+
packages in a ``program-options`` stanza or under a package stanza.
650+
651+
On the command line, these options are applied to all local packages.
652+
There is no per-package command line interface.
656653

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

0 commit comments

Comments
 (0)