-
Notifications
You must be signed in to change notification settings - Fork 37
move a bunch of types into dedicated modules #502
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module Context.Type where | ||
|
||
import Hadrian.Package.Type | ||
import Stage | ||
import Way.Type | ||
|
||
import GHC.Generics | ||
import Development.Shake.Classes | ||
|
||
-- | Build context for a currently built 'Target'. We generate potentially | ||
-- different build rules for each 'Context'. | ||
data Context = Context | ||
{ stage :: Stage -- ^ Currently build Stage | ||
, package :: Package -- ^ Currently build Package | ||
, way :: Way -- ^ Currently build Way (usually 'vanilla') | ||
} deriving (Eq, Generic, Show) | ||
|
||
instance Binary Context | ||
instance Hashable Context | ||
instance NFData Context |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module Expression.Type where | ||
|
||
import Builder | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, sorry, ignore the above comment, apparently there is no There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking at There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed I didn't add EDIT: looking at the comments below, looks like it doesn't just yet =) |
||
import Context.Type | ||
import qualified Hadrian.Expression as H | ||
import Way.Type | ||
|
||
-- | @Expr a@ is a computation that produces a value of type @Action a@ and can | ||
-- read parameters of the current build 'Target'. | ||
type Expr a = H.Expr Context Builder a | ||
|
||
-- | The following expressions are used throughout the build system for | ||
-- specifying conditions ('Predicate'), lists of arguments ('Args'), 'Ways' | ||
-- and 'Packages'. | ||
type Predicate = H.Predicate Context Builder | ||
type Args = H.Args Context Builder | ||
type Ways = Expr [Way] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module Hadrian.Haskell.Cabal.Type where | ||
|
||
import Development.Shake.Classes | ||
import Hadrian.Package.Type | ||
|
||
-- TODO: Use fine-grain tracking instead of tracking the whole Cabal file. | ||
-- | Haskell package metadata extracted from a Cabal file. | ||
data Cabal = Cabal | ||
{ dependencies :: [PackageName] | ||
, name :: PackageName | ||
, synopsis :: String | ||
, version :: String | ||
} deriving (Eq, Read, Show, Typeable) | ||
|
||
instance Binary Cabal where | ||
put = put . show | ||
get = fmap read get | ||
|
||
instance Hashable Cabal where | ||
hashWithSalt salt = hashWithSalt salt . show | ||
|
||
instance NFData Cabal where | ||
rnf (Cabal a b c d) = a `seq` b `seq` c `seq` d `seq` () |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
module Hadrian.Package.Type where | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From a quick look at There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it will be necessary shortly (as in, in a PR or two), and given that we're not really in a comparable situation as with the |
||
|
||
import GHC.Generics | ||
import Development.Shake.Classes | ||
|
||
data PackageLanguage = C | Haskell deriving (Generic, Show) | ||
|
||
-- TODO: Make PackageType more precise. | ||
-- See https://github.com/snowleopard/hadrian/issues/12. | ||
data PackageType = Library | Program deriving (Generic, Show) | ||
|
||
type PackageName = String | ||
|
||
-- TODO: Consider turning Package into a GADT indexed with language and type. | ||
data Package = Package { | ||
-- | The package language. 'C' and 'Haskell' packages are supported. | ||
pkgLanguage :: PackageLanguage, | ||
-- | The package type. 'Library' and 'Program' packages are supported. | ||
pkgType :: PackageType, | ||
-- | The package name. We assume that all packages have different names, | ||
-- hence two packages with the same name are considered equal. | ||
pkgName :: PackageName, | ||
-- | The path to the package source code relative to the root of the build | ||
-- system. For example, @libraries/Cabal/Cabal@ and @ghc@ are paths to the | ||
-- @Cabal@ and @ghc-bin@ packages in GHC. | ||
pkgPath :: FilePath | ||
} deriving (Generic, Show) | ||
|
||
instance Eq Package where | ||
p == q = pkgName p == pkgName q | ||
|
||
instance Ord Package where | ||
compare p q = compare (pkgName p) (pkgName q) | ||
|
||
instance Binary PackageLanguage | ||
instance Hashable PackageLanguage | ||
instance NFData PackageLanguage | ||
|
||
instance Binary PackageType | ||
instance Hashable PackageType | ||
instance NFData PackageType | ||
|
||
instance Binary Package | ||
instance Hashable Package | ||
instance NFData Package |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As an example of the kind of comment I'm looking for:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I doubt those comments will be of much use. They will document what the initial cycle that was broken was, but will ultimately bitrot pretty quickly. Any further refactoring or addition of code to hadrian that uses the
.Type
modules will not see that there could have been a cycle without the.Type
module and subsequently not update the comment.As such I believe the comment while it might be initially correct will be ultimately incorrect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I agree, these comments will likely get out-of-date quickly, and we probably don't want to keep changing the structure very often.
Instead it may be more useful to add a general comment somewhere in the overview document that explains the module structure. (We don't have such a document at the moment, so we don't need to do it now.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest we write such a description once we have integrated all of #445 as things will be in flux until we're done with that.