Commit 07b4b125 authored by John Ericson's avatar John Ericson

Dedicated modules for `*Dependency` types and `UnqualComponentName`

Also gets rid of `Distribution.Packages.TextClass`
parent ed90fffd
......@@ -143,7 +143,6 @@ library
Distribution.Make
Distribution.ModuleName
Distribution.Package
Distribution.Package.TextClass
Distribution.PackageDescription
Distribution.PackageDescription.Check
Distribution.PackageDescription.Configuration
......@@ -209,6 +208,9 @@ library
Distribution.Types.BenchmarkType
Distribution.Types.BuildInfo
Distribution.Types.BuildType
Distribution.Types.Dependency
Distribution.Types.LegacyExeDependency
Distribution.Types.PkgconfigDependency
Distribution.Types.Executable
Distribution.Types.Library
Distribution.Types.ForeignLib
......@@ -232,6 +234,7 @@ library
Distribution.Types.LocalBuildInfo
Distribution.Types.ComponentRequestedSpec
Distribution.Types.TargetInfo
Distribution.Types.UnqualComponentName
Distribution.Utils.NubList
Distribution.Utils.ShortText
Distribution.Utils.Progress
......
......@@ -11,6 +11,9 @@ import Distribution.Package
import Distribution.PackageDescription as PD hiding (Flag)
import Distribution.Simple.LocalBuildInfo
import Distribution.Types.ComponentRequestedSpec
import Distribution.Types.Dependency
import Distribution.Types.LegacyExeDependency
import Distribution.Types.UnqualComponentName
import Distribution.Simple.Utils
import Distribution.Compat.Graph (Node(..))
import qualified Distribution.Compat.Graph as Graph
......
......@@ -18,8 +18,11 @@ import Distribution.Compat.Prelude hiding ((<>))
import Distribution.Backpack.Id
import Distribution.Types.Dependency
import Distribution.Types.LegacyExeDependency
import Distribution.Types.IncludeRenaming
import Distribution.Types.Mixin
import Distribution.Types.UnqualComponentName
import Distribution.Package
import Distribution.PackageDescription as PD hiding (Flag)
import Distribution.Simple.Setup as Setup
......
......@@ -11,6 +11,7 @@ module Distribution.Backpack.Id(
import Prelude ()
import Distribution.Compat.Prelude
import Distribution.Types.UnqualComponentName
import Distribution.Simple.Compiler hiding (Flag)
import Distribution.Package
import Distribution.PackageDescription as PD hiding (Flag)
......
......@@ -50,7 +50,6 @@ import Distribution.Compat.Prelude
import Distribution.ParseUtils
import Distribution.License
import Distribution.Package hiding (installedUnitId, installedPackageId)
import Distribution.Package.TextClass ()
import Distribution.Backpack
import qualified Distribution.Package as Package
import Distribution.ModuleName
......@@ -288,7 +287,7 @@ fieldsInstalledPackageInfo = basicFieldDescrs ++ installedFieldDescrs
basicFieldDescrs :: [FieldDescr InstalledPackageInfo]
basicFieldDescrs =
[ simpleField "name"
disp parsePackageNameQ
disp (parseMaybeQuoted parse)
packageName (\name pkg -> pkg{sourcePackageId=(sourcePackageId pkg){pkgName=name}})
, simpleField "version"
disp parseOptVersion
......
......@@ -18,9 +18,7 @@
module Distribution.Package (
-- * Package ids
UnqualComponentName, unUnqualComponentName, mkUnqualComponentName,
PackageName, unPackageName, mkPackageName,
packageNameToUnqualComponentName, unqualComponentNameToPackageName,
PackageIdentifier(..),
PackageId,
PkgconfigName, unPkgconfigName, mkPkgconfigName,
......@@ -42,14 +40,6 @@ module Distribution.Package (
-- * ABI hash
AbiHash, unAbiHash, mkAbiHash,
-- * Package source dependencies
Dependency(..),
LegacyExeDependency(..),
PkgconfigDependency(..),
thisPackageVersion,
notThisPackageVersion,
simplifyDependency,
-- * Package classes
Package(..), packageName, packageVersion,
HasUnitId(..),
......@@ -62,66 +52,17 @@ import Distribution.Compat.Prelude
import Distribution.Utils.ShortText
import Distribution.Version
( Version, VersionRange, thisVersion
, notThisVersion, simplifyVersionRange
, nullVersion )
( Version, VersionRange, nullVersion )
import qualified Distribution.Compat.ReadP as Parse
import qualified Text.PrettyPrint as Disp
import Distribution.Compat.ReadP
import Distribution.ParseUtils
import Distribution.Text
import Distribution.ModuleName
import Text.PrettyPrint (text)
-- | An unqualified component name, for any kind of component.
--
-- This is distinguished from a 'ComponentName' and 'ComponentId'. The former
-- also states which of a library, executable, etc the name refers too. The
-- later uniquely identifiers a component and its closure.
--
-- @since 2.0
newtype UnqualComponentName = UnqualComponentName ShortText
deriving (Generic, Read, Show, Eq, Ord, Typeable, Data,
Semigroup, Monoid) -- TODO: bad enabler of bad monoids
-- | Convert 'UnqualComponentName' to 'String'
--
-- @since 2.0
unUnqualComponentName :: UnqualComponentName -> String
unUnqualComponentName (UnqualComponentName s) = fromShortText s
-- | Construct a 'UnqualComponentName' from a 'String'
--
-- 'mkUnqualComponentName' is the inverse to 'unUnqualComponentName'
--
-- Note: No validations are performed to ensure that the resulting
-- 'UnqualComponentName' is valid
--
-- @since 2.0
mkUnqualComponentName :: String -> UnqualComponentName
mkUnqualComponentName = UnqualComponentName . toShortText
instance Binary UnqualComponentName
parsePackageName :: Parse.ReadP r String
parsePackageName = do
ns <- Parse.sepBy1 component (Parse.char '-')
return $ intercalate "-" ns
where
component = do
cs <- Parse.munch1 isAlphaNum
if all isDigit cs then Parse.pfail else return cs
-- each component must contain an alphabetic character, to avoid
-- ambiguity in identifiers like foo-1 (the 1 is the version number).
instance Text UnqualComponentName where
disp = Disp.text . unUnqualComponentName
parse = mkUnqualComponentName <$> parsePackageName
instance NFData UnqualComponentName where
rnf (UnqualComponentName pkg) = rnf pkg
-- | A package name.
--
-- Use 'mkPackageName' and 'unPackageName' to convert from/to a
......@@ -148,27 +89,6 @@ unPackageName (PackageName s) = fromShortText s
mkPackageName :: String -> PackageName
mkPackageName = PackageName . toShortText
-- | Converts a package name to an unqualified component name
--
-- Useful in legacy situations where a package name may refer to an internal
-- component, if one is defined with that name.
--
-- @since 2.0
packageNameToUnqualComponentName :: PackageName -> UnqualComponentName
packageNameToUnqualComponentName (PackageName s) = UnqualComponentName s
-- | Converts an unqualified component name to a package name
--
-- `packageNameToUnqualComponentName` is the inverse of
-- `unqualComponentNameToPackageName`.
--
-- Useful in legacy situations where a package name may refer to an internal
-- component, if one is defined with that name.
--
-- @since 2.0
unqualComponentNameToPackageName :: UnqualComponentName -> PackageName
unqualComponentNameToPackageName (UnqualComponentName s) = PackageName s
instance Binary PackageName
instance Text PackageName where
......@@ -390,23 +310,6 @@ mkLegacyUnitId = newSimpleUnitId . mkComponentId . display
-- * Package source dependencies
-- ------------------------------------------------------------
-- | Describes a dependency on a source package (API)
--
data Dependency = Dependency PackageName VersionRange
deriving (Generic, Read, Show, Eq, Typeable, Data)
-- | Describes a legacy `build-tools`-style dependency on an executable
--
-- It is "legacy" because we do not know what the build-tool referred to. It
-- could refer to a pkg-config executable (PkgconfigName), or an internal
-- executable (UnqualComponentName). Thus the name is stringly typed.
--
-- @since 2.0
data LegacyExeDependency = LegacyExeDependency
String
VersionRange
deriving (Generic, Read, Show, Eq, Typeable, Data)
-- | Describes a dependency on a pkg-config library
--
-- @since 2.0
......@@ -415,29 +318,10 @@ data PkgconfigDependency = PkgconfigDependency
VersionRange
deriving (Generic, Read, Show, Eq, Typeable, Data)
instance Binary Dependency
instance Binary LegacyExeDependency
instance Binary PkgconfigDependency
instance NFData Dependency where rnf = genericRnf
instance NFData LegacyExeDependency where rnf = genericRnf
instance NFData PkgconfigDependency where rnf = genericRnf
thisPackageVersion :: PackageIdentifier -> Dependency
thisPackageVersion (PackageIdentifier n v) =
Dependency n (thisVersion v)
notThisPackageVersion :: PackageIdentifier -> Dependency
notThisPackageVersion (PackageIdentifier n v) =
Dependency n (notThisVersion v)
-- | Simplify the 'VersionRange' expression in a 'Dependency'.
-- See 'simplifyVersionRange'.
--
simplifyDependency :: Dependency -> Dependency
simplifyDependency (Dependency name range) =
Dependency name (simplifyVersionRange range)
-- | Class of things that have a 'PackageIdentifier'
--
-- Types in this class are all notions of a package. This allows us to have
......
......@@ -44,6 +44,8 @@ import Distribution.License
import Distribution.Simple.BuildPaths (autogenPathsModuleName)
import Distribution.Simple.CCompiler
import Distribution.Types.ComponentRequestedSpec
import Distribution.Types.Dependency
import Distribution.Types.UnqualComponentName
import Distribution.Simple.Utils hiding (findPackageDesc, notice)
import Distribution.Version
import Distribution.Package
......
......@@ -50,6 +50,8 @@ import qualified Distribution.Compat.ReadP as ReadP ( char )
import Distribution.Types.ComponentRequestedSpec
import Distribution.Types.ForeignLib
import Distribution.Types.Component
import Distribution.Types.Dependency
import Distribution.Types.UnqualComponentName
import qualified Data.Map as Map
import Data.Tree ( Tree(Node) )
......
......@@ -49,13 +49,14 @@ module Distribution.PackageDescription.Parse (
import Prelude ()
import Distribution.Compat.Prelude
import Distribution.Types.Dependency
import Distribution.Types.ForeignLib
import Distribution.Types.ForeignLibType
import Distribution.Types.UnqualComponentName
import Distribution.ParseUtils hiding (parseFields)
import Distribution.PackageDescription
import Distribution.PackageDescription.Utils
import Distribution.Package
import Distribution.Package.TextClass ()
import Distribution.ModuleName
import Distribution.Version
import Distribution.Verbosity
......
......@@ -34,7 +34,6 @@ import qualified Data.ByteString as BS
import Data.List (partition)
import qualified Data.Map as Map
import qualified Distribution.Compat.SnocList as SnocList
import Distribution.Package
import Distribution.PackageDescription
import Distribution.PackageDescription.Parsec.FieldDescr
import Distribution.Parsec.Class (parsec)
......@@ -51,6 +50,8 @@ import Distribution.Simple.Utils
(die, fromUTF8BS, warn)
import Distribution.Text (display)
import Distribution.Types.ForeignLib
import Distribution.Types.UnqualComponentName
(UnqualComponentName, mkUnqualComponentName)
import Distribution.Verbosity (Verbosity)
import Distribution.Version
(LowerBound (..), Version, asVersionIntervals, mkVersion,
......
......@@ -41,7 +41,6 @@ import qualified Distribution.Compat.Parsec as Parsec
import Distribution.Compiler (CompilerFlavor (..))
import Distribution.ModuleName (ModuleName)
import Distribution.Package
import Distribution.Package.TextClass ()
import Distribution.PackageDescription
import Distribution.Types.ForeignLib
import Distribution.Parsec.Class
......
......@@ -29,13 +29,14 @@ module Distribution.PackageDescription.PrettyPrint (
import Prelude ()
import Distribution.Compat.Prelude
import Distribution.Types.Dependency
import Distribution.Types.ForeignLib
import Distribution.Types.UnqualComponentName
import Distribution.PackageDescription
import Distribution.Simple.Utils
import Distribution.ParseUtils
import Distribution.PackageDescription.Parse
import Distribution.Package
import Distribution.Text
import Distribution.ModuleName
......
......@@ -29,7 +29,7 @@ module Distribution.ParseUtils (
parseFields, parseFieldsFlat,
parseFilePathQ, parseTokenQ, parseTokenQ',
parseModuleNameQ,
parseOptVersion, parsePackageNameQ,
parseOptVersion, parsePackageName,
parseTestedWithQ, parseLicenseQ, parseLanguageQ, parseExtensionQ,
parseSepList, parseCommaList, parseOptCommaList,
showFilePath, showToken, showTestedWith, showFreeText, parseFreeText,
......@@ -46,7 +46,6 @@ import Distribution.Compat.Prelude hiding (get)
import Distribution.Compiler
import Distribution.License
import Distribution.Version
import Distribution.Package
import Distribution.ModuleName
import qualified Distribution.Compat.MonadFail as Fail
import Distribution.Compat.ReadP as ReadP hiding (get)
......@@ -625,8 +624,16 @@ betweenSpaces act = do skipSpaces
skipSpaces
return res
parsePackageNameQ :: ReadP r PackageName
parsePackageNameQ = parseMaybeQuoted parse
parsePackageName :: ReadP r String
parsePackageName = do
ns <- sepBy1 component (char '-')
return $ intercalate "-" ns
where
component = do
cs <- munch1 isAlphaNum
if all isDigit cs then pfail else return cs
-- each component must contain an alphabetic character, to avoid
-- ambiguity in identifiers like foo-1 (the 1 is the version number).
parseOptVersion :: ReadP r Version
parseOptVersion = parseMaybeQuoted ver
......
......@@ -32,10 +32,7 @@ import Distribution.License (License (..))
import Distribution.ModuleName (ModuleName)
import qualified Distribution.ModuleName as ModuleName
import Distribution.Package
(Dependency (..),
LegacyExeDependency (..), PkgconfigDependency (..),
UnqualComponentName, mkUnqualComponentName,
PackageName, mkPackageName,
(PackageName, mkPackageName,
PkgconfigName, mkPkgconfigName)
import Distribution.System
(Arch (..), ClassificationStrictness (..), OS (..),
......@@ -44,6 +41,9 @@ import Distribution.Text (display)
import Distribution.Types.BenchmarkType
(BenchmarkType (..))
import Distribution.Types.BuildType (BuildType (..))
import Distribution.Types.Dependency (Dependency (..))
import Distribution.Types.LegacyExeDependency (LegacyExeDependency (..))
import Distribution.Types.PkgconfigDependency (PkgconfigDependency (..))
import Distribution.Types.GenericPackageDescription (FlagName, mkFlagName)
import Distribution.Types.ModuleReexport
(ModuleReexport (..))
......@@ -55,6 +55,8 @@ import Distribution.Types.ForeignLibOption (ForeignLibOption
import Distribution.Types.ModuleRenaming
import Distribution.Types.IncludeRenaming
import Distribution.Types.Mixin
import Distribution.Types.UnqualComponentName
(UnqualComponentName, mkUnqualComponentName)
import Distribution.Version
(Version, VersionRange (..), anyVersion, earlierVersion,
intersectVersionRanges, laterVersion, majorBoundVersion,
......
......@@ -21,7 +21,7 @@ module Distribution.Simple.Bench
import Prelude ()
import Distribution.Compat.Prelude
import Distribution.Package
import Distribution.Types.UnqualComponentName
import qualified Distribution.PackageDescription as PD
import Distribution.Simple.BuildPaths
import Distribution.Simple.Compiler
......
......@@ -29,10 +29,13 @@ module Distribution.Simple.Build (
import Prelude ()
import Distribution.Compat.Prelude
import Distribution.Types.Dependency
import Distribution.Types.LegacyExeDependency
import Distribution.Types.LocalBuildInfo
import Distribution.Types.TargetInfo
import Distribution.Types.ComponentRequestedSpec
import Distribution.Types.ForeignLib
import Distribution.Types.UnqualComponentName
import Distribution.Package
import Distribution.Backpack
......
......@@ -43,6 +43,7 @@ import Distribution.Types.TargetInfo
import Distribution.Types.LocalBuildInfo
import Distribution.Types.ComponentRequestedSpec
import Distribution.Types.ForeignLib
import Distribution.Types.UnqualComponentName
import Distribution.Package
import Distribution.PackageDescription
......
......@@ -79,12 +79,16 @@ import Distribution.Simple.Program
import Distribution.Simple.Setup as Setup
import Distribution.Simple.BuildTarget
import Distribution.Simple.LocalBuildInfo
import Distribution.Types.Dependency
import Distribution.Types.LegacyExeDependency
import Distribution.Types.PkgconfigDependency
import Distribution.Types.LocalBuildInfo
import Distribution.Types.ComponentRequestedSpec
import Distribution.Types.ForeignLib
import Distribution.Types.ForeignLibType
import Distribution.Types.ForeignLibOption
import Distribution.Types.Mixin
import Distribution.Types.UnqualComponentName
import Distribution.Simple.Utils
import Distribution.System
import Distribution.Version
......
......@@ -97,6 +97,7 @@ import Distribution.Text
import Distribution.Types.ForeignLib
import Distribution.Types.ForeignLibType
import Distribution.Types.ForeignLibOption
import Distribution.Types.UnqualComponentName
import Distribution.Utils.NubList
import Language.Haskell.Extension
......
......@@ -20,6 +20,7 @@ module Distribution.Simple.GHCJS (
import Prelude ()
import Distribution.Compat.Prelude
import Distribution.Types.UnqualComponentName
import Distribution.Simple.GHC.ImplInfo
import qualified Distribution.Simple.GHC.Internal as Internal
import Distribution.PackageDescription as PD
......
......@@ -32,6 +32,7 @@ import qualified Distribution.Simple.GHCJS as GHCJS
-- local
import Distribution.Types.ForeignLib
import Distribution.Types.UnqualComponentName
import Distribution.Package
import qualified Distribution.ModuleName as ModuleName
import Distribution.PackageDescription as PD hiding (Flag)
......
......@@ -27,8 +27,8 @@ module Distribution.Simple.Hpc
import Prelude ()
import Distribution.Compat.Prelude
import Distribution.Types.UnqualComponentName
import Distribution.ModuleName ( main )
import Distribution.Package
import Distribution.PackageDescription
( TestSuite(..)
, testModules
......
......@@ -26,6 +26,7 @@ import Distribution.Types.TargetInfo
import Distribution.Types.LocalBuildInfo
import Distribution.Types.ForeignLib
import Distribution.Types.PackageDescription
import Distribution.Types.UnqualComponentName
import Distribution.Package
import Distribution.PackageDescription
......
......@@ -46,6 +46,7 @@ module Distribution.Simple.LHC (
import Prelude ()
import Distribution.Compat.Prelude
import Distribution.Types.UnqualComponentName
import Distribution.PackageDescription as PD hiding (Flag)
import Distribution.InstalledPackageInfo
import qualified Distribution.InstalledPackageInfo as InstalledPackageInfo
......
......@@ -74,6 +74,7 @@ import Distribution.Types.PackageDescription
import Distribution.Types.ComponentLocalBuildInfo
import Distribution.Types.LocalBuildInfo
import Distribution.Types.TargetInfo
import Distribution.Types.UnqualComponentName
import Distribution.Simple.InstallDirs hiding (absoluteInstallDirs,
prefixRelativeInstallDirs,
......
......@@ -118,6 +118,7 @@ import Distribution.ModuleName
import qualified Distribution.InstalledPackageInfo as IPI
import Distribution.Version
import Distribution.Simple.Utils
import Distribution.Types.Dependency
import Control.Exception (assert)
import Data.Array ((!))
......
......@@ -51,6 +51,7 @@ import Distribution.Text
import Distribution.Version
import Distribution.Verbosity
import Distribution.Types.ForeignLib
import Distribution.Types.UnqualComponentName
import System.Directory (doesFileExist)
import System.Info (os, arch)
......
......@@ -85,7 +85,6 @@ import qualified Distribution.Compat.ReadP as Parse
import qualified Text.PrettyPrint as Disp
import Distribution.ModuleName
import Distribution.Package
import Distribution.Package.TextClass ()
import Distribution.PackageDescription hiding (Flag)
import Distribution.Simple.Command hiding (boolOpt, boolOpt')
import qualified Distribution.Simple.Command as Command
......@@ -95,6 +94,7 @@ import Distribution.Simple.Program
import Distribution.Simple.InstallDirs
import Distribution.Verbosity
import Distribution.Utils.NubList
import Distribution.Types.Dependency
import Distribution.Compat.Semigroup (Last' (..))
......
......@@ -21,7 +21,7 @@ module Distribution.Simple.Test
import Prelude ()
import Distribution.Compat.Prelude
import Distribution.Package
import Distribution.Types.UnqualComponentName
import qualified Distribution.PackageDescription as PD
import Distribution.Simple.Compiler
import Distribution.Simple.Hpc
......
......@@ -6,9 +6,9 @@ module Distribution.Simple.Test.ExeV10
) where
import Prelude ()
import Distribution.Package
import Distribution.Compat.Prelude
import Distribution.Types.UnqualComponentName
import Distribution.Compat.CreatePipe
import Distribution.Compat.Environment
import qualified Distribution.PackageDescription as PD
......
......@@ -10,8 +10,8 @@ module Distribution.Simple.Test.LibV09
) where
import Prelude ()
import Distribution.Package
import Distribution.Compat.Prelude
import Distribution.Types.UnqualComponentName
import Distribution.Compat.CreatePipe
import Distribution.Compat.Environment
......
......@@ -18,6 +18,7 @@ import Prelude ()
import Distribution.Compat.Prelude
import Distribution.Package
import Distribution.Types.UnqualComponentName
import qualified Distribution.PackageDescription as PD
import Distribution.Simple.Compiler
import Distribution.Simple.InstallDirs
......
......@@ -160,7 +160,7 @@ import Distribution.Compat.Prelude
import Distribution.Text