From fd04ebfe1112acfa019feaf321a12387b0a9b6a5 Mon Sep 17 00:00:00 2001 From: Kazu Yamamoto Date: Fri, 12 Mar 2010 00:20:02 +0900 Subject: [PATCH] output-dir. --- Check.hs | 19 ++++++++++++++++++- GHCMod.hs | 4 ++++ Param.hs | 1 + elisp/ghc-flymake.el | 22 +++++++++++++++------- 4 files changed, 38 insertions(+), 8 deletions(-) diff --git a/Check.hs b/Check.hs index 308551f..875040a 100644 --- a/Check.hs +++ b/Check.hs @@ -1,9 +1,12 @@ module Check (checkSyntax) where import Control.Applicative +import Control.Monad import Data.Char import Data.List import Param +import System.Directory +import System.FilePath import System.IO import System.Process @@ -11,7 +14,8 @@ import System.Process checkSyntax :: Options -> String -> IO String checkSyntax opt file = do - (_,_,herr,_) <- runInteractiveProcess (ghc opt) ["--make","-Wall",file] Nothing Nothing + makeDirectory (outDir opt) + (_,_,herr,_) <- runInteractiveProcess (ghc opt) ["--make","-Wall",file,"-outputdir","dist/flymake","-o","dist/flymake/a.out"] Nothing Nothing refine <$> hGetContents herr where refine = unfoldLines start . map (dropWhile isSpace) . filter (/="") . lines @@ -25,3 +29,16 @@ unfoldLines p (x:xs) = x ++ unfold xs unfold (l:ls) | p l = ('\n':l) ++ unfold ls | otherwise = (' ' :l) ++ unfold ls + +---------------------------------------------------------------- + +makeDirectory :: FilePath -> IO () +makeDirectory dir = makeDirectoryRecur $ normalise dir + where + makeDirectoryRecur "" = return () + makeDirectoryRecur cur = do + exist <- doesDirectoryExist cur + let par = takeDirectory cur + unless exist $ do + makeDirectoryRecur par + createDirectory cur diff --git a/GHCMod.hs b/GHCMod.hs index 5a08332..8bfcc19 100644 --- a/GHCMod.hs +++ b/GHCMod.hs @@ -27,6 +27,7 @@ defaultOptions = Options { convert = toPlain , ghc = "ghc" , ghci = "ghci" , ghcPkg = "ghc-pkg" + , outDir = "dist/flymake" } argspec :: [OptDescr (Options -> Options)] @@ -42,6 +43,9 @@ argspec = [ Option ['l'] ["tolisp"] , Option ['p'] ["ghc-pkg"] (ReqArg (\str opts -> opts { ghcPkg = str }) "ghc-pkg") "ghc-pkg path" + , Option ['o'] ["output-dir"] + (ReqArg (\str opts -> opts { outDir = str }) "dist/flymake") + "output directory" ] parseArgs :: [OptDescr (Options -> Options)] -> [String] -> (Options, [String]) diff --git a/Param.hs b/Param.hs index 01057ed..f666b6a 100644 --- a/Param.hs +++ b/Param.hs @@ -4,5 +4,6 @@ data Options = Options { convert :: [String] -> String , ghc :: FilePath , ghci :: FilePath , ghcPkg :: FilePath + , outDir :: FilePath } diff --git a/elisp/ghc-flymake.el b/elisp/ghc-flymake.el index c6d78d3..5a2fa4e 100644 --- a/elisp/ghc-flymake.el +++ b/elisp/ghc-flymake.el @@ -13,12 +13,20 @@ ghc-flymake-err-line-patterns) (defun ghc-flymake-init () - (let* ((temp-file (flymake-init-create-temp-buffer-copy - 'flymake-create-temp-inplace)) - (local-file (file-relative-name - temp-file - (file-name-directory buffer-file-name)))) - (list "ghc-mod" (append (ghc-module-command-args) - (list "check" local-file))))) + (let ((file (file-name-nondirectory (buffer-file-name)))) + (flymake-init-create-temp-buffer-copy 'flymake-create-temp-inplace) + (list ghc-module-command (append (ghc-module-command-args) + (list "check" file))))) + +;; ghc --make GHCMod.hs -outputdir dist/flymake -o dist/flymake/GHCMod + +;; (defun ghc-flymake-init () +;; (let* ((temp-file (flymake-init-create-temp-buffer-copy +;; 'flymake-create-temp-inplace)) +;; (local-file (file-relative-name +;; temp-file +;; (file-name-directory buffer-file-name)))) +;; (list ghc-module-command (append (ghc-module-command-args) +;; (list "check" local-file))))) (provide 'ghc-flymake) \ No newline at end of file