[commit: ghc] wip/nfs-locking: Refactor duplicated code into pathArgs, outputArgs and includeArgs functions. (9fbf3c8)

git at git.haskell.org git at git.haskell.org
Thu Oct 26 23:49:07 UTC 2017


Repository : ssh://git@git.haskell.org/ghc

On branch  : wip/nfs-locking
Link       : http://ghc.haskell.org/trac/ghc/changeset/9fbf3c8c37ac973da0574bd4a3dbe7bb2c012a32/ghc

>---------------------------------------------------------------

commit 9fbf3c8c37ac973da0574bd4a3dbe7bb2c012a32
Author: Andrey Mokhov <andrey.mokhov at gmail.com>
Date:   Sun Jan 11 13:33:27 2015 +0000

    Refactor duplicated code into pathArgs, outputArgs and includeArgs functions.


>---------------------------------------------------------------

9fbf3c8c37ac973da0574bd4a3dbe7bb2c012a32
 src/Package/Base.hs         | 26 +++++++++++++++++++++-----
 src/Package/Compile.hs      | 14 +++-----------
 src/Package/Dependencies.hs | 13 +++----------
 3 files changed, 27 insertions(+), 26 deletions(-)

diff --git a/src/Package/Base.hs b/src/Package/Base.hs
index 4ef03fb..d1bf6ac 100644
--- a/src/Package/Base.hs
+++ b/src/Package/Base.hs
@@ -8,6 +8,7 @@ module Package.Base (
     defaultSettings, libraryPackage,
     commonCcArgs, commonLdArgs, commonCppArgs, commonCcWarninigArgs,
     bootPkgConstraints,
+    pathArgs, outputArgs, 
     packageArgs, includeArgs, srcArgs
     ) where
 
@@ -77,6 +78,15 @@ bootPkgConstraints = mempty
 --        $(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
+
 packageArgs :: Stage -> FilePath -> Args
 packageArgs stage pkgData = do
     usePackageKey <- SupportsPackageKey || stage /= Stage0
@@ -89,11 +99,17 @@ packageArgs stage pkgData = do
     keyArgs False = prefixArgs "-package-name"     (PackageKey pkgData) <>
                     prefixArgs "-package"          (Deps       pkgData)
 
-includeArgs :: ShowArgs a => String -> FilePath -> a -> Args
-includeArgs prefix path as = map includePath <$> arg as
-  where
-    includePath dir | isRelative dir = prefix ++ path </> dir
-                    | isAbsolute dir = prefix         </> dir
+includeArgs :: FilePath -> FilePath -> Args
+includeArgs path dist = 
+    let buildDir = path </> dist
+        pkgData  = buildDir </> "package-data.mk"
+    in arg "-i"
+    <> pathArgs "-i" path     (SrcDirs pkgData)
+    <> pathArgs "-i" buildDir ["build", "build/autogen"]
+    <> pathArgs "-I" buildDir ["build", "build/autogen"]
+    <> pathArgs "-I" path     (IncludeDirs pkgData)
+    <> arg "-optP-include" -- TODO: Shall we also add -cpp?
+    <> pathArgs "-optP" buildDir "build/autogen/cabal_macros.h"
 
 srcArgs :: FilePath -> FilePath -> Args
 srcArgs path pkgData = do
diff --git a/src/Package/Compile.hs b/src/Package/Compile.hs
index 0733a46..14296c0 100644
--- a/src/Package/Compile.hs
+++ b/src/Package/Compile.hs
@@ -21,23 +21,15 @@ buildPackageCompile (Package name path _) (stage, dist, settings) =
         need [depFile]
         depContents <- parseMakefile <$> (liftIO $ readFile depFile)
         let deps = concat $ snd $ unzip $ filter ((== out) . fst) depContents
-            srcs = filter ("//*hs" ?==) deps
+            srcs = filter ("//*hs" ?==) deps -- TODO: handle *.c sources
         need deps
         run (Ghc stage) $ suffixArgs way
             <> wayHcArgs way
             <> arg SrcHcOpts
             <> packageArgs stage pkgData
-            <> arg "-i"
-            <> includeArgs "-i" path     (SrcDirs pkgData)
-            <> includeArgs "-i" buildDir ["build", "build/autogen"]
-            <> includeArgs "-I" buildDir ["build", "build/autogen"]
-            <> includeArgs "-I" path     (IncludeDirs pkgData)
-            <> arg "-optP-include" -- TODO: Shall we also add -cpp?
-            <> arg ("-optP" ++ buildDir </> "build/autogen/cabal_macros.h")
+            <> includeArgs path dist
             <> arg ["-Wall", "-XHaskell2010", "-O2"] -- TODO: now we have both -O and -O2
-            <> arg ["-odir"        , buildDir </> "build"]
-            <> arg ["-hidir"       , buildDir </> "build"]
-            <> arg ["-stubdir"     , buildDir </> "build"]
+            <> outputArgs ["-odir", "-hidir", "-stubdir"] (buildDir </> "build")
             <> arg "-split-objs"
             <> arg ("-c":srcs)
             <> arg ["-o", out]
diff --git a/src/Package/Dependencies.hs b/src/Package/Dependencies.hs
index 26b154f..18c2015 100644
--- a/src/Package/Dependencies.hs
+++ b/src/Package/Dependencies.hs
@@ -12,16 +12,9 @@ buildPackageDependencies (Package name path _) (stage, dist, settings) =
         need ["shake/src/Package/Dependencies.hs"] -- Track changes in this file
         run (Ghc stage) $ arg "-M"
             <> packageArgs stage pkgData
-            <> arg "-i"
-            <> includeArgs "-i" path     (SrcDirs pkgData)
-            <> includeArgs "-i" buildDir ["build", "build/autogen"]
-            <> includeArgs "-I" buildDir ["build", "build/autogen"]
-            <> includeArgs "-I" path     (IncludeDirs pkgData)
-            <> arg "-optP-include" -- TODO: Shall we also add -cpp?
-            <> arg ("-optP" ++ buildDir </> "build/autogen/cabal_macros.h")
-            <> arg ["-odir"        , buildDir </> "build"]
-            <> arg ["-stubdir"     , buildDir </> "build"]
-            <> arg ["-dep-makefile", out                 ]
+            <> includeArgs path dist
+            <> outputArgs ["-odir", "-stubdir"] (buildDir </> "build")
+            <> arg ["-dep-makefile", out]
             <> prefixArgs "-dep-suffix" (map suffix <$> ways settings)
             <> srcArgs path pkgData
             -- <> arg SrcHcOpts -- TODO: Check that skipping all _HC_OPTS is safe.



More information about the ghc-commits mailing list