------------------------------------------------------------------------------- |-- Module : Distribution.Compiler-- Copyright : Isaac Jones 2003-2004---- Maintainer : cabal-devel@haskell.org-- Portability : portable---- This has an enumeration of the various compilers that Cabal knows about. It-- also specifies the default compiler. Sadly you'll often see code that does-- case analysis on this compiler flavour enumeration like:---- > case compilerFlavor comp of-- > GHC -> GHC.getInstalledPackages verbosity packageDb progconf-- > JHC -> JHC.getInstalledPackages verbosity packageDb progconf---- Obviously it would be better to use the proper 'Compiler' abstraction-- because that would keep all the compiler-specific code together.-- Unfortunately we cannot make this change yet without breaking the-- 'UserHooks' api, which would break all custom @Setup.hs@ files, so for the-- moment we just have to live with this deficiency. If you're interested, see-- ticket #50.{- All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Isaac Jones nor the names of other
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -}moduleDistribution.Compiler(-- * Compiler flavorCompilerFlavor(..),buildCompilerFlavor,defaultCompilerFlavor,parseCompilerFlavorCompat,-- * Compiler idCompilerId(..),)whereimportDistribution.Version(Version(..))importqualifiedSystem.Info(compilerName)importDistribution.Text(Text(..),display)importqualifiedDistribution.Compat.ReadPasParseimportqualifiedText.PrettyPrintasDispimportText.PrettyPrint((<>))importqualifiedData.CharasChar(toLower,isDigit,isAlphaNum)importControl.Monad(when)dataCompilerFlavor=GHC|NHC|YHC|Hugs|HBC|Helium|JHC|LHC|UHC|OtherCompilerStringderiving(Show,Read,Eq,Ord)knownCompilerFlavors::[CompilerFlavor]knownCompilerFlavors=[GHC,NHC,YHC,Hugs,HBC,Helium,JHC,LHC,UHC]instanceTextCompilerFlavorwheredisp(OtherCompilername)=Disp.textnamedispNHC=Disp.text"nhc98"dispother=Disp.text(lowercase(showother))parse=docomp<-Parse.munch1Char.isAlphaNumwhen(allChar.isDigitcomp)Parse.pfailreturn(classifyCompilerFlavorcomp)classifyCompilerFlavor::String->CompilerFlavorclassifyCompilerFlavors=caselookup(lowercases)compilerMapofJustcompiler->compilerNothing->OtherCompilerswherecompilerMap=[(displaycompiler,compiler)|compiler<-knownCompilerFlavors]--TODO: In some future release, remove 'parseCompilerFlavorCompat' and use-- ordinary 'parse'. Also add ("nhc", NHC) to the above 'compilerMap'.-- | Like 'classifyCompilerFlavor' but compatible with the old ReadS parser.---- It is compatible in the sense that it accepts only the same strings,-- eg "GHC" but not "ghc". However other strings get mapped to 'OtherCompiler'.-- The point of this is that we do not allow extra valid values that would-- upset older Cabal versions that had a stricter parser however we cope with-- new values more gracefully so that we'll be able to introduce new value in-- future without breaking things so much.--parseCompilerFlavorCompat::Parse.ReadPrCompilerFlavorparseCompilerFlavorCompat=docomp<-Parse.munch1Char.isAlphaNumwhen(allChar.isDigitcomp)Parse.pfailcaselookupcompcompilerMapofJustcompiler->returncompilerNothing->return(OtherCompilercomp)wherecompilerMap=[(showcompiler,compiler)|compiler<-knownCompilerFlavors,compiler/=YHC]buildCompilerFlavor::CompilerFlavorbuildCompilerFlavor=classifyCompilerFlavorSystem.Info.compilerName-- | The default compiler flavour to pick when compiling stuff. This defaults-- to the compiler used to build the Cabal lib.---- However if it's not a recognised compiler then it's 'Nothing' and the user-- will have to specify which compiler they want.--defaultCompilerFlavor::MaybeCompilerFlavordefaultCompilerFlavor=casebuildCompilerFlavorofOtherCompiler_->Nothing_->JustbuildCompilerFlavor-- -------------------------------------------------------------- * Compiler Id-- ------------------------------------------------------------dataCompilerId=CompilerIdCompilerFlavorVersionderiving(Eq,Ord,Read,Show)instanceTextCompilerIdwheredisp(CompilerIdf(Version[]_))=dispfdisp(CompilerIdfv)=dispf<>Disp.char'-'<>dispvparse=doflavour<-parseversion<-(Parse.char'-'>>parse)Parse.<++return(Version[][])return(CompilerIdflavourversion)lowercase::String->Stringlowercase=mapChar.toLower