Commit 639cd007 authored by Edward Z. Yang's avatar Edward Z. Yang

Remove same-package import lists, fixes #2835.

Instead of qualifying, in some cases I just added an extra
'hiding' pragma to squelch errors.  Common conflicts
(just grep for hiding):

    - Flag
        - Distribution.Simple.Compiler
        - Distribution.PackageDescription
        - Distribution.Simple.Setup
    - installedComponentId
        - Distribution.Package
        - Distribution.InstalledPackageInfo
    - doesFileExist
        - Distribution.PackageDescription.Check
    - instantiatedWith
        - I renamed the field in InstalledPackageInfo.  But
          it's probably going away with Backpack bits; I
          migth just excise it soon.
    - absoluteInstallDirs and substPathTemplate
        - Distribution.Simple.InstallDirs
        - Distribution.Simple.LocalBuildInfo

I fixed some shadowing errors by renaming local variables in some cases.
Common shadowings (we should perhaps consider not using these as
method/field names):

    - freeVars
    - components
    - noVersion
    - verbosity
    - get
    - description
    - name

Some data structures were moved around (IPIConvert and ABIHash)
to make it easier to handle import lists.

Some functions in Utils could be turned into reexports of standard
library functions.

No explicit imports were removed from non-Cabal imports.  These
imports help maintain warning cleanliness across versions of GHC,
so I don't recommend removing them.
Signed-off-by: default avatarEdward Z. Yang <ezyang@cs.stanford.edu>
parent 710659cc
......@@ -265,6 +265,7 @@ library
Distribution.Simple.GHC.Internal
Distribution.Simple.GHC.IPI641
Distribution.Simple.GHC.IPI642
Distribution.Simple.GHC.IPIConvert
Distribution.Simple.GHC.ImplInfo
Paths_Cabal
......
......@@ -11,20 +11,18 @@ module Distribution.Compat.CopyFile (
setDirOrdinary,
) where
import Distribution.Compat.Exception
import Distribution.Compat.Internal.TempFile
import Control.Monad
( when, unless )
import Control.Exception
( bracketOnError, throwIO )
import qualified Data.ByteString.Lazy as BSL
import Distribution.Compat.Exception
( catchIO )
import System.IO.Error
( ioeSetLocation )
import System.Directory
( doesFileExist, renameFile, removeFile )
import Distribution.Compat.Internal.TempFile
( openBinaryTempFile )
import System.FilePath
( takeDirectory )
import System.IO
......
......@@ -7,6 +7,7 @@ module Distribution.Compat.Internal.TempFile (
createTempDirectory,
) where
import Distribution.Compat.Exception
import System.FilePath ((</>))
import Foreign.C (CInt, eEXIST, getErrno, errnoToIOError)
......@@ -18,7 +19,6 @@ import System.Posix.Internals (c_open, c_close, o_CREAT, o_EXCL, o_RDWR,
withFilePath, c_getpid)
import System.IO.Error (isAlreadyExistsError)
import GHC.IO.Handle.FD (fdToHandle)
import Distribution.Compat.Exception (tryIO)
import Control.Exception (onException)
#if defined(mingw32_HOST_OS) || defined(ghcjs_HOST_OS)
......
......@@ -42,15 +42,15 @@ module Distribution.Compiler (
AbiTag(..), abiTagString
) where
import Distribution.Compat.Binary (Binary)
import Distribution.Compat.Binary
import Language.Haskell.Extension
import Data.Data (Data)
import Data.Typeable (Typeable)
import Data.Maybe (fromMaybe)
import Distribution.Version (Version(..))
import GHC.Generics (Generic)
import Language.Haskell.Extension (Language, Extension)
import qualified System.Info (compilerName, compilerVersion)
import Distribution.Text (Text(..), display)
import qualified Distribution.Compat.ReadP as Parse
......
......@@ -27,7 +27,6 @@
-- This module is meant to be local-only to Distribution...
module Distribution.InstalledPackageInfo (
AbiHash(..),
InstalledPackageInfo(..),
OriginalModule(..), ExposedModule(..),
ParseResult(..), PError(..), PWarning,
......@@ -40,32 +39,18 @@ module Distribution.InstalledPackageInfo (
) where
import Distribution.ParseUtils
( FieldDescr(..), ParseResult(..), PError(..), PWarning
, simpleField, listField, parseLicenseQ
, showFields, showSingleNamedField, showSimpleSingleNamedField
, parseFieldsFlat
, parseFilePathQ, parseTokenQ, parseModuleNameQ, parsePackageNameQ
, showFilePath, showToken, boolField, parseOptVersion
, parseFreeText, showFreeText, parseOptCommaList )
import Distribution.License ( License(..) )
import Distribution.Package
( PackageName(..), PackageIdentifier(..)
, PackageId, ComponentId(..)
, packageName, packageVersion, ComponentId(..) )
import Distribution.License
import Distribution.Package hiding (installedComponentId)
import qualified Distribution.Package as Package
import Distribution.ModuleName
( ModuleName )
import Distribution.Version
( Version(..) )
import Distribution.Text
( Text(disp, parse) )
import Text.PrettyPrint as Disp
import qualified Distribution.Compat.ReadP as Parse
import Distribution.Compat.Binary
import Distribution.Compat.Binary (Binary)
import Text.PrettyPrint as Disp
import Data.Maybe (fromMaybe)
import GHC.Generics (Generic)
import qualified Data.Char as Char
-- -----------------------------------------------------------------------------
-- The InstalledPackageInfo type
......@@ -92,7 +77,7 @@ data InstalledPackageInfo
abiHash :: AbiHash,
exposed :: Bool,
exposedModules :: [ExposedModule],
instantiatedWith :: [(ModuleName, OriginalModule)],
installedInstantiatedWith :: [(ModuleName, OriginalModule)],
hiddenModules :: [ModuleName],
trusted :: Bool,
importDirs :: [FilePath],
......@@ -128,7 +113,7 @@ instance Package.PackageInstalled InstalledPackageInfo where
emptyInstalledPackageInfo :: InstalledPackageInfo
emptyInstalledPackageInfo
= InstalledPackageInfo {
sourcePackageId = PackageIdentifier (PackageName "") noVersion,
sourcePackageId = PackageIdentifier (PackageName "") (Version [] []),
installedComponentId = ComponentId "",
compatPackageKey = ComponentId "",
license = UnspecifiedLicense,
......@@ -145,7 +130,7 @@ emptyInstalledPackageInfo
exposed = False,
exposedModules = [],
hiddenModules = [],
instantiatedWith = [],
installedInstantiatedWith = [],
trusted = False,
importDirs = [],
libraryDirs = [],
......@@ -165,20 +150,6 @@ emptyInstalledPackageInfo
pkgRoot = Nothing
}
noVersion :: Version
noVersion = Version [] []
-- -----------------------------------------------------------------------------
-- Exposed modules
newtype AbiHash = AbiHash String
deriving (Eq, Show, Read, Generic)
instance Binary AbiHash
instance Text AbiHash where
disp (AbiHash abi) = Disp.text abi
parse = fmap AbiHash (Parse.munch Char.isAlphaNum)
-- -----------------------------------------------------------------------------
-- Exposed modules
......@@ -348,7 +319,7 @@ installedFieldDescrs = [
abiHash (\abi pkg -> pkg{abiHash=abi})
, listField "instantiated-with"
showInstantiatedWith parseInstantiatedWith
instantiatedWith (\xs pkg -> pkg{instantiatedWith=xs})
installedInstantiatedWith (\xs pkg -> pkg{installedInstantiatedWith=xs})
, boolField "trusted"
trusted (\val pkg -> pkg{trusted=val})
, listField "import-dirs"
......
......@@ -47,13 +47,13 @@ module Distribution.License (
knownLicenses,
) where
import Distribution.Version (Version(Version))
import Distribution.Text (Text(..), display)
import Distribution.Version
import Distribution.Text
import qualified Distribution.Compat.ReadP as Parse
import Distribution.Compat.Binary
import qualified Text.PrettyPrint as Disp
import Text.PrettyPrint ((<>))
import Distribution.Compat.Binary (Binary)
import qualified Data.Char as Char (isAlphaNum)
import Data.Data (Data)
import Data.Typeable (Typeable)
......
......@@ -62,22 +62,19 @@ module Distribution.Make (
-- local
import Distribution.Compat.Exception
import Distribution.Package --must not specify imports, since we're exporting moule.
import Distribution.Simple.Program(defaultProgramConfiguration)
import Distribution.Package
import Distribution.Simple.Program
import Distribution.PackageDescription
import Distribution.Simple.Setup
import Distribution.Simple.Command
import Distribution.Simple.Utils (rawSystemExit, cabalVersion)
import Distribution.Simple.Utils
import Distribution.License (License(..))
import Distribution.License
import Distribution.Version
( Version(..) )
import Distribution.Text
( display )
import System.Environment (getArgs, getProgName)
import Data.List (intercalate)
import System.Exit
defaultMain :: IO ()
......
......@@ -22,14 +22,13 @@ module Distribution.ModuleName (
) where
import Distribution.Text
( Text(..) )
import Distribution.Compat.Binary
import qualified Distribution.Compat.ReadP as Parse
import Distribution.Compat.Binary (Binary)
import qualified Data.Char as Char
( isAlphaNum, isUpper )
import Data.Data (Data)
import Data.Typeable (Typeable)
import qualified Distribution.Compat.ReadP as Parse
import qualified Text.PrettyPrint as Disp
import Data.List
( intercalate, intersperse )
......
......@@ -26,6 +26,9 @@ module Distribution.Package (
getHSLibraryName,
InstalledPackageId, -- backwards compat
-- * ABI hash
AbiHash(..),
-- * Package source dependencies
Dependency(..),
thisPackageVersion,
......@@ -42,13 +45,13 @@ import Distribution.Version
( Version(..), VersionRange, anyVersion, thisVersion
, notThisVersion, simplifyVersionRange )
import Distribution.Text (Text(..))
import qualified Distribution.Compat.ReadP as Parse
import Distribution.Compat.ReadP ((<++))
import qualified Text.PrettyPrint as Disp
import Distribution.Compat.ReadP
import Distribution.Compat.Binary
import Distribution.Text
import Control.DeepSeq (NFData(..))
import Distribution.Compat.Binary (Binary)
import qualified Data.Char as Char
( isDigit, isAlphaNum, )
import Data.Data ( Data )
......@@ -202,3 +205,14 @@ class Package pkg => HasComponentId pkg where
-- Installed packages have exact dependencies 'installedDepends'.
class (HasComponentId pkg) => PackageInstalled pkg where
installedDepends :: pkg -> [ComponentId]
-- -----------------------------------------------------------------------------
-- ABI hash
newtype AbiHash = AbiHash String
deriving (Eq, Show, Read, Generic)
instance Binary AbiHash
instance Text AbiHash where
disp (AbiHash abi) = Disp.text abi
parse = fmap AbiHash (Parse.munch Char.isAlphaNum)
......@@ -109,9 +109,20 @@ module Distribution.PackageDescription (
SetupBuildInfo(..),
) where
import Distribution.Compat.Binary (Binary)
import Distribution.Compat.Binary
import qualified Distribution.Compat.Semigroup as Semi ((<>))
import Distribution.Compat.Semigroup as Semi (Monoid(..), Semigroup)
import qualified Distribution.Compat.ReadP as Parse
import Distribution.Compat.ReadP ((<++))
import Distribution.Package
import Distribution.ModuleName
import Distribution.Version
import Distribution.License
import Distribution.Compiler
import Distribution.System
import Distribution.Text
import Language.Haskell.Extension
import Data.Data (Data)
import Data.Foldable (traverse_)
import Data.List (nub, intercalate)
......@@ -123,27 +134,10 @@ import Control.Applicative as AP (Alternative(..), Applicative(..))
import Control.Monad (MonadPlus(mplus,mzero), ap)
import GHC.Generics (Generic)
import Text.PrettyPrint as Disp
import qualified Distribution.Compat.ReadP as Parse
import Distribution.Compat.ReadP ((<++))
import qualified Data.Char as Char (isAlphaNum, isDigit, toLower)
import qualified Data.Map as Map
import Data.Map (Map)
import Distribution.Package
( PackageName(PackageName), PackageIdentifier(PackageIdentifier)
, Dependency, Package(..), PackageName, packageName )
import Distribution.ModuleName ( ModuleName )
import Distribution.Version
( Version(Version), VersionRange, anyVersion, orLaterVersion
, asVersionIntervals, LowerBound(..) )
import Distribution.License (License(UnspecifiedLicense))
import Distribution.Compiler (CompilerFlavor)
import Distribution.System (OS, Arch)
import Distribution.Text
( Text(..), display )
import Language.Haskell.Extension
( Language, Extension )
-- -----------------------------------------------------------------------------
-- The PackageDescription type
......
......@@ -33,50 +33,30 @@ module Distribution.PackageDescription.Check (
checkPackageFileNames,
) where
import Data.Maybe
( isNothing, isJust, catMaybes, mapMaybe, maybeToList, fromMaybe )
import Data.List (sort, group, isPrefixOf, nub, find)
import Control.Monad
( filterM, liftM )
import qualified System.Directory as System
( doesFileExist, doesDirectoryExist )
import qualified Data.Map as Map
import Distribution.PackageDescription
import Distribution.PackageDescription.Configuration
( flattenPackageDescription, finalizePackageDescription )
import Distribution.Compiler
( CompilerFlavor(..), buildCompilerFlavor, CompilerId(..)
, unknownCompilerInfo, AbiTag(..) )
import Distribution.System
( OS(..), Arch(..), buildPlatform )
import Distribution.License
( License(..), knownLicenses )
import Distribution.Simple.CCompiler
( filenameCDialect )
import Distribution.Simple.Utils
( cabalVersion, intercalate, parseFileGlob, FileGlob(..), lowercase, startsWithBOM, fromUTF8 )
import Distribution.Simple.Utils hiding (findPackageDesc, notice)
import Distribution.Version
( Version(..)
, VersionRange(..), foldVersionRange'
, anyVersion, noVersion, thisVersion, laterVersion, earlierVersion
, orLaterVersion, orEarlierVersion
, unionVersionRanges, intersectVersionRanges
, asVersionIntervals, UpperBound(..), isNoVersion )
import Distribution.Package
( PackageName(PackageName), packageName, packageVersion
, Dependency(..), pkgName )
import Distribution.Text
( display, disp )
import Language.Haskell.Extension
import Data.Maybe
( isNothing, isJust, catMaybes, mapMaybe, maybeToList, fromMaybe )
import Data.List (sort, group, isPrefixOf, nub, find)
import Control.Monad
( filterM, liftM )
import qualified System.Directory as System
( doesFileExist, doesDirectoryExist )
import qualified Data.Map as Map
import qualified Text.PrettyPrint as Disp
import Text.PrettyPrint ((<>), (<+>))
import qualified Language.Haskell.Extension as Extension (deprecatedExtensions)
import Language.Haskell.Extension
( Language(UnknownLanguage), knownLanguages
, Extension(..), KnownExtension(..) )
import qualified System.Directory (getDirectoryContents)
import System.IO (openBinaryFile, IOMode(ReadMode), hGetContents)
import System.FilePath
......@@ -442,14 +422,14 @@ checkFields pkg =
++ ". Languages must be specified in either the 'default-language' "
++ " or the 'other-languages' field."
, check (not (null deprecatedExtensions)) $
, check (not (null ourDeprecatedExtensions)) $
PackageDistSuspicious $
"Deprecated extensions: "
++ commaSep (map (quote . display . fst) deprecatedExtensions)
++ commaSep (map (quote . display . fst) ourDeprecatedExtensions)
++ ". " ++ unwords
[ "Instead of '" ++ display ext
++ "' use '" ++ display replacement ++ "'."
| (ext, Just replacement) <- deprecatedExtensions ]
| (ext, Just replacement) <- ourDeprecatedExtensions ]
, check (null (category pkg)) $
PackageDistSuspicious "No 'category' field."
......@@ -491,8 +471,8 @@ checkFields pkg =
unknownExtensions = [ name | bi <- allBuildInfo pkg
, UnknownExtension name <- allExtensions bi
, name `notElem` map display knownLanguages ]
deprecatedExtensions = nub $ catMaybes
[ find ((==ext) . fst) Extension.deprecatedExtensions
ourDeprecatedExtensions = nub $ catMaybes
[ find ((==ext) . fst) deprecatedExtensions
| bi <- allBuildInfo pkg
, ext <- allExtensions bi ]
languagesUsedAsExtensions =
......@@ -1340,10 +1320,10 @@ checkConditionals pkg =
unknownOSs = [ os | OS (OtherOS os) <- conditions ]
unknownArches = [ arch | Arch (OtherArch arch) <- conditions ]
unknownImpls = [ impl | Impl (OtherCompiler impl) _ <- conditions ]
conditions = maybe [] freeVars (condLibrary pkg)
++ concatMap (freeVars . snd) (condExecutables pkg)
freeVars (CondNode _ _ ifs) = concatMap compfv ifs
compfv (c, ct, mct) = condfv c ++ freeVars ct ++ maybe [] freeVars mct
conditions = maybe [] fvs (condLibrary pkg)
++ concatMap (fvs . snd) (condExecutables pkg)
fvs (CondNode _ _ ifs) = concatMap compfv ifs -- free variables
compfv (c, ct, mct) = condfv c ++ fvs ct ++ maybe [] fvs mct
condfv c = case c of
Var v -> [v]
Lit _ -> []
......@@ -1537,7 +1517,8 @@ checkCabalFileBOM ops = do
pdfile ++ " starts with an Unicode byte order mark (BOM). This may cause problems with older cabal versions."
-- |Find a package description file in the given directory. Looks for
-- @.cabal@ files.
-- @.cabal@ files. Like 'Distribution.Simple.Utils.findPackageDesc',
-- but generalized over monads.
findPackageDesc :: Monad m => CheckPackageContentOps m
-> m (Either PackageCheck FilePath) -- ^<pkgname>.cabal
findPackageDesc ops
......
......@@ -29,33 +29,18 @@ module Distribution.PackageDescription.Configuration (
) where
import Distribution.Package
( PackageName, Dependency(..) )
import Distribution.PackageDescription
( GenericPackageDescription(..), PackageDescription(..)
, Library(..), Executable(..), BuildInfo(..)
, Flag(..), FlagName(..), FlagAssignment
, Benchmark(..), CondTree(..), ConfVar(..), Condition(..)
, TestSuite(..) )
import Distribution.PackageDescription.Utils
( cabalBug, userBug )
import Distribution.Version
( VersionRange, anyVersion, intersectVersionRanges, withinRange )
import Distribution.Compiler
( CompilerId(CompilerId) )
import Distribution.System
( Platform(..), OS, Arch )
import Distribution.Simple.Utils
( currentDir, lowercase )
import Distribution.Simple.Compiler
( CompilerInfo(..) )
import Distribution.Text
( Text(parse) )
import Distribution.Compat.ReadP as ReadP hiding ( char )
import Control.Arrow (first)
import qualified Distribution.Compat.ReadP as ReadP ( char )
import Distribution.Compat.Semigroup as Semi
import Control.Arrow (first)
import Data.Char ( isAlphaNum )
import Data.Maybe ( mapMaybe, maybeToList )
import Data.Map ( Map, fromListWith, toList )
......
......@@ -41,6 +41,19 @@ module Distribution.PackageDescription.Parse (
flagFieldDescrs
) where
import Distribution.ParseUtils hiding (parseFields)
import Distribution.PackageDescription
import Distribution.PackageDescription.Utils
import Distribution.Package
import Distribution.ModuleName
import Distribution.Version
import Distribution.Verbosity
import Distribution.Compiler
import Distribution.PackageDescription.Configuration
import Distribution.Simple.Utils
import Distribution.Text
import Distribution.Compat.ReadP hiding (get)
import Data.Char (isSpace)
import Data.Foldable (traverse_)
import Data.Maybe (listToMaybe, isJust)
......@@ -54,30 +67,8 @@ import Control.Arrow (first)
import System.Directory (doesFileExist)
import qualified Data.ByteString.Lazy.Char8 as BS.Char8
import Distribution.Text
( Text(disp, parse), display, simpleParse )
import Distribution.Compat.ReadP
((+++), option)
import Text.PrettyPrint
import Distribution.ParseUtils hiding (parseFields)
import Distribution.PackageDescription
import Distribution.PackageDescription.Utils
( cabalBug, userBug )
import Distribution.Package
( PackageIdentifier(..), Dependency(..), packageName, packageVersion )
import Distribution.ModuleName ( ModuleName )
import Distribution.Version
( Version(Version), orLaterVersion
, LowerBound(..), asVersionIntervals )
import Distribution.Verbosity (Verbosity)
import Distribution.Compiler (CompilerFlavor(..))
import Distribution.PackageDescription.Configuration (parseCondition, freeVars)
import Distribution.Simple.Utils
( die, dieWithLocation, warn, intercalate, lowercase, cabalVersion
, withFileContents, withUTF8FileContents
, writeFileAtomic, writeUTF8File )
-- -----------------------------------------------------------------------------
-- The PackageDescription type
......@@ -902,7 +893,6 @@ parsePackageDescription file = do
-- Does the current node specify a test type?
hasTestType = testInterface ts'
/= testInterface emptyTestSuite
components = condTreeComponents ct
-- If the current level of the tree specifies a type,
-- then we are done. If not, then one of the conditional
-- branches below the current node must specify a type.
......@@ -910,7 +900,7 @@ parsePackageDescription file = do
-- only one need one to specify a type because the
-- configure step uses 'mappend' to join together the
-- results of flag resolution.
in hasTestType || any checkComponent components
in hasTestType || any checkComponent (condTreeComponents ct)
if checkTestType emptyTestSuite flds
then do
skipField
......@@ -951,7 +941,6 @@ parsePackageDescription file = do
-- Does the current node specify a benchmark type?
hasBenchmarkType = benchmarkInterface ts'
/= benchmarkInterface emptyBenchmark
components = condTreeComponents ct
-- If the current level of the tree specifies a type,
-- then we are done. If not, then one of the conditional
-- branches below the current node must specify a type.
......@@ -959,7 +948,7 @@ parsePackageDescription file = do
-- only one need one to specify a type because the
-- configure step uses 'mappend' to join together the
-- results of flag resolution.
in hasBenchmarkType || any checkComponent components
in hasBenchmarkType || any checkComponent (condTreeComponents ct)
if checkBenchmarkType emptyBenchmark flds
then do
skipField
......
......@@ -17,25 +17,18 @@ module Distribution.PackageDescription.PrettyPrint (
showGenericPackageDescription,
) where
import Data.Monoid as Mon (Monoid(mempty))
import Distribution.PackageDescription
( Benchmark(..), BenchmarkInterface(..), benchmarkType
, TestSuite(..), TestSuiteInterface(..), testType
, SourceRepo(..),
customFieldsBI, CondTree(..), Condition(..), cNot,
FlagName(..), ConfVar(..), Executable(..), Library(..),
Flag(..), PackageDescription(..),
GenericPackageDescription(..))
import Distribution.Simple.Utils
import Distribution.ParseUtils
import Distribution.PackageDescription.Parse
import Distribution.Package
import Distribution.Text
import Data.Monoid as Mon (Monoid(mempty))
import Data.Maybe (isJust)
import Text.PrettyPrint
(hsep, parens, char, nest, empty, isEmpty, ($$), (<+>),