[commit: ghc] wip/nfs-locking: Refactor libffi build rule (c391842)

git at git.haskell.org git at git.haskell.org
Fri Oct 27 01:10:01 UTC 2017


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

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

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

commit c3918421098ab7da0d6c62689ccfbe37abe26b24
Author: Andrey Mokhov <andrey.mokhov at gmail.com>
Date:   Mon Oct 3 18:22:48 2016 +0100

    Refactor libffi build rule
    
    See #289


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

c3918421098ab7da0d6c62689ccfbe37abe26b24
 src/Rules/Libffi.hs | 79 ++++++++++++++++++++++++++---------------------------
 1 file changed, 39 insertions(+), 40 deletions(-)

diff --git a/src/Rules/Libffi.hs b/src/Rules/Libffi.hs
index 4434f50..5ca17ea 100644
--- a/src/Rules/Libffi.hs
+++ b/src/Rules/Libffi.hs
@@ -6,6 +6,7 @@ import Expression
 import GHC
 import Oracles.Config.Flag
 import Oracles.Config.Setting
+import Oracles.WindowsPath
 import Rules.Actions
 import Settings.Builders.Common
 import Settings.Packages.Rts
@@ -30,11 +31,11 @@ libffiLibrary = libffiBuildPath -/- "inst/lib/libffi.a"
 libffiMakefile :: FilePath
 libffiMakefile = libffiBuildPath -/- "Makefile"
 
-fixLibffiMakefile :: String -> String
-fixLibffiMakefile =
+fixLibffiMakefile :: FilePath -> String -> String
+fixLibffiMakefile top =
       replace "-MD" "-MMD"
     . replace "@toolexeclibdir@" "$(libdir)"
-    . replace "@INSTALL@" "$(subst ../install-sh,C:/msys/home/chEEtah/ghc/install-sh, at INSTALL@)"
+    . replace "@INSTALL@" ("$(subst ../install-sh," ++ top ++ "/install-sh, at INSTALL@)")
 
 -- TODO: remove code duplication (see Settings/Builders/GhcCabal.hs)
 -- TODO: check code duplication w.r.t. ConfCcArgs
@@ -53,12 +54,9 @@ configureEnvironment = do
              , return . AddEnv  "CFLAGS" $ unwords  cFlags ++ " -w"
              , return . AddEnv "LDFLAGS" $ unwords ldFlags ++ " -w" ]
 
--- TODO: remove code duplication (need sourcePath)
--- TODO: split into multiple rules
 libffiRules :: Rules ()
 libffiRules = do
     libffiDependencies &%> \_ -> do
-        need [sourcePath -/- "Rules/Libffi.hs"]
         useSystemFfi <- flag UseSystemFfi
         if useSystemFfi
         then do
@@ -68,44 +66,45 @@ libffiRules = do
                 copyFile (ffiIncludeDir -/- file) (rtsBuildPath -/- file)
             putSuccess $ "| Successfully copied system FFI library header files"
         else do
-            removeDirectory libffiBuildPath
-            createDirectory $ buildRootPath -/- stageString Stage0
-
-            tarballs <- getDirectoryFiles "" ["libffi-tarballs/libffi*.tar.gz"]
-            tarball  <- case tarballs of -- TODO: Drop code duplication.
-                [file] -> return $ unifyPath file
-                _      -> error $ "libffiRules: exactly one tarball expected"
-                          ++ "(found: " ++ show tarballs ++ ")."
-
-            need [tarball]
-            let libname = dropExtension . dropExtension $ takeFileName tarball
-
-            removeDirectory (buildRootPath -/- libname)
-            -- TODO: Simplify.
-            actionFinally (do
-                build $ Target libffiContext Tar [tarball] [buildRootPath]
-                moveDirectory (buildRootPath -/- libname) libffiBuildPath) $
-                    removeFiles buildRootPath [libname <//> "*"]
-
-            fixFile (libffiMakefile <.> "in") fixLibffiMakefile
-
-            forM_ ["config.guess", "config.sub"] $ \file ->
-                copyFile file (libffiBuildPath -/- file)
-
-            env <- configureEnvironment
-            buildWithCmdOptions env $
-                Target libffiContext (Configure libffiBuildPath)
-                       [libffiMakefile <.> "in"] [libffiMakefile]
-
-            -- The old build system did runMake libffiBuildPath ["MAKEFLAGS="]
-            -- TODO: Find out why. It seems redundant, so I removed it.
             build $ Target libffiContext (Make libffiBuildPath) [] []
 
-            let ffiHDir = libffiBuildPath -/- "inst/lib" -/- libname -/- "include"
-            forM_ ["ffi.h", "ffitarget.h"] $ \file -> do
-                copyFile (ffiHDir -/- file) (rtsBuildPath -/- file)
+            hs <- getDirectoryFiles "" [libffiBuildPath -/- "inst/lib/*/include/*"]
+            forM_ hs $ \header ->
+                copyFile header (rtsBuildPath -/- takeFileName header)
 
             libffiName <- rtsLibffiLibraryName
             copyFile libffiLibrary (rtsBuildPath -/- "lib" ++ libffiName <.> "a")
 
             putSuccess $ "| Successfully built custom library 'libffi'"
+
+    libffiMakefile <.> "in" %> \mkIn -> do
+        removeDirectory libffiBuildPath
+        createDirectory $ buildRootPath -/- stageString Stage0
+
+        tarballs <- getDirectoryFiles "" ["libffi-tarballs/libffi*.tar.gz"]
+        tarball  <- case tarballs of -- TODO: Drop code duplication.
+            [file] -> return $ unifyPath file
+            _      -> error $ "libffiRules: exactly one tarball expected"
+                      ++ "(found: " ++ show tarballs ++ ")."
+
+        need [tarball]
+        let libname = dropExtension . dropExtension $ takeFileName tarball
+
+        removeDirectory (buildRootPath -/- libname)
+        -- TODO: Simplify.
+        actionFinally (do
+            build $ Target libffiContext Tar [tarball] [buildRootPath]
+            moveDirectory (buildRootPath -/- libname) libffiBuildPath) $
+                removeFiles buildRootPath [libname <//> "*"]
+
+        top <- topDirectory
+        fixFile mkIn (fixLibffiMakefile top)
+
+    libffiMakefile %> \mk -> do
+        need [mk <.> "in"]
+        forM_ ["config.guess", "config.sub"] $ \file ->
+            copyFile file (libffiBuildPath -/- file)
+
+        env <- configureEnvironment
+        buildWithCmdOptions env $
+            Target libffiContext (Configure libffiBuildPath) [mk <.> "in"] [mk]



More information about the ghc-commits mailing list