summaryrefslogtreecommitdiff
path: root/testsuite/tests/cabal
diff options
context:
space:
mode:
authorMichael Peyton Jones <me@michaelpj.com>2019-03-13 11:46:56 +0000
committerMarge Bot <ben+marge-bot@smart-cactus.org>2019-03-29 14:18:14 -0400
commit8a20bfc21da6a47087c8069f92691629eb47951d (patch)
tree1427b9cf1dea767129fa545a97e87b987eb74e16 /testsuite/tests/cabal
parent97ad5cfb1c41d19cc56f7450c1e42d988dc9fd2d (diff)
downloadhaskell-8a20bfc21da6a47087c8069f92691629eb47951d.tar.gz
Visibility: handle multiple units with the same name
Fixes #16228. The included test case is adapted from the reproduction in the issue, and fails without this patch. ------ We compute an initial visilibity mapping for units based on what is present in the package databases. To seed this, we compute a set of all the package configs to add visibilities for. However, this set was keyed off the unit's *package name*. This is correct, since we compare packages across databases by version. However, we would only ever consider a single, most-preferable unit from the database in which it was found. The effect of this was that only one of the libraries in a Cabal package would be added to this initial set. This would cause attempts to use modules from the omitted libraries to fail, claiming that the package was hidden (even though `ghc-pkg` would correctly show it as visible). A solution is to do the selection of the most preferable packages separately, and then be sure to consider exposing all units in the same package in the same package db. We can do this by picking a most-preferable unit for each package name, and then considering exposing all units that are equi-preferable with that unit. ------ Why wasn't this bug apparent to all people trying to use sub-libraries in Cabal? The answer is that Cabal explicitly passes `-package` and `-package-id` flags for all the packages it wants to use, rather than relying on the state of the package database. So this bug only really affects people who are trying to use package databases produced by Cabal outside of Cabal itself. One particular example of this is the way that the Nixpkgs Haskell infrastructure provides wrapped GHCs: typically these are equipped with a package database containing all the needed package dependencies, and the user is not expected to pass `-package` flags explicitly.
Diffstat (limited to 'testsuite/tests/cabal')
-rw-r--r--testsuite/tests/cabal/cabal10/Makefile21
-rw-r--r--testsuite/tests/cabal/cabal10/Setup.hs2
-rw-r--r--testsuite/tests/cabal/cabal10/Use.hs3
-rw-r--r--testsuite/tests/cabal/cabal10/all.T9
-rw-r--r--testsuite/tests/cabal/cabal10/cabal10.stdout1
-rw-r--r--testsuite/tests/cabal/cabal10/internal-lib.cabal13
-rw-r--r--testsuite/tests/cabal/cabal10/src/TestLib.hs1
7 files changed, 50 insertions, 0 deletions
diff --git a/testsuite/tests/cabal/cabal10/Makefile b/testsuite/tests/cabal/cabal10/Makefile
new file mode 100644
index 0000000000..b59c964db4
--- /dev/null
+++ b/testsuite/tests/cabal/cabal10/Makefile
@@ -0,0 +1,21 @@
+TOP=../../..
+include $(TOP)/mk/boilerplate.mk
+include $(TOP)/mk/test.mk
+
+SETUP = ./Setup -v0
+
+# This test is for packages in internal libraries
+
+cabal10: clean
+ $(MAKE) clean
+ '$(TEST_HC)' $(TEST_HC_OPTS) -v0 --make Setup
+ $(SETUP) clean
+ $(SETUP) configure $(CABAL_MINIMAL_BUILD) --with-ghc='$(TEST_HC)' --ghc-options='$(TEST_HC_OPTS)'
+ $(SETUP) build
+ '$(TEST_HC)' $(TEST_HC_OPTS) -package-db dist/package.conf.inplace Use.hs
+ifneq "$(CLEANUP)" ""
+ $(MAKE) clean
+endif
+
+clean :
+ $(RM) -r */dist Setup$(exeext) *.o *.hi
diff --git a/testsuite/tests/cabal/cabal10/Setup.hs b/testsuite/tests/cabal/cabal10/Setup.hs
new file mode 100644
index 0000000000..9a994af677
--- /dev/null
+++ b/testsuite/tests/cabal/cabal10/Setup.hs
@@ -0,0 +1,2 @@
+import Distribution.Simple
+main = defaultMain
diff --git a/testsuite/tests/cabal/cabal10/Use.hs b/testsuite/tests/cabal/cabal10/Use.hs
new file mode 100644
index 0000000000..b770515501
--- /dev/null
+++ b/testsuite/tests/cabal/cabal10/Use.hs
@@ -0,0 +1,3 @@
+module Use where
+
+import TestLib
diff --git a/testsuite/tests/cabal/cabal10/all.T b/testsuite/tests/cabal/cabal10/all.T
new file mode 100644
index 0000000000..778637d948
--- /dev/null
+++ b/testsuite/tests/cabal/cabal10/all.T
@@ -0,0 +1,9 @@
+if config.cleanup:
+ cleanup = 'CLEANUP=1'
+else:
+ cleanup = 'CLEANUP=0'
+
+test('cabal10',
+ extra_files(['Use.hs', 'Setup.hs', 'src/', 'internal-lib.cabal']),
+ run_command,
+ ['$MAKE -s --no-print-directory cabal10 ' + cleanup])
diff --git a/testsuite/tests/cabal/cabal10/cabal10.stdout b/testsuite/tests/cabal/cabal10/cabal10.stdout
new file mode 100644
index 0000000000..b7ea26c0d1
--- /dev/null
+++ b/testsuite/tests/cabal/cabal10/cabal10.stdout
@@ -0,0 +1 @@
+[1 of 1] Compiling Use ( Use.hs, Use.o )
diff --git a/testsuite/tests/cabal/cabal10/internal-lib.cabal b/testsuite/tests/cabal/cabal10/internal-lib.cabal
new file mode 100644
index 0000000000..27e8ded0bf
--- /dev/null
+++ b/testsuite/tests/cabal/cabal10/internal-lib.cabal
@@ -0,0 +1,13 @@
+name: internal-lib
+version: 0.1.0.0
+license: BSD3
+build-type: Simple
+cabal-version: >=2.0
+
+library
+ hs-source-dirs: src
+ exposed-modules: TestLib
+ build-depends: base
+ default-language: Haskell2010
+
+library sublib
diff --git a/testsuite/tests/cabal/cabal10/src/TestLib.hs b/testsuite/tests/cabal/cabal10/src/TestLib.hs
new file mode 100644
index 0000000000..c031432cb1
--- /dev/null
+++ b/testsuite/tests/cabal/cabal10/src/TestLib.hs
@@ -0,0 +1 @@
+module TestLib where