diff options
author | Thomas Miedema <thomasmiedema@gmail.com> | 2014-11-18 22:17:47 -0600 |
---|---|---|
committer | Austin Seipp <austin@well-typed.com> | 2014-11-19 17:03:05 -0600 |
commit | 6fc78fdfa1482a31ed7b586f20c9d7cb592ea944 (patch) | |
tree | faca1cc9e2eab107c6ca86606ed0e3e42d4bf005 | |
parent | 101c62e26286353dd3fac1ef54323529b64c9902 (diff) | |
download | haskell-6fc78fdfa1482a31ed7b586f20c9d7cb592ea944.tar.gz |
Refactor: use System.FilePath.splitSearchPath
Summary:
To address #2521 ("Trailing colon on GHC_PACKAGE_PATH doesn't work with
ghc-pkg"), we were using a custom version of splitSearchPath (e4f46f5de). This
solution however caused issue #9698 ("GHC_PACKAGE_PATH should be more lenient
for empty paths").
This patch reverts back to System.FilePath.splitSearchPath (fixes #9698) and
adresses (#2521) by testing for a trailing search path separators explicitly
(instead of implicitly using empty search path elements).
Empty paths are now allowed (ignored on Windows, interpreted as current
directory on Posix systems), and trailing path separator still tack on the
user and system package databases.
Also update submodule filepath, which has a version of splitSearchPath which
handles quotes in the same way as our custom version did.
Test Plan:
$ GHC_PACKAGE_PATH=/::/home: ./ghc-pkg list
...
db stack: ["/",".","/home","<userdb>","<systemdb>"]
...
Reviewers: austin
Reviewed By: austin
Subscribers: thomie, carter, simonmar
Differential Revision: https://phabricator.haskell.org/D414
GHC Trac Issues: #2521, #9698
-rw-r--r-- | compiler/main/Packages.lhs | 9 | ||||
-rw-r--r-- | compiler/utils/Util.lhs | 21 | ||||
m--------- | libraries/filepath | 0 | ||||
-rw-r--r-- | utils/ghc-pkg/Main.hs | 27 |
4 files changed, 7 insertions, 50 deletions
diff --git a/compiler/main/Packages.lhs b/compiler/main/Packages.lhs index 2f4a4d7663..40b5e24a19 100644 --- a/compiler/main/Packages.lhs +++ b/compiler/main/Packages.lhs @@ -334,13 +334,10 @@ readPackageConfigs dflags = do let base_conf_refs = case e_pkg_path of Left _ -> system_conf_refs Right path - | null (last cs) - -> map PkgConfFile (init cs) ++ system_conf_refs + | not (null path) && isSearchPathSeparator (last path) + -> map PkgConfFile (splitSearchPath (init path)) ++ system_conf_refs | otherwise - -> map PkgConfFile cs - where cs = parseSearchPath path - -- if the path ends in a separator (eg. "/foo/bar:") - -- then we tack on the system paths. + -> map PkgConfFile (splitSearchPath path) let conf_refs = reverse (extraPkgConfs dflags base_conf_refs) -- later packages shadow earlier ones. extraPkgConfs diff --git a/compiler/utils/Util.lhs b/compiler/utils/Util.lhs index aa5f6f9c95..df293f091b 100644 --- a/compiler/utils/Util.lhs +++ b/compiler/utils/Util.lhs @@ -89,7 +89,6 @@ module Util ( Suffix, splitLongestPrefix, escapeSpaces, - parseSearchPath, Direction(..), reslash, makeRelativeTo, @@ -1005,26 +1004,6 @@ type Suffix = String -- * Search path -------------------------------------------------------------- --- | The function splits the given string to substrings --- using the 'searchPathSeparator'. -parseSearchPath :: String -> [FilePath] -parseSearchPath path = split path - where - split :: String -> [String] - split s = - case rest' of - [] -> [chunk] - _:rest -> chunk : split rest - where - chunk = - case chunk' of -#ifdef mingw32_HOST_OS - ('\"':xs@(_:_)) | last xs == '\"' -> init xs -#endif - _ -> chunk' - - (chunk', rest') = break isSearchPathSeparator s - data Direction = Forwards | Backwards reslash :: Direction -> FilePath -> FilePath diff --git a/libraries/filepath b/libraries/filepath -Subproject 7011e20dbe30f96f34f6cfb1fd3f3aad9e7a653 +Subproject 83b6d8c555d278f5bb79cef6661d02bc38e72c1 diff --git a/utils/ghc-pkg/Main.hs b/utils/ghc-pkg/Main.hs index a67dbb2330..b1c7a4b51f 100644 --- a/utils/ghc-pkg/Main.hs +++ b/utils/ghc-pkg/Main.hs @@ -600,9 +600,10 @@ getPkgDatabases verbosity modify use_user use_cache expand_vars my_flags = do case e_pkg_path of Left _ -> sys_databases Right path - | last cs == "" -> init cs ++ sys_databases - | otherwise -> cs - where cs = parseSearchPath path + | not (null path) && isSearchPathSeparator (last path) + -> splitSearchPath (init path) ++ sys_databases + | otherwise + -> splitSearchPath path -- The "global" database is always the one at the bottom of the stack. -- This is the database we modify by default. @@ -2006,26 +2007,6 @@ openNewFile dir template = do -- in binary mode. openTempFileWithDefaultPermissions dir template --- | The function splits the given string to substrings --- using 'isSearchPathSeparator'. -parseSearchPath :: String -> [FilePath] -parseSearchPath path = split path - where - split :: String -> [String] - split s = - case rest' of - [] -> [chunk] - _:rest -> chunk : split rest - where - chunk = - case chunk' of -#ifdef mingw32_HOST_OS - ('\"':xs@(_:_)) | last xs == '\"' -> init xs -#endif - _ -> chunk' - - (chunk', rest') = break isSearchPathSeparator s - readUTF8File :: FilePath -> IO String readUTF8File file = do h <- openFile file ReadMode |