Handle trailing path separator in package DB names (#16360)
authorKevin Buhr <buhr@asaurus.net>
Fri, 3 May 2019 23:15:44 +0000 (18:15 -0500)
committerMarge Bot <ben+marge-bot@smart-cactus.org>
Sun, 9 Jun 2019 22:42:57 +0000 (18:42 -0400)
Package DB directories with trailing separator (provided via
GHC_PACKAGE_PATH or via -package-db) resulted in incorrect calculation of
${pkgroot} substitution variable.  Keep the trailing separator while
resolving as directory or file, but remove it before dropping the last
path component with takeDirectory.

Closes #16360.

compiler/main/Packages.hs
testsuite/tests/driver/T16360/Hello.hs [new file with mode: 0644]
testsuite/tests/driver/T16360/Makefile [new file with mode: 0644]
testsuite/tests/driver/T16360/all.T [new file with mode: 0644]
testsuite/tests/driver/T16360/test/Test.hs [new file with mode: 0644]
testsuite/tests/driver/T16360/test/test.pkg [new file with mode: 0644]

index cdb4f9b..64e012c 100644 (file)
@@ -559,13 +559,15 @@ readPackageConfig dflags conf_file = do
                       "can't find a package database at " ++ conf_file
 
   let
+      -- Fix #16360: remove trailing slash from conf_file before calculting pkgroot
+      conf_file' = dropTrailingPathSeparator conf_file
       top_dir = topDir dflags
-      pkgroot = takeDirectory conf_file
+      pkgroot = takeDirectory conf_file'
       pkg_configs1 = map (mungePackageConfig top_dir pkgroot)
                          proto_pkg_configs
       pkg_configs2 = setBatchPackageFlags dflags pkg_configs1
   --
-  return (conf_file, pkg_configs2)
+  return (conf_file', pkg_configs2)
   where
     readDirStylePackageConfig conf_dir = do
       let filename = conf_dir </> "package.cache"
diff --git a/testsuite/tests/driver/T16360/Hello.hs b/testsuite/tests/driver/T16360/Hello.hs
new file mode 100644 (file)
index 0000000..56109fa
--- /dev/null
@@ -0,0 +1,3 @@
+import Test
+
+main = print test
diff --git a/testsuite/tests/driver/T16360/Makefile b/testsuite/tests/driver/T16360/Makefile
new file mode 100644 (file)
index 0000000..67dcf80
--- /dev/null
@@ -0,0 +1,17 @@
+TOP=../../..
+include $(TOP)/mk/boilerplate.mk
+include $(TOP)/mk/test.mk
+
+LOCAL_PKGCONF=package.conf.d
+
+clean:
+       rm -f test/*.o test/*.hi *.o *.hi
+       rm -rf $(LOCAL_PKGCONF)
+
+.PHONY: T16360
+T16360:
+       @rm -rf $(LOCAL_PKGCONF)
+       "$(TEST_HC)" $(TEST_HC_OPTS) -this-unit-id test-1.0 -c test/Test.hs
+       "$(GHC_PKG)" init $(LOCAL_PKGCONF)
+       "$(GHC_PKG)" --no-user-package-db -f $(LOCAL_PKGCONF) register test/test.pkg -v0
+       "$(TEST_HC)" $(TEST_HC_OPTS) -package-db $(LOCAL_PKGCONF)/ -c Hello.hs
diff --git a/testsuite/tests/driver/T16360/all.T b/testsuite/tests/driver/T16360/all.T
new file mode 100644 (file)
index 0000000..1cc1945
--- /dev/null
@@ -0,0 +1 @@
+test('T16360', [extra_files(['Hello.hs', 'test/'])], makefile_test, [])
diff --git a/testsuite/tests/driver/T16360/test/Test.hs b/testsuite/tests/driver/T16360/test/Test.hs
new file mode 100644 (file)
index 0000000..b4d7f27
--- /dev/null
@@ -0,0 +1,4 @@
+module Test where
+
+test :: Int
+test = 42
diff --git a/testsuite/tests/driver/T16360/test/test.pkg b/testsuite/tests/driver/T16360/test/test.pkg
new file mode 100644 (file)
index 0000000..f925cfe
--- /dev/null
@@ -0,0 +1,8 @@
+name: test
+version: 1.0
+id: test-1.0
+key: test-1.0
+exposed-modules: Test
+import-dirs: ${pkgroot}/test
+library-dirs: ${pkgroot}/test
+exposed: True