Commit 765de7b3 authored by Mikhail Glushenkov's avatar Mikhail Glushenkov

Make cabal-dev-scripts work with 8.4.2.

parent 72409b09
......@@ -16,8 +16,9 @@ executable gen-extra-source-files
main-is: GenExtraSourceFiles.hs
hs-source-dirs: src
build-depends:
base >=4.10 && <4.11,
Cabal >=2.0 && <2.4,
base >=4.10 && <4.12,
Cabal >=2.2 && <2.4,
bytestring,
directory,
filepath,
process
......@@ -27,11 +28,11 @@ executable gen-spdx
main-is: GenSPDX.hs
hs-source-dirs: src
build-depends:
base >=4.10 && <4.11,
base >=4.10 && <4.12,
aeson >=1.2.3.0 && <1.3,
bytestring,
containers,
lens >=4.15.4 && <4.16,
lens >=4.15.4 && <4.17,
microstache >=1.0.1.1 && <1.1,
optparse-applicative >=0.13 && <0.15,
text
......@@ -41,11 +42,11 @@ executable gen-spdx-exc
main-is: GenSPDXExc.hs
hs-source-dirs: src
build-depends:
base >=4.10 && <4.11,
base >=4.10 && <4.12,
aeson >=1.2.3.0 && <1.3,
bytestring,
containers,
lens >=4.15.4 && <4.16,
lens >=4.15.4 && <4.17,
microstache >=1.0.1.1 && <1.1,
optparse-applicative >=0.13 && <0.15,
text
{-# LANGUAGE OverloadedStrings #-}
import qualified Distribution.ModuleName as ModuleName
import Distribution.PackageDescription
import Distribution.PackageDescription.Parse
(ParseResult (..), parseGenericPackageDescription)
import Distribution.PackageDescription.Parsec
(parseGenericPackageDescription, runParseResult)
import Distribution.Verbosity (silent)
import Control.Monad (liftM, filterM)
......@@ -11,6 +13,9 @@ import System.Environment (getArgs, getProgName)
import System.FilePath ((</>), takeDirectory, takeExtension, takeFileName)
import System.Process (readProcess)
import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as BS8
import qualified System.IO as IO
main' :: FilePath -> IO ()
......@@ -19,10 +24,11 @@ main' fp' = do
setCurrentDirectory (takeDirectory fp)
-- Read cabal file, so we can determine test modules
contents <- strictReadFile fp
cabal <- case parseGenericPackageDescription contents of
ParseOk _ x -> pure x
ParseFailed errs -> fail (show errs)
contents <- BS.readFile fp
cabal <-
case snd . runParseResult . parseGenericPackageDescription $ contents of
Right x -> pure x
Left (_mver, errs) -> fail (show errs)
-- We skip some files
testModuleFiles <- getOtherModulesFiles cabal
......@@ -40,13 +46,16 @@ main' fp' = do
let files = files3
-- Read current file
let inputLines = lines contents
linesBefore = takeWhile (/= topLine) inputLines
linesAfter = dropWhile (/= bottomLine) inputLines
let topLine' = BS8.pack topLine
bottomLine' = BS8.pack bottomLine
inputLines = BS8.lines contents
linesBefore = takeWhile (/= topLine') inputLines
linesAfter = dropWhile (/= bottomLine') inputLines
-- Output
let outputLines = linesBefore ++ [topLine] ++ map (" " ++) files ++ linesAfter
writeFile fp (unlines outputLines)
let outputLines = linesBefore ++ [topLine']
++ map ((<>) " " . BS8.pack) files ++ linesAfter
BS.writeFile fp (BS8.unlines outputLines)
topLine, bottomLine :: String
......@@ -106,12 +115,3 @@ main = do
putStrLn $ "Usage: " ++ progName ++ " FILE"
putStrLn $ " where FILE is Cabal.cabal, cabal-testsuite.cabal, "
++ "or cabal-install.cabal"
strictReadFile :: FilePath -> IO String
strictReadFile fp = do
handle <- IO.openFile fp IO.ReadMode
contents <- get handle
IO.hClose handle
return contents
where
get h = IO.hGetContents h >>= \s -> length s `seq` return s
#!/bin/sh
(cd Cabal; misc/gen-extra-source-files.hs Cabal.cabal)
(cd cabal-install; ../Cabal/misc/gen-extra-source-files.hs cabal-install.cabal)
Markdown is supported
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