Commit 9d13cd84 authored by Andrey Mokhov's avatar Andrey Mokhov
Browse files

Improve code consistency, simplify, fix comments

parent f52e582d
......@@ -6,7 +6,7 @@ module Builder (
import Control.Monad.Trans.Reader
import Data.Char
import GHC.Generics (Generic)
import GHC.Generics
import Base
import Context
......@@ -16,22 +16,20 @@ import Oracles.LookupInPath
import Oracles.WindowsPath
import Stage
-- | A compiler can typically be used in one of three modes:
-- 1) Compiling sources into object files.
-- 2) Extracting source dependencies, e.g. by passing -M command line argument.
-- 3) Linking object files & static libraries into an executable.
-- | A compiler can typically be used in different modes:
-- * Compiling or preprocessing a source file;
-- * Extracting source dependencies, e.g. by passing @-M@ command line argument;
-- * Linking object files & static libraries into an executable.
-- We have CcMode for C compiler and GhcMode for GHC.
data CcMode = CompileC | FindCDependencies deriving (Eq, Generic, Show)
data GhcMode = CompileHs | FindHsDependencies | LinkHs
deriving (Eq, Generic, Show)
-- TODO: Do we really need HsCpp builder? Can't we use Cc instead?
-- | A 'Builder' is an external command invoked in separate process using 'Shake.cmd'
--
-- @Ghc Stage0@ is the bootstrapping compiler
-- @Ghc StageN@, N > 0, is the one built on stage (N - 1)
-- @GhcPkg Stage0@ is the bootstrapping @GhcPkg@
-- @GhcPkg StageN@, N > 0, is the one built in Stage0 (TODO: need only Stage1?)
-- | A 'Builder' is an external command invoked in a separate process via 'cmd'.
-- @Ghc Stage0@ is the bootstrapping compiler.
-- @Ghc StageN@, N > 0, is the one built in stage (N - 1).
-- @GhcPkg Stage0@ is the bootstrapping @GhcPkg@.
-- @GhcPkg Stage1@ is the one built in Stage0.
data Builder = Alex
| Ar
| DeriveConstants
......@@ -169,7 +167,10 @@ needBuilder = \case
path <- builderPath builder
need [path]
-- | Instances for storing in the Shake database.
instance Binary Builder
instance Hashable Builder
instance NFData Builder
instance Binary CcMode
instance Hashable CcMode
instance NFData CcMode
......@@ -177,7 +178,3 @@ instance NFData CcMode
instance Binary GhcMode
instance Hashable GhcMode
instance NFData GhcMode
instance Binary Builder
instance Hashable Builder
instance NFData Builder
{-# LANGUAGE DeriveGeneric #-}
module Context (Context (..), vanillaContext, stageContext) where
import GHC.Generics (Generic)
import GHC.Generics
import Base
import Package
......@@ -26,5 +26,5 @@ stageContext :: Stage -> Context
stageContext s = vanillaContext s $ error "stageContext: package not set"
instance Binary Context
instance NFData Context
instance Hashable Context
instance NFData Context
......@@ -8,7 +8,7 @@ module Package (
) where
import Data.String
import GHC.Generics (Generic)
import GHC.Generics
import Base
......@@ -77,10 +77,8 @@ instance Eq Package where
instance Ord Package where
compare = compare `on` pkgName
-- | Instances for storing in the Shake database.
instance Binary Package
instance Hashable Package where
hashWithSalt salt = hashWithSalt salt . show
instance NFData Package
instance Binary PackageType
......
......@@ -14,7 +14,7 @@ import Settings.Paths
cabalRules :: Rules ()
cabalRules = do
-- Cache boot package constraints (to be used in cabalArgs).
-- Cache boot package constraints (to be used in 'cabalArgs').
bootPackageConstraints %> \out -> do
bootPkgs <- interpretInContext (stageContext Stage0) getPackages
let pkgs = filter (\p -> p /= compiler && isLibrary p) bootPkgs
......
......@@ -17,7 +17,7 @@ haddockHtmlLib = "inplace/lib/html/haddock-util.js"
-- Note: this build rule creates plenty of files, not just the .haddock one.
-- All of them go into the 'doc' subdirectory. Pedantically tracking all built
-- files in the Shake databases seems fragile and unnecessary.
-- files in the Shake database seems fragile and unnecessary.
buildPackageDocumentation :: Context -> Rules ()
buildPackageDocumentation context@Context {..} =
let cabalFile = pkgCabalFile package
......
......@@ -139,7 +139,7 @@ generatePackageCode context@(Context stage pkg _) =
liftIO $ IO.copyFile file newFile
putBuild $ "| Duplicate file " ++ file ++ " -> " ++ newFile
when (pkg == rts) $ path -/- "cmm/AutoApply.cmm" %> \file -> do
when (pkg == rts) $ path -/- "cmm/AutoApply.cmm" %> \file ->
build $ Target context GenApply [] [file]
priority 2.0 $ do
......
......@@ -4,11 +4,10 @@ import Base
import Expression
import Rules.Actions
-- TODO: get rid of perl scripts
-- | Generate perl scripts the build system requires, such as @ghc-split@,
-- from the corresponding literate perl source.
-- | Build Perl scripts, such as @ghc-split@, from their literate Perl sources.
perlScriptRules :: Rules ()
perlScriptRules = do
"//*.prl" %> \out -> do
let src = out -<.> "lprl"
need [src]
runBuilder Unlit [src, out]
......@@ -5,7 +5,6 @@ import Oracles.Config.Flag
import Oracles.Config.Setting
import Predicate
-- | Default arguments for 'Ar' builder.
arBuilderArgs :: Args
arBuilderArgs = builder Ar ? mconcat [ arg "q"
, arg =<< getOutput
......
......@@ -20,12 +20,8 @@ ccBuilderArgs = builder Cc ? mconcat
, builder (Cc FindCDependencies) ? do
output <- getOutput
mconcat [ arg "-E"
, arg "-MM"
, arg "-MG"
, arg "-MF"
, arg output
, arg "-MT"
, arg $ dropExtension output -<.> "o"
, arg "-x"
, arg "c"
, arg "-MM", arg "-MG"
, arg "-MF", arg output
, arg "-MT", arg $ dropExtension output -<.> "o"
, arg "-x", arg "c"
, arg =<< getInput ] ]
......@@ -2,7 +2,6 @@ module Settings.Builders.GenApply (genApplyBuilderArgs) where
import Predicate
-- Stdin/stdout are handled in a special way. See Rules/Actions.hs.
-- TODO: Dead code? ifeq "$(GhcUnregisterised)" "YES" GENAPPLY_OPTS = -u
genApplyBuilderArgs :: Args
genApplyBuilderArgs = mempty
......@@ -2,7 +2,6 @@ module Settings.Builders.GenPrimopCode (genPrimopCodeBuilderArgs) where
import Predicate
-- Stdin/stdout are handled in a special way. See Rules/Actions.hs.
genPrimopCodeBuilderArgs :: Args
genPrimopCodeBuilderArgs = builder GenPrimopCode ? mconcat
[ output "//PrimopWrappers.hs" ? arg "--make-haskell-wrappers"
......
......@@ -62,7 +62,6 @@ libraryArgs = do
else "--disable-shared" ]
-- TODO: LD_OPTS?
-- TODO: WARNING: unrecognized options: --with-compiler, --with-gmp-libraries, --with-cc
configureArgs :: Args
configureArgs = do
top <- getTopDirectory
......
......@@ -3,16 +3,16 @@ module Settings.Builders.HsCpp (hsCppBuilderArgs) where
import GHC
import Oracles.Config.Setting
import Predicate
import Settings.Builders.Common
import Settings.Paths
hsCppBuilderArgs :: Args
hsCppBuilderArgs = builder HsCpp ? do
stage <- getStage
mconcat [ append =<< getSettingList HsCppArgs
mconcat [ argSettingList HsCppArgs
, arg "-P"
, arg "-Iincludes"
, arg $ "-I" ++ generatedPath
, arg $ "-I" ++ buildPath (vanillaContext stage compiler)
, arg "-x"
, arg "c"
, arg "-x", arg "c"
, arg =<< getInput ]
......@@ -25,7 +25,7 @@ hsc2hsBuilderArgs = builder Hsc2Hs ? do
tArch <- getSetting TargetArch
tOs <- getSetting TargetOs
version <- if stage == Stage0
then lift $ ghcCanonVersion
then lift ghcCanonVersion
else getSetting ProjectVersionInt
lift $ need [templateHsc]
mconcat [ arg $ "--cc=" ++ ccPath
......
......@@ -2,11 +2,10 @@ module Settings.Builders.Ld (ldBuilderArgs) where
import Oracles.Config.Setting
import Predicate
import Settings.Builders.Common
ldBuilderArgs :: Args
ldBuilderArgs = builder Ld ? do
args <- getSettingList . ConfLdLinkerArgs =<< getStage
mconcat [ append args
, arg "-r"
, arg "-o", arg =<< getOutput
, append =<< getInputs ]
ldBuilderArgs = builder Ld ? mconcat [ argStagedSettingList ConfLdLinkerArgs
, arg "-r"
, arg "-o", arg =<< getOutput
, append =<< getInputs ]
......@@ -3,9 +3,8 @@ module Settings.Builders.Tar (tarBuilderArgs) where
import Predicate
tarBuilderArgs :: Args
tarBuilderArgs = builder Tar ? do
mconcat [ arg "-xf"
, input "*.gz" ? arg "--gzip"
, input "*.bz2" ? arg "--bzip2"
, arg =<< getInput
, arg "-C", arg =<< getOutput ]
tarBuilderArgs = builder Tar ? mconcat [ arg "-xf"
, input "*.gz" ? arg "--gzip"
, input "*.bz2" ? arg "--bzip2"
, arg =<< getInput
, arg "-C", arg =<< getOutput ]
......@@ -2,7 +2,7 @@
module Stage (Stage (..), stageString) where
import Development.Shake.Classes
import GHC.Generics (Generic)
import GHC.Generics
-- | A stage refers to a certain compiler in GHC's build process.
--
......@@ -27,7 +27,6 @@ data Stage = Stage0 | Stage1 | Stage2 | Stage3
stageString :: Stage -> String
stageString stage = "stage" ++ show (fromEnum stage)
-- Instances for storing in the Shake database
instance Binary Stage
instance Hashable Stage
instance NFData Stage
......@@ -2,7 +2,7 @@
module Target (Target (..), dummyTarget) where
import Control.Monad.Trans.Reader
import GHC.Generics (Generic)
import GHC.Generics
import Base
import Builder
......@@ -18,7 +18,6 @@ data Target = Target
-- | If values of type @a@ form a 'Monoid' then we can also derive a 'Monoid'
-- instance for values of type @'ReaderT' 'Target' 'Action' a@:
--
-- * the empty computation is the identity element of the underlying type
-- * two computations can be combined by combining their results
instance Monoid a => Monoid (ReaderT Target Action a) where
......@@ -33,5 +32,5 @@ dummyTarget ctx = Target
, outputs = error "dummyTarget: outputs not set" }
instance Binary Target
instance NFData Target
instance Hashable Target
instance NFData Target
......@@ -160,7 +160,6 @@ libsuf way@(Way set) =
-- e.g., p_ghc7.11.20141222.dll (the result)
return $ prefix ++ "ghc" ++ version ++ extension
-- Instances for storing in the Shake database
instance Binary Way where
put = put . show
get = fmap read get
......
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