@@ -23,6 +23,7 @@ module Hpack.Render (
23
23
, Alignment (.. )
24
24
, CommaStyle (.. )
25
25
#ifdef TEST
26
+ , RenderEnv (.. )
26
27
, renderConditional
27
28
, renderDependencies
28
29
, renderLibraryFields
@@ -48,7 +49,18 @@ import Hpack.Render.Hints
48
49
import Hpack.Render.Dsl hiding (sortFieldsBy )
49
50
import qualified Hpack.Render.Dsl as Dsl
50
51
51
- type RenderM = Reader CabalVersion
52
+ data RenderEnv = RenderEnv {
53
+ renderEnvCabalVersion :: CabalVersion
54
+ , renderEnvPackageName :: String
55
+ }
56
+
57
+ type RenderM = Reader RenderEnv
58
+
59
+ getCabalVersion :: RenderM CabalVersion
60
+ getCabalVersion = asks renderEnvCabalVersion
61
+
62
+ getPackageName :: RenderM String
63
+ getPackageName = asks renderEnvPackageName
52
64
53
65
renderPackage :: [String ] -> Package -> String
54
66
renderPackage oldCabalFile = renderPackageWith settings headerFieldsAlignment formattingHintsFieldOrder formattingHintsSectionsFieldOrder
@@ -82,7 +94,7 @@ renderPackageWith settings headerFieldsAlignment existingFieldOrder sectionsFiel
82
94
customSetup = maybe [] (return . renderCustomSetup) packageCustomSetup
83
95
84
96
stanzas :: [Element ]
85
- stanzas = flip runReader packageCabalVersion $ do
97
+ stanzas = flip runReader ( RenderEnv packageCabalVersion packageName) $ do
86
98
library <- maybe (return [] ) (fmap return . renderLibrary) packageLibrary
87
99
internalLibraries <- renderInternalLibraries packageInternalLibraries
88
100
executables <- renderExecutables packageExecutables
@@ -357,21 +369,28 @@ renderBuildTools :: Map BuildTool DependencyVersion -> SystemBuildTools -> Rende
357
369
renderBuildTools buildTools systemBuildTools = do
358
370
xs <- traverse renderBuildTool $ Map. toList buildTools
359
371
return [
360
- Field " build-tools" ( CommaSeparatedList $ [x | BuildTools x <- xs] ++ renderSystemBuildTools systemBuildTools)
361
- , Field " build-tool-depends" ( CommaSeparatedList [x | BuildToolDepends x <- xs])
372
+ Field " build-tools" $ CommaSeparatedList $ [x | BuildTools x <- xs] ++ renderSystemBuildTools systemBuildTools
373
+ , Field " build-tool-depends" $ CommaSeparatedList [x | BuildToolDepends x <- xs]
362
374
]
363
375
364
376
data RenderBuildTool = BuildTools String | BuildToolDepends String
365
377
366
378
renderBuildTool :: (BuildTool , DependencyVersion ) -> RenderM RenderBuildTool
367
379
renderBuildTool (buildTool, renderVersion -> version) = do
368
- cabalVersion <- ask
380
+ cabalVersion <- getCabalVersion
381
+ packageName <- getPackageName
382
+ let supportsBuildTools = cabalVersion < makeCabalVersion [2 ]
369
383
return $ case buildTool of
370
- LocalBuildTool executable -> BuildTools (executable ++ version)
384
+ LocalBuildTool executable
385
+ | supportsBuildTools -> BuildTools (executable ++ version)
386
+ | otherwise -> BuildToolDepends (packageName ++ " :" ++ executable ++ version)
371
387
BuildTool pkg executable
372
- | cabalVersion < makeCabalVersion [ 2 ] && pkg == executable && executable `elem` knownBuildTools -> BuildTools (executable ++ version)
388
+ | supportsBuildTools && isknownBuildTool pkg executable -> BuildTools (executable ++ version)
373
389
| otherwise -> BuildToolDepends (pkg ++ " :" ++ executable ++ version)
374
390
where
391
+ isknownBuildTool :: String -> String -> Bool
392
+ isknownBuildTool pkg executable = pkg == executable && executable `elem` knownBuildTools
393
+
375
394
knownBuildTools :: [String ]
376
395
knownBuildTools = [
377
396
" alex"
0 commit comments