diff --git a/src/GitRunner.hs b/src/GitRunner.hs index 02a8320..3b6e8e7 100644 --- a/src/GitRunner.hs +++ b/src/GitRunner.hs @@ -19,15 +19,12 @@ data GitCommand = GitRevisionInfoCmd gitCommandArgs :: GitCommand -> [String] gitCommandArgs GitUpdateIndexCmd = ["update-index", "-q", "--refresh"] gitCommandArgs GitDiffIndexNamesCmd = ["diff-index", "--name-only", "HEAD", "--"] -gitCommandArgs GitRevisionInfoCmd = ["describe", "--tags"] +gitCommandArgs GitRevisionInfoCmd = ["describe", "--tags", "--dirty"] buildGitRevisionString :: GitRepo -> IO String buildGitRevisionString repo = do - isDirty <- gitIsDirtyTree repo (_, revStr) <- runGit repo GitRevisionInfoCmd - if isDirty - then return $ revStr ++ "-dirty" - else return revStr + return revStr gitIsDirtyTree :: GitRepo -> IO Bool gitIsDirtyTree repo = do @@ -36,6 +33,10 @@ gitIsDirtyTree repo = do let changedFiles = length output return $ changedFiles > 0 +concatenateArgs :: [String] -> String +concatenateArgs [] = [] +concatenateArgs (x:xs) = x ++ " " ++ concatenateArgs xs + runGit :: GitRepo -> GitCommand -> IO (ExitCode, String) runGit repo command = do let gitArgs = gitCommandArgs command @@ -53,5 +54,5 @@ runGit repo command = do return (ExitSuccess, trimmedOutput) (ExitFailure errorCode) -> do gitErrorStr <- hGetContents gitErrorStream - let msg = "Git failed with code " ++ (show errorCode) ++ " and message:\n" ++ gitErrorStr + let msg = "`git " ++ (concatenateArgs gitArgs) ++ "` failed with code " ++ (show errorCode) ++ " and message:\n" ++ gitErrorStr return (exitCode, msg) diff --git a/src/SedRunner.hs b/src/SedRunner.hs index 62270f5..2863969 100644 --- a/src/SedRunner.hs +++ b/src/SedRunner.hs @@ -15,27 +15,24 @@ data SedCommand = SedIntToG4Int | SedCommentIncludeCassert | SedFixG4G4 | SedFixUnsignedG4Int - | SedFixG4boolalpha deriving (Show, Eq) --toG4TypeRegexp t = ["\\'s/\\b\\(" ++ t ++"\\)\\b/G4\\1/g\'"] toG4TypeRegexp :: String -> [String] -toG4TypeRegexp t = ["s/" ++ t ++ "/G4" ++ t ++ "/g"] +toG4TypeRegexp t = ["s/\\(\\b\\)" ++ t ++ "\\(\\b\\)/\\1G4" ++ t ++ "\\2/g"] --let substitute x y s = subRegex (mkRegex x) s y -- substitute "int" "G4int" sedCommandArgs :: SedCommand -> [String] -sedCommandArgs SedIntToG4Int = ["s/int/G4int/g"] ---sedCommandArgs SedIntToG4Int = toG4TypeRegexp "int" +sedCommandArgs SedIntToG4Int = toG4TypeRegexp "int" sedCommandArgs SedFloatToG4Float = toG4TypeRegexp "float" sedCommandArgs SedDoubleToG4Double = toG4TypeRegexp "double" sedCommandArgs SedBoolToG4Bool = toG4TypeRegexp "bool" -sedCommandArgs SedCommentAsserts = ["s/^ *assert/\\/\\/ assert/g"] +sedCommandArgs SedCommentAsserts = ["s/^\\s*assert/\\/\\/ assert/g"] sedCommandArgs SedCommentIncludeCassert = ["s/#include \\+/\\/\\/ #include /g"] sedCommandArgs SedFixG4G4 = ["s/G4G4/G4/g"] sedCommandArgs SedFixUnsignedG4Int = ["s/unsigned\\ G4int/unsigned\\ int/g"] -sedCommandArgs SedFixG4boolalpha = ["s/G4boolalpha/boolalpha/g"] useG4Int :: String -> IO String useG4Int = runSed SedIntToG4Int @@ -64,13 +61,10 @@ fixG4G4 = runSed SedFixG4G4 fixUnsignedG4int :: String -> IO String fixUnsignedG4int = runSed SedFixUnsignedG4Int -fixG4boolalpha :: String -> IO String -fixG4boolalpha = runSed SedFixG4boolalpha - -- Chain the useG4 functions together. useG4Types :: String -> IO String --useG4Types code = (useG4Int code) -useG4Types code = (useG4Int code) >>= useG4Float >>= useG4Double >>= useG4Bool >>= fixG4G4 >>= fixUnsignedG4int >>= fixG4boolalpha +useG4Types code = (useG4Int code) >>= useG4Float >>= useG4Double >>= useG4Bool >>= fixG4G4 >>= fixUnsignedG4int runSed :: SedCommand -> String -> IO String runSed command inputData = do