|
|
1
|
+{-# LANGUAGE TupleSections #-}
|
|
|
2
|
+{-# LANGUAGE TypeFamilies #-}
|
|
|
3
|
+
|
|
1
|
4
|
module Settings (
|
|
2
|
5
|
getExtraArgs, getArgs, getLibraryWays, getRtsWays, flavour, knownPackages,
|
|
3
|
6
|
findPackageByName, unsafeFindPackageByName, unsafeFindPackageByPath,
|
|
4
|
7
|
isLibrary, stagePackages, getBignumBackend, completeSetting,
|
|
5
|
8
|
queryBuildTarget, queryHostTarget,
|
|
6
|
9
|
queryBuild, queryHost,
|
|
7
|
|
- queryArch, queryOS, queryVendor
|
|
|
10
|
+ queryArch, queryOS, queryVendor,
|
|
|
11
|
+ flavourFileRules
|
|
8
|
12
|
) where
|
|
9
|
13
|
|
|
10
|
14
|
import CommandLine
|
| ... |
... |
@@ -58,6 +62,56 @@ hadrianFlavours = |
|
58
|
62
|
, ghcInGhciFlavour, validateFlavour, slowValidateFlavour
|
|
59
|
63
|
]
|
|
60
|
64
|
|
|
|
65
|
+{-
|
|
|
66
|
+Note [Persisting the flavour]
|
|
|
67
|
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
68
|
+Passing the flavour on the command-line means the user must consistently pass
|
|
|
69
|
+the same --flavour flag to all Hadrian invocations on a particular build root.
|
|
|
70
|
+Forgetting even once can result in a full rebuild of the tree.
|
|
|
71
|
+
|
|
|
72
|
+To avoid this we persist the flavour name in the build root itself
|
|
|
73
|
+(specifically, in `<build root>/flavour`). We refer to this file when looking
|
|
|
74
|
+up the active flavour, defaulting to it if the user does not specify a flavour
|
|
|
75
|
+name explicitly.
|
|
|
76
|
+-}
|
|
|
77
|
+
|
|
|
78
|
+-- | Oracle query type for the active flavour name.
|
|
|
79
|
+-- See Note [Persisting the flavour].
|
|
|
80
|
+newtype FlavourName = FlavourName ()
|
|
|
81
|
+ deriving (Binary, Eq, Hashable, NFData, Show)
|
|
|
82
|
+type instance RuleResult FlavourName = String
|
|
|
83
|
+
|
|
|
84
|
+flavourFileRules :: Rules ()
|
|
|
85
|
+flavourFileRules = do
|
|
|
86
|
+ root <- buildRootRules
|
|
|
87
|
+
|
|
|
88
|
+ -- Cache the flavour name lookup for the whole Shake run.
|
|
|
89
|
+ -- alwaysRerun ensures the oracle re-executes on every new invocation so
|
|
|
90
|
+ -- that a changed --flavour flag is never ignored due to a stale cross-run
|
|
|
91
|
+ -- cache entry (CLI args are not tracked as Shake dependencies).
|
|
|
92
|
+ -- See Note [Persisting the flavour].
|
|
|
93
|
+ void $ addOracleCache $ \(FlavourName _) -> do
|
|
|
94
|
+ alwaysRerun
|
|
|
95
|
+ let flavourFile = root -/- "flavour"
|
|
|
96
|
+ cmdFlavour >>= \case
|
|
|
97
|
+ Just nm -> do
|
|
|
98
|
+ putBuild $ "Flavour: " ++ nm
|
|
|
99
|
+ liftIO $ writeFile flavourFile nm
|
|
|
100
|
+ return nm
|
|
|
101
|
+ Nothing -> do
|
|
|
102
|
+ exists <- doesFileExist flavourFile
|
|
|
103
|
+ if exists
|
|
|
104
|
+ then do nm <- liftIO $ readFile flavourFile
|
|
|
105
|
+ putBuild $ "Flavour: " ++ nm ++ " (cached from last build, override by passing --flavour=... explicitly)"
|
|
|
106
|
+ return nm
|
|
|
107
|
+ else return userDefaultFlavour
|
|
|
108
|
+
|
|
|
109
|
+-- | Lookup the requested flavour name, referring to the persistent flavour
|
|
|
110
|
+-- file saved from the previous Hadrian execution if not specified.
|
|
|
111
|
+-- The result is cached for the whole Shake run via the 'FlavourName' oracle.
|
|
|
112
|
+getFlavourName :: Action String
|
|
|
113
|
+getFlavourName = askOracle (FlavourName ())
|
|
|
114
|
+
|
|
61
|
115
|
-- | This action looks up a flavour with the name given on the
|
|
62
|
116
|
-- command line with @--flavour@, defaulting to 'userDefaultFlavour'
|
|
63
|
117
|
-- when no explicit @--flavour@ is passed. It then applies any
|
| ... |
... |
@@ -66,7 +120,7 @@ hadrianFlavours = |
|
66
|
120
|
-- syntax. See Note [Hadrian settings] at the bottom of this file.
|
|
67
|
121
|
flavour :: Action Flavour
|
|
68
|
122
|
flavour = do
|
|
69
|
|
- flavourName <- fromMaybe userDefaultFlavour <$> cmdFlavour
|
|
|
123
|
+ flavourName <- getFlavourName
|
|
70
|
124
|
when ("quickest" `isPrefixOf` flavourName) $
|
|
71
|
125
|
fail $ "The `quickest` flavour has been deprecated. Use `quick` instead.\n"
|
|
72
|
126
|
++ "Skip building dynamic libraries with `quick+no_dynamic_libs`\n"
|