Created
August 27, 2020 20:13
-
-
Save JustusAdam/5904249d909e975edb612e5eea581ba1 to your computer and use it in GitHub Desktop.
Copy data files from installed Haskell libraries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE LambdaCase #-} | |
import System.Directory | |
import System.FilePath | |
import System.Process | |
import Data.List | |
import System.Environment | |
import GHC.Stack | |
import Control.Monad | |
import System.IO.Unsafe | |
mustBeOne :: (HasCallStack, Show a) => [a] -> a | |
mustBeOne = \case | |
[one] -> one | |
[] -> error "Expected one element, got 0" | |
other -> error $ "Expected one element, got " ++ show (length other) ++ ": " ++ show other | |
main = do | |
packages <- getArgs | |
dir <- getEnv "DIR" | |
forM_ packages $ \package -> do | |
dataDir <- drop (length "data-dir: ") . head . lines <$> readProcess "stack" ["exec", "--", "ghc-pkg", "field", package, "data-dir"] "" | |
let targetDir = dir </> "vendor-data" | |
createDirectoryIfMissing True targetDir | |
callProcess "cp" ["-R", dataDir, targetDir </> package] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment