Commit d15eb1cb authored by Duncan Coutts's avatar Duncan Coutts
Browse files

Add a CompilerId type and use it in appropriate places

Especially instead of abusing a PackageIdentifier for the purpose.
parent 31185708
......@@ -40,13 +40,20 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -}
module Distribution.Compiler (
-- * Compiler flavor
CompilerFlavor(..),
showCompilerFlavor,
readCompilerFlavor,
buildCompilerFlavor,
defaultCompilerFlavor
defaultCompilerFlavor,
-- * Compiler id
CompilerId(..),
showCompilerId,
) where
import Distribution.Version (Version(..), showVersion)
import qualified System.Info (compilerName)
import qualified Data.Char as Char (toLower)
......@@ -79,5 +86,16 @@ defaultCompilerFlavor = case buildCompilerFlavor of
OtherCompiler _ -> Nothing
_ -> Just buildCompilerFlavor
-- ------------------------------------------------------------
-- * Compiler Id
-- ------------------------------------------------------------
data CompilerId = CompilerId CompilerFlavor Version
deriving (Eq, Ord, Read, Show)
showCompilerId :: CompilerId -> String
showCompilerId (CompilerId f (Version [] _)) = showCompilerFlavor f
showCompilerId (CompilerId f v) = showCompilerFlavor f ++ '-': showVersion v
lowercase :: String -> String
lowercase = map Char.toLower
......@@ -45,7 +45,8 @@ module Distribution.Simple.Build (
build, makefile, initialBuildSteps
) where
import Distribution.Simple.Compiler ( Compiler(..), CompilerFlavor(..) )
import Distribution.Simple.Compiler
( CompilerFlavor(..), compilerFlavor )
import Distribution.PackageDescription
( PackageDescription(..), BuildInfo(..),
Executable(..), Library(..) )
......
......@@ -63,7 +63,9 @@ module Distribution.Simple.BuildPaths (
import System.FilePath (FilePath, (</>), (<.>))
import Distribution.Package
( PackageIdentifier(PackageIdentifier), packageName )
( packageName )
import Distribution.Compiler
( CompilerId(..), showCompilerFlavor )
import Distribution.PackageDescription (PackageDescription)
import Distribution.Simple.LocalBuildInfo (LocalBuildInfo(buildDir))
import Distribution.Version (showVersion)
......@@ -118,11 +120,12 @@ mkProfLibName pref lib = mkLibName pref (lib++"_p")
-- e.g. libHSbase-2.1-ghc6.6.1.so
mkSharedLibName :: FilePath -- ^file Prefix
-> String -- ^library name.
-> PackageIdentifier -- ^package identifier of the compiler
-> CompilerId -- ^identifier of the compiler
-> String
mkSharedLibName pref lib (PackageIdentifier compilerName compilerVersion)
mkSharedLibName pref lib (CompilerId compilerFlavor compilerVersion)
= pref </> ("libHS" ++ lib ++ "-" ++ comp) <.> dllExtension
where comp = compilerName ++ showVersion compilerVersion
where comp = showCompilerFlavor compilerFlavor
++ showVersion compilerVersion
-- ------------------------------------------------------------
-- * Platform file extensions
......
......@@ -43,7 +43,7 @@ module Distribution.Simple.Compiler (
-- * Haskell implementations
module Distribution.Compiler,
Compiler(..),
showCompilerId, compilerVersion,
showCompilerId, compilerFlavor, compilerVersion,
-- * Support for package databases
PackageDB(..),
......@@ -58,26 +58,28 @@ module Distribution.Simple.Compiler (
unsupportedExtensions
) where
import Distribution.Compiler
import Distribution.Compiler hiding (showCompilerId)
import qualified Distribution.Compiler (showCompilerId)
import Distribution.Version (Version(..))
import Distribution.Package (PackageIdentifier, packageVersion, showPackageId)
import Language.Haskell.Extension (Extension(..))
import Data.List (nub)
import Data.Maybe (catMaybes, isNothing)
data Compiler = Compiler {
compilerFlavor :: CompilerFlavor,
compilerId :: PackageIdentifier,
compilerExtensions :: [(Extension, Flag)]
compilerId :: CompilerId,
compilerExtensions :: [(Extension, String)]
}
deriving (Show, Read)
showCompilerId :: Compiler -> String
showCompilerId = showPackageId . compilerId
showCompilerId = Distribution.Compiler.showCompilerId . compilerId
compilerFlavor :: Compiler -> CompilerFlavor
compilerFlavor = (\(CompilerId f _) -> f) . compilerId
compilerVersion :: Compiler -> Version
compilerVersion = packageVersion . compilerId
compilerVersion = (\(CompilerId _ v) -> v) . compilerId
-- ------------------------------------------------------------
-- * Package databases
......
......@@ -55,8 +55,8 @@ module Distribution.Simple.Configure (configure,
where
import Distribution.Simple.Compiler
( CompilerFlavor(..), Compiler(compilerFlavor), compilerVersion, showCompilerId
, unsupportedExtensions, PackageDB(..) )
( CompilerFlavor(..), Compiler, compilerFlavor, compilerVersion
, showCompilerId, unsupportedExtensions, PackageDB(..) )
import Distribution.Package
( PackageIdentifier(PackageIdentifier), packageVersion, Package(..)
, showPackageId, parsePackageId
......
......@@ -66,7 +66,7 @@ import Distribution.Simple.LocalBuildInfo
import Distribution.Simple.BuildPaths
import Distribution.Simple.Utils
import Distribution.Package
( PackageIdentifier(PackageIdentifier), showPackageId, Package(..) )
( showPackageId, Package(..) )
import Distribution.Simple.Program ( rawSystemProgram, rawSystemProgramConf,
rawSystemProgramStdoutConf,
rawSystemProgramStdout,
......@@ -77,6 +77,8 @@ import Distribution.Simple.Program ( rawSystemProgram, rawSystemProgramConf,
ghcProgram, ghcPkgProgram,
arProgram, ranlibProgram, ldProgram )
import Distribution.Simple.Compiler
( CompilerFlavor(..), CompilerId(..), Compiler(..), compilerVersion
, OptimisationLevel(..), PackageDB(..), Flag, extensionsToFlags )
import Distribution.Version ( Version(..), showVersion,
VersionRange(..), orLaterVersion )
import Distribution.System
......@@ -168,8 +170,7 @@ configure verbosity hcPath hcPkgPath conf = do
else return oldLanguageExtensions
let comp = Compiler {
compilerFlavor = GHC,
compilerId = PackageIdentifier "ghc" ghcVersion,
compilerId = CompilerId GHC ghcVersion,
compilerExtensions = languageExtensions
}
return (comp, conf'''')
......
......@@ -47,7 +47,8 @@ module Distribution.Simple.Hugs (
import Distribution.PackageDescription
( PackageDescription(..), BuildInfo(..), hcOptions,
Executable(..), withExe, Library(..), withLib, libModules )
import Distribution.Simple.Compiler ( Compiler(..), CompilerFlavor(..), Flag )
import Distribution.Simple.Compiler
( CompilerFlavor(..), CompilerId(..), Compiler(..), Flag )
import Distribution.Simple.Program ( ProgramConfiguration, userMaybeSpecifyPath,
requireProgram, rawSystemProgramConf,
ffihugsProgram, hugsProgram )
......@@ -71,7 +72,6 @@ import System.FilePath ( (</>), takeExtension, (<.>),
import Distribution.System
( OS(..), buildOS )
import Distribution.Verbosity
import Distribution.Package ( PackageIdentifier(PackageIdentifier) )
import Data.Char ( isSpace )
import Data.Maybe ( mapMaybe, catMaybes )
......@@ -95,8 +95,7 @@ configure verbosity hcPath _hcPkgPath conf = do
(_hugsProg, conf'') <- requireProgram verbosity hugsProgram AnyVersion conf'
let comp = Compiler {
compilerFlavor = Hugs,
compilerId = PackageIdentifier "hugs" (Version [] []),
compilerId = CompilerId Hugs (Version [] []),
compilerExtensions = hugsLanguageExtensions
}
return (comp, conf'')
......
......@@ -56,7 +56,8 @@ import Distribution.Simple.BuildPaths (haddockName, haddockPref)
import Distribution.Simple.Utils (createDirectoryIfMissingVerbose,
copyFileVerbose, die, info, notice,
copyDirectoryRecursiveVerbose)
import Distribution.Simple.Compiler (CompilerFlavor(..), Compiler(..))
import Distribution.Simple.Compiler
( CompilerFlavor(..), compilerFlavor )
import Distribution.Simple.Setup (CopyFlags(..), CopyDest(..), fromFlag)
import qualified Distribution.Simple.GHC as GHC
......
......@@ -79,7 +79,8 @@ import Distribution.Package
import Distribution.Version (showVersion)
import Distribution.System
( OS(..), buildOS )
import Distribution.Simple.Compiler (CompilerFlavor(..))
import Distribution.Compiler
( CompilerId, showCompilerId, CompilerFlavor(..) )
#if mingw32_HOST_OS || mingw32_TARGET_OS
import Foreign
......@@ -259,7 +260,7 @@ defaultInstallDirs comp userInstall hasLibs = do
-- 'PathTemplate's that still have the 'PrefixVar' in them. Doing this makes it
-- each to check which paths are relative to the $prefix.
--
substituteTemplates :: PackageIdentifier -> PackageIdentifier
substituteTemplates :: PackageIdentifier -> CompilerId
-> InstallDirTemplates -> InstallDirTemplates
substituteTemplates pkgId compilerId dirs = dirs'
where
......@@ -299,7 +300,7 @@ substituteTemplates pkgId compilerId dirs = dirs'
-- | Convert from abstract install directories to actual absolute ones by
-- substituting for all the variables in the abstract paths, to get real
-- absolute path.
absoluteInstallDirs :: PackageIdentifier -> PackageIdentifier -> CopyDest
absoluteInstallDirs :: PackageIdentifier -> CompilerId -> CopyDest
-> InstallDirTemplates -> InstallDirs FilePath
absoluteInstallDirs pkgId compilerId copydest dirs =
(case copydest of
......@@ -327,7 +328,7 @@ data CopyDest
-- prevents us from making a relocatable package (also known as a \"prefix
-- independent\" package).
--
prefixRelativeInstallDirs :: PackageIdentifier -> PackageIdentifier
prefixRelativeInstallDirs :: PackageIdentifier -> CompilerId
-> InstallDirTemplates
-> InstallDirs (Maybe FilePath)
prefixRelativeInstallDirs pkgId compilerId dirs =
......@@ -402,14 +403,14 @@ substPathTemplate environment (PathTemplate template) =
Nothing -> [component]
-- | The initial environment has all the static stuff but no paths
initialPathTemplateEnv :: PackageIdentifier -> PackageIdentifier
initialPathTemplateEnv :: PackageIdentifier -> CompilerId
-> [(PathTemplateVariable, PathTemplate)]
initialPathTemplateEnv pkgId compilerId =
map (\(v,s) -> (v, PathTemplate [Ordinary s]))
[(PkgNameVar, packageName pkgId)
,(PkgVerVar, showVersion (packageVersion pkgId))
,(PkgIdVar, showPackageId pkgId)
,(CompilerVar, showPackageId compilerId)]
,(CompilerVar, showCompilerId compilerId)]
-- ---------------------------------------------------------------------------
-- Parsing and showing path templates:
......
......@@ -59,8 +59,9 @@ import Distribution.Simple.LocalBuildInfo
( LocalBuildInfo(..) )
import Distribution.Simple.BuildPaths
( autogenModulesDir, exeExtension )
import Distribution.Simple.Compiler ( Compiler(..), CompilerFlavor(..), Flag,
PackageDB, extensionsToFlags )
import Distribution.Simple.Compiler
( CompilerFlavor(..), CompilerId(..), Compiler(..)
, PackageDB, Flag, extensionsToFlags )
import Language.Haskell.Extension (Extension(..))
import Distribution.Simple.Program ( ConfiguredProgram(..), jhcProgram,
ProgramConfiguration, userMaybeSpecifyPath,
......@@ -68,8 +69,7 @@ import Distribution.Simple.Program ( ConfiguredProgram(..), jhcProgram,
rawSystemProgram, rawSystemProgramStdoutConf )
import Distribution.Version ( VersionRange(AnyVersion) )
import Distribution.Package
( PackageIdentifier(PackageIdentifier), showPackageId, parsePackageId
, Package(..) )
( showPackageId, parsePackageId, Package(..) )
import Distribution.Simple.Utils
( createDirectoryIfMissingVerbose, copyFileVerbose
, die, info, intercalate )
......@@ -95,8 +95,7 @@ configure verbosity hcPath _hcPkgPath conf = do
let Just version = programVersion jhcProg
comp = Compiler {
compilerFlavor = JHC,
compilerId = PackageIdentifier "jhc" version,
compilerId = CompilerId JHC version,
compilerExtensions = jhcLanguageExtensions
}
return (comp, conf')
......
......@@ -46,7 +46,7 @@ module Distribution.Simple.NHC
) where
import Distribution.Package
( PackageIdentifier(PackageIdentifier), packageName )
( PackageIdentifier, packageName )
import Distribution.PackageDescription
( PackageDescription(..), BuildInfo(..), Library(..), Executable(..),
withLib, withExe, hcOptions )
......@@ -55,7 +55,8 @@ import Distribution.Simple.LocalBuildInfo
import Distribution.Simple.BuildPaths
( mkLibName, objExtension, exeExtension )
import Distribution.Simple.Compiler
( Compiler(..), CompilerFlavor(..), Flag, extensionsToFlags )
( CompilerFlavor(..), CompilerId(..), Compiler(..)
, Flag, extensionsToFlags )
import Language.Haskell.Extension
( Extension(..) )
import Distribution.Simple.Program
......@@ -102,8 +103,7 @@ configure verbosity hcPath _hcPkgPath conf = do
-- unless (null (cSources bi)) $ requireProgram ccProgram AnyVersion
let comp = Compiler {
compilerFlavor = NHC,
compilerId = PackageIdentifier "nhc98" nhcVersion,
compilerId = CompilerId NHC nhcVersion,
compilerExtensions = nhcLanguageExtensions
}
return (comp, conf'''')
......
......@@ -60,7 +60,8 @@ import Distribution.PackageDescription (PackageDescription(..),
BuildInfo(..), Executable(..), withExe,
Library(..), withLib, libModules)
import Distribution.Package (showPackageId, Package(..))
import Distribution.Simple.Compiler (CompilerFlavor(..), Compiler(..), compilerVersion)
import Distribution.Simple.Compiler
( CompilerFlavor(..), Compiler(..), compilerFlavor, compilerVersion )
import Distribution.Simple.LocalBuildInfo (LocalBuildInfo(..))
import Distribution.Simple.Utils
( createDirectoryIfMissingVerbose, readUTF8File, writeUTF8File
......
......@@ -53,8 +53,8 @@ import Distribution.Simple.LocalBuildInfo (LocalBuildInfo(..),
InstallDirs(..),
absoluteInstallDirs)
import Distribution.Simple.BuildPaths (distPref, haddockName)
import Distribution.Simple.Compiler (CompilerFlavor(..), Compiler(..),
PackageDB(..))
import Distribution.Simple.Compiler
( CompilerFlavor(..), compilerFlavor, PackageDB(..) )
import Distribution.Simple.Program (ConfiguredProgram, programPath,
programArgs, rawSystemProgram,
lookupProgram, ghcPkgProgram)
......
Markdown is supported
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