Skip to content
This repository was archived by the owner on Feb 3, 2022. It is now read-only.

Commit c158864

Browse files
authored
Merge pull request #319 from atsampson/shake0.16
Fix #288: Upgrade hptool for shake version 0.16
2 parents 645ae70 + b60231b commit c158864

File tree

3 files changed

+35
-31
lines changed

3 files changed

+35
-31
lines changed

hptool/hptool.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Executable hptool
5555
containers,
5656
directory,
5757
hastache >=0.6.0,
58-
shake >= 0.14 && < 0.16,
58+
shake >= 0.16,
5959
split,
6060
text,
6161
transformers,

hptool/src/Config.hs

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{-# LANGUAGE ConstraintKinds, DeriveDataTypeable, GeneralizedNewtypeDeriving,
2-
RecordWildCards #-}
2+
RecordWildCards, TypeFamilies #-}
33

44
module Config
55
( askHpRelease
@@ -19,35 +19,22 @@ import Development.Shake.FilePath
1919
import Development.Shake.Rule
2020

2121
import Types
22-
import Utils (readMaybe, version)
22+
import Utils (version)
2323

2424

25-
readOracle :: (ShakeValue q, Read a) => String -> q -> Action a
26-
readOracle name q = do
27-
s <- askOracle q
28-
maybe (error $ msg s) return $ readMaybe reads s
29-
where
30-
msg s = "readOracle failed to parse " ++ name ++ " from " ++ show s
31-
32-
{-
33-
Release and BuildConfig are not used directly in the oracles because writing all
34-
the required instances is possible but lengthly, and Version is missing
35-
instances for both Hashable and Binary. It is easier to just rely on the
36-
generated instances of Show and Read for these, and use String in the oracle.
37-
-}
38-
3925
newtype HpReleaseQ = HpReleaseQ ()
4026
deriving (Show,Typeable,Eq,Hashable,Binary,NFData)
27+
type instance RuleResult HpReleaseQ = Release
4128

4229
-- | Provide the Platform release information
4330
-- The release information will be tracked as a dependency
44-
4531
askHpRelease :: Action Release
46-
askHpRelease = readOracle "HpRelease" (HpReleaseQ ())
32+
askHpRelease = askOracle $ HpReleaseQ ()
4733

4834

4935
newtype GhcBinDistTarFileQ = GhcBinDistTarFileQ ()
5036
deriving (Show,Typeable,Eq,Hashable,Binary,NFData)
37+
type instance RuleResult GhcBinDistTarFileQ = FilePath
5138

5239
-- | Provide the bindist tar file.
5340
-- The filepath will be tracked as a dependency.
@@ -60,18 +47,17 @@ askGhcBinDistTarFile = do
6047

6148
newtype BuildConfigQ = BuildConfigQ ()
6249
deriving (Show,Typeable,Eq,Hashable,Binary,NFData)
50+
type instance RuleResult BuildConfigQ = BuildConfig
6351

6452
-- | Provide the Platform release information
6553
-- The release information will be tracked as a dependency
66-
6754
askBuildConfig :: Action BuildConfig
68-
askBuildConfig = readOracle "BuildConfig" (BuildConfigQ ())
55+
askBuildConfig = askOracle $ BuildConfigQ ()
6956

70-
newtype StackExeQ = StackExeQ ()
71-
deriving (Show,Typeable,Eq,Hashable,Binary,NFData)
7257

73-
newtype CabalExeQ = CabalExeQ ()
58+
newtype StackExeQ = StackExeQ ()
7459
deriving (Show,Typeable,Eq,Hashable,Binary,NFData)
60+
type instance RuleResult StackExeQ = FilePath
7561

7662
-- | Provide the stack executable
7763
-- The filepath will be tracked as a dependency
@@ -81,6 +67,11 @@ askStackExe = do
8167
need [stackexe]
8268
return stackexe
8369

70+
71+
newtype CabalExeQ = CabalExeQ ()
72+
deriving (Show,Typeable,Eq,Hashable,Binary,NFData)
73+
type instance RuleResult CabalExeQ = FilePath
74+
8475
-- | Provide the stack executable
8576
-- The filepath will be tracked as a dependency
8677
askCabalExe :: Action FilePath
@@ -89,18 +80,19 @@ askCabalExe = do
8980
need [cabalexe]
9081
return cabalexe
9182

83+
9284
addConfigOracle :: Release -> FilePath -> (FilePath,FilePath) -> Maybe FilePath -> Bool -> Rules BuildConfig
9385
addConfigOracle hpRel tarFile (cabalexe,stackexe) prefix includeExtra = do
9486
_ <- addOracle $
95-
\(HpReleaseQ _) -> return $ show hpRel
87+
\(HpReleaseQ _) -> return hpRel
9688
_ <- addOracle $
9789
\(GhcBinDistTarFileQ _) -> return tarFile
9890
_ <- addOracle $
9991
\(CabalExeQ _) -> return cabalexe
10092
_ <- addOracle $
10193
\(StackExeQ _) -> return stackexe
10294
_ <- addOracle $
103-
\(BuildConfigQ _) -> either fail (return . show) buildConfig
95+
\(BuildConfigQ _) -> either fail return buildConfig
10496
either fail return buildConfig
10597
where
10698
buildConfig = extractBuildConfig hpRel tarFile prefix includeExtra

hptool/src/Types.hs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{-# LANGUAGE CPP, RecordWildCards #-}
1+
{-# LANGUAGE CPP, RecordWildCards, DeriveAnyClass, DeriveGeneric #-}
22

33
module Types
44
( PackageName
@@ -17,9 +17,11 @@ module Types
1717

1818
import Control.Applicative
1919
import Data.Char (isDigit)
20-
import Data.List (intercalate)
20+
import Data.List (intercalate, sort)
2121
import Data.Version (Version, showVersion, parseVersion)
2222
import Development.Shake (Action)
23+
import Development.Shake.Classes (Binary, Hashable, NFData)
24+
import GHC.Generics
2325
import Text.ParserCombinators.ReadP (ReadP,
2426
char, endBy1, munch, readP_to_S, satisfy, skipSpaces)
2527

@@ -32,6 +34,7 @@ type PackageName = String
3234
-- a hyphen between the two parts. i.e.: "acme-inator-0.1.0.0". Note that no
3335
-- component of a package name can start with a digit.
3436
data Package = Package { pkgName :: PackageName, pkgVersion :: Version }
37+
deriving (Eq, Ord, Generic, Hashable, Binary, NFData)
3538

3639
readPackageP :: ReadP Package
3740
readPackageP = do
@@ -58,7 +61,7 @@ instance Show Package where
5861
data IncludeType = IncGHC | IncGHCLib | IncGHCTool | IncLib | IncTool
5962
| IncIfWindows IncludeType
6063
| IncIfNotWindows IncludeType
61-
deriving (Eq, Read, Show)
64+
deriving (Eq, Read, Show, Ord, Generic, Hashable, Binary, NFData)
6265

6366

6467
readFixedPacakgeP :: (Version -> a) -> String -> ReadP a
@@ -72,6 +75,7 @@ readFixedPacakgeP f fixedName = do
7275
-- | Version of the platform itself.
7376
-- 'Read'/'Show' format is "haskell-platform-<version>"
7477
newtype HpVersion = HpVersion { hpVersion :: Version }
78+
deriving (Eq, Generic, Hashable, Binary, NFData)
7579
instance Read HpVersion where
7680
readsPrec _ = readP_to_S $ readFixedPacakgeP HpVersion "haskell-platform"
7781
instance Show HpVersion where
@@ -80,6 +84,7 @@ instance Show HpVersion where
8084
-- | Version of the GHC.
8185
-- 'Read'/'Show' format is "ghc-<version>"
8286
newtype GhcVersion = GhcVersion { ghcVersion :: Version }
87+
deriving (Eq, Generic, Hashable, Binary, NFData)
8388
instance Read GhcVersion where
8489
readsPrec _ = readP_to_S $ readFixedPacakgeP GhcVersion "ghc"
8590
instance Show GhcVersion where
@@ -94,7 +99,14 @@ data Release = Release
9499
, relMinimalIncludes :: [Include]
95100
, relIncludes :: [Include]
96101
}
97-
deriving (Read, Show)
102+
deriving (Read, Show, Generic, Hashable, Binary, NFData)
103+
-- The order of entries in the relMinimalIncludes and relIncludes does not
104+
-- matter for equality (and these lists will have 20-40 entries max with no
105+
-- duplicates), so this Eq instance addresses that.
106+
instance Eq Release where
107+
(Release v1 m1 i1) == (Release v2 m2 i2) =
108+
(v1 == v2) && (sortedEq m1 m2) && (sortedEq i1 i2)
109+
where sortedEq as bs = (sort as) == (sort bs)
98110

99111
-- | The configuration of a build. These are the parameters of the build that
100112
-- specify what type of system this build of Haskell Platform is for. It
@@ -111,7 +123,7 @@ data BuildConfig = BuildConfig
111123
, bcPrefix :: Maybe FilePath -- ex.: "/usr/local/haskell"
112124
, bcIncludeExtra :: Bool
113125
}
114-
deriving (Read, Show)
126+
deriving (Read, Show, Eq, Generic, Hashable, Binary, NFData)
115127

116128
-- | A function that is used for the actions after untar-ing GHC.
117129
-- The build configuration and file path of the untar-ed directory is

0 commit comments

Comments
 (0)