X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=blobdiff_plain;f=utils%2Fghc-pkg%2FMain.hs;h=52b79146b7e224f4b81731645b3a999c0ebdb7a2;hp=8e08c4fb9701d468cbcedb3f005e2d04ee364927;hb=091fceaeb313c2d2504c005ddc1067ad6f9c60c6;hpb=237fea9fd27a276f6674c76e2eeff0c6634576dd diff --git a/utils/ghc-pkg/Main.hs b/utils/ghc-pkg/Main.hs index 8e08c4f..52b7914 100644 --- a/utils/ghc-pkg/Main.hs +++ b/utils/ghc-pkg/Main.hs @@ -661,6 +661,7 @@ mungePackageDBPaths top_dir db@PackageDB { packages = pkgs } = -- files and "package.conf.d" dirs) the pkgroot is the parent directory -- ${pkgroot}/package.conf or ${pkgroot}/package.conf.d/ +-- TODO: This code is duplicated in compiler/main/Packages.lhs mungePackagePaths :: FilePath -> FilePath -> InstalledPackageInfo -> InstalledPackageInfo -- Perform path/URL variable substitution as per the Cabal ${pkgroot} spec @@ -679,36 +680,37 @@ mungePackagePaths top_dir pkgroot pkg = frameworkDirs = munge_paths (frameworkDirs pkg), haddockInterfaces = munge_paths (haddockInterfaces pkg), -- haddock-html is allowed to be either a URL or a file - haddockHTMLs = munge_path (munge_urls (haddockHTMLs pkg)) + haddockHTMLs = munge_paths (munge_urls (haddockHTMLs pkg)) } where munge_paths = map munge_path munge_urls = map munge_url munge_path p - | Just p' <- stripVarPrefix "${pkgroot}" sp = pkgroot p' - | Just p' <- stripVarPrefix "$topdir" sp = top_dir p' - | otherwise = p - where - sp = splitPath p + | Just p' <- stripVarPrefix "${pkgroot}" p = pkgroot ++ p' + | Just p' <- stripVarPrefix "$topdir" p = top_dir ++ p' + | otherwise = p munge_url p - | Just p' <- stripVarPrefix "${pkgrooturl}" sp = toUrlPath pkgroot p' - | Just p' <- stripVarPrefix "$httptopdir" sp = toUrlPath top_dir p' - | otherwise = p - where - sp = splitPath p + | Just p' <- stripVarPrefix "${pkgrooturl}" p = toUrlPath pkgroot p' + | Just p' <- stripVarPrefix "$httptopdir" p = toUrlPath top_dir p' + | otherwise = p toUrlPath r p = "file:///" -- URLs always use posix style '/' separators: - ++ FilePath.Posix.joinPath (r : FilePath.splitDirectories p) - - stripVarPrefix var (root:path') - | Just [sep] <- stripPrefix var root - , isPathSeparator sep - = Just (joinPath path') - - stripVarPrefix _ _ = Nothing + ++ FilePath.Posix.joinPath + (r : -- We need to drop a leading "/" or "\\" + -- if there is one: + dropWhile (all isPathSeparator) + (FilePath.splitDirectories p)) + + -- We could drop the separator here, and then use above. However, + -- by leaving it in and using ++ we keep the same path separator + -- rather than letting FilePath change it to use \ as the separator + stripVarPrefix var path = case stripPrefix var path of + Just [] -> Just [] + Just cs@(c : _) | isPathSeparator c -> Just cs + _ -> Nothing -- -----------------------------------------------------------------------------