Browse files

Added ability to use local run configurations

  • Loading branch information...
1 parent 12882e8 commit 031c2662ea32259df9ccd1ae16b848dc0ccb41db @dmpots committed Aug 4, 2010
View
47 Setup.hs
@@ -1,3 +1,48 @@
#!/usr/bin/env runhaskell
import Distribution.Simple
-main = defaultMain
+import Control.Monad
+import Data.List
+import System.Directory
+import System.FilePath
+import System.IO
+
+main = defaultMainWithHooks simpleUserHooks {postConf = writeLocalConf, postClean = deleteLocalConf}
+
+writeLocalConf _ _ _ _ = do
+ findLocalConfigModules
+
+deleteLocalConf _ _ _ _ = do
+ safeDelete importsFileName
+ safeDelete modulesFileName
+
+safeDelete :: FilePath -> IO ()
+safeDelete f = do
+ e <- doesFileExist f
+ when e (removeFile f)
+
+findLocalConfigModules :: IO ()
+findLocalConfigModules = do
+ fs <- getDirectoryContents configDir
+ putStr "\nLooking for local configuration modules... "
+ let modNames = map dropExtension $ filter (".hs" `isSuffixOf`) fs
+ let imports = map importStmt $ modNames
+ let modules = map importAs $ modNames
+ putStrLn $ "found ("++ (show.length$ modNames)++")"
+ writeToFile importsFileName imports
+ writeToFile modulesFileName modules
+ where
+ importStmt m = "import qualified "++m++" as " ++importAs m
+ writeToFile fName contents = do
+ h <- openFile fName WriteMode
+ putStrLn $ "writing " ++ fName
+ putStrLn $ unlines contents
+ hPutStr h (unlines contents)
+ hClose h
+
+importAs :: String -> String
+importAs modName = modName++"_Config"
+
+importsFileName, modulesFileName :: FilePath
+configDir = "config"
+importsFileName = configDir </> "LocalConfigImports.txt"
+modulesFileName = configDir </> "LocalConfigModules.txt"
View
4 fibon.cabal
@@ -9,7 +9,7 @@ Author: David M Peixotto
Maintainer: dmp@rice.edu
Stability: Experimental
Category: Testing
-Build-type: Simple
+Build-type: Custom
-- Extra files to be distributed with the package, such as examples or
-- a README.
@@ -29,6 +29,7 @@ Cabal-version: >=1.2
Executable fibon-run
main-is: Fibon/Run/Main.hs
ghc-options: -Wall
+ include-dirs: config
hs-source-dirs: tools/fibon-run
lib
benchmarks
@@ -42,6 +43,7 @@ Executable fibon-run
, hslogger == 1.0.*
, process == 1.0.*
, time == 1.1.*
+ , template-haskell == 2.4.*
, criterion == 0.5.*
, statistics == 0.6.*
View
18 tools/fibon-run/Fibon/Run/Config.hs
@@ -1,4 +1,20 @@
-module Fibon.Run.Config where
+module Fibon.Run.Config (
+ Fibon.ConfigMonad.append
+ , Fibon.ConfigMonad.done
+ , Fibon.ConfigMonad.ConfigParameter(..)
+ , Fibon.Benchmarks.FibonGroup(..)
+ , Fibon.Benchmarks.FibonBenchmark(..)
+ , Fibon.InputSize.InputSize(..)
+ , RunConfig(..)
+ , TuneSetting(..)
+ , TuneSelection(..)
+ , BenchmarkRunSelection(..)
+ , BenchmarkConfigSelection(..)
+ , FlagBuilder
+ , ConfigId
+ , mkFlagConfig
+)
+where
import Fibon.Benchmarks
import Fibon.BenchmarkInstance
import Fibon.InputSize
View
3 tools/fibon-run/Fibon/Run/Config/Default.hs
@@ -3,9 +3,6 @@ module Fibon.Run.Config.Default (
)
where
import Fibon.Run.Config
-import Fibon.Benchmarks
-import Fibon.InputSize
-import Fibon.ConfigMonad
config :: RunConfig
config = RunConfig {
View
16 tools/fibon-run/Fibon/Run/Config/Local.hs
@@ -0,0 +1,16 @@
+{-# LANGUAGE TemplateHaskell, CPP #-}
+module Fibon.Run.Config.Local(
+ configs
+)
+where
+
+import Fibon.Run.Config
+import Fibon.Run.Config.LocalConfigFinder as LocalConfigFinder
+
+#include "LocalConfigImports.txt"
+
+configs :: [(ConfigId, RunConfig)]
+configs = map (\x -> (configId x,x)) ms
+ where
+ ms = $(findLocalConfigModules "config")
+
View
26 tools/fibon-run/Fibon/Run/Config/LocalConfigFinder.hs
@@ -0,0 +1,26 @@
+{-# LANGUAGE TemplateHaskell #-}
+module Fibon.Run.Config.LocalConfigFinder (
+ findLocalConfigModules
+)
+where
+
+import Data.List
+import Language.Haskell.TH
+import System.Directory
+import System.FilePath
+import System.IO
+
+modulesFileName :: FilePath
+modulesFileName = "LocalConfigModules.txt"
+
+readLocalConfigModules :: FilePath -> IO [String]
+readLocalConfigModules baseDir = do
+ ms <- readFile (baseDir </> modulesFileName)
+ return (lines ms)
+ where
+
+findLocalConfigModules :: FilePath -> Q Exp
+findLocalConfigModules baseDir = do
+ ms <- runIO $ readLocalConfigModules baseDir
+ return $ ListE $ map (\m -> (VarE . mkName) (m ++ ".config")) ms
+
View
12 tools/fibon-run/Fibon/Run/Main.hs
@@ -6,10 +6,11 @@ import Control.Monad
import Control.Exception
import Data.Char
import Data.List
---import qualified Data.Map as Map
+import qualified Data.Map as Map
import Fibon.Benchmarks
import Fibon.Run.Config.Default as DefaultConfig
import Fibon.Run.Config
+import Fibon.Run.Config.Local as Local
import Fibon.Run.Actions
import Fibon.Run.BenchmarkBundle
import Fibon.Run.Log as Log
@@ -53,15 +54,12 @@ runAndReport bundle = do
defaultConfig :: RunConfig
-defaultConfig =
- DefaultConfig.config
+defaultConfig = snd . head $ Map.toList availableConfigs
-{-
availableConfigs :: Map.Map ConfigId RunConfig
-availableConfigs = Map.singleton (configId c) c
+availableConfigs = Map.fromList $ (configId def, def) : Local.configs
where
- c = DefaultConfig.config
--}
+ def = DefaultConfig.config
makeBundles :: RunConfig
-> FilePath -- ^ Working directory

0 comments on commit 031c266

Please sign in to comment.