diff options
author | Daniel Gröber <dxld@darkboxed.org> | 2018-10-10 21:42:13 +0200 |
---|---|---|
committer | Daniel Gröber <dxld@darkboxed.org> | 2018-10-26 04:33:07 +0200 |
commit | c8f1af5397c8a95b6522d44857c146f9aacfc540 (patch) | |
tree | 45814f55bd54b8020511298fe235e3b4b8153c9a /src | |
parent | 2968c76b2c4bf60a273f2da161b1552cb1e15fe9 (diff) |
Move compat code out of Runtime/Main.hs
Diffstat (limited to 'src')
-rw-r--r-- | src/CabalHelper/Compiletime/Data.hs | 1 | ||||
-rw-r--r-- | src/CabalHelper/Runtime/Compat.hs | 210 | ||||
-rw-r--r-- | src/CabalHelper/Runtime/Main.hs | 55 |
3 files changed, 212 insertions, 54 deletions
diff --git a/src/CabalHelper/Compiletime/Data.hs b/src/CabalHelper/Compiletime/Data.hs index 76019fa..9fb5a53 100644 --- a/src/CabalHelper/Compiletime/Data.hs +++ b/src/CabalHelper/Compiletime/Data.hs @@ -85,6 +85,7 @@ runtimeSources :: (String, [(FilePath, FilePath)]) runtimeSources = $( let files = map (\f -> (f, ("src/CabalHelper" </> f))) $ sort $ [ ("Runtime/Main.hs") + , ("Runtime/Compat.hs") , ("Shared/Common.hs") , ("Shared/Sandbox.hs") , ("Shared/InterfaceTypes.hs") diff --git a/src/CabalHelper/Runtime/Compat.hs b/src/CabalHelper/Runtime/Compat.hs new file mode 100644 index 0000000..c1bb3b3 --- /dev/null +++ b/src/CabalHelper/Runtime/Compat.hs @@ -0,0 +1,210 @@ +-- cabal-helper: Simple interface to Cabal's configuration state +-- Copyright (C) 2015-2018 Daniel Gröber <cabal-helper@dxld.at> +-- +-- This program is free software: you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation, either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see <http://www.gnu.org/licenses/>. + +{-# LANGUAGE CPP, BangPatterns, RecordWildCards, RankNTypes, ViewPatterns, + TupleSections #-} + +#ifdef MIN_VERSION_Cabal +#undef CH_MIN_VERSION_Cabal +#define CH_MIN_VERSION_Cabal MIN_VERSION_Cabal +#endif + +module CabalHelper.Runtime.Compat + ( UnitId + , componentNameToCh + , unUnqualComponentName' + , componentNameFromComponent + , componentOutDir + ) where + +import System.FilePath + +import Distribution.PackageDescription + ( PackageDescription + , GenericPackageDescription(..) + , Flag(..) + , FlagName + , FlagAssignment + , Executable(..) + , Library(..) + , TestSuite(..) + , Benchmark(..) + , BuildInfo(..) + , TestSuiteInterface(..) + , BenchmarkInterface(..) + , withLib + ) +import Distribution.Simple.LocalBuildInfo + ( ComponentName(..) + , Component(..) + , LocalBuildInfo(..) + ) + + +#if CH_MIN_VERSION_Cabal(1,24,0) +import Distribution.Package (UnitId) +#else +import Distribution.Package (InstalledPackageId) +#endif + +#if CH_MIN_VERSION_Cabal(1,25,0) +-- >=1.25 +import Distribution.PackageDescription + ( unFlagName + -- , mkFlagName + ) +import Distribution.Types.ForeignLib + ( ForeignLib(..) + ) +import Distribution.Types.UnqualComponentName + ( UnqualComponentName + , unUnqualComponentName + ) +#else +-- <1.25 +import Distribution.PackageDescription + ( FlagName(FlagName) + ) +#endif + +#if CH_MIN_VERSION_Cabal(2,0,0) +-- CPP >= 2.0 +import Distribution.Simple.LocalBuildInfo + ( allLibModules + , componentBuildDir + ) +import Distribution.Simple.Register + ( internalPackageDBPath + ) +import Distribution.Backpack + ( OpenUnitId(..), + OpenModule(..) + ) +import Distribution.ModuleName + ( ModuleName + ) +import Distribution.Types.ComponentId + ( unComponentId + ) +import Distribution.Types.ComponentLocalBuildInfo + ( maybeComponentInstantiatedWith + ) +import Distribution.Types.ModuleRenaming + ( ModuleRenaming(..), + isDefaultRenaming + ) +import Distribution.Types.MungedPackageId + ( MungedPackageId + ) +import Distribution.Types.UnitId + ( UnitId + , unDefUnitId + , unUnitId + ) +import Distribution.Types.UnitId + ( DefUnitId + ) +import Distribution.Utils.NubList + ( toNubListR + ) +import Distribution.Version + ( versionNumbers + , mkVersion + ) +import qualified Distribution.InstalledPackageInfo as Installed +#endif + +#if CH_MIN_VERSION_Cabal(2,2,0) +import Distribution.Types.GenericPackageDescription + ( unFlagAssignment + ) +#endif + + +import CabalHelper.Shared.Sandbox +import CabalHelper.Shared.Common +import CabalHelper.Shared.InterfaceTypes + + + + + + + +#if !CH_MIN_VERSION_Cabal(1,24,0) +type UnitId = InstalledPackageId +#endif + + + +componentNameToCh :: a -> ComponentName -> ChComponentName +componentNameToCh _ CLibName = ChLibName +#if CH_MIN_VERSION_Cabal(2,0,0) +componentNameToCh _ (CSubLibName n) = ChSubLibName (unUnqualComponentName' n) +componentNameToCh _ (CFLibName n) = ChFLibName (unUnqualComponentName' n) +#endif +componentNameToCh _ (CExeName n) = ChExeName (unUnqualComponentName' n) +componentNameToCh _ (CTestName n) = ChTestName (unUnqualComponentName' n) +componentNameToCh _ (CBenchName n) = ChBenchName (unUnqualComponentName' n) + + +#if CH_MIN_VERSION_Cabal(1,25,0) +-- CPP >= 1.25 +unUnqualComponentName' :: UnqualComponentName -> String +unUnqualComponentName' = unUnqualComponentName +#else +unUnqualComponentName' :: a -> a +unUnqualComponentName' = id +#endif + + +componentNameFromComponent :: Component -> ComponentName +#if !CH_MIN_VERSION_Cabal(1,25,0) +-- CPP < 1.25 +componentNameFromComponent (CLib Library {}) = CLibName +#elif CH_MIN_VERSION_Cabal(1,25,0) +-- CPP >= 1.25 (redundant) +componentNameFromComponent (CLib Library { libName = Nothing }) = CLibName +componentNameFromComponent (CLib Library { libName = Just n }) = CSubLibName n +componentNameFromComponent (CFLib ForeignLib {..}) = CFLibName foreignLibName +#endif +componentNameFromComponent (CExe Executable {..}) = CExeName exeName +componentNameFromComponent (CTest TestSuite {..}) = CTestName testName +componentNameFromComponent (CBench Benchmark {..}) = CBenchName benchmarkName + + +componentOutDir :: LocalBuildInfo -> Component -> FilePath +componentOutDir lbi (CLib Library {..})= + buildDir lbi +#if CH_MIN_VERSION_Cabal(2,0,0) +componentOutDir lbi (CFLib ForeignLib {..}) = + componentOutDir' lbi (unUnqualComponentName foreignLibName) +#endif +componentOutDir lbi (CExe Executable {..}) = + componentOutDir' lbi (unUnqualComponentName' exeName) +componentOutDir lbi (CTest TestSuite { testInterface = TestSuiteLibV09 _ _, ..}) = + componentOutDir' lbi (unUnqualComponentName' testName ++ "Stub") +componentOutDir lbi (CTest TestSuite { testInterface = _, ..}) = + componentOutDir' lbi (unUnqualComponentName' testName) +componentOutDir lbi (CBench Benchmark { benchmarkInterface = _, ..})= + componentOutDir' lbi (unUnqualComponentName' benchmarkName) + +componentOutDir' :: LocalBuildInfo -> String -> FilePath +componentOutDir' lbi compName' = + ----- Copied from Distribution/Simple/GHC.hs:buildOrReplExe + let targetDir = (buildDir lbi) </> compName' + compDir = targetDir </> (compName' ++ "-tmp") + in compDir diff --git a/src/CabalHelper/Runtime/Main.hs b/src/CabalHelper/Runtime/Main.hs index 78260f8..3c90fbd 100644 --- a/src/CabalHelper/Runtime/Main.hs +++ b/src/CabalHelper/Runtime/Main.hs @@ -219,6 +219,7 @@ import Text.Printf import CabalHelper.Shared.Sandbox import CabalHelper.Shared.Common import CabalHelper.Shared.InterfaceTypes +import CabalHelper.Runtime.Compat usage :: IO () usage = do @@ -704,61 +705,7 @@ toDataVersion = id --fromDataVersion = id #endif -componentNameToCh _uid CLibName = ChLibName -#if CH_MIN_VERSION_Cabal(1,25,0) --- CPP >= 1.25 -#if CH_MIN_VERSION_Cabal(2,0,0) -componentNameToCh uid (CSubLibName n) = ChSubLibName uid -#else -componentNameToCh _uid (CSubLibName n) = ChSubLibName (unUnqualComponentName' n) -#endif -componentNameToCh uid (CFLibName n) = ChFLibName (unUnqualComponentName' n) -#endif -componentNameToCh _uid (CExeName n) = ChExeName (unUnqualComponentName' n) -componentNameToCh _uid (CTestName n) = ChTestName (unUnqualComponentName' n) -componentNameToCh _uid (CBenchName n) = ChBenchName (unUnqualComponentName' n) -#if CH_MIN_VERSION_Cabal(1,25,0) --- CPP >= 1.25 -unUnqualComponentName' = unUnqualComponentName -#else -unUnqualComponentName' = id -#endif - -#if !CH_MIN_VERSION_Cabal(1,25,0) --- CPP < 1.25 -componentNameFromComponent (CLib Library {}) = CLibName -#elif CH_MIN_VERSION_Cabal(1,25,0) --- CPP >= 1.25 (redundant) -componentNameFromComponent (CLib Library { libName = Nothing }) = CLibName -componentNameFromComponent (CLib Library { libName = Just n }) = CSubLibName n -componentNameFromComponent (CFLib ForeignLib {..}) = CFLibName foreignLibName -#endif -componentNameFromComponent (CExe Executable {..}) = CExeName exeName -componentNameFromComponent (CTest TestSuite {..}) = CTestName testName -componentNameFromComponent (CBench Benchmark {..}) = CBenchName benchmarkName - -componentOutDir lbi (CLib Library {..})= - buildDir lbi -#if CH_MIN_VERSION_Cabal(2,0,0) -componentOutDir lbi (CFLib ForeignLib {..}) = - componentOutDir' lbi (unUnqualComponentName foreignLibName) -#endif -componentOutDir lbi (CExe Executable {..}) = - componentOutDir' lbi (unUnqualComponentName' exeName) -componentOutDir lbi (CTest TestSuite { testInterface = TestSuiteExeV10 _ _, ..}) = - componentOutDir' lbi (unUnqualComponentName' testName) -componentOutDir lbi (CTest TestSuite { testInterface = TestSuiteLibV09 _ _, ..}) = - componentOutDir' lbi (unUnqualComponentName' testName ++ "Stub") -componentOutDir lbi (CBench Benchmark { benchmarkInterface = BenchmarkExeV10 _ _, ..})= - componentOutDir' lbi (unUnqualComponentName' benchmarkName) - -componentOutDir' :: LocalBuildInfo -> String -> FilePath -componentOutDir' lbi compName' = - ----- Copied from Distribution/Simple/GHC.hs:buildOrReplExe - let targetDir = (buildDir lbi) </> compName' - compDir = targetDir </> (compName' ++ "-tmp") - in compDir componentEntrypoints :: Component -> ChEntrypoint componentEntrypoints (CLib Library {..}) |