Skip to content

Commit a387779

Browse files
committed
Fix for-hackage rendering to distinguish NoFlag and default case.
This commit fixes one instances of a general bug where noFlag command line flags do not translate correctly when converted into the field description format (and in fact, cannot be converted correctly.) The bug goes something like this: 1. A noArg command line parser translates into a "choice" command line parser, for which there is only one choice (the flag that would be set when you toggle it on.) 2. Choice command line parsers get translated into the field format by having a rendering for each defined choice, and then default to empty (omit the field entirely) if no choices apply. 3. This means that NoFlag and the "default choice" (if you hadn't specified the flag at all) render identically, because there is never a choice for the default choice in the no arg field. In the interest of getting this to work, I manually made for-hackage work correctly, but there is probably a way to refactor this into a more universal fix. CC @dcoutts Signed-off-by: Edward Z. Yang <ezyang@cs.stanford.edu>
1 parent df53e50 commit a387779

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

Cabal/Distribution/Simple/Setup.hs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,6 +1480,13 @@ data HaddockTarget = ForHackage | ForDevelopment deriving (Eq, Show, Generic)
14801480

14811481
instance Binary HaddockTarget
14821482

1483+
instance Text HaddockTarget where
1484+
disp ForHackage = Disp.text "for-hackage"
1485+
disp ForDevelopment = Disp.text "for-development"
1486+
1487+
parse = Parse.choice [ Parse.string "for-hackage" >> return ForHackage
1488+
, Parse.string "for-development" >> return ForDevelopment]
1489+
14831490
data HaddockFlags = HaddockFlags {
14841491
haddockProgramPaths :: [(String, FilePath)],
14851492
haddockProgramArgs :: [(String, [String])],

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -953,12 +953,18 @@ legacyPackageConfigFieldDescrs =
953953
(\flags conf -> conf { legacyHaddockFlags = flags })
954954
. mapFieldNames
955955
("haddock-"++)
956+
. addFields
957+
[ simpleField "for-hackage"
958+
-- TODO: turn this into a library function
959+
(fromFlagOrDefault Disp.empty . fmap disp) (Parse.option mempty (fmap toFlag parse))
960+
haddockForHackage (\v conf -> conf { haddockForHackage = v })
961+
]
956962
. filterFields
957963
[ "hoogle", "html", "html-location"
958964
, "foreign-libraries"
959965
, "executables", "tests", "benchmarks", "all", "internal", "css"
960966
, "hyperlink-source", "hscolour-css"
961-
, "contents-location", "keep-temp-files", "for-hackage"
967+
, "contents-location", "keep-temp-files"
962968
]
963969
. commandOptionsToFields
964970
) (haddockOptions ParseArgs)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ instance Arbitrary PackageConfig where
503503
. Map.mapKeys getNoShrink
504504

505505
instance Arbitrary HaddockTarget where
506-
arbitrary = elements [ForHackage]
506+
arbitrary = elements [ForHackage, ForDevelopment]
507507

508508
instance Arbitrary SourceRepo where
509509
arbitrary = (SourceRepo RepoThis

0 commit comments

Comments
 (0)