[commit: ghc] wip/nfs-locking: Get rid of partial functions. (a7adf8c)

git at git.haskell.org git at git.haskell.org
Fri Oct 27 00:28:42 UTC 2017


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

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

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

commit a7adf8c5b2719aed8c17b029a74ebc190360df28
Author: Andrey Mokhov <andrey.mokhov at gmail.com>
Date:   Thu May 5 03:13:49 2016 +0100

    Get rid of partial functions.


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

a7adf8c5b2719aed8c17b029a74ebc190360df28
 src/Rules/Gmp.hs | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/src/Rules/Gmp.hs b/src/Rules/Gmp.hs
index cceda8e..d98bc3b 100644
--- a/src/Rules/Gmp.hs
+++ b/src/Rules/Gmp.hs
@@ -71,14 +71,15 @@ gmpRules = do
             -- That's because the doc/ directory contents are under the GFDL,
             -- which causes problems for Debian.
             tarballs <- getDirectoryFiles "" [gmpBase -/- "tarball/gmp*.tar.bz2"]
-            when (length tarballs /= 1) $
-                putError $ "gmpRules: exactly one tarball expected"
-                         ++ "(found: " ++ show tarballs ++ ")."
+            tarball  <- case tarballs of
+                [file] -> return $ unifyPath file
+                _      -> putError $ "gmpRules: exactly one tarball expected"
+                          ++ "(found: " ++ show tarballs ++ ")."
 
-            need tarballs
             withTempDir $ \dir -> do
                 let tmp = unifyPath dir
-                build $ Target gmpContext Tar tarballs [tmp]
+                need [tarball]
+                build $ Target gmpContext Tar [tarball] [tmp]
 
                 forM_ gmpPatches $ \src -> do
                     let patch     = takeFileName src
@@ -86,13 +87,11 @@ gmpRules = do
                     copyFile src patchPath
                     applyPatch tmp patch
 
-                let filename = dropExtension . dropExtension . takeFileName
-                             $ head tarballs
-                    suffix   = "-nodoc-patched"
-                unless (suffix `isSuffixOf` filename) $
-                    putError $ "gmpRules: expected suffix " ++ suffix
-                        ++ " (found: " ++ filename ++ ")."
-                let libName = take (length filename - length suffix) filename
+                let name = dropExtension . dropExtension $ takeFileName tarball
+                libName <- case stripSuffix "-nodoc-patched" name of
+                    Just rest -> return rest
+                    Nothing   -> putError $ "gmpRules: expected suffix "
+                        ++ "-nodoc-patched (found: " ++ name ++ ")."
 
                 moveDirectory (tmp -/- libName) gmpBuildPath
 



More information about the ghc-commits mailing list