Skip to content

Instantly share code, notes, and snippets.

@JustusAdam
Created August 27, 2020 20:13
Show Gist options
  • Save JustusAdam/5904249d909e975edb612e5eea581ba1 to your computer and use it in GitHub Desktop.
Save JustusAdam/5904249d909e975edb612e5eea581ba1 to your computer and use it in GitHub Desktop.
Copy data files from installed Haskell libraries
{-# 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