Commit 5d20551e authored by Edward Z. Yang's avatar Edward Z. Yang
Browse files

Stop parsing thinning/renaming from build-depends.


Signed-off-by: default avatarEdward Z. Yang <ezyang@cs.stanford.edu>
parent 0d6e71ed
......@@ -1152,8 +1152,7 @@ checkCabalVersion pkg =
depsUsingThinningRenamingSyntax =
[ name
| bi <- allBuildInfo pkg
, (name, rns) <- Map.toList (targetBuildRenaming bi)
, rns /= ModuleRenaming True [] ]
, (name, _) <- Map.toList (targetBuildRenaming bi) ]
testedWithUsingWildcardSyntax =
[ Dependency (PackageName (display compiler)) vr
......
......@@ -53,15 +53,11 @@ import Control.Applicative (Applicative(..))
import Control.Arrow (first)
import System.Directory (doesFileExist)
import qualified Data.ByteString.Lazy.Char8 as BS.Char8
import Data.Typeable
import Data.Data
import qualified Data.Map as Map
import Distribution.Text
( Text(disp, parse), display, simpleParse )
import Distribution.Compat.ReadP
((+++), option)
import qualified Distribution.Compat.ReadP as Parse
import Text.PrettyPrint
import Distribution.ParseUtils hiding (parseFields)
......@@ -402,8 +398,7 @@ binfoFieldDescrs =
buildTools (\xs binfo -> binfo{buildTools=xs})
, commaListFieldWithSep vcat "build-depends"
disp parse
buildDependsWithRenaming
setBuildDependsWithRenaming
targetBuildDepends (\xs binfo -> binfo{targetBuildDepends=xs})
, spaceListField "cpp-options"
showToken parseTokenQ'
cppOptions (\val binfo -> binfo{cppOptions=val})
......@@ -597,7 +592,8 @@ mapSimpleFields f = mapM walk
-- prop_isMapM fs = mapSimpleFields return fs == return fs
-- names of fields that represents dependencies, thus consrca
-- names of fields that represents dependencies
-- TODO: maybe build-tools should go here too?
constraintFieldNames :: [String]
constraintFieldNames = ["build-depends"]
......@@ -605,9 +601,9 @@ constraintFieldNames = ["build-depends"]
-- they add and define an accessor that specifies what the dependencies
-- are. This way we would completely reuse the parsing knowledge from the
-- field descriptor.
parseConstraint :: Field -> ParseResult [DependencyWithRenaming]
parseConstraint :: Field -> ParseResult [Dependency]
parseConstraint (F l n v)
| n == "build-depends" = runP l n (parseCommaList parse) v
| n `elem` constraintFieldNames = runP l n (parseCommaList parse) v
parseConstraint f = userBug $ "Constraint was expected (got: " ++ show f ++ ")"
{-
......@@ -1066,17 +1062,29 @@ parsePackageDescription file = do
condFlds = [ f | f@IfBlock{} <- allflds ]
sections = [ s | s@Section{} <- allflds ]
-- Put these through the normal parsing pass too, so that we
-- collect the ModRenamings
let depFlds = filter isConstraint simplFlds
mapM_
(\(Section l n _ _) -> lift . warning $
"Unexpected section '" ++ n ++ "' on line " ++ show l)
sections
a <- parser simplFlds
deps <- liftM concat . mapM (lift . fmap (map dependency) . parseConstraint) $ depFlds
-- Dependencies must be treated specially: when we
-- parse into a CondTree, not only do we parse them into
-- the targetBuildDepends/etc field inside the
-- PackageDescription, but we also have to put the
-- combined dependencies into CondTree.
--
-- This information is, in principle, redundant, but
-- putting it here makes it easier for the constraint
-- solver to pick a flag assignment which supports
-- all of the dependencies (because it only has
-- to check the CondTree, rather than grovel everywhere
-- inside the conditional bits).
deps <- liftM concat
. mapM (lift . parseConstraint)
. filter isConstraint
$ simplFlds
ifs <- mapM processIfs condFlds
......@@ -1280,32 +1288,3 @@ findIndentTabs = concatMap checkLine
--test_findIndentTabs = findIndentTabs $ unlines $
-- [ "foo", " bar", " \t baz", "\t biz\t", "\t\t \t mib" ]
-- | Dependencies plus module renamings. This is what users specify; however,
-- renaming information is not used for dependency resolution.
data DependencyWithRenaming = DependencyWithRenaming Dependency ModuleRenaming
deriving (Read, Show, Eq, Typeable, Data)
dependency :: DependencyWithRenaming -> Dependency
dependency (DependencyWithRenaming dep _) = dep
instance Text DependencyWithRenaming where
disp (DependencyWithRenaming d rns) = disp d <+> disp rns
parse = do d <- parse
Parse.skipSpaces
rns <- parse
Parse.skipSpaces
return (DependencyWithRenaming d rns)
buildDependsWithRenaming :: BuildInfo -> [DependencyWithRenaming]
buildDependsWithRenaming pkg =
map (\dep@(Dependency n _) ->
DependencyWithRenaming dep
(Map.findWithDefault defaultRenaming n (targetBuildRenaming pkg)))
(targetBuildDepends pkg)
setBuildDependsWithRenaming :: [DependencyWithRenaming] -> BuildInfo -> BuildInfo
setBuildDependsWithRenaming deps pkg = pkg {
targetBuildDepends = map dependency deps,
targetBuildRenaming = Map.fromList (map (\(DependencyWithRenaming (Dependency n _) rns) -> (n, rns)) deps)
}
......@@ -428,9 +428,7 @@ testSuiteLibV09AsLibAndExe pkg_descr
hsSourceDirs = [ testDir ],
targetBuildDepends = testLibDep
: (targetBuildDepends $ testBuildInfo test),
targetBuildRenaming =
Map.insert (packageName pkg) defaultRenaming
(targetBuildRenaming $ testBuildInfo test)
targetBuildRenaming = Map.empty
}
}
-- | The stub executable needs a new 'ComponentLocalBuildInfo'
......
......@@ -483,9 +483,9 @@ configure (pkg_descr0, pbi) cfg
let pkg_descr = addExtraIncludeLibDirs pkg_descr0'
unless (renamingPackageFlagsSupported comp ||
and [ rn == defaultRenaming
and [ True
| bi <- allBuildInfo pkg_descr
, rn <- Map.elems (targetBuildRenaming bi)]) $
, _ <- Map.elems (targetBuildRenaming bi)]) $
die $ "Your compiler does not support thinning and renaming on "
++ "package flags. To use this feature you probably must use "
++ "GHC 7.9 or later."
......
......@@ -1290,29 +1290,16 @@ values for these fields.
It is only syntactic sugar. It is exactly equivalent to `foo >= 1.2 && < 1.3`.
With Cabal 1.20 and GHC 7.10, `build-depends` also supports module
thinning and renaming, which allows you to selectively decide what
modules become visible from a package dependency. For example:
~~~~~~~~~~~~~~~~
build-depends: containers (Data.Set, Data.IntMap as Map)
~~~~~~~~~~~~~~~~
This results in only the modules `Data.Set` and `Map` being visible to
the user from containers, hiding all other modules. To add additional
names for modules without hiding the others, you can use the `with`
keyword:
~~~~~~~~~~~~~~~~
build-depends: containers with (Data.IntMap as Map)
~~~~~~~~~~~~~~~~
Note: Prior to Cabal 1.8, build-depends specified in each section
were global to all sections. This was unintentional, but some packages
were written to depend on it, so if you need your build-depends to
be local to each section, you must specify at least
`Cabal-Version: >= 1.8` in your `.cabal` file.
Note: Cabal 1.20 experimentally supported module thinning and
renaming in `build-depends`; however, this support has since been
removed and should not be used.
`other-modules:` _identifier list_
: A list of modules used by the component but not exposed to users.
For a library component, these would be hidden modules of the
......
......@@ -2,7 +2,6 @@ module PackageTests.BenchmarkStanza.Check where
import Test.Tasty.HUnit
import System.FilePath
import qualified Data.Map as Map
import PackageTests.PackageTester
import Distribution.Version
import Distribution.PackageDescription.Parse
......@@ -15,7 +14,7 @@ import Distribution.PackageDescription
( PackageDescription(..), BuildInfo(..), Benchmark(..)
, BenchmarkInterface(..)
, emptyBuildInfo
, emptyBenchmark, defaultRenaming )
, emptyBenchmark )
import Distribution.Verbosity (silent)
import Distribution.System (buildPlatform)
import Distribution.Compiler
......@@ -37,8 +36,6 @@ suite config = do
, benchmarkBuildInfo = emptyBuildInfo
{ targetBuildDepends =
[ Dependency (PackageName "base") anyVersion ]
, targetBuildRenaming =
Map.singleton (PackageName "base") defaultRenaming
, hsSourceDirs = ["."]
}
, benchmarkEnabled = False
......
......@@ -2,7 +2,6 @@ module PackageTests.TestStanza.Check where
import Test.Tasty.HUnit
import System.FilePath
import qualified Data.Map as Map
import PackageTests.PackageTester
import Distribution.Version
import Distribution.PackageDescription.Parse (readPackageDescription)
......@@ -11,8 +10,7 @@ import Distribution.PackageDescription.Configuration
import Distribution.Package (PackageName(..), Dependency(..))
import Distribution.PackageDescription
( PackageDescription(..), BuildInfo(..), TestSuite(..)
, TestSuiteInterface(..), emptyBuildInfo, emptyTestSuite
, defaultRenaming)
, TestSuiteInterface(..), emptyBuildInfo, emptyTestSuite )
import Distribution.Verbosity (silent)
import Distribution.System (buildPlatform)
import Distribution.Compiler
......@@ -38,8 +36,6 @@ suite config = do
, testBuildInfo = emptyBuildInfo
{ targetBuildDepends =
[ Dependency (PackageName "base") anyVersion ]
, targetBuildRenaming =
Map.singleton (PackageName "base") defaultRenaming
, hsSourceDirs = ["."]
}
, testEnabled = False
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment