Commit 128c5acb authored by Andrey Mokhov's avatar Andrey Mokhov
Browse files

Refactor, limit lines at 80 characters.

parent 018f8501
......@@ -8,8 +8,7 @@ module Package.Base (
defaultSettings, libraryPackage,
commonCcArgs, commonLdArgs, commonCppArgs, commonCcWarninigArgs,
bootPkgConstraints,
pathArgs, outputArgs,
packageArgs, includeArgs, srcArgs
pathArgs, packageArgs, includeArgs, srcArgs
) where
import Base
......@@ -29,18 +28,20 @@ data Settings = Settings
}
defaultSettings :: Stage -> Settings
defaultSettings stage = Settings mempty mempty mempty mempty mempty True (defaultWays stage)
defaultSettings stage =
Settings mempty mempty mempty mempty mempty True (defaultWays stage)
type TodoItem = (Stage, FilePath, Settings)
-- Stage is the stage of the GHC that we use to build the package
-- FilePath is the directory to put the build results
-- Settings are various Args which may be different for different combinations of Stage & FilePath
-- Settings may be different for different combinations of Stage & FilePath
type TodoItem = (Stage, FilePath, Settings)
-- pkgPath is the path to the source code relative to the root
data Package = Package
{
pkgName :: String, -- e.g., "deepseq"
pkgPath :: FilePath, -- e.g., "libraries/deepseq"
pkgTodo :: [TodoItem] -- e.g., [(Stage1, "dist-install", defaultSettings)]
pkgName :: String, -- For example: "deepseq"
pkgPath :: FilePath, -- "libraries/deepseq"
pkgTodo :: [TodoItem] -- [(Stage1, "dist-install", defaultSettings)]
}
libraryPackage :: String -> Stage -> (Stage -> Settings) -> Package
......@@ -63,58 +64,57 @@ commonLdArgs = mempty -- TODO: Why empty? Perhaps drop it altogether?
commonCppArgs :: Args
commonCppArgs = mempty -- TODO: Why empty? Perhaps drop it altogether?
-- TODO: simplify
commonCcWarninigArgs :: Args
commonCcWarninigArgs = when Validating $
when GccIsClang (arg "-Wno-unknown-pragmas")
<> when (not GccIsClang && not GccLt46) (arg "-Wno-error=inline")
<> when ( GccIsClang && not GccLt46 && windowsHost) (arg "-Werror=unused-but-set-variable")
GccIsClang <?> arg "-Wno-unknown-pragmas"
<> (not GccIsClang && not GccLt46) <?> arg "-Wno-error=inline"
<> (GccIsClang && not GccLt46 && windowsHost) <?>
arg "-Werror=unused-but-set-variable"
bootPkgConstraints :: Args
bootPkgConstraints = mempty
-- TODO: implement bootPkgConstraints oracle
--BOOT_PKG_CONSTRAINTS := \
-- $(foreach d,$(PACKAGES_STAGE0),\
-- $(foreach p,$(basename $(notdir $(wildcard libraries/$d/*.cabal))),\
-- --constraint "$p == $(shell grep -i "^Version:" libraries/$d/$p.cabal | sed "s/[^0-9.]//g")"))
-- BOOT_PKG_CONSTRAINTS := \
-- $(foreach d,$(PACKAGES_STAGE0),\
-- $(foreach p,$(basename $(notdir $(wildcard libraries/$d/*.cabal))),\
-- --constraint "$p == $(shell grep -i "^Version:" libraries/$d/$p.cabal |
-- sed "s/[^0-9.]//g")"))
pathArgs :: ShowArgs a => String -> FilePath -> a -> Args
pathArgs prefix path as = map includePath <$> arg as
where
includePath dir | isRelative dir = prefix ++ normaliseEx (path </> dir)
| isAbsolute dir = prefix </> normaliseEx dir
outputArgs :: [String] -> FilePath -> Args
outputArgs keys dir = arg $ concatMap (\k -> [k, normaliseEx dir]) keys
pathArgs key path as = map (\a -> key ++ normaliseEx (path </> a)) <$> arg as
packageArgs :: Stage -> FilePath -> Args
packageArgs stage pkgData = do
usePackageKey <- SupportsPackageKey || stage /= Stage0
arg ["-hide-all-packages", "-no-user-package-db", "-include-pkg-deps"]
<> when (stage == Stage0) (arg "-package-db libraries/bootstrapping.conf")
<> (stage == Stage0) <?> arg "-package-db libraries/bootstrapping.conf"
<> keyArgs usePackageKey
where
keyArgs True = prefixArgs "-this-package-key" (PackageKey pkgData) <>
prefixArgs "-package-key" (DepKeys pkgData)
keyArgs False = prefixArgs "-package-name" (PackageKey pkgData) <>
prefixArgs "-package" (Deps pkgData)
keyArgs True = productArgs "-this-package-key" (PackageKey pkgData) <>
productArgs "-package-key" (DepKeys pkgData)
keyArgs False = productArgs "-package-name" (PackageKey pkgData) <>
productArgs "-package" (Deps pkgData)
includeArgs :: FilePath -> FilePath -> Args
includeArgs path dist =
let buildDir = path </> dist
pkgData = buildDir </> "package-data.mk"
let pkgData = path </> dist </> "package-data.mk"
buildDir = path </> dist </> "build"
in arg "-i"
<> pathArgs "-i" path (SrcDirs pkgData)
<> pathArgs "-i" buildDir ["build", "build/autogen"]
<> pathArgs "-I" buildDir ["build", "build/autogen"]
<> concatArgs ["-i", "-I"] [buildDir, buildDir </> "autogen"]
<> pathArgs "-I" path (IncludeDirs pkgData)
<> arg "-optP-include" -- TODO: Shall we also add -cpp?
<> pathArgs "-optP" buildDir "build/autogen/cabal_macros.h"
<> concatArgs "-optP" (buildDir </> "autogen/cabal_macros.h")
srcArgs :: FilePath -> FilePath -> Args
srcArgs path pkgData = do
mods <- map (replaceEq '.' pathSeparator) <$> arg (Modules pkgData)
mods <- arg (Modules pkgData)
dirs <- arg (SrcDirs pkgData)
srcs <- getDirectoryFiles ""
[path </> dir </> mPath <.> ext | dir <- dirs, mPath <- mods, ext <- ["hs", "lhs"]]
srcs <- getDirectoryFiles "" $ do
dir <- dirs
modPath <- map (replaceEq '.' pathSeparator) mods
extension <- ["hs", "lhs"]
return $ path </> dir </> modPath <.> extension
arg (map normaliseEx srcs)
......@@ -4,20 +4,40 @@ module Package.Compile (buildPackageCompile) where
import Package.Base
import Development.Shake.Util
-- "inplace/bin/ghc-stage1.exe" -hisuf hi -osuf o -hcsuf hc -static -H32m -O -this-package-key deeps_FT5iVCELxOr62eHY0nbvnU -hide-all-packages -i -ilibraries/deepseq/. -ilibraries/deepseq/dist-install/build -ilibraries/deepseq/dist-install/build/autogen -Ilibraries/deepseq/dist-install/build -Ilibraries/deepseq/dist-install/build/autogen -Ilibraries/deepseq/. -optP-include -optPlibraries/deepseq/dist-install/build/autogen/cabal_macros.h -package-key array_3w0nMK0JfaFJPpLFn2yWAJ -package-key base_469rOtLAqwTGFEOGWxSUiQ -package-key ghcpr_FgrV6cgh2JHBlbcx1OSlwt -Wall -XHaskell2010 -O2 -no-user-package-db -rtsopts -odir libraries/deepseq/dist-install/build -hidir libraries/deepseq/dist-install/build -stubdir libraries/deepseq/dist-install/build -split-objs -c libraries/deepseq/./Control/DeepSeq.hs -o libraries/deepseq/dist-install/build/Control/DeepSeq.o
{- "inplace/bin/ghc-stage1.exe" -hisuf hi -osuf o -hcsuf hc
-static -H32m -O
-this-package-key deeps_FT5iVCELxOr62eHY0nbvnU -hide-all-packages
-i -ilibraries/deepseq/. -ilibraries/deepseq/dist-install/build
-ilibraries/deepseq/dist-install/build/autogen
-Ilibraries/deepseq/dist-install/build
-Ilibraries/deepseq/dist-install/build/autogen
-Ilibraries/deepseq/.
-optP-include -optPlibraries/deepseq/dist-install/build/autogen/cabal_macros.h
-package-key array_3w0nMK0JfaFJPpLFn2yWAJ
-package-key base_469rOtLAqwTGFEOGWxSUiQ
-package-key ghcpr_FgrV6cgh2JHBlbcx1OSlwt
-Wall -XHaskell2010 -O2 -no-user-package-db -rtsopts
-odir libraries/deepseq/dist-install/build
-hidir libraries/deepseq/dist-install/build
-stubdir libraries/deepseq/dist-install/build
-split-objs
-c libraries/deepseq/./Control/DeepSeq.hs
-o libraries/deepseq/dist-install/build/Control/DeepSeq.o -}
suffixArgs :: Way -> Args
suffixArgs way = arg ["-hisuf", hisuf way, "-osuf", osuf way, "-hcsuf", hcsuf way]
suffixArgs way = arg ["-hisuf", hisuf way]
<> arg [ "-osuf", osuf way]
<> arg ["-hcsuf", hcsuf way]
buildPackageCompile :: Package -> TodoItem -> Rules ()
buildPackageCompile (Package name path _) (stage, dist, settings) =
let buildDir = path </> dist
pkgData = buildDir </> "package-data.mk"
depFile = buildDir </> "build" </> name <.> "m"
let buildDir = path </> dist </> "build"
pkgData = path </> dist </> "package-data.mk"
depFile = buildDir </> name <.> "m"
in
(buildDir </> "build//*o") %> \out -> do
(buildDir <//> "*o") %> \out -> do
let way = detectWay $ tail $ takeExtension out
need ["shake/src/Package/Compile.hs"] -- Track changes in this file
need ["shake/src/Package/Compile.hs"]
need [depFile]
depContents <- parseMakefile <$> (liftIO $ readFile depFile)
let deps = concat $ snd $ unzip $ filter ((== out) . fst) depContents
......@@ -28,8 +48,9 @@ buildPackageCompile (Package name path _) (stage, dist, settings) =
<> arg SrcHcOpts
<> packageArgs stage pkgData
<> includeArgs path dist
<> arg ["-Wall", "-XHaskell2010", "-O2"] -- TODO: now we have both -O and -O2
<> outputArgs ["-odir", "-hidir", "-stubdir"] (buildDir </> "build")
-- TODO: now we have both -O and -O2
<> arg ["-Wall", "-XHaskell2010", "-O2"]
<> productArgs ["-odir", "-hidir", "-stubdir"] buildDir
<> arg "-split-objs"
<> arg ("-c":srcs)
<> arg ["-o", out]
......@@ -7,11 +7,12 @@ libraryArgs :: [Way] -> Args
libraryArgs ways =
argEnable False "library-for-ghci" -- TODO: why always disable?
<> argEnable (vanilla `elem` ways) "library-vanilla"
<> when (ghcWithInterpreter && not DynamicGhcPrograms && vanilla `elem` ways) (argEnable True "library-for-ghci")
<> (ghcWithInterpreter && not DynamicGhcPrograms && vanilla `elem` ways)
<?> argEnable True "library-for-ghci"
<> argEnable (profiling `elem` ways) "library-profiling"
<> argEnable (dynamic `elem` ways) "shared"
where
argEnable x suffix = arg $ (if x then "--enable-" else "--disable-") ++ suffix
argEnable x key = arg $ (if x then "--enable-" else "--disable-") ++ key
configureArgs :: Stage -> Settings -> Args
configureArgs stage settings =
......@@ -23,8 +24,12 @@ configureArgs stage settings =
<+> ConfCcArgs stage
<+> customCcArgs settings
<+> commonCcWarninigArgs
ldflags = commonLdArgs <+> ConfGccLinkerArgs stage <+> customLdArgs settings
cppflags = commonCppArgs <+> ConfCppArgs stage <+> customCppArgs settings
ldflags = commonLdArgs
<+> ConfGccLinkerArgs stage
<+> customLdArgs settings
cppflags = commonCppArgs
<+> ConfCppArgs stage
<+> customCppArgs settings
in argConf "CFLAGS" cflags
<> argConf "LDFLAGS" ldflags
......@@ -34,18 +39,20 @@ configureArgs stage settings =
<> argConf "--with-iconv-libraries" IconvLibDirs
<> argConf "--with-gmp-includes" GmpIncludeDirs
<> argConf "--with-gmp-libraries" GmpLibDirs
<> when CrossCompiling (argConf "--host" TargetPlatformFull) -- TODO: why not host?
-- TODO: why TargetPlatformFull and not host?
<> when CrossCompiling (argConf "--host" TargetPlatformFull)
<> argConf "--with-cc" Gcc
buildPackageData :: Package -> TodoItem -> Rules ()
buildPackageData (Package name path _) (stage, dist, settings) =
let buildDir = path </> dist
let pathDist = path </> dist
configure = path </> "configure"
cabalArgs = arg ["configure", path, dist]
-- this is a positional argument, hence:
-- * if it is empty, we need to emit one empty string argument
-- * if there are many, we must collapse them into one space-separated string
-- * otherwise, we must collapse it into one space-separated string
<> arg (unwords <$> customDllArgs settings)
<> with (Ghc stage) -- TODO: used to be stage01 (using max stage1 GHC)
<> with (Ghc stage) -- TODO: used limited to max stage1 GHC
<> with (GhcPkg stage)
<> customConfArgs settings
<> (libraryArgs =<< ways settings)
......@@ -58,20 +65,22 @@ buildPackageData (Package name path _) (stage, dist, settings) =
<> with Alex
<> with Happy -- TODO: reorder with's
ghcPkgArgs = arg ["update", "--force"]
<> when (stage == Stage0) (arg "--package-db=libraries/bootstrapping.conf")
<> arg (buildDir </> "inplace-pkg-config")
<> (stage == Stage0) <?>
arg "--package-db=libraries/bootstrapping.conf"
<> arg (pathDist </> "inplace-pkg-config")
in
(buildDir </>) <$>
(pathDist </>) <$>
[ "package-data.mk"
, "haddock-prologue.txt"
, "inplace-pkg-config"
, "setup-config"
, "build" </> "autogen" </> "cabal_macros.h"
, "build" </> "autogen" </> ("Paths_" ++ name) <.> "hs" -- TODO: Is this needed? Also check out Paths_cpsa.hs.
-- TODO: Is this needed? Also check out Paths_cpsa.hs.
, "build" </> "autogen" </> ("Paths_" ++ name) <.> "hs"
] &%> \_ -> do
need ["shake/src/Package/Data.hs"] -- Track changes in this file
need ["shake/src/Package/Data.hs"]
need [path </> name <.> "cabal"]
when (doesFileExist $ path </> "configure.ac") $ need [path </> "configure"]
when (doesFileExist $ configure <.> "ac") $ need [configure]
run GhcCabal cabalArgs
when (registerPackage settings) $ run (GhcPkg stage) ghcPkgArgs
postProcessPackageData $ buildDir </> "package-data.mk"
postProcessPackageData $ pathDist </> "package-data.mk"
......@@ -5,17 +5,19 @@ import Package.Base
buildPackageDependencies :: Package -> TodoItem -> Rules ()
buildPackageDependencies (Package name path _) (stage, dist, settings) =
let buildDir = path </> dist
pkgData = buildDir </> "package-data.mk"
let buildDir = path </> dist </> "build"
pkgData = path </> dist </> "package-data.mk"
in
(buildDir </> "build" </> name <.> "m") %> \out -> do
need ["shake/src/Package/Dependencies.hs"] -- Track changes in this file
(buildDir </> name <.> "m") %> \out -> do
need ["shake/src/Package/Dependencies.hs"]
run (Ghc stage) $ arg "-M"
<> packageArgs stage pkgData
<> includeArgs path dist
<> outputArgs ["-odir", "-stubdir"] (buildDir </> "build")
<> productArgs ["-odir", "-stubdir"] buildDir
<> arg ["-dep-makefile", out]
<> prefixArgs "-dep-suffix" (map suffix <$> ways settings)
<> productArgs "-dep-suffix" (map suffix <$> ways settings)
<> srcArgs path pkgData
-- <> arg SrcHcOpts -- TODO: Check that skipping all _HC_OPTS is safe.
-- <> wayHcOpts vanilla -- TODO: i) is this needed? ii) shall we run GHC -M multiple times?
-- TODO: Check that skipping all _HC_OPTS is safe.
-- <> arg SrcHcOpts
-- TODO: i) is this needed? ii) shall we run GHC -M multiple times?
-- <> wayHcOpts vanilla
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