Support for abi-depends for computing shadowing.
[ghc.git] / testsuite / tests / cabal / Makefile
1 TOP=../..
2 include $(TOP)/mk/boilerplate.mk
3 include $(TOP)/mk/test.mk
4
5 PKGCONF01=local01.package.conf
6 LOCAL_GHC_PKG01 = '$(GHC_PKG)' --no-user-package-db -f $(PKGCONF01)
7
8 STRIP_PKGROOT=sed 's/^pkgroot: .*$$/pkgroot: /'
9
10 # a bunch of tests for ghc-pkg
11 ghcpkg01 :
12 @rm -rf $(PKGCONF01)
13 $(LOCAL_GHC_PKG01) init $(PKGCONF01)
14 $(LOCAL_GHC_PKG01) list
15 $(LOCAL_GHC_PKG01) register --force test.pkg 2>/dev/null
16 $(LOCAL_GHC_PKG01) describe testpkg | $(STRIP_PKGROOT)
17 $(LOCAL_GHC_PKG01) describe testpkg-1.2.3.4 | $(STRIP_PKGROOT)
18 $(LOCAL_GHC_PKG01) field testpkg-1.2.3.4 import-dirs
19
20 @: # test2.pkg is a later version of testpkg-1.2.3.4
21 $(LOCAL_GHC_PKG01) register --force test2.pkg 2>/dev/null
22 $(LOCAL_GHC_PKG01) list
23 $(LOCAL_GHC_PKG01) describe testpkg-2.0 | $(STRIP_PKGROOT)
24 $(LOCAL_GHC_PKG01) describe testpkg-* | $(STRIP_PKGROOT)
25 $(LOCAL_GHC_PKG01) field testpkg-* version
26
27 @: # test hiding/exposing
28 $(LOCAL_GHC_PKG01) hide testpkg-1.2.3.4
29 $(LOCAL_GHC_PKG01) field testpkg-1.2.3.4 exposed | grep False
30 $(LOCAL_GHC_PKG01) expose testpkg-2.0
31 $(LOCAL_GHC_PKG01) field testpkg-2.0 exposed | grep True
32 $(LOCAL_GHC_PKG01) hide testpkg-*
33 $(LOCAL_GHC_PKG01) field testpkg-* exposed
34
35 @: # test3.pkg depends on testpkg-2.0
36 $(LOCAL_GHC_PKG01) register test3.pkg
37
38 @: # unregistering testpkg-2.0 should fail now, testpkg-3.0 depends on it
39 if $(LOCAL_GHC_PKG01) unregister testpkg-2.0; then false; else true; fi
40
41 $(LOCAL_GHC_PKG01) unregister testpkg-3.0
42
43 $(LOCAL_GHC_PKG01) unregister testpkg-2.0
44 $(LOCAL_GHC_PKG01) describe testpkg | $(STRIP_PKGROOT)
45 $(LOCAL_GHC_PKG01) unregister testpkg-*
46 $(LOCAL_GHC_PKG01) list
47
48 @: # registering test3.pkg should fail now, its dependency has gone
49 if $(LOCAL_GHC_PKG01) register test3.pkg; then false; else true; fi
50
51 PKGCONF03=local03.package.conf
52 LOCAL_GHC_PKG03 = '$(GHC_PKG)' --no-user-package-db -f $(PKGCONF03)
53
54 ghcpkg03 :
55 @rm -rf $(PKGCONF03)
56 $(LOCAL_GHC_PKG03) init $(PKGCONF03)
57 @: # update should hide conflicting packages
58 $(LOCAL_GHC_PKG03) register --force test.pkg
59 $(LOCAL_GHC_PKG03) register --force test2.pkg
60
61 @: # test4.pkg depends on testpkg-2.0, which conflicts with testpkg-1.2.3.4,
62 @: # ghc-pkg will happily register it now (it didn't in GHC 6.4)
63 $(LOCAL_GHC_PKG03) register test4.pkg
64 $(LOCAL_GHC_PKG03) update test4.pkg
65
66 @: # and another update of test.pkg will now hide dep-2.0
67 $(LOCAL_GHC_PKG03) update --force test.pkg
68
69 PKGCONF04=local04.package.conf
70 LOCAL_GHC_PKG04 = '$(GHC_PKG)' --no-user-package-db -f $(PKGCONF04)
71
72 # Test that importing a module exposed by two packages reports a conflict
73 ghcpkg04 :
74 rm -rf $(PKGCONF04)
75 $(LOCAL_GHC_PKG04) init $(PKGCONF04)
76 $(LOCAL_GHC_PKG04) register --force test.pkg >/dev/null 2>&1
77 $(LOCAL_GHC_PKG04) update --force test5.pkg >/dev/null 2>&1
78 $(LOCAL_GHC_PKG04) expose testpkg-1.2.3.4 >/dev/null 2>&1
79 @: # testpkg-1.2.3.4 and newtestpkg-2.0 are both exposed now
80 '$(TEST_HC)' $(TEST_HC_OPTS) -package-db $(PKGCONF04) -c ghcpkg04.hs || true
81
82 # Test stacking of package.confs (also #2441)
83 PKGCONF05a=local05a.package.conf
84 PKGCONF05b=local05b.package.conf
85 LOCAL_GHC_PKG05a = '$(GHC_PKG)' --no-user-package-db -f $(PKGCONF05a)
86 LOCAL_GHC_PKG05b = '$(GHC_PKG)' --no-user-package-db -f $(PKGCONF05a) -f $(PKGCONF05b)
87
88 ghcpkg05 :
89 rm -rf $(PKGCONF05a) $(PKGCONF05b)
90 $(LOCAL_GHC_PKG05a) init $(PKGCONF05a)
91 $(LOCAL_GHC_PKG05b) init $(PKGCONF05b)
92 $(LOCAL_GHC_PKG05a) register --force test2.pkg >/dev/null 2>&1
93 $(LOCAL_GHC_PKG05b) register --force test3.pkg >/dev/null 2>&1
94 $(LOCAL_GHC_PKG05b) check || true
95 $(LOCAL_GHC_PKG05b) list
96 $(LOCAL_GHC_PKG05b) expose testpkg-2.0
97 $(LOCAL_GHC_PKG05b) hide testpkg-2.0
98 if $(LOCAL_GHC_PKG05b) unregister testpkg-2.0; then false; else true; fi
99 $(LOCAL_GHC_PKG05b) unregister testpkg-3.0
100 $(LOCAL_GHC_PKG05b) unregister testpkg-2.0
101
102 # Test for #2330: reject duplicate dependencies
103 PKGCONF06=local06.package.conf
104 LOCAL_GHC_PKG06 = '$(GHC_PKG)' --no-user-package-db -f $(PKGCONF06)
105
106 ghcpkg06 :
107 rm -rf $(PKGCONF06)
108 $(LOCAL_GHC_PKG06) init $(PKGCONF06)
109 $(LOCAL_GHC_PKG06) register --force test.pkg >/dev/null 2>&1
110 if $(LOCAL_GHC_PKG06) register testdup.pkg; then false else true; fi
111 $(LOCAL_GHC_PKG06) register --force testdup.pkg
112
113 PKGCONFT1750=localT1750.package.conf
114 LOCAL_GHC_PKGT1750 = '$(GHC_PKG)' --no-user-package-db -f $(PKGCONFT1750)
115
116 T1750:
117 rm -rf $(PKGCONFT1750) T1750.hs T1750.o T1750.hi T1750.out
118 $(LOCAL_GHC_PKGT1750) init $(PKGCONFT1750)
119 $(LOCAL_GHC_PKGT1750) register --force T1750A.pkg >T1750.out 2>&1
120 $(LOCAL_GHC_PKGT1750) register --force T1750B.pkg >T1750.out 2>&1
121 GHC_PACKAGE_PATH=$(PKGCONFT1750) '$(GHC_PKG)' --no-user-package-db list
122 # GHC_PACKAGE_PATH trick is to make this work with 6.8.2 which doesn't have
123 # the patch "Change the command-line semantics for query commands" to
124 # ghc-pkg
125 echo "main = return ()" >T1750.hs
126 '$(TEST_HC)' $(TEST_HC_OPTS) -package-db $(PKGCONFT1750) -package T1750A T1750.hs || true
127
128 PKGCONFSHADOW1=localshadow1.package.conf
129 PKGCONFSHADOW2=localshadow2.package.conf
130 PKGCONFSHADOW3=localshadow3.package.conf
131 LOCAL_GHC_PKGSHADOW1 = '$(GHC_PKG)' --no-user-package-db -f $(PKGCONFSHADOW1)
132 LOCAL_GHC_PKGSHADOW2 = '$(GHC_PKG)' --no-user-package-db -f $(PKGCONFSHADOW2)
133 LOCAL_GHC_PKGSHADOW3 = '$(GHC_PKG)' --no-user-package-db -f $(PKGCONFSHADOW3)
134 LOCAL_GHC_PKGSHADOW12 = '$(GHC_PKG)' --no-user-package-db -f $(PKGCONFSHADOW1) -f $(PKGCONFSHADOW2)
135 LOCAL_GHC_PKGSHADOW13 = '$(GHC_PKG)' --no-user-package-db -f $(PKGCONFSHADOW1) -f $(PKGCONFSHADOW3)
136
137 # Test package shadowing behaviour.
138 #
139 # The general principle is that we shadow in order of declarations,
140 # but we determine what gets overridden based on ABI dependencies.
141 #
142 # Here is the structure of our databases (unitid=abi):
143 #
144 # localshadow1.package.conf: shadowdep-1-XXX=ddd -> shadow-1-XXX=aaa
145 # localshadow2.package.conf: shadow-1-XXX=bbb
146 # localshadow3.package.conf: shadow-1-XXX=aaa
147 shadow:
148 rm -rf $(PKGCONFSHADOW1) $(PKGCONFSHADOW2) $(PKGCONFSHADOW3) shadow.hs shadow.o shadow.hi shadow.out shadow.hs shadow.hi
149 $(LOCAL_GHC_PKGSHADOW1) init $(PKGCONFSHADOW1)
150 $(LOCAL_GHC_PKGSHADOW2) init $(PKGCONFSHADOW2)
151 $(LOCAL_GHC_PKGSHADOW3) init $(PKGCONFSHADOW3)
152 $(LOCAL_GHC_PKGSHADOW1) register -v0 --force shadow1.pkg
153 $(LOCAL_GHC_PKGSHADOW1) register -v0 --force shadow2.pkg
154 $(LOCAL_GHC_PKGSHADOW2) register -v0 --force shadow3.pkg
155 $(LOCAL_GHC_PKGSHADOW3) register -v0 --force shadow1.pkg
156 @echo "databases 1 and 2:"
157 $(LOCAL_GHC_PKGSHADOW12) list
158 @echo "databases 1 and 3:"
159 $(LOCAL_GHC_PKGSHADOW13) list
160 echo "main = return ()" >shadow.hs
161 #
162 # In this test, the later database defines a new shadow-1-XXX which
163 # shadows the old one, making shadowdep unsatisfiable.
164 #
165 @echo "should FAIL:"
166 if '$(TEST_HC)' $(TEST_HC_OPTS) -package-db $(PKGCONFSHADOW1) -package-db $(PKGCONFSHADOW2) -package shadowdep -c shadow.hs -fno-code; then false; else true; fi
167 #
168 # Reversing the orders of the configs fixes the problem, because now
169 # we prefer the shadow-1 from the first database, which has the correct
170 # ABI hash for shadowdep-1.
171 #
172 @echo "should SUCCEED:"
173 '$(TEST_HC)' $(TEST_HC_OPTS) -package-db $(PKGCONFSHADOW2) -package-db $(PKGCONFSHADOW1) -package shadowdep -c shadow.hs -fno-code
174 #
175 # When the ABIs are the same, dependencies don't break, we just swap it in
176 #
177 @echo "should SUCCEED:"
178 '$(TEST_HC)' $(TEST_HC_OPTS) -package-db $(PKGCONFSHADOW3) -package-db $(PKGCONFSHADOW1) -package shadowdep -c shadow.hs -fno-code
179
180 # Test that order we pass databases doesn't matter
181 #
182 # 1. shadow-1-XXX=aaa
183 # 2. shadowdep-1-XXX=ddd (shadow-1-XXX=aaa)
184 # 3. shadow-1-XXX=bbb
185 .PHONY: T12485a
186 T12485a:
187 rm -rf T12485a.package.conf T12485b.package.conf T12485c.package.conf
188 '$(GHC_PKG)' --no-user-package-db init T12485a.package.conf
189 '$(GHC_PKG)' --no-user-package-db init T12485b.package.conf
190 '$(GHC_PKG)' --no-user-package-db init T12485c.package.conf
191 '$(GHC_PKG)' --no-user-package-db -f T12485a.package.conf register -v0 --force shadow1.pkg
192 '$(GHC_PKG)' --no-user-package-db -f T12485b.package.conf register -v0 --force shadow2.pkg
193 '$(GHC_PKG)' --no-user-package-db -f T12485c.package.conf register -v0 --force shadow3.pkg
194 echo "main = return ()" > T12485a.hs
195 # Normal test
196 @echo "should SUCCEED"
197 '$(TEST_HC)' $(TEST_HC_OPTS) -package-db T12485a.package.conf -package-db T12485b.package.conf -package shadowdep -c T12485a.hs -fno-code
198 # Reversed test
199 @echo "should SUCCEED"
200 '$(TEST_HC)' $(TEST_HC_OPTS) -package-db T12485b.package.conf -package-db T12485a.package.conf -package shadowdep -c T12485a.hs -fno-code
201 # Shadow OK, as long as correct one is chosen eventually, even when reversed
202 @echo "should SUCCEED"
203 '$(TEST_HC)' $(TEST_HC_OPTS) -package-db T12485b.package.conf -package-db T12485c.package.conf -package-db T12485a.package.conf -package shadowdep -c T12485a.hs -fno-code
204
205 # If we pass --global, we should ignore instances in the user database
206 T5442a:
207 @rm -rf package.conf.T5442a.global package.conf.T5442a.user
208 '$(GHC_PKG)' init package.conf.T5442a.global
209 '$(GHC_PKG)' init package.conf.T5442a.user
210 '$(GHC_PKG)' -f package.conf.T5442a.global register --force-files test.pkg 2>/dev/null
211 '$(GHC_PKG)' -f package.conf.T5442a.user register --force-files test.pkg 2>/dev/null
212 '$(GHC_PKG)' --global-package-db=package.conf.T5442a.global --user-package-db=package.conf.T5442a.user --global unregister testpkg
213 @echo "global (should be empty):"
214 '$(GHC_PKG)' -f package.conf.T5442a.global list --simple-output
215 @echo "user:"
216 '$(GHC_PKG)' -f package.conf.T5442a.user list --simple-output
217
218 # If we pass --user, we should ignore instances in the global database
219 T5442b:
220 @rm -rf package.conf.T5442b.global package.conf.T5442b.user
221 '$(GHC_PKG)' init package.conf.T5442b.global
222 '$(GHC_PKG)' init package.conf.T5442b.user
223 '$(GHC_PKG)' -f package.conf.T5442b.global register --force-files test.pkg 2>/dev/null
224 ! '$(GHC_PKG)' --global-package-db=package.conf.T5442b.global --user-package-db=package.conf.T5442b.user --user unregister testpkg
225 @echo "global (should have testpkg):"
226 '$(GHC_PKG)' -f package.conf.T5442b.global list --simple-output
227
228 # If we pass -f, we should ignore the user and global databases
229 T5442c:
230 @rm -rf package.conf.T5442c.global package.conf.T5442c.user package.conf.T5442c.extra
231 '$(GHC_PKG)' init package.conf.T5442c.global
232 '$(GHC_PKG)' init package.conf.T5442c.user
233 '$(GHC_PKG)' init package.conf.T5442c.extra
234 '$(GHC_PKG)' -f package.conf.T5442c.global register --force-files test.pkg 2>/dev/null
235 '$(GHC_PKG)' -f package.conf.T5442c.user register --force-files test.pkg 2>/dev/null
236 ! '$(GHC_PKG)' --global-package-db=package.conf.T5442c.global --user-package-db=package.conf.T5442c.user -f package.conf.T5442c.extra unregister testpkg
237 @echo "global (should have testpkg):"
238 '$(GHC_PKG)' -f package.conf.T5442c.global list --simple-output
239 @echo "use (should have testpkg):"
240 '$(GHC_PKG)' -f package.conf.T5442c.user list --simple-output
241
242 # If we pass --global and -f, we remove from the global database, but
243 # warn about possible breakage in the full package stack
244 T5442d:
245 @rm -rf package.conf.T5442d.global package.conf.T5442d.user package.conf.T5442d.extra
246 '$(GHC_PKG)' init package.conf.T5442d.global
247 '$(GHC_PKG)' init package.conf.T5442d.user
248 '$(GHC_PKG)' init package.conf.T5442d.extra
249 '$(GHC_PKG)' -f package.conf.T5442d.global register --force-files shadow1.pkg 2>/dev/null
250 '$(GHC_PKG)' -f package.conf.T5442d.user register --force-files shadow4.pkg 2>/dev/null
251 '$(GHC_PKG)' --global-package-db=package.conf.T5442d.global -f package.conf.T5442d.extra register --force-files shadow2.pkg 2>/dev/null
252 '$(GHC_PKG)' --global-package-db=package.conf.T5442d.global --user-package-db=package.conf.T5442d.user -f package.conf.T5442d.extra --global unregister shadow --force
253 @echo "global (should be empty):"
254 '$(GHC_PKG)' -f package.conf.T5442d.global list --simple-output
255 @echo "user:"
256 '$(GHC_PKG)' -f package.conf.T5442d.user list --simple-output
257 @echo "extra:"
258 '$(GHC_PKG)' -f package.conf.T5442d.extra list --simple-output
259
260 # -----------------------------------------------------------------------------
261 # Try piping the output of "ghc-pkg describe" into "ghc-pkg update" for
262 # every package we know about. This is for testing the pretty printing/parsing
263 # of InstalledPackageInfo.
264
265 PACKAGE_CONF_ghcpkg02 = package.conf.ghcpkg02
266 GHC_PKG_ghcpkg02 = '$(GHC_PKG)' --no-user-package-db --global-package-db=$(PACKAGE_CONF_ghcpkg02)
267
268 ghcpkg02:
269 rm -rf $(PACKAGE_CONF_ghcpkg02)
270 $(GHC_PKG_ghcpkg02) init $(PACKAGE_CONF_ghcpkg02)
271 set -e; \
272 for i in `'$(GHC_PKG)' list --global --simple-output -v0`; do \
273 '$(GHC_PKG)' describe --global $$i | $(GHC_PKG_ghcpkg02) -v0 update --global --force -; \
274 done
275
276 PKGCONF07=local07.package.conf
277 LOCAL_GHC_PKG07 = '$(GHC_PKG)' --no-user-package-db -f $(PKGCONF07)
278 ghcpkg07:
279 @rm -rf $(PKGCONF07)
280 $(LOCAL_GHC_PKG07) init $(PKGCONF07)
281 $(LOCAL_GHC_PKG07) register --force test.pkg 2>/dev/null
282 $(LOCAL_GHC_PKG07) register --force test7a.pkg 2>&1 | grep "module" || :
283 $(LOCAL_GHC_PKG07) field testpkg7a exposed-modules
284 $(LOCAL_GHC_PKG07) register --force test7b.pkg 2>&1 | grep "module" || :
285 $(LOCAL_GHC_PKG07) field testpkg7b exposed-modules
286
287 recache_reexport:
288 @rm -rf recache_reexport_db/package.cache
289 '$(GHC_PKG)' --no-user-package-db --global-package-db=recache_reexport_db recache