[Git][ghc/ghc][master] hadrian: Persist the used flavour name in the build root (#20650)
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: b3b89d32 by mangoiv at 2026-10-05T22:03:32-04:00 hadrian: Persist the used flavour name in the build root (#20650) This executes the idea proposed in #20650, teaching Hadrian to persist the flavour used to build a build root. This both makes use of multiple build roots more ergonomic (as the user no longer needs to repeat themselves) and avoids a tiresome foot-gun (forgetting to specify a flavour, often wholly invalidating a build root). Closes #20650. Co-authored-by: Sylvain Henry <sylvain@haskus.fr> - - - - - 4 changed files: - + changelog.d/hadrian-persist-flavour - hadrian/doc/flavours.md - hadrian/src/Rules.hs - hadrian/src/Settings.hs Changes: ===================================== changelog.d/hadrian-persist-flavour ===================================== @@ -0,0 +1,7 @@ +section: packaging +synopsis: Hadrian now persists the flavour name in the build root. When + rebuilding, the previously used flavour is automatically restored, removing + the need to re-specify it on every invocation and avoiding accidental build + root invalidation. +issues: #20650 +mrs: !7017 ===================================== hadrian/doc/flavours.md ===================================== @@ -3,7 +3,14 @@ Hadrian supports a few predefined _build flavours_, i.e. collections of build settings that fully define a GHC build (see `src/Flavour.hs`). Users can add their own build flavours if need be, as described -[here](https://gitlab.haskell.org/ghc/ghc/blob/master/hadrian/doc/user-settings.md#...). +[here](https://gitlab.haskell.org/ghc/ghc/blob/master/hadrian/doc/user-settings.md#...) or modify existing flavours using the flavour transformers notion seem below. + +The flavour to be used for a build root can be specified on the command-line +via the `--flavour` flag. Moreover, this flavour name is saved in the build +root; future invocations of Hadrian without a `--flavour` flag will default to +the last-used flavour. + +See `Note [Persisting the flavour]` in `hadrian/src/Settings.hs` ## Arguments ===================================== hadrian/src/Rules.hs ===================================== @@ -129,6 +129,7 @@ packageRules = do buildRules :: Rules () buildRules = do + Settings.flavourFileRules Rules.BinaryDist.bindistRules Rules.Generate.copyRules Rules.Generate.generateRules ===================================== hadrian/src/Settings.hs ===================================== @@ -1,10 +1,14 @@ +{-# LANGUAGE TupleSections #-} +{-# LANGUAGE TypeFamilies #-} + module Settings ( getExtraArgs, getArgs, getLibraryWays, getRtsWays, flavour, knownPackages, findPackageByName, unsafeFindPackageByName, unsafeFindPackageByPath, isLibrary, stagePackages, getBignumBackend, completeSetting, queryBuildTarget, queryHostTarget, queryBuild, queryHost, - queryArch, queryOS, queryVendor + queryArch, queryOS, queryVendor, + flavourFileRules ) where import CommandLine @@ -58,6 +62,56 @@ hadrianFlavours = , ghcInGhciFlavour, validateFlavour, slowValidateFlavour ] +{- +Note [Persisting the flavour] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Passing the flavour on the command-line means the user must consistently pass +the same --flavour flag to all Hadrian invocations on a particular build root. +Forgetting even once can result in a full rebuild of the tree. + +To avoid this we persist the flavour name in the build root itself +(specifically, in `<build root>/flavour`). We refer to this file when looking +up the active flavour, defaulting to it if the user does not specify a flavour +name explicitly. +-} + +-- | Oracle query type for the active flavour name. +-- See Note [Persisting the flavour]. +newtype FlavourName = FlavourName () + deriving (Binary, Eq, Hashable, NFData, Show) +type instance RuleResult FlavourName = String + +flavourFileRules :: Rules () +flavourFileRules = do + root <- buildRootRules + + -- Cache the flavour name lookup for the whole Shake run. + -- alwaysRerun ensures the oracle re-executes on every new invocation so + -- that a changed --flavour flag is never ignored due to a stale cross-run + -- cache entry (CLI args are not tracked as Shake dependencies). + -- See Note [Persisting the flavour]. + void $ addOracleCache $ \(FlavourName _) -> do + alwaysRerun + let flavourFile = root -/- "flavour" + cmdFlavour >>= \case + Just nm -> do + putBuild $ "Flavour: " ++ nm + liftIO $ writeFile flavourFile nm + return nm + Nothing -> do + exists <- doesFileExist flavourFile + if exists + then do nm <- liftIO $ readFile flavourFile + putBuild $ "Flavour: " ++ nm ++ " (cached from last build, override by passing --flavour=... explicitly)" + return nm + else return userDefaultFlavour + +-- | Lookup the requested flavour name, referring to the persistent flavour +-- file saved from the previous Hadrian execution if not specified. +-- The result is cached for the whole Shake run via the 'FlavourName' oracle. +getFlavourName :: Action String +getFlavourName = askOracle (FlavourName ()) + -- | This action looks up a flavour with the name given on the -- command line with @--flavour@, defaulting to 'userDefaultFlavour' -- when no explicit @--flavour@ is passed. It then applies any @@ -66,7 +120,7 @@ hadrianFlavours = -- syntax. See Note [Hadrian settings] at the bottom of this file. flavour :: Action Flavour flavour = do - flavourName <- fromMaybe userDefaultFlavour <$> cmdFlavour + flavourName <- getFlavourName when ("quickest" `isPrefixOf` flavourName) $ fail $ "The `quickest` flavour has been deprecated. Use `quick` instead.\n" ++ "Skip building dynamic libraries with `quick+no_dynamic_libs`\n" View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/b3b89d3245c4b4ed93508e69919e2886... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/b3b89d3245c4b4ed93508e69919e2886... You're receiving this email because of your account on gitlab.haskell.org. Manage all notifications: https://gitlab.haskell.org/-/profile/notifications | Help: https://gitlab.haskell.org/help
participants (1)
-
Marge Bot (@marge-bot)