| ... |
... |
@@ -103,6 +103,8 @@ import GHC.Data.Maybe |
|
103
|
103
|
import System.Environment ( getEnv )
|
|
104
|
104
|
import GHC.Data.FastString
|
|
105
|
105
|
import qualified GHC.Data.ShortText as ST
|
|
|
106
|
+import GHC.Data.OsPath (OsPath)
|
|
|
107
|
+import qualified GHC.Data.OsPath as OsPath
|
|
106
|
108
|
import GHC.Utils.Logger
|
|
107
|
109
|
import GHC.Utils.Error
|
|
108
|
110
|
import GHC.Utils.Exception
|
| ... |
... |
@@ -112,7 +114,7 @@ import System.FilePath as FilePath |
|
112
|
114
|
import Control.Monad
|
|
113
|
115
|
import Data.Graph (stronglyConnComp, SCC(..))
|
|
114
|
116
|
import Data.Char ( toUpper )
|
|
115
|
|
-import Data.List ( intersperse, partition, sortBy, isSuffixOf, sortOn )
|
|
|
117
|
+import Data.List ( intersperse, partition, sortBy, sortOn )
|
|
116
|
118
|
import Data.Set (Set)
|
|
117
|
119
|
import Data.Monoid (First(..))
|
|
118
|
120
|
import qualified Data.Semigroup as Semigroup
|
| ... |
... |
@@ -405,7 +407,7 @@ initUnitConfig dflags cached_dbs home_units = |
|
405
|
407
|
|
|
406
|
408
|
where
|
|
407
|
409
|
offsetPackageDb :: Maybe FilePath -> PackageDBFlag -> PackageDBFlag
|
|
408
|
|
- offsetPackageDb (Just offset) (PackageDB (PkgDbPath p)) | isRelative p = PackageDB (PkgDbPath (offset </> p))
|
|
|
410
|
+ offsetPackageDb (Just offset) (PackageDB (PkgDbPath p)) | OsPath.isRelative p = PackageDB (PkgDbPath (OsPath.unsafeEncodeUtf offset OsPath.</> p))
|
|
409
|
411
|
offsetPackageDb _ p = p
|
|
410
|
412
|
|
|
411
|
413
|
|
| ... |
... |
@@ -500,12 +502,12 @@ emptyUnitState = UnitState { |
|
500
|
502
|
|
|
501
|
503
|
-- | Unit database
|
|
502
|
504
|
data UnitDatabase unit = UnitDatabase
|
|
503
|
|
- { unitDatabasePath :: FilePath
|
|
|
505
|
+ { unitDatabasePath :: OsPath
|
|
504
|
506
|
, unitDatabaseUnits :: [GenUnitInfo unit]
|
|
505
|
507
|
}
|
|
506
|
508
|
|
|
507
|
509
|
instance Outputable u => Outputable (UnitDatabase u) where
|
|
508
|
|
- ppr (UnitDatabase fp _u) = text "DB:" <+> text fp
|
|
|
510
|
+ ppr (UnitDatabase fp _u) = text "DB:" <+> OsPath.pprOsPath fp
|
|
509
|
511
|
|
|
510
|
512
|
type UnitInfoMap = UniqMap UnitId UnitInfo
|
|
511
|
513
|
|
| ... |
... |
@@ -720,9 +722,9 @@ getUnitDbRefs cfg = do |
|
720
|
722
|
Left _ -> system_conf_refs
|
|
721
|
723
|
Right path
|
|
722
|
724
|
| Just (xs, x) <- snocView path, isSearchPathSeparator x
|
|
723
|
|
- -> map PkgDbPath (splitSearchPath xs) ++ system_conf_refs
|
|
|
725
|
+ -> map PkgDbPath (OsPath.splitSearchPath (OsPath.unsafeEncodeUtf xs)) ++ system_conf_refs
|
|
724
|
726
|
| otherwise
|
|
725
|
|
- -> map PkgDbPath (splitSearchPath path)
|
|
|
727
|
+ -> map PkgDbPath (OsPath.splitSearchPath (OsPath.unsafeEncodeUtf path))
|
|
726
|
728
|
|
|
727
|
729
|
-- Apply the package DB-related flags from the command line to get the
|
|
728
|
730
|
-- final list of package DBs.
|
| ... |
... |
@@ -751,24 +753,24 @@ getUnitDbRefs cfg = do |
|
751
|
753
|
-- NB: This logic is reimplemented in Cabal, so if you change it,
|
|
752
|
754
|
-- make sure you update Cabal. (Or, better yet, dump it in the
|
|
753
|
755
|
-- compiler info so Cabal can use the info.)
|
|
754
|
|
-resolveUnitDatabase :: UnitConfig -> PkgDbRef -> IO (Maybe FilePath)
|
|
755
|
|
-resolveUnitDatabase cfg GlobalPkgDb = return $ Just (unitConfigGlobalDB cfg)
|
|
|
756
|
+resolveUnitDatabase :: UnitConfig -> PkgDbRef -> IO (Maybe OsPath)
|
|
|
757
|
+resolveUnitDatabase cfg GlobalPkgDb = return $ Just $ OsPath.unsafeEncodeUtf $ unitConfigGlobalDB cfg
|
|
756
|
758
|
resolveUnitDatabase cfg UserPkgDb = runMaybeT $ do
|
|
757
|
759
|
dir <- versionedAppDir (unitConfigProgramName cfg) (unitConfigPlatformArchOS cfg)
|
|
758
|
760
|
let pkgconf = dir </> unitConfigDBName cfg
|
|
759
|
761
|
exist <- tryMaybeT $ doesDirectoryExist pkgconf
|
|
760
|
|
- if exist then return pkgconf else mzero
|
|
|
762
|
+ if exist then return (OsPath.unsafeEncodeUtf pkgconf) else mzero
|
|
761
|
763
|
resolveUnitDatabase _ (PkgDbPath name) = return $ Just name
|
|
762
|
764
|
|
|
763
|
|
-readUnitDatabase :: Logger -> UnitConfig -> FilePath -> IO (UnitDatabase UnitId)
|
|
|
765
|
+readUnitDatabase :: Logger -> UnitConfig -> OsPath -> IO (UnitDatabase UnitId)
|
|
764
|
766
|
readUnitDatabase logger cfg conf_file = do
|
|
765
|
|
- isdir <- doesDirectoryExist conf_file
|
|
|
767
|
+ isdir <- OsPath.doesDirectoryExist conf_file
|
|
766
|
768
|
|
|
767
|
769
|
proto_pkg_configs <-
|
|
768
|
770
|
if isdir
|
|
769
|
771
|
then readDirStyleUnitInfo conf_file
|
|
770
|
772
|
else do
|
|
771
|
|
- isfile <- doesFileExist conf_file
|
|
|
773
|
+ isfile <- OsPath.doesFileExist conf_file
|
|
772
|
774
|
if isfile
|
|
773
|
775
|
then do
|
|
774
|
776
|
mpkgs <- tryReadOldFileStyleUnitInfo
|
| ... |
... |
@@ -776,48 +778,49 @@ readUnitDatabase logger cfg conf_file = do |
|
776
|
778
|
Just pkgs -> return pkgs
|
|
777
|
779
|
Nothing -> throwGhcExceptionIO $ InstallationError $
|
|
778
|
780
|
"ghc no longer supports single-file style package " ++
|
|
779
|
|
- "databases (" ++ conf_file ++
|
|
|
781
|
+ "databases (" ++ show conf_file ++
|
|
780
|
782
|
") use 'ghc-pkg init' to create the database with " ++
|
|
781
|
783
|
"the correct format."
|
|
782
|
784
|
else throwGhcExceptionIO $ InstallationError $
|
|
783
|
|
- "can't find a package database at " ++ conf_file
|
|
|
785
|
+ "can't find a package database at " ++ show conf_file
|
|
784
|
786
|
|
|
785
|
787
|
let
|
|
786
|
788
|
-- Fix #16360: remove trailing slash from conf_file before calculating pkgroot
|
|
787
|
|
- conf_file' = dropTrailingPathSeparator conf_file
|
|
788
|
|
- top_dir = unitConfigGHCDir cfg
|
|
789
|
|
- pkgroot = takeDirectory conf_file'
|
|
|
789
|
+ conf_file' = OsPath.dropTrailingPathSeparator conf_file
|
|
|
790
|
+ top_dir = OsPath.unsafeEncodeUtf (unitConfigGHCDir cfg) -- TODO: hm.
|
|
|
791
|
+ pkgroot = OsPath.takeDirectory conf_file'
|
|
790
|
792
|
pkg_configs1 = map (mungeUnitInfo top_dir pkgroot . mapUnitInfo (\(UnitKey x) -> UnitId x) . mkUnitKeyInfo)
|
|
791
|
793
|
proto_pkg_configs
|
|
792
|
794
|
--
|
|
793
|
795
|
return $ UnitDatabase conf_file' pkg_configs1
|
|
794
|
796
|
where
|
|
|
797
|
+ readDirStyleUnitInfo :: OsPath -> IO [DbUnitInfo]
|
|
795
|
798
|
readDirStyleUnitInfo conf_dir = do
|
|
796
|
|
- let filename = conf_dir </> "package.cache"
|
|
797
|
|
- cache_exists <- doesFileExist filename
|
|
|
799
|
+ let filename = conf_dir OsPath.</> (OsPath.unsafeEncodeUtf "package.cache")
|
|
|
800
|
+ cache_exists <- OsPath.doesFileExist filename
|
|
798
|
801
|
if cache_exists
|
|
799
|
802
|
then do
|
|
800
|
|
- debugTraceMsg logger 2 $ text "Using binary package database:" <+> text filename
|
|
801
|
|
- readPackageDbForGhc filename
|
|
|
803
|
+ debugTraceMsg logger 2 $ text "Using binary package database:" <+> OsPath.pprOsPath filename
|
|
|
804
|
+ readPackageDbForGhc (OsPath.unsafeDecodeUtf filename) -- TODO: Can we help it with this one? it comes from the ghc-boot package
|
|
802
|
805
|
else do
|
|
803
|
806
|
-- If there is no package.cache file, we check if the database is not
|
|
804
|
807
|
-- empty by inspecting if the directory contains any .conf file. If it
|
|
805
|
808
|
-- does, something is wrong and we fail. Otherwise we assume that the
|
|
806
|
809
|
-- database is empty.
|
|
807
|
810
|
debugTraceMsg logger 2 $ text "There is no package.cache in"
|
|
808
|
|
- <+> text conf_dir
|
|
|
811
|
+ <+> OsPath.pprOsPath conf_dir
|
|
809
|
812
|
<> text ", checking if the database is empty"
|
|
810
|
|
- db_empty <- all (not . isSuffixOf ".conf")
|
|
811
|
|
- <$> getDirectoryContents conf_dir
|
|
|
813
|
+ db_empty <- all (not . OsPath.isSuffixOf (OsPath.unsafeEncodeUtf ".conf"))
|
|
|
814
|
+ <$> OsPath.getDirectoryContents conf_dir
|
|
812
|
815
|
if db_empty
|
|
813
|
816
|
then do
|
|
814
|
817
|
debugTraceMsg logger 3 $ text "There are no .conf files in"
|
|
815
|
|
- <+> text conf_dir <> text ", treating"
|
|
|
818
|
+ <+> OsPath.pprOsPath conf_dir <> text ", treating"
|
|
816
|
819
|
<+> text "package database as empty"
|
|
817
|
820
|
return []
|
|
818
|
821
|
else
|
|
819
|
822
|
throwGhcExceptionIO $ InstallationError $
|
|
820
|
|
- "there is no package.cache in " ++ conf_dir ++
|
|
|
823
|
+ "there is no package.cache in " ++ show conf_dir ++
|
|
821
|
824
|
" even though package database is not empty"
|
|
822
|
825
|
|
|
823
|
826
|
|
| ... |
... |
@@ -830,13 +833,13 @@ readUnitDatabase logger cfg conf_file = do |
|
830
|
833
|
-- assumes it's a file and tries to overwrite with 'writeFile'.
|
|
831
|
834
|
-- ghc-pkg also cooperates with this workaround.
|
|
832
|
835
|
tryReadOldFileStyleUnitInfo = do
|
|
833
|
|
- content <- readFile conf_file `catchIO` \_ -> return ""
|
|
|
836
|
+ content <- readFile (OsPath.unsafeDecodeUtf conf_file) `catchIO` \_ -> return ""
|
|
834
|
837
|
if take 2 content == "[]"
|
|
835
|
838
|
then do
|
|
836
|
|
- let conf_dir = conf_file <.> "d"
|
|
837
|
|
- direxists <- doesDirectoryExist conf_dir
|
|
|
839
|
+ let conf_dir = conf_file OsPath.<.> OsPath.unsafeEncodeUtf "d"
|
|
|
840
|
+ direxists <- OsPath.doesDirectoryExist conf_dir
|
|
838
|
841
|
if direxists
|
|
839
|
|
- then do debugTraceMsg logger 2 (text "Ignoring old file-style db and trying:" <+> text conf_dir)
|
|
|
842
|
+ then do debugTraceMsg logger 2 (text "Ignoring old file-style db and trying:" <+> OsPath.pprOsPath conf_dir)
|
|
840
|
843
|
liftM Just (readDirStyleUnitInfo conf_dir)
|
|
841
|
844
|
else return (Just []) -- ghc-pkg will create it when it's updated
|
|
842
|
845
|
else return Nothing
|
| ... |
... |
@@ -846,11 +849,12 @@ distrustAllUnits pkgs = map distrust pkgs |
|
846
|
849
|
where
|
|
847
|
850
|
distrust pkg = pkg{ unitIsTrusted = False }
|
|
848
|
851
|
|
|
849
|
|
-mungeUnitInfo :: FilePath -> FilePath
|
|
|
852
|
+-- TODO: Can we help it with this one? it comes from the ghc-boot package
|
|
|
853
|
+mungeUnitInfo :: OsPath -> OsPath
|
|
850
|
854
|
-> UnitInfo -> UnitInfo
|
|
851
|
855
|
mungeUnitInfo top_dir pkgroot =
|
|
852
|
856
|
mungeDynLibFields
|
|
853
|
|
- . mungeUnitInfoPaths (ST.pack top_dir) (ST.pack pkgroot)
|
|
|
857
|
+ . mungeUnitInfoPaths (ST.pack (OsPath.unsafeDecodeUtf top_dir)) (ST.pack (OsPath.unsafeDecodeUtf pkgroot))
|
|
854
|
858
|
|
|
855
|
859
|
mungeDynLibFields :: UnitInfo -> UnitInfo
|
|
856
|
860
|
mungeDynLibFields pkg =
|
| ... |
... |
@@ -1388,7 +1392,7 @@ mergeDatabases logger = foldM merge (emptyUniqMap, emptyUniqMap) . zip [1..] |
|
1388
|
1392
|
where
|
|
1389
|
1393
|
merge (pkg_map, prec_map) (i, UnitDatabase db_path db) = do
|
|
1390
|
1394
|
debugTraceMsg logger 2 $
|
|
1391
|
|
- text "loading package database" <+> text db_path
|
|
|
1395
|
+ text "loading package database" <+> OsPath.pprOsPath db_path
|
|
1392
|
1396
|
forM_ (Set.toList override_set) $ \pkg ->
|
|
1393
|
1397
|
debugTraceMsg logger 2 $
|
|
1394
|
1398
|
text "package" <+> ppr pkg <+>
|