Skip to content

Commit 3770156

Browse files
authored
Merge pull request #4654 from phadej/parsec-only
Use parsec, drop parsec flag
2 parents a78ce90 + 3151cbe commit 3770156

37 files changed

+923
-287
lines changed

.travis.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@ matrix:
5454
- env: GHCVER=8.0.2 SCRIPT=solver-debug-flags USE_GOLD=YES
5555
sudo: required
5656
os: linux
57-
- env: GHCVER=8.0.2 SCRIPT=script PARSEC=YES TAGSUFFIX="-parsec" USE_GOLD=YES
58-
os: linux
59-
sudo: required
6057
- env: GHCVER=8.0.2 SCRIPT=script DEBUG_EXPENSIVE_ASSERTIONS=YES TAGSUFFIX="-fdebug-expensive-assertions" USE_GOLD=YES
6158
os: linux
6259
sudo: required

Cabal/Cabal.cabal

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ extra-source-files:
3232
-- Generated with 'misc/gen-extra-source-files.sh'
3333
-- Do NOT edit this section manually; instead, run the script.
3434
-- BEGIN gen-extra-source-files
35+
tests/ParserTests/regressions/Octree-0.5.cabal
36+
tests/ParserTests/regressions/encoding-0.8.cabal
3537
tests/ParserTests/warnings/bom.cabal
3638
tests/ParserTests/warnings/bool.cabal
3739
tests/ParserTests/warnings/deprecatedfield.cabal
@@ -64,11 +66,6 @@ flag old-directory
6466
description: Use directory < 1.2 and old-time
6567
default: False
6668

67-
flag parsec
68-
description: Use parsec parser
69-
default: False
70-
manual: True
71-
7269
flag parsec-struct-diff
7370
description: Use StructDiff in parsec tests. Affects only parsec tests.
7471
default: False
@@ -267,26 +264,23 @@ library
267264
Language.Haskell.Extension
268265
Distribution.Compat.Binary
269266

270-
if flag(parsec)
271-
cpp-options: -DCABAL_PARSEC
272-
build-depends:
273-
transformers,
274-
parsec >= 3.1.9 && <3.2
275-
build-tools:
276-
alex >=3.1.4 && <3.3
277-
exposed-modules:
278-
Distribution.Compat.Parsec
279-
Distribution.PackageDescription.Parsec
280-
Distribution.PackageDescription.Parsec.FieldDescr
281-
Distribution.Parsec.Class
282-
Distribution.Parsec.ConfVar
283-
Distribution.Parsec.Lexer
284-
Distribution.Parsec.LexerMonad
285-
Distribution.Parsec.Parser
286-
Distribution.Parsec.Types.Common
287-
Distribution.Parsec.Types.Field
288-
Distribution.Parsec.Types.FieldDescr
289-
Distribution.Parsec.Types.ParseResult
267+
build-depends:
268+
transformers,
269+
parsec >= 3.1.9 && <3.2
270+
exposed-modules:
271+
Distribution.Compat.Parsec
272+
Distribution.PackageDescription.Parsec
273+
Distribution.PackageDescription.Parsec.FieldDescr
274+
Distribution.PackageDescription.Parsec.Legacy
275+
Distribution.Parsec.Class
276+
Distribution.Parsec.ConfVar
277+
Distribution.Parsec.Lexer
278+
Distribution.Parsec.LexerMonad
279+
Distribution.Parsec.Parser
280+
Distribution.Parsec.Types.Common
281+
Distribution.Parsec.Types.Field
282+
Distribution.Parsec.Types.FieldDescr
283+
Distribution.Parsec.Types.ParseResult
290284

291285
other-modules:
292286
Distribution.Backpack.PreExistingComponent
@@ -382,9 +376,6 @@ test-suite unit-tests
382376
default-language: Haskell2010
383377

384378
test-suite parser-tests
385-
if !flag(parsec)
386-
buildable: False
387-
388379
type: exitcode-stdio-1.0
389380
hs-source-dirs: tests
390381
main-is: ParserTests.hs
@@ -400,15 +391,18 @@ test-suite parser-tests
400391
default-language: Haskell2010
401392

402393
test-suite parser-hackage-tests
403-
if !flag(parsec)
404-
buildable: False
405-
406394
type: exitcode-stdio-1.0
407395
main-is: ParserHackageTests.hs
408396

397+
-- TODO: need to get 01-index.tar on appveyor
398+
if os(windows)
399+
buildable: False
400+
409401
hs-source-dirs: tests
410402
build-depends:
411403
base,
404+
base-orphans == 0.6.*,
405+
base-compat >=0.9.3 && <0.10,
412406
containers,
413407
tar >=0.5 && <0.6,
414408
bytestring,
@@ -418,7 +412,7 @@ test-suite parser-hackage-tests
418412

419413
if flag(parsec-struct-diff)
420414
build-depends:
421-
generics-sop ==0.2.*,
415+
generics-sop >= 0.2.5 && <0.3,
422416
these >=0.7.1 && <0.8,
423417
singleton-bool >=0.1.1.0 && <0.2,
424418
keys

Cabal/Distribution/PackageDescription/Parsec.hs

Lines changed: 11 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import qualified Data.Map as Map
3838
import qualified Distribution.Compat.SnocList as SnocList
3939
import Distribution.PackageDescription
4040
import Distribution.PackageDescription.Parsec.FieldDescr
41+
import Distribution.PackageDescription.Parsec.Legacy (patchLegacy)
4142
import Distribution.Parsec.Class (parsec)
4243
import Distribution.Parsec.ConfVar
4344
(parseConditionConfVar)
@@ -103,10 +104,15 @@ readGenericPackageDescription = readAndParseFile parseGenericPackageDescription
103104
--
104105
-- TODO: add lex warnings
105106
parseGenericPackageDescription :: BS.ByteString -> ParseResult GenericPackageDescription
106-
parseGenericPackageDescription bs = case readFields' bs of
107-
Right (fs, lexWarnings) -> parseGenericPackageDescription' lexWarnings fs
107+
parseGenericPackageDescription bs = case readFields' bs' of
108+
Right (fs, lexWarnings) -> do
109+
when patched $
110+
parseWarning zeroPos PWTLegacyCabalFile "Legacy cabal file"
111+
parseGenericPackageDescription' lexWarnings fs
108112
-- TODO: better marshalling of errors
109-
Left perr -> parseFatalFailure (Position 0 0) (show perr)
113+
Left perr -> parseFatalFailure zeroPos (show perr)
114+
where
115+
(patched, bs') = patchLegacy bs
110116

111117
-- | 'Maybe' variant of 'parseGenericPackageDescription'
112118
parseGenericPackageDescriptionMaybe :: BS.ByteString -> Maybe GenericPackageDescription
@@ -168,7 +174,8 @@ parseGenericPackageDescription' lexWarnings fs = do
168174
gpd <- goFields emptyGpd fs'
169175
-- Various post checks
170176
maybeWarnCabalVersion syntax (packageDescription gpd)
171-
checkForUndefinedFlags gpd
177+
-- TODO: this does nothing
178+
-- checkForUndefinedFlags gpd
172179
-- TODO: do other validations
173180
return gpd
174181
where
@@ -326,42 +333,6 @@ parseGenericPackageDescription' lexWarnings fs = do
326333

327334
maybeWarnCabalVersion _ _ = return ()
328335

329-
{-
330-
handleFutureVersionParseFailure :: Version -> ParseResult a -> ParseResult GenericPackageDescription
331-
handleFutureVersionParseFailure _cabalVersionNeeded _parseBody =
332-
error "handleFutureVersionParseFailure"
333-
-}
334-
335-
{-
336-
undefined (unless versionOk (warning message) >> parseBody)
337-
`catchParseError` \parseError -> case parseError of
338-
TabsError _ -> parseFail parseError
339-
_ | versionOk -> parseFail parseError
340-
| otherwise -> fail message
341-
where versionOk = cabalVersionNeeded <= cabalVersion
342-
message = "This package requires at least Cabal version "
343-
++ display cabalVersionNeeded
344-
-}
345-
346-
checkForUndefinedFlags
347-
:: GenericPackageDescription
348-
-> ParseResult ()
349-
checkForUndefinedFlags _gpd = pure ()
350-
{-
351-
let definedFlags = map flagName flags
352-
mapM_ (checkCondTreeFlags definedFlags) (maybeToList mlib)
353-
mapM_ (checkCondTreeFlags definedFlags . snd) sub_libs
354-
mapM_ (checkCondTreeFlags definedFlags . snd) exes
355-
mapM_ (checkCondTreeFlags definedFlags . snd) tests
356-
357-
checkCondTreeFlags :: [FlagName] -> CondTree ConfVar c a -> PM ()
358-
checkCondTreeFlags definedFlags ct = do
359-
let fv = nub $ freeVars ct
360-
unless (all (`elem` definedFlags) fv) $
361-
fail $ "These flags are used without having been defined: "
362-
++ intercalate ", " [ n | FlagName n <- fv \\ definedFlags ]
363-
-}
364-
365336
parseName :: Position -> [SectionArg Position] -> ParseResult String
366337
parseName pos args = case args of
367338
[SecArgName _pos secName] ->
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
{-# LANGUAGE RankNTypes #-}
2+
{-# LANGUAGE OverloadedStrings #-}
3+
-- |
4+
--
5+
-- @since 2.2.0.0
6+
module Distribution.PackageDescription.Parsec.Legacy (patchLegacy) where
7+
8+
import Prelude ()
9+
import Distribution.Compat.Prelude
10+
import GHC.Fingerprint (Fingerprint (..), fingerprintData)
11+
import Foreign.Ptr (castPtr)
12+
import System.IO.Unsafe (unsafeDupablePerformIO)
13+
14+
import qualified Data.ByteString as BS
15+
import qualified Data.ByteString.Unsafe as BS
16+
import qualified Data.Map as Map
17+
18+
-- | Patch legacy @.cabal@ file contents to allow parsec parser to accept
19+
-- all of Hackage.
20+
--
21+
-- Bool part of the result tells whether the output is modified.
22+
--
23+
-- @since 2.2.0.0
24+
patchLegacy :: BS.ByteString -> (Bool, BS.ByteString)
25+
patchLegacy bs = case Map.lookup (BS.take 256 bs, md5 bs) patches of
26+
Nothing -> (False, bs)
27+
Just (post, f)
28+
| post /= md5 output -> (False, bs)
29+
| otherwise -> (True, output)
30+
where
31+
output = f bs
32+
33+
md5 :: BS.ByteString -> Fingerprint
34+
md5 bs = unsafeDupablePerformIO $ BS.unsafeUseAsCStringLen bs $ \(ptr, len) ->
35+
fingerprintData (castPtr ptr) len
36+
37+
-- | 'patches' contains first 256 bytes, pre- and post-fingerprints and a patch function.
38+
--
39+
--
40+
patches :: Map.Map (BS.ByteString, Fingerprint) (Fingerprint, BS.ByteString -> BS.ByteString)
41+
patches = Map.fromList
42+
-- http://hackage.haskell.org/package/unicode-transforms-0.3.3
43+
-- other-modules: .
44+
-- ReadP assumed dot is empty line
45+
[ mk "-- This file has been generated from package.yaml by hpack version 0.17.0.\n--\n-- see: https://github.com/sol/hpack\n\nname: unicode-transforms\nversion: 0.3.3\nsynopsis: Unicode normalization\ndescription: Fast Unic"
46+
(Fingerprint 15958160436627155571 10318709190730872881)
47+
(Fingerprint 11008465475756725834 13815629925116264363)
48+
(bsRemove " other-modules:\n .\n") -- TODO: remove traling \n to test structural-diff
49+
-- http://hackage.haskell.org/package/DSTM-0.1.2
50+
-- http://hackage.haskell.org/package/DSTM-0.1.1
51+
-- http://hackage.haskell.org/package/DSTM-0.1
52+
-- Other Modules: no dash
53+
-- ReadP parsed as section
54+
, mk "Name: DSTM\nVersion: 0.1.2\nCopyright: (c) 2010, Frank Kupke\nLicense: LGPL\nLicense-File: LICENSE\nAuthor: Frank Kupke\nMaintainer: [email protected]\nCabal-Version: >= 1.2.3\nStability: provisional\nSynopsis: A framework for using STM within distributed "
55+
(Fingerprint 6919263071548559054 9050746360708965827)
56+
(Fingerprint 17015177514298962556 11943164891661867280)
57+
(bsReplace "Other modules:" "-- ")
58+
, mk "Name: DSTM\nVersion: 0.1.1\nCopyright: (c) 2010, Frank Kupke\nLicense: LGPL\nLicense-File: LICENSE\nAuthor: Frank Kupke\nMaintainer: [email protected]\nCabal-Version: >= 1.2.3\nStability: provisional\nSynopsis: A framework for using STM within distributed "
59+
(Fingerprint 17313105789069667153 9610429408495338584)
60+
(Fingerprint 17250946493484671738 17629939328766863497)
61+
(bsReplace "Other modules:" "-- ")
62+
, mk "Name: DSTM\nVersion: 0.1\nCopyright: (c) 2010, Frank Kupke\nLicense: LGPL\nLicense-File: LICENSE\nAuthor: Frank Kupke\nMaintainer: [email protected]\nCabal-Version: >= 1.2.3\nStability: provisional\nSynopsis: A framework for using STM within distributed sy"
63+
(Fingerprint 10502599650530614586 16424112934471063115)
64+
(Fingerprint 13562014713536696107 17899511905611879358)
65+
(bsReplace "Other modules:" "-- ")
66+
-- http://hackage.haskell.org/package/control-monad-exception-mtl-0.10.3
67+
, mk "name: control-monad-exception-mtl\nversion: 0.10.3\nCabal-Version: >= 1.10\nbuild-type: Simple\nlicense: PublicDomain\nauthor: Pepe Iborra\nmaintainer: [email protected]\nhomepage: http://pepeiborra.github.com/control-monad-exception\nsynopsis: MTL instances f"
68+
(Fingerprint 18274748422558568404 4043538769550834851)
69+
(Fingerprint 11395257416101232635 4303318131190196308)
70+
(bsReplace " default- extensions:" "unknown-section")
71+
-- http://hackage.haskell.org/package/vacuum-opengl-0.0
72+
-- \DEL character
73+
, mk "Name: vacuum-opengl\nVersion: 0.0\nSynopsis: Visualize live Haskell data structures using vacuum, graphviz and OpenGL.\nDescription: \DELVisualize live Haskell data structures using vacuum, graphviz and OpenGL.\n "
74+
(Fingerprint 5946760521961682577 16933361639326309422)
75+
(Fingerprint 14034745101467101555 14024175957788447824)
76+
(bsRemove "\DEL")
77+
, mk "Name: vacuum-opengl\nVersion: 0.0.1\nSynopsis: Visualize live Haskell data structures using vacuum, graphviz and OpenGL.\nDescription: \DELVisualize live Haskell data structures using vacuum, graphviz and OpenGL.\n "
78+
(Fingerprint 10790950110330119503 1309560249972452700)
79+
(Fingerprint 1565743557025952928 13645502325715033593)
80+
(bsRemove "\DEL")
81+
-- http://hackage.haskell.org/package/ixset-1.0.4
82+
-- {- comments -}
83+
, mk "Name: ixset\nVersion: 1.0.4\nSynopsis: Efficient relational queries on Haskell sets.\nDescription:\n Create and query sets that are indexed by multiple indices.\nLicense: BSD3\nLicense-file: COPYING\nAut"
84+
(Fingerprint 11886092342440414185 4150518943472101551)
85+
(Fingerprint 5731367240051983879 17473925006273577821)
86+
(bsRemoveStarting "{-")
87+
-- : after section
88+
-- http://hackage.haskell.org/package/ds-kanren
89+
, mk "name: ds-kanren\nversion: 0.2.0.0\nsynopsis: A subset of the miniKanren language\ndescription:\n ds-kanren is an implementation of the <http://minikanren.org miniKanren> language.\n .\n == What's in ds-kanren?\n .\n ['dis"
90+
(Fingerprint 2804006762382336875 9677726932108735838)
91+
(Fingerprint 9830506174094917897 12812107316777006473)
92+
(bsReplace "Test-Suite test-unify:" "Test-Suite \"test-unify:\"" . bsReplace "Test-Suite test-list-ops:" "Test-Suite \"test-list-ops:\"")
93+
, mk "name: ds-kanren\nversion: 0.2.0.1\nsynopsis: A subset of the miniKanren language\ndescription:\n ds-kanren is an implementation of the <http://minikanren.org miniKanren> language.\n\nlicense: MIT\nlicense-file: "
94+
(Fingerprint 9130259649220396193 2155671144384738932)
95+
(Fingerprint 1847988234352024240 4597789823227580457)
96+
(bsReplace "Test-Suite test-unify:" "Test-Suite \"test-unify:\"" . bsReplace "Test-Suite test-list-ops:" "Test-Suite \"test-list-ops:\"")
97+
, mk "name: metric\nversion: 0.1.4\nsynopsis: Metric spaces.\nlicense: MIT\nlicense-file: LICENSE\nauthor: Vikram Verma\nmaintainer: [email protected]\ncategory: Data\nbuild-type:"
98+
(Fingerprint 6150019278861565482 3066802658031228162)
99+
(Fingerprint 9124826020564520548 15629704249829132420)
100+
(bsReplace "test-suite metric-tests:" "test-suite \"metric-tests:\"")
101+
, mk "name: metric\nversion: 0.2.0\nsynopsis: Metric spaces.\nlicense: MIT\nlicense-file: LICENSE\nauthor: Vikram Verma\nmaintainer: [email protected]\ncategory: Data\nbuild-type:"
102+
(Fingerprint 4639805967994715694 7859317050376284551)
103+
(Fingerprint 5566222290622325231 873197212916959151)
104+
(bsReplace "test-suite metric-tests:" "test-suite \"metric-tests:\"")
105+
, mk "name: phasechange\ncategory: Data\nversion: 0.1\nauthor: G\195\161bor Lehel\nmaintainer: G\195\161bor Lehel <[email protected]>\nhomepage: http://github.com/glehel/phasechange\ncopyright: Copyright (C) 2012 G\195\161bor Lehel\nlicense: "
106+
(Fingerprint 10546509771395401582 245508422312751943)
107+
(Fingerprint 5169853482576003304 7247091607933993833)
108+
(bsReplace "impl(ghc >= 7.4):" "erroneous-section" . bsReplace "impl(ghc >= 7.6):" "erroneous-section")
109+
, mk "Name: smartword\nSynopsis: Web based flash card for Word Smart I and II vocabularies\nVersion: 0.0.0.5\nHomepage: http://kyagrd.dyndns.org/~kyagrd/project/smartword/\nCategory: Web,Education\nLicense: "
110+
(Fingerprint 7803544783533485151 10807347873998191750)
111+
(Fingerprint 1665635316718752601 16212378357991151549)
112+
(bsReplace "build depends:" "--")
113+
, mk "name: shelltestrunner\n-- sync with README.md, ANNOUNCE:\nversion: 1.3\ncategory: Testing\nsynopsis: A tool for testing command-line programs.\ndescription:\n shelltestrunner is a cross-platform tool for testing command-line\n program"
114+
(Fingerprint 4403237110790078829 15392625961066653722)
115+
(Fingerprint 10218887328390239431 4644205837817510221)
116+
(bsReplace "other modules:" "--")
117+
]
118+
where
119+
mk a b c d = ((a, b), (c, d))
120+
121+
-- | Helper to create entries in patches
122+
_makePatchKey :: FilePath -> (BS.ByteString -> BS.ByteString) -> NoCallStackIO ()
123+
_makePatchKey fp transform = do
124+
contents <- BS.readFile fp
125+
let output = transform contents
126+
let Fingerprint hi lo = md5 contents
127+
let Fingerprint hi' lo' = md5 output
128+
putStrLn
129+
$ showString " , mk "
130+
. shows (BS.take 256 contents)
131+
. showString "\n (Fingerprint "
132+
. shows hi
133+
. showString " "
134+
. shows lo
135+
. showString ")\n (Fingerprint "
136+
. shows hi'
137+
. showString " "
138+
. shows lo'
139+
. showString ")"
140+
$ ""
141+
142+
-------------------------------------------------------------------------------
143+
-- Patch helpers
144+
-------------------------------------------------------------------------------
145+
146+
bsRemove
147+
:: BS.ByteString -- ^ needle
148+
-> BS.ByteString -> BS.ByteString
149+
bsRemove needle haystack = case BS.breakSubstring needle haystack of
150+
(h, t) -> BS.append h (BS.drop (BS.length needle) t)
151+
152+
bsReplace
153+
:: BS.ByteString -- ^ needle
154+
-> BS.ByteString -- ^ replacement
155+
-> BS.ByteString -> BS.ByteString
156+
bsReplace needle repl haystack = case BS.breakSubstring needle haystack of
157+
(h, t)
158+
| not (BS.null t) -> BS.append h (BS.append repl (BS.drop (BS.length needle) t))
159+
| otherwise -> haystack
160+
161+
bsRemoveStarting
162+
:: BS.ByteString -- ^ needle
163+
-> BS.ByteString -> BS.ByteString
164+
bsRemoveStarting needle haystack = case BS.breakSubstring needle haystack of
165+
(h, _) -> h

Cabal/Distribution/Parsec/Class.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import Data.Functor.Identity (Identity)
2020
import qualified Distribution.Compat.Parsec as P
2121
import Distribution.Parsec.Types.Common
2222
(PWarnType (..), PWarning (..), Position (..))
23+
import Distribution.Utils.Generic (lowercase)
2324
import qualified Text.Parsec as Parsec
2425
import qualified Text.Parsec.Language as Parsec
2526
import qualified Text.Parsec.Token as Parsec
@@ -126,12 +127,11 @@ instance Parsec ModuleName where
126127
validModuleChar c = isAlphaNum c || c == '_' || c == '\''
127128

128129
instance Parsec FlagName where
129-
parsec = mkFlagName . map toLower . intercalate "-" <$> P.sepBy1 component (P.char '-')
130+
parsec = mkFlagName . lowercase <$> parsec'
130131
where
131-
-- http://hackage.haskell.org/package/cabal-debian-4.24.8/cabal-debian.cabal
132-
-- has flag with all digit component: pretty-112
133-
component :: P.Stream s Identity Char => P.Parsec s [PWarning] String
134-
component = P.munch1 (\c -> isAlphaNum c || c `elem` "_")
132+
parsec' = (:) <$> lead <*> rest
133+
lead = P.satisfy (\c -> isAlphaNum c || c == '_')
134+
rest = P.munch (\c -> isAlphaNum c || c == '_' || c == '-')
135135

136136
instance Parsec Dependency where
137137
parsec = do

0 commit comments

Comments
 (0)