Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Applied HLint suggestions.

  • Loading branch information...
commit 0c64a14d091563406df9716149cf3bef500a5791 1 parent bdeb15e
@willdonnelly authored
View
23 Config/Dyre.hs
@@ -87,6 +87,8 @@ import System.IO ( hPutStrLn, stderr )
import System.Directory ( doesFileExist, removeFile )
import System.Environment ( getArgs )
+import Control.Monad ( when )
+
import Config.Dyre.Params ( Params(..) )
import Config.Dyre.Compile ( customCompile, getErrorPath, getErrorString )
import Config.Dyre.Compat ( customExec )
@@ -114,7 +116,7 @@ defaultParams = Params
-- entry point, which will then be called by the 'main' function, as well
-- as by any custom configurations.
wrapMain :: Params cfgType -> cfgType -> IO ()
-wrapMain params@Params{projectName = pName} cfg = withDyreOptions params $ do
+wrapMain params@Params{projectName = pName} cfg = withDyreOptions params $
-- Allow the 'configCheck' parameter to disable all of Dyre's recompilation
-- checks, in favor of simply proceeding ahead to the 'realMain' function.
if not $ configCheck params
@@ -127,18 +129,20 @@ wrapMain params@Params{projectName = pName} cfg = withDyreOptions params $ do
thisTime <- maybeModTime thisBinary
tempTime <- maybeModTime tempBinary
confTime <- maybeModTime configFile
-
let confExists = confTime /= Nothing
- -- If there's a config file, and the temp binary is older than something
- -- else, or we were specially told to recompile, then we should recompile.
denyReconf <- getDenyReconf
forceReconf <- getForceReconf
+ -- Either the user or timestamps indicate we need to recompile
+ let needReconf = or [ tempTime < confTime
+ , tempTime < thisTime
+ , forceReconf
+ ]
- if not denyReconf && confExists &&
- (tempTime < confTime || tempTime < thisTime || forceReconf)
- then customCompile params
- else return ()
+ -- If we're allowed to reconfigure, a configuration exists, and
+ -- we detect a need to recompile it, then go ahead and compile.
+ when (not denyReconf && confExists && needReconf)
+ (customCompile params)
-- If there's a custom binary and we're not it, run it. Otherwise
-- just launch the main function, reporting errors if appropriate.
@@ -165,7 +169,6 @@ wrapMain params@Params{projectName = pName} cfg = withDyreOptions params $ do
-- Remove the error file if it exists
errorFile <- getErrorPath params
errorExists <- doesFileExist errorFile
- if errorExists then removeFile errorFile
- else return ()
+ when errorExists $ removeFile errorFile
-- Enter the main program
realMain params mainConfig
View
7 Config/Dyre/Compat.hs
@@ -1,5 +1,8 @@
{-# LANGUAGE CPP #-}
+
+#if defined(mingw32_HOST_OS) || defined(__MINGW32__)
{-# LANGUAGE ForeignFunctionInterface #-}
+#endif
{- |
Compatibility code for things that need to be done differently
@@ -54,8 +57,8 @@ foreign import stdcall unsafe "winbase.h ExitProcess"
#else
-import System.Posix.Process ( executeFile, getProcessID )
-import System.Posix.Process ( forkProcess, exitImmediately, getProcessStatus, ProcessStatus(..) )
+import System.Posix.Process ( executeFile, getProcessID, exitImmediately
+ , forkProcess, getProcessStatus, ProcessStatus(..) )
import System.Posix.Signals ( raiseSignal, sigTSTP )
import System.Exit ( ExitCode(..) )
View
8 Config/Dyre/Compile.hs
@@ -53,8 +53,8 @@ customCompile params@Params{statusOut = output} = do
-- Display a helpful little status message
if result /= ExitSuccess
- then output $ "Error occurred while loading configuration file."
- else output $ "Program reconfiguration successful."
+ then output "Error occurred while loading configuration file."
+ else output "Program reconfiguration successful."
-- | Assemble the arguments to GHC so everything compiles right.
makeFlags :: Params cfgType -> FilePath -> FilePath -> FilePath -> IO [String]
@@ -65,6 +65,6 @@ makeFlags Params{ghcOpts = flags, hidePackages = hides, forceRecomp = force}
, ["-outputdir", cacheDir]
, prefix "-hide-package" hides, flags
, ["--make", cfgFile, "-o", tmpFile]
- , if force then ["-fforce-recomp"] else []
+ , ["-fforce-recomp" | force] -- Only if force is true
]
- where prefix y xs = concat . map (\x -> [y,x]) $ xs
+ where prefix y = concatMap $ \x -> [y,x]
View
2  Config/Dyre/Options.hs
@@ -111,7 +111,7 @@ customOptions otherArgs = do
, case stateFile of
Nothing -> ""
Just sf -> "--dyre-state-persist=" ++ sf
- , "--dyre-master-binary=" ++ (fromJust masterPath)
+ , "--dyre-master-binary=" ++ fromJust masterPath
]
return args
View
4 Config/Dyre/Paths.hs
@@ -22,12 +22,12 @@ getPaths params@Params{projectName = pName} = do
(False, Nothing) -> getUserCacheDir pName
(False, Just cd) -> cd
configDir <- case (debugMode, configDir params) of
- (True, _ ) -> return $ cwd
+ (True, _ ) -> return cwd
(False, Nothing) -> getUserConfigDir pName
(False, Just cd) -> cd
let tempBinary = cacheDir </> pName ++ "-" ++ os ++ "-" ++ arch
let configFile = configDir </> pName ++ ".hs"
- return $ (thisBinary, tempBinary, configFile, cacheDir)
+ return (thisBinary, tempBinary, configFile, cacheDir)
-- | Check if a file exists. If it exists, return Just the modification
-- time. If it doesn't exist, return Nothing.
View
15 Tests/basic/BasicTest.hs
@@ -3,6 +3,7 @@ module BasicTest where
import qualified Config.Dyre as Dyre
import Config.Dyre.Relaunch
+import Control.Monad
import System.IO
data Config = Config { message :: String, errorMsg :: Maybe String }
@@ -13,15 +14,11 @@ defaultConfig = Config "Basic Test Version 1.0" Nothing
showError :: Config -> String -> Config
showError cfg msg = cfg { errorMsg = Just msg }
-realMain Config{message = message, errorMsg = errorMsg } = do
- case errorMsg of
- Just em -> putStrLn "Compile Error"
- Nothing -> do
- state <- restoreTextState 1
- if state < 3
- then relaunchWithTextState (state + 1) Nothing
- else return ()
- putStrLn $ message ++ " - " ++ show state
+realMain (Config message (Just err)) = putStrLn "Compile Error"
+realMain (Config message Nothing) = do
+ state <- restoreTextState 1
+ when (state < 3) $ relaunchWithTextState (state + 1) Nothing
+ putStrLn $ message ++ " - " ++ show state
basicTest = Dyre.wrapMain $ Dyre.defaultParams
{ Dyre.projectName = "basicTest"
View
2  Tests/basic/badConfig.hs
@@ -1,2 +1,2 @@
import BasicTest
-main = basicTest $ defaultConfig { message = "Basic Test Version 3.0 }
+main = basicTest $ defaultConfig { massage = "Basic Test Version 3.0" }
Please sign in to comment.
Something went wrong with that request. Please try again.