output-dir.

This commit is contained in:
Kazu Yamamoto 2010-03-12 00:20:02 +09:00
parent 133086e1a8
commit fd04ebfe11
4 changed files with 38 additions and 8 deletions

View File

@ -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

View File

@ -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])

View File

@ -4,5 +4,6 @@ data Options = Options { convert :: [String] -> String
, ghc :: FilePath
, ghci :: FilePath
, ghcPkg :: FilePath
, outDir :: FilePath
}

View File

@ -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)