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