@@ -24,7 +24,7 @@ module Stack.Build
2424import Stack.Prelude
2525import Data.Aeson (Value (Object , Array ), (.=) , object )
2626import qualified Data.HashMap.Strict as HM
27- import Data.List ((\\) )
27+ import Data.List ((\\) , isPrefixOf )
2828import Data.List.Extra (groupSort )
2929import Data.List.NonEmpty (NonEmpty (.. ))
3030import qualified Data.List.NonEmpty as NE
@@ -347,7 +347,7 @@ queryBuildInfo :: HasEnvConfig env
347347queryBuildInfo selectors0 =
348348 rawBuildInfo
349349 >>= select id selectors0
350- >>= liftIO . TIO. putStrLn . decodeUtf8 . Yaml. encode
350+ >>= liftIO . TIO. putStrLn . addGlobalHintsComment . decodeUtf8 . Yaml. encode
351351 where
352352 select _ [] value = return value
353353 select front (sel: sels) value =
@@ -366,7 +366,21 @@ queryBuildInfo selectors0 =
366366 where
367367 cont = select (front . (sel: )) sels
368368 err msg = throwString $ msg ++ " : " ++ show (front [sel])
369-
369+ -- Include comments to indicate that this portion of the "stack
370+ -- query" API is not necessarily stable.
371+ addGlobalHintsComment
372+ | null selectors0 = T. replace globalHintsLine (" \n " <> globalHintsComment <> globalHintsLine)
373+ -- Append comment instead of pre-pending. The reasoning here is
374+ -- that something *could* expect that the result of 'stack query
375+ -- global-hints ghc-boot' is just a string literal. Seems easier
376+ -- for to expect the first line of the output to be the literal.
377+ | [" global-hints" ] `isPrefixOf` selectors0 = (<> (" \n " <> globalHintsComment))
378+ | otherwise = id
379+ globalHintsLine = " \n global-hints:\n "
380+ globalHintsComment = T. concat
381+ [ " # Note: global-hints is experimental and may be renamed / removed in the future.\n "
382+ , " # See https://github.com/commercialhaskell/stack/issues/3796"
383+ ]
370384-- | Get the raw build information object
371385rawBuildInfo :: HasEnvConfig env => RIO env Value
372386rawBuildInfo = do
0 commit comments