aboutsummaryrefslogtreecommitdiff
path: root/tests/Examples.hs
blob: e1fda9e1c238d8370ff67a00ef4f9196903b995c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
{-# LANGUAGE ScopedTypeVariables #-}

module Main where

import Distribution.Helper
import Data.Foldable
    ( toList )
import System.Process
    ( system )
import System.Environment
    ( getArgs )
import System.Exit
    ( ExitCode(ExitSuccess) )
import System.IO
    ( hPutStrLn, stderr )
import System.Console.GetOpt
    ( OptDescr(Option), ArgDescr(NoArg), ArgOrder(RequireOrder), getOpt
    , usageInfo )

main :: IO ()
main = do
  args <- getArgs
  actions <- parseOpts args
  sequence_ actions

-- | Run shell command and
systemV :: String -> IO ()
systemV shell_cmd = do
  hPutStrLn stderr $ "$ " ++ shell_cmd
  ExitSuccess <- system shell_cmd
  return ()

options :: [OptDescr (IO ())]
options =
 [ Option [] ["cabal"]          (NoArg doCabalV2)     ""
 , Option [] ["cabal-old-v1"]   (NoArg doCabalV1)     ""
 , Option [] ["stack"]          (NoArg doCabalV2)     ""
 ]

parseOpts :: [String] -> IO [IO ()]
parseOpts argv =
   case getOpt RequireOrder options argv of
      (o, [], []  ) ->
          return o
      (_, _, errs) ->
          ioError (userError (concat errs ++ usageInfo header options))
  where header = "Usage: examples (--cabal|--cabal-old-v1|--stack)..."

doCabalV2 :: IO ()
doCabalV2 = do
  _ <- systemV "cabal new-build --builddir=dist-newstyle"
  qe <- mkQueryEnv (ProjLocV2Dir ".") (DistDirCabal SCV2 "dist-newstyle/")
  printUnitInfos qe

doCabalV1 :: IO ()
doCabalV1 = return ()

doStack :: IO ()
doStack = return ()

printUnitInfos :: QueryEnv pt -> IO ()
printUnitInfos qe = do
  components :: [ChComponentInfo]
      <- concat <$> runQuery (allUnits (toList . uiComponents)) qe
  print components