mach

A work-in-progress implementation of make(1)

git clone https://git.8pit.net/mach.git

 1module Util where
 2
 3import Control.Monad (void)
 4import System.Directory
 5  ( copyFile,
 6    createDirectoryIfMissing,
 7    getTemporaryDirectory,
 8    listDirectory,
 9    removePathForcibly,
10  )
11import System.FilePath (takeFileName, (</>))
12
13-- Path to temporary directory for golden tests.
14getTestDir :: IO FilePath
15getTestDir = do
16  tempDir <- getTemporaryDirectory
17  pure $ tempDir </> "mach-tests"
18
19-- Copy files in skelekton directory to a subdirectory with the
20-- given name in a temporary directory obtained via 'getTestDir'.
21prepTempDir :: String -> FilePath -> IO FilePath
22prepTempDir name skel = do
23  tempDir <- (</> name) <$> getTestDir
24  removePathForcibly tempDir
25    >> createDirectoryIfMissing True tempDir
26
27  -- Copy files from the skeleton dir to the tempDir.
28  -- Only works for regular files, probably doesn't recurse.
29  void $ listDirectory skel >>= mapM (\n -> copyFile (skel </> n) $ tempDir </> takeFileName n)
30
31  pure tempDir