1 import Test
.Cabal
.Prelude
5 data BuildWay
= StaticWay | DynWay | ProfWay | ProfDynWay
6 deriving (Eq
, Ord
, Show, Read, Enum
)
8 -- Test building with profiling shared support
10 setupTest
$ recordMode DoNotRecord
$ do
11 has_prof_shared
<- hasProfiledSharedLibraries
12 has_shared
<- hasSharedLibraries
13 -- Tests are not robust against missing dynamic libraries yet. Would
14 -- be better to fix this.
15 skipUnless
"Missing shared libraries" has_shared
17 let analyse_result expected r
= do
19 let ls
= lines (resultOutput r
)
21 library_prefix
= "Wanted build ways(True): "
22 executable_prefix
= "Wanted build ways(False): "
24 get_ways prefix
= map (drop (length prefix
)) (filter (prefix `
isPrefixOf`
) ls
)
25 library_ways
= read_ways
(get_ways library_prefix
)
26 executable_ways
= read_ways
(get_ways executable_prefix
)
30 -- There should only be one
31 [x
] -> (read :: String -> [BuildWay
]) x
32 -- Unless there are none, when we don't built the executable for example
34 xs
-> error "Unexpected number of log lines"
36 way
= (library_ways
, executable_ways
)
38 unless (bimap
(nub . sort) (nub . sort) expected
== bimap
(nub . sort) (nub . sort) way
) $
39 assertFailure
$ "Expected:" ++ show expected
++ "\n" ++ "Got:" ++ show way
42 setupTest
$ recordMode DoNotRecord
$ do
44 has_prof_shared
<- hasProfiledSharedLibraries
45 has_shared
<- hasSharedLibraries
48 dyn
= [ DynWay | has_shared
]
49 p_dyn
= if has_prof_shared
then [ProfDynWay
] else p
53 let run_test args expected
= do
54 setup
"configure" args
55 res
<- setup
' "build" []
56 analyse_result expected res
64 run_test
["--disable-library-vanilla", "--enable-executable-dynamic"]
67 run_test
["--enable-profiling-shared"]
68 (v
<> dyn
<> p_dyn
, v
)
70 run_test
["--enable-profiling-shared", "--enable-executable-dynamic"]
71 (v
<> dyn
<> p_dyn
, dyn
)
73 run_test
["--enable-executable-dynamic", "--disable-library-vanilla"]
76 run_test
["--enable-profiling"]
79 run_test
["--enable-executable-profiling"]
82 run_test
["--enable-executable-profiling", "--enable-executable-dynamic"]
83 (v
<> dyn
<> p_dyn
, p_dyn
)
85 run_test
["--enable-profiling", "--enable-executable-dynamic"]
86 (v
<> dyn
<> p_dyn
, p_dyn
)
89 run_test
["--enable-library-profiling", "--enable-executable-profiling"]
92 run_test
["prof-shared", "--enable-profiling-shared", "--disable-library-vanilla", "--disable-shared"]
96 run_test
["prof-shared", "--enable-profiling-shared", "--enable-library-profiling", "--disable-library-vanilla", "--disable-shared"]
100 run_test
["prof-shared","--enable-profiling-shared", "--enable-library-profiling", "--enable-library-vanilla", "--disable-shared"]
101 (v
<> p
<> p_dyn
, none
)
104 run_test
["prof-shared", "--enable-profiling-shared", "--enable-library-profiling", "--enable-library-vanilla", "--enable-shared"]
105 (v
<> dyn
<> p
<> p_dyn
, none
)
107 let run_cabal_test args expected
= cabalTest
$ recordMode DoNotRecord
$ do
108 has_prof_shared
<- hasProfiledSharedLibraries
109 has_shared
<- hasSharedLibraries
110 -- See GHC commit e400b9babdcf11669f963aeec20078fe7ccfca0d
111 -- Only installing profiled library is broken on very old ghc-pkg versions
112 broken_ghc_pkg
<- isGhcVersion
"<= 8.6.5"
114 let cvt_l StaticWay
= [ StaticWay
]
115 cvt_l DynWay
= [ DynWay | has_shared
]
116 cvt_l ProfDynWay
= [ProfDynWay | has_prof_shared
]
117 cvt_l ProfWay
= [ ProfWay
]
119 let cvt_e StaticWay
= StaticWay
120 cvt_e DynWay
= if has_shared
then DynWay
else error "DynWay"
121 cvt_e ProfDynWay
= if has_prof_shared
then ProfDynWay
else ProfWay
122 cvt_e ProfWay
= ProfWay
124 unless (broken_ghc_pkg
&& (fst expected
== [ProfWay
])) $ do
125 res
<- cabal
' "v2-build" args
126 void
$ analyse_result
(bimap
(concatMap cvt_l
) (map cvt_e
) expected
) res
128 run_cabal_test
["--disable-shared"] ([StaticWay
], [StaticWay
])
129 run_cabal_test
["--disable-shared", "--disable-executable-dynamic"] ([StaticWay
], [StaticWay
])
130 run_cabal_test
["--enable-shared"] ([DynWay
, StaticWay
], [StaticWay
])
131 run_cabal_test
["--enable-executable-dynamic"] ([DynWay
, StaticWay
], [DynWay
])
132 run_cabal_test
["--enable-shared", "--disable-library-vanilla", "--enable-executable-dynamic"] ([DynWay
], [DynWay
])
134 run_cabal_test
["--disable-shared", "--disable-library-vanilla", "--enable-profiling"] ([ProfWay
], [ProfWay
])
136 run_cabal_test
["--disable-shared", "--enable-profiling"] ([ProfWay
, StaticWay
], [ProfWay
])
138 run_cabal_test
["--disable-shared", "--enable-profiling-shared", "--enable-profiling"] ([ProfDynWay
, ProfWay
, StaticWay
], [ProfWay
])
140 run_cabal_test
["--disable-shared", "--enable-profiling", "--enable-profiling-shared", "--enable-executable-dynamic"] ([ProfWay
, ProfDynWay
, StaticWay
], [ProfDynWay
])
142 run_cabal_test
["--enable-profiling", "--enable-executable-dynamic"] ([ProfDynWay
, ProfWay
, DynWay
, StaticWay
], [ProfDynWay
])
144 run_cabal_test
["prof-shared", "--disable-library-profiling", "--enable-profiling", "--enable-executable-dynamic"] ([ProfDynWay
, DynWay
, StaticWay
], [])