packages feed

seqaid-0.1.5: Seqaid/Demo.hs

  {-# LANGUAGE CPP #-}

-- |
-- Module      :  Seqaid.Demo
-- Copyright   :  (c) 2014, Andrew G. Seniuk
-- License     :  BSD-style (see the file LICENSE)
--
-- Maintainer  :  Andrew Seniuk <rasfar@gmail.com>
-- Stability   :  provisional
-- Portability :  POSIX, Cabal
--
-- Instrument a sample program (package
-- <http://hackage.haskell.org/package/leaky leaky>)
-- with dynamic forcing functions.  Refer to
-- <http://hackage.haskell.org/package/deepseq-bounded deepseq-bounded>
-- for more information about this methodology.

  module Main ( main ) where
--module Seqaid.Demo ( main ) where

  import System.Environment ( getArgs )
  import System.IO.Temp
  import System.Directory
  import System.Process
  import System.Exit

  leaky_version = "0.1.0.5"  -- XXX need a better way!!....

  main :: IO ExitCode
  main = do
            args <- getArgs
            if args /= ["demo"]
            then do
              putStrLn "seqaid: \"seqaid demo\" is the only supported invocation at this time."
              return $ ExitFailure 1
            else do
              tdir <- createTempDirectory "." "leaky_"
-- XXX Note that "cabal get" already extracts the tarball for you.
#if IS_WINDOWS
              let bang_lines = ""
#else
              let bang_lines = "#!/bin/bash\nset -e\n"
#endif
              let seqaid_init_bash = bang_lines ++ "\
\cabal get leaky-" ++ leaky_version ++ "\n\
\cd leaky-" ++ leaky_version ++ "\n\
\cabal configure\n\
\cabal build\n\
\cabal run 123\n\
\echo\n\
\echo \"(Please see " ++ tdir ++ "/leaky-" ++ leaky_version ++ "/README for the interpretation.)\"\n\
\echo\n"
              setCurrentDirectory tdir
              writeFile "seqaidinit.sh" seqaid_init_bash
              p <- getPermissions "seqaidinit.sh"
              setPermissions "seqaidinit.sh" (p { executable = True })
              st <- system "./seqaidinit.sh"
              case st of
                ExitSuccess -> return ExitSuccess
                ExitFailure n -> do
                  putStrLn $ "Sorry, seqaid demo had a problem (status=" ++ show st ++ ").\nPlease report this bug to rasfar@gmail.com"
                  return $ ExitFailure 2
                _ -> error $ "unexpected ExitCode = " ++ show st ++ "\nPlease report this bug to rasfar@gmail.com"