Commit c4cc0dc7 authored by Andrey Mokhov's avatar Andrey Mokhov
Browse files

Factor out postProcessPackageData to Util.hs.

parent d2f3a74a
......@@ -122,15 +122,13 @@ buildPackageData pkg @ (Package name path _) (stage, dist, settings) =
"inplace-pkg-config",
"setup-config",
"build" </> "autogen" </> "cabal_macros.h",
"build" </> "autogen" </> ("Paths_" ++ name) <.> "hs" -- TODO: Is this needed? What's up with Paths_cpsa.hs?
"build" </> "autogen" </> ("Paths_" ++ name) <.> "hs" -- TODO: Is this needed? Also check out Paths_cpsa.hs.
] &%> \_ -> do
need [path </> name <.> "cabal"]
when (doesFileExist $ path </> "configure.ac") $ need [path </> "configure"]
run GhcCabal cabalArgs
when (registerPackage settings) $ run (GhcPkg stage) ghcPkgArgs
let pkgDataFile = path </> dist </> "package-data.mk"
pkgData <- lines <$> liftIO (readFile pkgDataFile)
length pkgData `seq` writeFileLines pkgDataFile $ map (replaceIf isSlash '_') $ filter ('$' `notElem`) pkgData
postProcessPackageData $ path </> dist </> "package-data.mk"
where
cabalArgs, ghcPkgArgs :: Args
cabalArgs = mconcat
......
module Util (
module Data.Char,
isSlash,
replaceIf, replaceEq
replaceIf, replaceEq,
postProcessPackageData
) where
import Base
import Data.Char
isSlash :: Char -> Bool
......@@ -14,3 +16,11 @@ replaceIf p to = map (\from -> if p from then to else from)
replaceEq :: Eq a => a -> a -> [a] -> [a]
replaceEq from = replaceIf (== from)
-- Prepare a given 'packaga-data.mk' file for parsing by readConfigFile:
-- 1) Drop lines containing '$'
-- 2) Replace '/' and '\' with '_'
postProcessPackageData :: FilePath -> Action ()
postProcessPackageData file = do
pkgData <- (filter ('$' `notElem`) . lines) <$> liftIO (readFile file)
length pkgData `seq` writeFileLines file $ map (replaceIf isSlash '_') pkgData
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment