Commit fbe22e6f authored by Andrey Mokhov's avatar Andrey Mokhov

Simplify getSingleton, add comments

parent a0afb987
......@@ -192,8 +192,8 @@ getInputs = asks inputs
getInput :: Expr FilePath
getInput = do
target <- ask
getSingleton getInputs $
"getInput: exactly one input file expected in target " ++ show target
getSingleton ("Exactly one input file expected in " ++ show target)
<$> getInputs
-- | Get the files produced by the current 'Target'.
getOutputs :: Expr [FilePath]
......@@ -203,10 +203,11 @@ getOutputs = asks outputs
getOutput :: Expr FilePath
getOutput = do
target <- ask
getSingleton getOutputs $
"getOutput: exactly one output file expected in target " ++ show target
getSingleton :: Monad m => m [a] -> String -> m a
getSingleton expr msg = expr >>= \case
[res] -> return res
_ -> error msg
getSingleton ("Exactly one output file expected in " ++ show target)
<$> getOutputs
-- | Extract a value from a singleton list, or raise an error if the list does
-- not contain exactly one value.
getSingleton :: String -> [a] -> a
getSingleton _ [res] = res
getSingleton msg _ = error msg
......@@ -81,9 +81,9 @@ gmpRules = do
-- gmp-4.2.4.tar.bz2 repacked without the doc/ directory contents.
-- That's because the doc/ directory contents are under the GFDL,
-- which causes problems for Debian.
let tarballs = gmpBase -/- "tarball/gmp*.tar.bz2"
tarball <- unifyPath <$> getSingleton (getDirectoryFiles "" [tarballs])
"Exactly one GMP tarball is expected."
tarball <- unifyPath . getSingleton "Exactly one GMP tarball is expected"
<$> getDirectoryFiles "" [gmpBase -/- "tarball/gmp*.tar.bz2"]
withTempDir $ \dir -> do
let tmp = unifyPath dir
need [tarball]
......
......@@ -80,9 +80,9 @@ libffiRules = do
libffiMakefile <.> "in" %> \mkIn -> do
removeDirectory libffiBuildPath
createDirectory $ buildRootPath -/- stageString Stage0
let tarballs = "libffi-tarballs/libffi*.tar.gz"
tarball <- unifyPath <$> getSingleton (getDirectoryFiles "" [tarballs])
"Exactly one LibFFI tarball is expected."
tarball <- unifyPath . getSingleton "Exactly one LibFFI tarball is expected"
<$> getDirectoryFiles "" ["libffi-tarballs/libffi*.tar.gz"]
need [tarball]
let libname = dropExtension . dropExtension $ takeFileName tarball
......
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