Skip to content

Commit

Permalink
Make cabal-dev-scripts work with 8.4.2.
Browse files Browse the repository at this point in the history
  • Loading branch information
23Skidoo committed May 10, 2018
1 parent 72409b0 commit 765de7b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 30 deletions.
13 changes: 7 additions & 6 deletions cabal-dev-scripts/cabal-dev-scripts.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
42 changes: 21 additions & 21 deletions cabal-dev-scripts/src/GenExtraSourceFiles.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{-# 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)
Expand All @@ -11,18 +13,22 @@ import System.Environment (getArgs, getProgName)
import System.FilePath ((</>), takeDirectory, takeExtension, takeFileName)
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' fp' = do
fp <- canonicalizePath fp'
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
Expand All @@ -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
Expand Down Expand Up @@ -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
3 changes: 0 additions & 3 deletions update-cabal-files.sh

This file was deleted.

0 comments on commit 765de7b

Please sign in to comment.