Commit d3ef19d2 authored by Andrey Mokhov's avatar Andrey Mokhov

Move the Config oracle to the library

See #347
parent 5dd20f0d
......@@ -28,13 +28,13 @@ executable hadrian
, GHC
, Hadrian.Expression
, Hadrian.Oracles.ArgsHash
, Hadrian.Oracles.Config
, Hadrian.Oracles.DirectoryContents
, Hadrian.Oracles.Path
, Hadrian.Target
, Hadrian.Utilities
, Oracles.Config
, Oracles.Config.Flag
, Oracles.Config.Setting
, Oracles.Flag
, Oracles.Setting
, Oracles.Dependencies
, Oracles.ModuleFiles
, Oracles.PackageData
......
......@@ -40,7 +40,7 @@ import Stage
import Target hiding (builder, inputs, outputs)
import Way
import Oracles.Config.Setting
import Oracles.Setting
-- | @Expr a@ is a computation that produces a value of type @Action a@ and can
-- read parameters of the current build 'Target'.
......
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Oracles.Config (askConfig, unsafeAskConfig, configOracle) where
module Hadrian.Oracles.Config (askConfig, unsafeAskConfig, configOracle) where
import Control.Monad
import qualified Data.HashMap.Strict as Map
import Data.Maybe
import Development.Shake
import Development.Shake.Classes
import Development.Shake.Config
import Base
import Hadrian.Utilities
newtype ConfigKey = ConfigKey String
deriving (Binary, Eq, Hashable, NFData, Show, Typeable)
-- | Lookup a configuration setting raising an error if the key is not found.
unsafeAskConfig :: String -> Action String
unsafeAskConfig key = (fromMaybe $ error msg) <$> askConfig key
where
msg = "Key " ++ quote key ++ " not found in configuration files."
-- | Lookup a configuration setting.
askConfig :: String -> Action (Maybe String)
askConfig = askOracle . ConfigKey
-- Oracle for configuration files
configOracle :: Rules ()
configOracle = void $ do
-- | This oracle reads and parses a configuration file consisting of key-value
-- pairs @key = value@ and answers 'askConfig' queries tracking the results.
configOracle :: FilePath -> Rules ()
configOracle configFile = void $ do
cfg <- newCache $ \() -> do
need [configFile]
putLoud $ "Reading " ++ configFile ++ "..."
......
module Oracles.Config.Flag (
module Oracles.Flag (
Flag (..), flag, crossCompiling, platformSupportsSharedLibs,
ghcWithSMP, ghcWithNativeCodeGen, supportsSplitObjects
) where
import Hadrian.Oracles.Config
import Base
import Oracles.Config
import Oracles.Config.Setting
import Oracles.Setting
data Flag = ArSupportsAtFile
| CrossCompiling
......
module Oracles.Config.Setting (
module Oracles.Setting (
Setting (..), SettingList (..), setting, settingList,
anyTargetPlatform, anyTargetOs, anyTargetArch, anyHostOs,
ghcWithInterpreter, ghcEnableTablesNextToCode, useLibFFIForAdjustors,
......@@ -6,8 +6,9 @@ module Oracles.Config.Setting (
relocatableBuild, installDocDir, installGhcLibDir
) where
import Hadrian.Oracles.Config
import Base
import Oracles.Config
import Stage
-- TODO: Reduce the variety of similar flags (e.g. CPP and non-CPP versions).
......@@ -202,8 +203,9 @@ relocatableBuild = windowsHost
installDocDir :: Action String
installDocDir = do
version <- setting ProjectVersion
(-/- ("doc/ghc-" ++ version)) <$> setting InstallDataRootDir
version <- setting ProjectVersion
dataDir <- setting InstallDataRootDir
return $ dataDir -/- ("doc/ghc-" ++ version)
-- ref: mk/install.mk:101
-- TODO: CroosCompilePrefix
......@@ -211,9 +213,9 @@ installDocDir = do
-- subdirectory with the version number included.
installGhcLibDir :: Action String
installGhcLibDir = do
r <- relocatableBuild
libdir <- setting InstallLibDir
if r then return libdir
else do
v <- setting ProjectVersion
return $ libdir -/- ("ghc-" ++ v)
rBuild <- relocatableBuild
libdir <- setting InstallLibDir
if rBuild then return libdir
else do
version <- setting ProjectVersion
return $ libdir -/- ("ghc-" ++ version)
......@@ -4,8 +4,8 @@ import Base
import Context
import Expression
import GHC
import Oracles.Config.Setting
import Oracles.Dependencies
import Oracles.Setting
import Rules.Generate
import Settings.Path
import Target
......
......@@ -10,9 +10,9 @@ import Context hiding (package)
import Expression
import Flavour
import GHC
import Oracles.Config.Flag
import Oracles.Config.Setting
import Oracles.Flag
import Oracles.ModuleFiles
import Oracles.Setting
import Rules.Libffi
import Settings
import Settings.Path
......
......@@ -5,7 +5,7 @@ import Hadrian.Utilities
import Base
import Builder
import GHC
import Oracles.Config.Setting
import Oracles.Setting
import Package
import Settings.Packages.IntegerGmp
import Settings.Path
......
......@@ -2,24 +2,23 @@
module Rules.Install (installRules) where
import Hadrian.Oracles.DirectoryContents
import qualified System.Directory as IO
import Base
import Expression hiding (builder)
import Target
import Context
import Settings
import Settings.Path
import Util
import Expression hiding (builder)
import GHC
import Oracles.Dependencies
import Oracles.Setting
import Rules
import Rules.Generate
import Rules.Libffi
import Rules.Wrappers
import Settings
import Settings.Packages.Rts
import Oracles.Config.Setting
import Oracles.Dependencies
import qualified System.Directory as IO
import Settings.Path
import Target
import Util
{- | Install the built binaries etc. to the @destDir ++ prefix@.
......
module Rules.Oracles (oracleRules) where
import qualified Hadrian.Oracles.ArgsHash
import qualified Hadrian.Oracles.Config
import qualified Hadrian.Oracles.DirectoryContents
import qualified Hadrian.Oracles.Path
import Base
import qualified Oracles.Config
import qualified Oracles.Dependencies
import qualified Oracles.ModuleFiles
import qualified Oracles.PackageData
......@@ -15,9 +15,9 @@ import Settings
oracleRules :: Rules ()
oracleRules = do
Hadrian.Oracles.ArgsHash.argsHashOracle trackArgument getArgs
Hadrian.Oracles.Config.configOracle configFile
Hadrian.Oracles.DirectoryContents.directoryContentsOracle
Hadrian.Oracles.Path.pathOracle
Oracles.Config.configOracle
Oracles.Dependencies.dependenciesOracles
Oracles.ModuleFiles.moduleFilesOracle
Oracles.PackageData.packageDataOracle
......@@ -6,10 +6,10 @@ import Base
import Context
import Expression hiding (stage, way)
import GHC
import Oracles.Config.Setting
import Oracles.Dependencies
import Oracles.ModuleFiles
import Oracles.PackageData
import Oracles.Setting
import Rules.Wrappers
import Settings
import Settings.Path
......
......@@ -9,8 +9,8 @@ import Test.QuickCheck
import Base
import Expression
import GHC
import Oracles.Config.Setting
import Oracles.ModuleFiles
import Oracles.Setting
import Settings
import Settings.Builders.Ar
import Target
......
......@@ -4,7 +4,7 @@ import Hadrian.Oracles.DirectoryContents
import Base
import Builder
import Oracles.Config.Setting
import Oracles.Setting
import Rules.Clean
import UserSettings
import Util
......
......@@ -7,8 +7,8 @@ import Builder
import Expression
import Flavour
import GHC
import Oracles.Config.Flag
import Oracles.Config.Setting
import Oracles.Flag
import Oracles.Setting
import Settings
import Settings.Path
import Target
......
......@@ -5,7 +5,7 @@ module Rules.Wrappers (
import Base
import Expression
import GHC
import Oracles.Config.Setting
import Oracles.Setting
import Settings
import Settings.Install
import Settings.Path
......
......@@ -6,6 +6,7 @@ module Settings (
integerLibraryName, destDir, pkgConfInstallPath, stage1Only
) where
import Hadrian.Oracles.Config
import Hadrian.Oracles.Path
import Base
......@@ -14,7 +15,6 @@ import CmdLineFlag
import Expression
import Flavour
import GHC
import Oracles.Config
import Oracles.PackageData
import {-# SOURCE #-} Settings.Default
import Settings.Flavours.Development
......
......@@ -2,9 +2,9 @@ module Settings.Builders.Common (
module Base,
module Expression,
module GHC,
module Oracles.Config.Flag,
module Oracles.Config.Setting,
module Oracles.Flag,
module Oracles.PackageData,
module Oracles.Setting,
module Settings,
module Settings.Path,
module UserSettings,
......@@ -14,9 +14,9 @@ module Settings.Builders.Common (
import Base
import Expression
import GHC
import Oracles.Config.Flag
import Oracles.Config.Setting
import Oracles.Flag
import Oracles.PackageData
import Oracles.Setting
import Settings
import Settings.Path
import UserSettings
......
......@@ -8,9 +8,9 @@ import CmdLineFlag
import Expression
import Flavour
import GHC
import Oracles.Config.Flag
import Oracles.Config.Setting
import Oracles.Flag
import Oracles.PackageData
import Oracles.Setting
import Settings
import Settings.Builders.Alex
import Settings.Builders.Ar
......
......@@ -2,7 +2,7 @@ module Settings.Flavours.Quick (quickFlavour) where
import Flavour
import Expression
import Oracles.Config.Flag (platformSupportsSharedLibs)
import Oracles.Flag
import {-# SOURCE #-} Settings.Default
quickFlavour :: Flavour
......
......@@ -4,8 +4,8 @@ import Base
import Expression
import Flavour
import GHC
import Oracles.Config.Flag
import Oracles.Config.Setting
import Oracles.Flag
import Oracles.Setting
import Settings
compilerPackageArgs :: Args
......
......@@ -2,7 +2,7 @@ module Settings.Packages.Ghc (ghcPackageArgs) where
import GHC
import Expression
import Oracles.Config.Setting
import Oracles.Setting
import Settings.Path
ghcPackageArgs :: Args
......
module Settings.Packages.GhcPrim (ghcPrimPackageArgs) where
import GHC
import Oracles.Config.Flag
import Oracles.Flag
import Expression
ghcPrimPackageArgs :: Args
......
......@@ -3,7 +3,7 @@ module Settings.Packages.IntegerGmp (integerGmpPackageArgs, gmpBuildPath) where
import Base
import Expression
import GHC
import Oracles.Config.Setting
import Oracles.Setting
import Settings.Path
-- TODO: Is this needed?
......
......@@ -5,8 +5,8 @@ import Hadrian.Utilities
import Base
import Expression
import GHC
import Oracles.Config.Flag
import Oracles.Config.Setting
import Oracles.Flag
import Oracles.Setting
import Settings
import Settings.Path
......
module Settings.Packages.RunGhc (runGhcPackageArgs) where
import GHC
import Oracles.Config.Setting
import Oracles.Setting
import Expression
runGhcPackageArgs :: Args
......
......@@ -16,7 +16,7 @@ import Context
import Expression hiding (stage)
import GHC
import Oracles.PackageData
import Oracles.Config.Setting
import Oracles.Setting
import UserSettings
-- | Path to the directory containing the Shake database and other auxiliary
......
......@@ -20,7 +20,7 @@ import CmdLineFlag
import Context
import Expression hiding (builder, inputs, outputs, way, stage, package)
import GHC
import Oracles.Config.Setting
import Oracles.Setting
import Settings
import Settings.Path
import Settings.Builders.Ar
......
......@@ -14,7 +14,7 @@ import qualified Data.IntSet as Set
import Hadrian.Utilities
import Base
import Oracles.Config.Setting
import Oracles.Setting
-- Note: order of constructors is important for compatibility with the old build
-- system, e.g. we want "thr_p", not "p_thr" (see instance Show Way).
......
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