Commit 821d9e9c authored by Andrey Mokhov's avatar Andrey Mokhov
Browse files

Merge pull request #8 from bgamari/master

Miscellany
parents f48da184 86ed4e32
......@@ -4,3 +4,18 @@ Shaking up GHC
As part of my 6-month research secondment to Microsoft Research in Cambridge I am taking up the challenge of migrating the current [GHC](https://en.wikipedia.org/wiki/Glasgow_Haskell_Compiler) build system based on standard `make` into a new and (hopefully) better one based on [Shake](https://github.com/ndmitchell/shake/blob/master/README.md). If you are curious about the project you can find more details on the [wiki page](https://ghc.haskell.org/trac/ghc/wiki/Building/Shake) and in this [blog post](https://blogs.ncl.ac.uk/andreymokhov/shaking-up-ghc/).
This is supposed to go into the `shake-build` directory of the GHC source tree.
Trying it
---------
On Linux,
```
$ git clone git://git.haskell.org/ghc
$ cd ghc
$ git submodule update --init
$ git clone git://github.com/snowleopard/shaking-up-ghc shake-build
$ ./boot
$ ./configure
$ make inplace/bin/ghc-cabal # This needs to be fixed
$ shake-build/build.sh
```
......@@ -51,7 +51,7 @@ dllSplit = utility "dll-split"
filepath = library "filepath"
genapply = utility "genapply"
genprimopcode = utility "genprimopcode"
ghc = topLevel "ghc-bin" `setPath` "ghc"
ghc = topLevel "ghc-bin" `setPath` "ghc" `setPkgType` Program
ghcBoot = library "ghc-boot"
ghcCabal = utility "ghc-cabal"
ghci = library "ghci"
......
{-# LANGUAGE DeriveGeneric #-}
module Package (
Package (..), PackageName, pkgCabalFile, setPath, topLevel, library, utility,
matchPackageNames
Package (..), PackageName, PackageType (..),
-- * Queries
pkgCabalFile,
matchPackageNames,
-- * Helpers for constructing 'Package's
setPath, topLevel, library, utility, setPkgType
) where
import Base
import GHC.Generics (Generic)
-- It is helpful to distinguish package names from strings.
-- | It is helpful to distinguish package names from strings.
type PackageName = String
-- type PackageType = Program | Library
-- | We regard packages as either being libraries or programs. This is
-- bit of a convenient lie as Cabal packages can be both, but it works
-- for now.
data PackageType = Program | Library
deriving Generic
-- pkgPath is the path to the source code relative to the root
data Package = Package
{
pkgName :: PackageName, -- Examples: "ghc", "Cabal"
pkgPath :: FilePath -- "compiler", "libraries/Cabal/Cabal"
-- pkgType :: PackageType -- TopLevel, Library
pkgName :: PackageName, -- ^ Examples: "ghc", "Cabal"
pkgPath :: FilePath, -- ^ pkgPath is the path to the source code relative to the root.
-- e.g. "compiler", "libraries/Cabal/Cabal"
pkgType :: PackageType
}
deriving Generic
......@@ -26,17 +34,20 @@ pkgCabalFile :: Package -> FilePath
pkgCabalFile pkg = pkgPath pkg -/- pkgName pkg <.> "cabal"
topLevel :: PackageName -> Package
topLevel name = Package name name
topLevel name = Package name name Library
library :: PackageName -> Package
library name = Package name ("libraries" -/- name)
library name = Package name ("libraries" -/- name) Library
utility :: PackageName -> Package
utility name = Package name ("utils" -/- name)
utility name = Package name ("utils" -/- name) Program
setPath :: Package -> FilePath -> Package
setPath pkg path = pkg { pkgPath = path }
setPkgType :: Package -> PackageType -> Package
setPkgType pkg ty = pkg { pkgType = ty }
instance Show Package where
show = pkgName
......@@ -56,3 +67,7 @@ instance Binary Package
instance Hashable Package where
hashWithSalt salt = hashWithSalt salt . show
instance NFData Package
instance Binary PackageType
instance Hashable PackageType
instance NFData PackageType
......@@ -7,6 +7,22 @@ import Settings.Args
import Settings.Builders.Ar
import qualified Target
insideBox :: [String] -> String
insideBox ls =
unlines $ [begin] ++ map (bar++) ls ++ [end]
where
(begin,bar,end)
| useUnicode = ( "╭──────────"
, "│ "
, "╰──────────"
)
| otherwise = ( "/----------"
, "| "
, "\\----------"
)
-- FIXME: See Shake #364.
useUnicode = False
-- Build a given target using an appropriate builder and acquiring necessary
-- resources. Force a rebuilt if the argument list has changed since the last
-- built (that is, track changes in the build system).
......@@ -17,15 +33,14 @@ buildWithResources rs target = do
path <- builderPath builder
argList <- interpret target getArgs
verbose <- interpret target verboseCommands
let quitelyUnlessVerbose = if verbose then withVerbosity Loud else quietly
let quietlyUnlessVerbose = if verbose then withVerbosity Loud else quietly
-- The line below forces the rule to be rerun if the args hash has changed
checkArgsHash target
withResources rs $ do
unless verbose $ do
putBuild $ "/--------\n| Running " ++ show builder ++ " with arguments:"
mapM_ (putBuild . ("| " ++)) $ interestingInfo builder argList
putBuild $ "\\--------"
quitelyUnlessVerbose $ case builder of
putBuild $ insideBox $ [ "Running " ++ show builder ++ " with arguments:" ]
++ map (" "++) (interestingInfo builder argList)
quietlyUnlessVerbose $ case builder of
Ar -> arCmd path argList
HsCpp -> do
......
......@@ -38,7 +38,8 @@ buildPackageData rs target @ (PartialTarget stage pkg) = do
buildWithResources [(ghcCabal rs, 1)] $
fullTarget target GhcCabal [cabalFile] outs
-- TODO: find out of ghc-cabal can be concurrent with ghc-pkg
-- ghc-pkg produces inplace-pkg-config when run on packages with
-- library components only
when (isLibrary pkg) .
whenM (interpretPartial target registerPackage) .
buildWithResources [(ghcPkg rs, 1)] $
......
......@@ -15,14 +15,18 @@ buildPackageDocumentation _ target @ (PartialTarget stage package) =
haddockFile = pkgHaddockFile package
in when (stage == Stage1) $ do
haddockFile %> \file -> do
whenM (specified HsColour) $ do
need [cabalFile]
build $ fullTarget target GhcCabalHsColour [cabalFile] []
srcs <- interpretPartial target getPackageSources
deps <- interpretPartial target $ getPkgDataList DepNames
let haddocks = [ pkgHaddockFile depPkg
| Just depPkg <- map findKnownPackage deps ]
need $ srcs ++ haddocks
-- HsColour sources
whenM (specified HsColour) $ do
need [cabalFile]
build $ fullTarget target GhcCabalHsColour [cabalFile] []
-- Build Haddock documentation
let haddockWay = if dynamicGhcPrograms then dynamic else vanilla
build $ fullTargetWithWay target Haddock haddockWay srcs [file]
......
......@@ -33,7 +33,8 @@ programPath :: Stage -> Package -> Maybe FilePath
programPath = userProgramPath
isLibrary :: Package -> Bool
isLibrary pkg = programPath Stage0 pkg == Nothing
isLibrary (Package {pkgType=Library}) = True
isLibrary _ = False
-- Find all Haskell source files for the current target. TODO: simplify.
getPackageSources :: Expr [FilePath]
......
......@@ -22,7 +22,7 @@ pkgDataFile stage pkg = targetPath stage pkg -/- "package-data.mk"
-- Relative path to a package haddock file, e.g.:
-- "libraries/array/dist-install/doc/html/array/array.haddock"
pkgHaddockFile :: Package -> FilePath
pkgHaddockFile pkg @ (Package name _) =
pkgHaddockFile pkg @ (Package name _ _) =
targetPath Stage1 pkg -/- "doc/html" -/- name -/- name <.> "haddock"
-- Relative path to a package library file, e.g.:
......
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