Fix DPH make file and test suite
[packages/dph.git] / dph-test / framework / DPH / War / Job / Compile.hs
1
2 module DPH.War.Job.Compile
3 (jobCompile)
4 where
5 import DPH.War.Result
6 import DPH.War.Job
7 import BuildBox
8 import System.FilePath
9 import System.Directory
10 import Control.Monad
11 import Data.List
12
13
14 -- | Compile a Haskell Source File
15 jobCompile :: Job -> Build [Result]
16 jobCompile (JobCompile
17 testName _wayName srcHS optionsGHC
18 buildDir mainCompOut mainCompErr
19 mainBin)
20
21 = do needs srcHS
22
23 -- The directory holding the Main.hs file.
24 let (srcDir, srcFile) = splitFileName srcHS
25
26 -- Copy the .hs files to the build directory.
27 -- This freshens them and ensures we won't conflict with other make jobs
28 -- running on the same source files, but in different ways.
29 ensureDir buildDir
30 sources <- io
31 $ liftM (filter (\f -> isSuffixOf ".hs" f))
32 $ lsFilesIn srcDir
33
34 qssystem $ "cp " ++ (intercalate " " sources) ++ " " ++ buildDir
35
36 -- The copied version of the root source file.
37 let srcCopyHS = buildDir </> srcFile
38
39 (time, (code, strOut, strErr))
40 <- runTimedCommand
41 $ systemTee False
42 ("ghc " ++ ghc_exts
43 ++ " -Idph-prim-interface/interface"
44 ++ " -Idph-base/include"
45 ++ dph_code_includes
46 ++ " -package ghc"
47 ++ " -Odph -fno-liberate-case"
48 ++ " -outputdir " ++ buildDir
49 ++ " --make " ++ srcCopyHS
50 ++ " -o " ++ mainBin)
51 ""
52
53 atomicWriteFile mainCompOut strOut
54 atomicWriteFile mainCompErr strErr
55
56 let success = case code of
57 ExitFailure _ -> False
58 _ -> True
59
60 when (not success)
61 $ do io $ putStrLn strErr
62 io $ putStrLn strOut
63
64 let ftime = fromRational $ toRational time
65 return $ [ ResultAspect $ Time TotalWall `secs` ftime]
66 ++ (if success then [] else [ResultUnexpectedFailure])
67
68
69 ghc_exts :: String
70 ghc_exts = concat
71 [ "-XBangPatterns "
72 , "-XCPP "
73 , "-XDeriveDataTypeable "
74 , "-XEmptyDataDecls "
75 , "-XExistentialQuantification "
76 , "-XExplicitForAll "
77 , "-XFlexibleContexts "
78 , "-XFlexibleInstances "
79 , "-XGADTs "
80 , "-XMagicHash "
81 , "-XMultiParamTypeClasses "
82 , "-XNoMonomorphismRestriction "
83 , "-XParallelListComp "
84 , "-XPatternGuards "
85 , "-XRankNTypes "
86 , "-XScopedTypeVariables "
87 , "-XStandaloneDeriving "
88 , "-XTemplateHaskell "
89 , "-XTypeFamilies "
90 , "-XTypeOperators "
91 , "-XUnboxedTuples "]
92
93
94 dph_code_includes :: String
95 dph_code_includes = concat $ map (" -i"++)
96 [ "dph-test/framework"
97 , "dph-base"
98 -- not dph-prim-interface
99 --
100 -- put prim-par before so par's Data.Array.Parallel.Unlifted is used
101 , "dph-prim-par"
102 , "dph-prim-seq"
103 , "dph-lifted-base"
104 , "dph-lifted-vseg" ]