summaryrefslogtreecommitdiff
path: root/hadrian/src/Settings.hs
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2018-10-23 14:20:13 -0400
committerBen Gamari <ben@smart-cactus.org>2018-10-23 14:20:13 -0400
commit94756201349685a34c4495addd3484fdfcc8b498 (patch)
treefd4a9cee20d3c2b79f56ded7e02fb0c01b26b6c9 /hadrian/src/Settings.hs
parent575b35f4cdc18045bccd42d341d6f25d95c0696c (diff)
parent45f3bff7016a2a0cd9a5455a882ced984655e90b (diff)
downloadhaskell-94756201349685a34c4495addd3484fdfcc8b498.tar.gz
Add 'hadrian/' from commit '45f3bff7016a2a0cd9a5455a882ced984655e90b'
git-subtree-dir: hadrian git-subtree-mainline: 575b35f4cdc18045bccd42d341d6f25d95c0696c git-subtree-split: 45f3bff7016a2a0cd9a5455a882ced984655e90b
Diffstat (limited to 'hadrian/src/Settings.hs')
-rwxr-xr-xhadrian/src/Settings.hs66
1 files changed, 66 insertions, 0 deletions
diff --git a/hadrian/src/Settings.hs b/hadrian/src/Settings.hs
new file mode 100755
index 0000000000..3497f43a1e
--- /dev/null
+++ b/hadrian/src/Settings.hs
@@ -0,0 +1,66 @@
+module Settings (
+ getArgs, getLibraryWays, getRtsWays, flavour, knownPackages,
+ findPackageByName, isLibrary, stagePackages, programContext,
+ getIntegerPackage
+ ) where
+
+import CommandLine
+import Expression
+import Flavour
+import Packages
+import UserSettings
+
+import {-# SOURCE #-} Settings.Default
+import Settings.Flavours.Development
+import Settings.Flavours.Performance
+import Settings.Flavours.Profiled
+import Settings.Flavours.Quick
+import Settings.Flavours.Quickest
+import Settings.Flavours.QuickCross
+
+getArgs :: Args
+getArgs = expr flavour >>= args
+
+getLibraryWays :: Ways
+getLibraryWays = expr flavour >>= libraryWays
+
+getRtsWays :: Ways
+getRtsWays = expr flavour >>= rtsWays
+
+stagePackages :: Stage -> Action [Package]
+stagePackages stage = do
+ f <- flavour
+ packages f stage
+
+hadrianFlavours :: [Flavour]
+hadrianFlavours =
+ [ defaultFlavour, developmentFlavour Stage1, developmentFlavour Stage2
+ , performanceFlavour, profiledFlavour, quickFlavour, quickestFlavour
+ , quickCrossFlavour ]
+
+flavour :: Action Flavour
+flavour = do
+ flavourName <- fromMaybe "default" <$> cmdFlavour
+ let unknownFlavour = error $ "Unknown build flavour: " ++ flavourName
+ flavours = hadrianFlavours ++ userFlavours
+ return $ fromMaybe unknownFlavour $ find ((== flavourName) . name) flavours
+
+getIntegerPackage :: Expr Package
+getIntegerPackage = expr (integerLibrary =<< flavour)
+
+programContext :: Stage -> Package -> Action Context
+programContext stage pkg = do
+ profiled <- ghcProfiled <$> flavour
+ return $ if pkg == ghc && profiled && stage > Stage0
+ then Context stage pkg profiling
+ else vanillaContext stage pkg
+
+-- TODO: switch to Set Package as the order of packages should not matter?
+-- Otherwise we have to keep remembering to sort packages from time to time.
+knownPackages :: [Package]
+knownPackages = sort $ ghcPackages ++ userPackages
+
+-- TODO: Speed up? Switch to Set?
+-- Note: this is slow but we keep it simple as there are just ~50 packages
+findPackageByName :: PackageName -> Maybe Package
+findPackageByName name = find (\pkg -> pkgName pkg == name) knownPackages