packages feed

buildwrapper 0.2 → 0.2.1

raw patch · 9 files changed

+165/−33 lines, 9 filessetup-changed

Files

Setup.hs view
@@ -1,4 +1,4 @@-#!/usr/bin/env runhaskell-import Distribution.Simple-main :: IO ()+#!/usr/bin/env runhaskell
+import Distribution.Simple
+main :: IO ()
 main = defaultMain
buildwrapper.cabal view
@@ -1,5 +1,5 @@ name:           buildwrapper
-version:        0.2
+version:        0.2.1
 cabal-version:  >= 1.8
 build-type:     Simple
 license:        BSD3
@@ -17,12 +17,36 @@ 
 library
   hs-source-dirs:  src
-  build-depends:   base < 5 , filepath, mtl, directory, Cabal, process, regex-tdfa, ghc, ghc-paths, syb, ghc-syb-utils, 
-                   text, containers, vector, haskell-src-exts, cpphs, old-time, aeson-native
+  build-depends:   
+                   base < 5,
+                   filepath,
+                   mtl,
+                   directory,
+                   Cabal,
+                   process,
+                   regex-tdfa,
+                   ghc,
+                   ghc-paths,
+                   syb,
+                   ghc-syb-utils,
+                   text,
+                   containers,
+                   vector,
+                   haskell-src-exts,
+                   cpphs,
+                   old-time,
+                   aeson-native
   ghc-options:     -Wall -fno-warn-unused-do-bind
-  exposed-modules: Language.Haskell.BuildWrapper.API,Language.Haskell.BuildWrapper.Base,Language.Haskell.BuildWrapper.Cabal
+  exposed-modules: 
+                   Language.Haskell.BuildWrapper.API,
+                   Language.Haskell.BuildWrapper.Base,
+                   Language.Haskell.BuildWrapper.Cabal,
+                   Language.Haskell.BuildWrapper.GHC
   extensions:      CPP
-  other-modules:   Language.Haskell.BuildWrapper.GHC, Language.Haskell.BuildWrapper.Src, Language.Haskell.BuildWrapper.Find, Language.Haskell.BuildWrapper.Packages
+  other-modules:   
+                   Language.Haskell.BuildWrapper.Find,
+                   Language.Haskell.BuildWrapper.Packages,
+                   Language.Haskell.BuildWrapper.Src
 
 executable buildwrapper
   hs-source-dirs:  src-exe
@@ -39,7 +63,9 @@   main-is:         Main.hs
   ghc-options:     -Wall -fno-warn-unused-do-bind
   x-uses-tf:       true
-  other-modules:   Language.Haskell.BuildWrapper.APITest, Language.Haskell.BuildWrapper.Tests, Language.Haskell.BuildWrapper.CMDTests
+  other-modules:   
+                   Language.Haskell.BuildWrapper.APITest, Language.Haskell.BuildWrapper.Tests, Language.Haskell.BuildWrapper.CMDTests,
+                   Language.Haskell.BuildWrapper.GHCTests
 
 source-repository head
   type:     git
src/Language/Haskell/BuildWrapper/Cabal.hs view
@@ -297,13 +297,13 @@                                                 else 
                                                         let
                                                                 (loc,rest)=span (/= ':') s2
-                                                                (realloc,line,msg)=if null rest
-                                                                        then    ("","0",s2)
+                                                                (realloc,line,msg)=if null rest || ":"==rest
+                                                                        then    (cf,"1",s2)
                                                                         else 
                                                                                 let tr=tail rest
                                                                                     (line',msg')=span (/= ':') tr
                                                                                 in if null msg'
-                                                                                        then (loc,"0",tr)
+                                                                                        then (loc,"1",tr)
                                                                                         else (loc,line',tail msg')
                                                         in (Just (BWNote BWError "" (BWLocation realloc (read line) 1),[msg]),addCurrent currentNote ls)
                         | Just (jcn,msgs)<-currentNote=
@@ -316,7 +316,7 @@                 extractLine el=let
                         (_,_,_,ls)=el =~ "\\(line ([0-9]*)\\)" :: (String,String,String,[String])
                         in if null ls
-                                then 0
+                                then 1
                                 else (read $ head ls)
  
 
src/Language/Haskell/BuildWrapper/GHC.hs view
@@ -535,27 +535,37 @@                 (ts1,s2)=if literate then ppSF contents ppSLit else ([],contents) 
                 (ts2,s3)=ppSF s2 ppSCpp
         in (ts1++ts2,s3)
-        where 
+        where
                 ppSF contents2 p= let
                         linesWithCount=zip (lines contents2) [1..]
-                        (ts,nc,_)= List.foldl' p ([],[],False) linesWithCount
+                        (ts,nc,_)= List.foldl' p ([],[],Start) linesWithCount
                         in (reverse ts, unlines $ reverse nc)
-                ppSCpp :: ([TokenDef],[String],Bool) -> (String,Int) -> ([TokenDef],[String],Bool)
+                ppSCpp :: ([TokenDef],[String],PPBehavior) -> (String,Int) -> ([TokenDef],[String],PPBehavior)
                 ppSCpp (ts2,l2,f) (l,c) 
-                        | f = addPPToken "PP" (l,c) (ts2,l2,'\\' == (last l))
-                        | ('#':_)<-l =addPPToken "PP" (l,c) (ts2,l2,'\\' == (last l)) 
-                        | ("{-# " `List.isPrefixOf` l)=addPPToken "D" (l,c) (ts2,l2,False) 
-                        | otherwise =(ts2,l:l2,False)
-                ppSLit :: ([TokenDef],[String],Bool) -> (String,Int) -> ([TokenDef],[String],Bool)
+                        | (Continue _)<-f = addPPToken "PP" (l,c) (ts2,l2,lineBehavior l f)
+                        | ('#':_)<-l =addPPToken "PP" (l,c) (ts2,l2,lineBehavior l f) 
+                        | ("{-# " `List.isPrefixOf` l)=addPPToken "D" (l,c) (ts2,"":l2,Start) 
+                        | (Indent n)<-f=(ts2,l:((replicate n (takeWhile (==' ') l))++l2),Start)
+                        | otherwise =(ts2,l:l2,Start)
+                ppSLit :: ([TokenDef],[String],PPBehavior) -> (String,Int) -> ([TokenDef],[String],PPBehavior)
                 ppSLit (ts2,l2,f) (l,c) 
-                        | "\\begin{code}" `List.isPrefixOf` l=addPPToken "DL" ("\\begin{code}",c) (ts2,l2,True)
-                        | "\\end{code}" `List.isPrefixOf` l=addPPToken "DL" ("\\end{code}",c) (ts2,l2,False)
-                        | f = (ts2,l:l2,True)
+                        | "\\begin{code}" `List.isPrefixOf` l=addPPToken "DL" ("\\begin{code}",c) (ts2,"":l2,Continue 1)
+                        | "\\end{code}" `List.isPrefixOf` l=addPPToken "DL" ("\\end{code}",c) (ts2,"":l2,Start)
+                        | (Continue n)<-f = (ts2,l:l2,Continue (n+1))
                         | ('>':lCode)<-l=(ts2, (' ':lCode ):l2,f)
-                        | otherwise =addPPToken "DL" (l,c) (ts2,l2,f)  
-                addPPToken :: T.Text -> (String,Int) -> ([TokenDef],[String],Bool) -> ([TokenDef],[String],Bool)
-                addPPToken name (l,c) (ts2,l2,f) =((TokenDef name (mkFileSpan c 1 c ((length l)+1))):ts2 ,"":l2,f)
+                        | otherwise =addPPToken "DL" (l,c) (ts2,"":l2,f)  
+                addPPToken :: T.Text -> (String,Int) -> ([TokenDef],[String],PPBehavior) -> ([TokenDef],[String],PPBehavior)
+                addPPToken name (l,c) (ts2,l2,f) =((TokenDef name (mkFileSpan c 1 c ((length l)+1))):ts2 ,l2,f)
+                lineBehavior l f 
+                        | '\\' == (last l) = case f of
+                                Continue n->Continue (n+1)
+                                _ -> Continue 1
+                        | otherwise = case f of
+                                Continue n->Indent (n+1)
+                                _ -> Indent 1
 
+data PPBehavior=Continue Int | Indent Int | Start
+        deriving Eq
 
 ghcErrMsgToNote :: FilePath -> ErrMsg -> BWNote
 ghcErrMsgToNote = ghcMsgToNote BWError
src/Language/Haskell/BuildWrapper/Src.hs view
@@ -32,7 +32,8 @@                 else exts
         --putStrLn input
         --putStrLn $ show exts
-        let mode=defaultParseMode {extensions=extsFull,ignoreLinePragmas=False,ignoreLanguagePragmas=False} 
+        -- fixities necessary (see http://trac.haskell.org/haskell-src-exts/ticket/189 and https://sourceforge.net/projects/eclipsefp/forums/forum/371922/topic/4808590)
+        let mode=defaultParseMode {extensions=extsFull,ignoreLinePragmas=False,ignoreLanguagePragmas=False,fixities = Just baseFixities} 
         return $ parseFileContentsWithComments mode input
         --return $ makeObj  [("parse" , (showJSON $ pr))]
         
test/Language/Haskell/BuildWrapper/APITest.hs view
@@ -19,7 +19,7 @@ 
 
 unitTests :: [Test]
-unitTests=[testGetBuiltPath,testParseBuildMessages]
+unitTests=[testGetBuiltPath,testParseBuildMessages,testParseConfigureMessages]
 
 --apiTests::Test
 --apiTests=TestList $ map (\f->f DirectAPI) tests
@@ -57,4 +57,12 @@         let notes=Cabal.parseBuildMessages s
         assertEqual "not 1 note" 1 (length notes)
         assertEqual ("not expected note") (BWNote BWWarning "Top-level binding with no type signature:\n           tests :: [test-framework-0.4.1.1:Test.Framework.Core.Test]\n" (BWLocation "Main.hs" 2 3)) (head notes)
+        ))
+        
+testParseConfigureMessages :: Test
+testParseConfigureMessages = TestLabel "testParseConfigureMessages" (TestCase (do
+        let s="cabal.exe: Missing dependencies on foreign libraries:\n* Missing C libraries: tinfo, tinfo\n"
+        let notes=Cabal.parseCabalMessages "test.cabal" "cabal.exe" s
+        assertEqual "not 1 note" 1 (length notes)   
+        assertEqual ("not expected note") (BWNote BWError "Missing dependencies on foreign libraries:\n* Missing C libraries: tinfo, tinfo\n" (BWLocation "test.cabal" 1 1)) (head notes)
         ))
+ test/Language/Haskell/BuildWrapper/GHCTests.hs view
@@ -0,0 +1,85 @@+{-# LANGUAGE OverloadedStrings #-}
+module Language.Haskell.BuildWrapper.GHCTests where
+
+import Test.HUnit
+import Language.Haskell.BuildWrapper.Base
+import Language.Haskell.BuildWrapper.GHC
+
+
+ghcTests :: [Test]
+ghcTests=[testNoPreproc,testPreproc,testPreproc2Lines,testLiterate,testLiterateLatex
+        ,testKeepIndent]
+
+testNoPreproc:: Test
+testNoPreproc=TestLabel "testNoPreproc" (TestCase (
+        do
+        let s="module Main\nwhere\nimport Data.Map\nmain=undefined\n"
+        let (tt,s2)=preprocessSource s False
+        assertBool "tt is not empty" (null tt)
+        assertEqual ("content has changed: "++ s2) s s2
+        ))
+        
+testPreproc:: Test
+testPreproc=TestLabel "testPreproc" (TestCase (
+        do
+        let s="\nmodule Main\nwhere\n#if GHC_VERSION=612\nimport Data.Map\n#endif\nmain=undefined\n"
+        let (tt,s2)=preprocessSource s False
+        assertEqual "tt is not 2" 2 (length tt)
+        let (t1:t2:[])=tt
+        assertEqual "first tt is not correct" (TokenDef "PP" (mkLocation 4 1 4 20)) (t1)
+        assertEqual "second tt is not correct" (TokenDef "PP" (mkLocation 6 1 6 7)) (t2)
+        assertEqual ("content is not what expected: "++ s2) "\nmodule Main\nwhere\n\nimport Data.Map\n\nmain=undefined\n" s2
+        ))       
+
+testPreproc2Lines:: Test
+testPreproc2Lines=TestLabel "testPreproc2Lines" (TestCase (
+        do
+        let s="\nmodule Main\nwhere\n#if GHC_VERSION\\\n=612\nimport Data.Map\n#endif\nmain=undefined\n"
+        let (tt,s2)=preprocessSource s False
+        assertEqual "tt is not 3" 3 (length tt)
+        let (t1:t2:t3:[])=tt
+        --putStrLn $ show tt
+        assertEqual "first tt is not correct" (TokenDef "PP" (mkLocation 4 1 4 17)) (t1)
+        assertEqual "second tt is not correct" (TokenDef "PP" (mkLocation 5 1 5 5)) (t2)
+        assertEqual "third tt is not correct" (TokenDef "PP" (mkLocation 7 1 7 7)) (t3)
+        assertEqual ("content is not what expected: "++ s2) "\nmodule Main\nwhere\n\n\nimport Data.Map\n\nmain=undefined\n" s2
+        ))       
+        
+testLiterate:: Test
+testLiterate= TestLabel "testLiterate" (TestCase (
+        do
+        let s="comment for literate module\n> module Main\n2nd comment\n> where\n> import Data.Map\n"
+        let (tt,s2)=preprocessSource s True
+        assertEqual "tt is not 2" 2 (length tt)
+        let (t1:t2:[])=tt
+        assertEqual "first tt is not correct" (TokenDef "DL" (mkLocation 1 1 1 28)) (t1)
+        assertEqual "second tt is not correct" (TokenDef "DL" (mkLocation 3 1 3 12)) (t2)
+        assertEqual ("content is not what expected: "++ s2) "\n  module Main\n\n  where\n  import Data.Map\n" s2
+        ))
+
+testLiterateLatex:: Test
+testLiterateLatex= TestLabel "testLiterateLatex" (TestCase (
+        do
+        assertEqual "lines does not give 2" 2 (length $ lines "line1\r\nline2")
+        let s="\\begin{code}\r\n module Main\n where\n import Data.Map\n\\end{code}\n"
+        let (tt,s2)=preprocessSource s True
+        assertEqual "tt is not 2" 2 (length tt)
+        let (t1:t2:[])=tt
+        assertEqual "first tt is not correct" (TokenDef "DL" (mkLocation 1 1 1 13)) (t1)
+        assertEqual "second tt is not correct" (TokenDef "DL" (mkLocation 5 1 5 11)) (t2)
+        assertEqual ("content is not what expected: "++ s2) "\n module Main\n where\n import Data.Map\n\n" s2
+        ))
+        
+testKeepIndent :: Test
+testKeepIndent = TestLabel "testKeepIndent" (TestCase ( do
+        let s="\nmodule Main\nwhere\nmain=do\n#if GHC_VERSION=612\n    do1\n#endif\n    do2\n"
+        let (tt,s2)=preprocessSource s False
+        assertEqual "tt is not 2" 2 (length tt)
+        let (t1:t2:[])=tt
+        assertEqual "first tt is not correct" (TokenDef "PP" (mkLocation 5 1 5 20)) (t1)
+        assertEqual "second tt is not correct" (TokenDef "PP" (mkLocation 7 1 7 7)) (t2)
+        assertEqual ("content is not what expected: "++ s2) "\nmodule Main\nwhere\nmain=do\n    \n    do1\n    \n    do2\n" s2
+        ))
+        
+mkLocation :: Int -> Int -> Int -> Int -> InFileSpan         
+mkLocation sl sc el ec=InFileSpan (InFileLoc sl sc) (InFileLoc el ec)
test/Language/Haskell/BuildWrapper/Tests.hs view
@@ -200,7 +200,7 @@         assertBool ("returned false 2 "++ (show ns2)) bool2
         assertEqual ("didn't return 1 warning") 1 (length ns2)
         let (nsWarning2:[])=ns2
-        assertEqual "not proper warning 2" (BWNote BWWarning "A package using section syntax must specify at least\n'cabal-version: >= 1.2'.\n" (BWLocation cfn 0 1)) nsWarning2
+        assertEqual "not proper warning 2" (BWNote BWWarning "A package using section syntax must specify at least\n'cabal-version: >= 1.2'.\n" (BWLocation cfn 1 1)) nsWarning2
         writeFile cf $ unlines ["name: "++testProjectName,
                 "version:0.1",
                 "cabal-version:  >= 1.2",
@@ -217,7 +217,7 @@         assertBool ("returned false 3 "++ (show ns3)) bool3
         assertEqual ("didn't return 1 warning") 1 (length ns3)
         let (nsWarning3:[])=ns3
-        assertEqual "not proper warning 3" (BWNote BWWarning "No 'build-type' specified. If you do not need a custom Setup.hs or\n./configure script then use 'build-type: Simple'.\n" (BWLocation cfn 0 1)) nsWarning3
+        assertEqual "not proper warning 3" (BWNote BWWarning "No 'build-type' specified. If you do not need a custom Setup.hs or\n./configure script then use 'build-type: Simple'.\n" (BWLocation cfn 1 1)) nsWarning3
 
         ))   
         
test/Main.hs view
@@ -14,6 +14,7 @@ 
 import Language.Haskell.BuildWrapper.APITest
 import Language.Haskell.BuildWrapper.CMDTests
+import Language.Haskell.BuildWrapper.GHCTests
 
 import Test.Framework (defaultMain, testGroup,Test)
 import Test.Framework.Providers.HUnit
@@ -22,8 +23,9 @@ main = defaultMain tests
 
 tests :: [Test]
-tests = [testGroup "Unit Tests" (concatMap (hUnitTestToTests) unitTests)
-        ,testGroup "Command Tests" (concatMap (hUnitTestToTests) cmdTests)
+tests = [testGroup "Unit Tests" (concatMap hUnitTestToTests unitTests)
+        ,testGroup "GHC Tests" (concatMap hUnitTestToTests ghcTests)
+        ,testGroup "Command Tests" (concatMap hUnitTestToTests cmdTests)
         ]
 
 --import Language.Haskell.BuildWrapper.APITest