Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cabal lib for nix local build #2948

Merged
merged 28 commits into from Dec 16, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
89fd3e0
Add more standard derived instances, Eq, Generic and Binary
dcoutts Dec 14, 2015
7d01c2e
Export a few more BuildTarget utils
dcoutts Dec 15, 2015
3004316
Add and export a showProfDetailLevel utlity
dcoutts Dec 15, 2015
0501e50
UHC: factor out getGlobalPackageDir function
dcoutts Dec 15, 2015
17af6b9
UHC: registerPackage stop using source pkg and inplace args
dcoutts Dec 15, 2015
f1ca968
Change the interface to the per-compiler registerPackage functions
dcoutts Dec 15, 2015
27dd76a
Move user logging out of registerPackage and into some callers
dcoutts Dec 15, 2015
b0b57da
Don't pass LocalBuildInfo to per-compiler registerPackage functions
dcoutts Dec 15, 2015
dee7e0a
Change regiserPackage to not require so much info
dcoutts Dec 15, 2015
12b222a
Extend HcPkg.init support for dir-style package dbs
dcoutts Dec 15, 2015
ea6dabe
Add new compiler independent package db utils
dcoutts Dec 15, 2015
e86851d
Use the new package db utils to simplify createInternalPackageDB
dcoutts Dec 15, 2015
b54f36a
Factor impl of registerInvocation' slightly
dcoutts Dec 15, 2015
728fdcf
Extend HcPkgInfo for mulit-package instances capabilities
dcoutts Dec 15, 2015
ae78ae0
Add internal support for hc-pkg recache and --enable-multi-instance
dcoutts Dec 15, 2015
7b4df7e
Add new HcPkg.registerMultiInstance
dcoutts Dec 15, 2015
2d0a878
Add mutli-instance support to registerPackage
dcoutts Dec 15, 2015
3ff32fc
Export a command line unescaping utility
dcoutts Dec 15, 2015
7e409fc
Add new getInstalledPackagesMonitorFiles
dcoutts Dec 15, 2015
7d4fbb2
Be consistent about using findProgramOnSearchPath
dcoutts Dec 16, 2015
ee0ed0b
Generalise findProgramOnSearchPath to calculate locations looked in
dcoutts Dec 16, 2015
b39b906
Extend ConfiguredProgram with search locations looked at
dcoutts Dec 16, 2015
96a010a
Adjust instance Binary ProgramDb to include the ProgramSearchPath
dcoutts Dec 16, 2015
adcfe14
Fix bootstrapping CPP problem
dcoutts Dec 16, 2015
fc1a23f
Further CPP fix
dcoutts Dec 16, 2015
3761cf4
Add a comment to explain the HcPkg.recache trick
dcoutts Dec 16, 2015
4164e01
Add a few comments explaining implementation assumptions
dcoutts Dec 16, 2015
dc42037
Clarify comments about the ProgramDb Read/Show/Binary instances
dcoutts Dec 16, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cabal/Distribution/Compiler.hs
Expand Up @@ -180,7 +180,7 @@ instance Binary CompilerInfo
data AbiTag
= NoAbiTag
| AbiTag String
deriving (Generic, Show, Read)
deriving (Eq, Generic, Show, Read)

instance Binary AbiTag

Expand Down
6 changes: 3 additions & 3 deletions Cabal/Distribution/InstalledPackageInfo.hs
Expand Up @@ -112,7 +112,7 @@ data InstalledPackageInfo
haddockHTMLs :: [FilePath],
pkgRoot :: Maybe FilePath
}
deriving (Generic, Read, Show)
deriving (Eq, Generic, Read, Show)

instance Binary InstalledPackageInfo

Expand Down Expand Up @@ -172,7 +172,7 @@ noVersion = Version [] []
-- Exposed modules

newtype AbiHash = AbiHash String
deriving (Show, Read, Generic)
deriving (Eq, Show, Read, Generic)
instance Binary AbiHash

instance Text AbiHash where
Expand All @@ -195,7 +195,7 @@ data ExposedModule
exposedReexport :: Maybe OriginalModule,
exposedSignature :: Maybe OriginalModule -- This field is unused for now.
}
deriving (Generic, Read, Show)
deriving (Eq, Generic, Read, Show)

instance Text OriginalModule where
disp (OriginalModule ipi m) =
Expand Down
20 changes: 14 additions & 6 deletions Cabal/Distribution/PackageDescription.hs
Expand Up @@ -1129,12 +1129,12 @@ data GenericPackageDescription =
condTestSuites :: [(String, CondTree ConfVar [Dependency] TestSuite)],
condBenchmarks :: [(String, CondTree ConfVar [Dependency] Benchmark)]
}
deriving (Show, Eq, Typeable, Data)
deriving (Show, Eq, Typeable, Data, Generic)

instance Package GenericPackageDescription where
packageId = packageId . packageDescription

--TODO: make PackageDescription an instance of Text.
instance Binary GenericPackageDescription

-- | A flag can represent a feature to be included, or a way of linking
-- a target against its dependencies, or in fact whatever you can think of.
Expand All @@ -1144,7 +1144,9 @@ data Flag = MkFlag
, flagDefault :: Bool
, flagManual :: Bool
}
deriving (Show, Eq, Typeable, Data)
deriving (Show, Eq, Typeable, Data, Generic)

instance Binary Flag

-- | A 'FlagName' is the name of a user-defined configuration flag
newtype FlagName = FlagName String
Expand All @@ -1164,15 +1166,17 @@ data ConfVar = OS OS
| Arch Arch
| Flag FlagName
| Impl CompilerFlavor VersionRange
deriving (Eq, Show, Typeable, Data)
deriving (Eq, Show, Typeable, Data, Generic)

instance Binary ConfVar

-- | A boolean expression parameterized over the variable type used.
data Condition c = Var c
| Lit Bool
| CNot (Condition c)
| COr (Condition c) (Condition c)
| CAnd (Condition c) (Condition c)
deriving (Show, Eq, Typeable, Data)
deriving (Show, Eq, Typeable, Data, Generic)

cNot :: Condition a -> Condition a
cNot (Lit b) = Lit (not b)
Expand Down Expand Up @@ -1226,11 +1230,15 @@ instance MonadPlus Condition where
mzero = mempty
mplus = mappend

instance Binary c => Binary (Condition c)

data CondTree v c a = CondNode
{ condTreeData :: a
, condTreeConstraints :: c
, condTreeComponents :: [( Condition v
, CondTree v c a
, Maybe (CondTree v c a))]
}
deriving (Show, Eq, Typeable, Data)
deriving (Show, Eq, Typeable, Data, Generic)

instance (Binary v, Binary c, Binary a) => Binary (CondTree v c a)
41 changes: 15 additions & 26 deletions Cabal/Distribution/Simple/Build.hs
Expand Up @@ -63,11 +63,11 @@ import Distribution.Simple.LocalBuildInfo
, ComponentDisabledReason(..), componentDisabledReason )
import Distribution.Simple.Program.Types
import Distribution.Simple.Program.Db
import qualified Distribution.Simple.Program.HcPkg as HcPkg
import Distribution.Simple.BuildPaths
( autogenModulesDir, autogenModuleName, cppHeaderName, exeExtension )
import Distribution.Simple.Register
( registerPackage, inplaceInstalledPackageInfo )
( registerPackage, inplaceInstalledPackageInfo
, doesPackageDBExist, deletePackageDB, createPackageDB )
import Distribution.Simple.Test.LibV09 ( stubFilePath, stubName )
import Distribution.Simple.Utils
( createDirectoryIfMissingVerbose, rewriteFile
Expand All @@ -89,8 +89,7 @@ import Control.Monad
import System.FilePath
( (</>), (<.>) )
import System.Directory
( getCurrentDirectory, removeDirectoryRecursive, removeFile
, doesDirectoryExist, doesFileExist )
( getCurrentDirectory )

-- -----------------------------------------------------------------------------
-- |Build the libraries and executables in this package.
Expand Down Expand Up @@ -209,9 +208,8 @@ buildComponent verbosity numJobs pkg_descr lbi suffixes
installedPkgInfo = inplaceInstalledPackageInfo pwd distPref pkg_descr
(IPI.AbiHash "") lib' lbi clbi

registerPackage verbosity
installedPkgInfo pkg_descr lbi True -- True meaning in place
(withPackageDB lbi)
registerPackage verbosity (compiler lbi) (withPrograms lbi) False
(withPackageDB lbi) installedPkgInfo

buildComponent verbosity numJobs pkg_descr lbi suffixes
comp@(CExe exe) clbi _ = do
Expand Down Expand Up @@ -251,7 +249,8 @@ buildComponent verbosity numJobs pkg_descr lbi0 suffixes
extras <- preprocessExtras comp lbi
info verbosity $ "Building test suite " ++ testName test ++ "..."
buildLib verbosity numJobs pkg lbi lib libClbi
registerPackage verbosity ipi pkg lbi True $ withPackageDB lbi
registerPackage verbosity (compiler lbi) (withPrograms lbi) False
(withPackageDB lbi) ipi
let ebi = buildInfo exe
exe' = exe { buildInfo = addExtraCSources ebi extras }
buildExe verbosity numJobs pkg_descr lbi exe' exeClbi
Expand Down Expand Up @@ -472,24 +471,14 @@ benchmarkExeV10asExe Benchmark{} _ = error "benchmarkExeV10asExe: wrong kind"
createInternalPackageDB :: Verbosity -> LocalBuildInfo -> FilePath
-> IO PackageDB
createInternalPackageDB verbosity lbi distPref = do
case compilerFlavor (compiler lbi) of
GHC -> createWith $ GHC.hcPkgInfo (withPrograms lbi)
GHCJS -> createWith $ GHCJS.hcPkgInfo (withPrograms lbi)
LHC -> createWith $ LHC.hcPkgInfo (withPrograms lbi)
_ -> return packageDB
where
dbPath = distPref </> "package.conf.inplace"
packageDB = SpecificPackageDB dbPath
createWith hpi = do
dir_exists <- doesDirectoryExist dbPath
if dir_exists
then removeDirectoryRecursive dbPath
else do file_exists <- doesFileExist dbPath
when file_exists $ removeFile dbPath
if HcPkg.useSingleFileDb hpi
then writeFile dbPath "[]"
else HcPkg.init hpi verbosity dbPath
return packageDB
existsAlready <- doesPackageDBExist dbPath
when existsAlready $ deletePackageDB dbPath
createPackageDB verbosity (compiler lbi) (withPrograms lbi) True dbPath
return (SpecificPackageDB dbPath)
where
dbPath = case compilerFlavor (compiler lbi) of
UHC -> UHC.inplacePackageDbPath lbi
_ -> distPref </> "package.conf.inplace"

addInternalBuildTools :: PackageDescription -> LocalBuildInfo -> BuildInfo
-> ProgramDb -> ProgramDb
Expand Down
19 changes: 18 additions & 1 deletion Cabal/Distribution/Simple/BuildTarget.hs
@@ -1,3 +1,4 @@
{-# LANGUAGE DeriveGeneric #-}
-----------------------------------------------------------------------------
-- |
-- Module : Distribution.Client.BuildTargets
Expand All @@ -13,10 +14,14 @@ module Distribution.Simple.BuildTarget (
-- * Build targets
BuildTarget(..),
readBuildTargets,
showBuildTarget,
QualLevel(..),
buildTargetComponentName,

-- * Parsing user build targets
UserBuildTarget,
readUserBuildTargets,
showUserBuildTarget,
UserBuildTargetProblem(..),
reportUserBuildTargetProblems,

Expand Down Expand Up @@ -53,6 +58,8 @@ import Data.Maybe
( listToMaybe, catMaybes )
import Data.Either
( partitionEithers )
import Distribution.Compat.Binary (Binary)
import GHC.Generics (Generic)
import qualified Data.Map as Map
import Control.Monad
import Control.Applicative as AP (Alternative(..), Applicative(..))
Expand Down Expand Up @@ -123,8 +130,14 @@ data BuildTarget =
-- | A specific file within a specific component.
--
| BuildTargetFile ComponentName FilePath
deriving (Show,Eq)
deriving (Eq, Show, Generic)

instance Binary BuildTarget

buildTargetComponentName :: BuildTarget -> ComponentName
buildTargetComponentName (BuildTargetComponent cn) = cn
buildTargetComponentName (BuildTargetModule cn _) = cn
buildTargetComponentName (BuildTargetFile cn _) = cn

-- | Read a list of user-supplied build target strings and resolve them to
-- 'BuildTarget's according to a 'PackageDescription'. If there are problems
Expand Down Expand Up @@ -228,6 +241,10 @@ showUserBuildTarget = intercalate ":" . components
components (UserBuildTargetDouble s1 s2) = [s1,s2]
components (UserBuildTargetTriple s1 s2 s3) = [s1,s2,s3]

showBuildTarget :: QualLevel -> PackageId -> BuildTarget -> String
showBuildTarget ql pkgid bt =
showUserBuildTarget (renderBuildTarget ql bt pkgid)


-- ------------------------------------------------------------
-- * Resolving user targets to build targets
Expand Down
12 changes: 11 additions & 1 deletion Cabal/Distribution/Simple/Compiler.hs
Expand Up @@ -60,6 +60,7 @@ module Distribution.Simple.Compiler (
ProfDetailLevel(..),
knownProfDetailLevels,
flagToProfDetailLevel,
showProfDetailLevel,
) where

import Distribution.Compiler
Expand Down Expand Up @@ -90,7 +91,7 @@ data Compiler = Compiler {
compilerProperties :: M.Map String String
-- ^ A key-value map for properties not covered by the above fields.
}
deriving (Generic, Show, Read)
deriving (Eq, Generic, Show, Read)

instance Binary Compiler

Expand Down Expand Up @@ -337,3 +338,12 @@ knownProfDetailLevels =
, ("all-functions", ["all"], ProfDetailAllFunctions)
]

showProfDetailLevel :: ProfDetailLevel -> String
showProfDetailLevel dl = case dl of
ProfDetailNone -> "none"
ProfDetailDefault -> "default"
ProfDetailExportedFunctions -> "exported-functions"
ProfDetailToplevelFunctions -> "toplevel-functions"
ProfDetailAllFunctions -> "all-functions"
ProfDetailOther other -> other

20 changes: 19 additions & 1 deletion Cabal/Distribution/Simple/Configure.hs
Expand Up @@ -39,7 +39,9 @@ module Distribution.Simple.Configure (configure,
findDistPref, findDistPrefOrDefault,
computeComponentId,
localBuildInfoFile,
getInstalledPackages, getPackageDBContents,
getInstalledPackages,
getInstalledPackagesMonitorFiles,
getPackageDBContents,
configCompiler, configCompilerAux,
configCompilerEx, configCompilerAuxEx,
ccLdOptionsBuildInfo,
Expand Down Expand Up @@ -941,6 +943,22 @@ getPackageDBContents verbosity comp packageDB progconf = do
_ -> getInstalledPackages verbosity comp [packageDB] progconf


-- | A set of files (or directories) that can be monitored to detect when
-- there might have been a change in the installed packages.
--
getInstalledPackagesMonitorFiles :: Verbosity -> Compiler
-> PackageDBStack
-> ProgramConfiguration -> Platform
-> IO [FilePath]
getInstalledPackagesMonitorFiles verbosity comp packageDBs progconf platform =
case compilerFlavor comp of
GHC -> GHC.getInstalledPackagesMonitorFiles
verbosity platform progconf packageDBs
other -> do
warn verbosity $ "don't know how to find change monitoring files for "
++ "the installed package databases for " ++ display other
return []

-- | The user interface specifies the package dbs to use with a combination of
-- @--global@, @--user@ and @--package-db=global|user|clear|$file@.
-- This function combines the global/user flag and interprets the package-db
Expand Down