Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC

Commits:

8 changed files:

Changes:

  • compiler/GHC/Data/OsPath.hs
    ... ... @@ -11,6 +11,15 @@ module GHC.Data.OsPath
    11 11
       -- * Common utility functions
    
    12 12
       , (</>)
    
    13 13
       , (<.>)
    
    14
    +  , splitSearchPath
    
    15
    +  , isRelative
    
    16
    +  , dropTrailingPathSeparator
    
    17
    +  , takeDirectory
    
    18
    +  , isSuffixOf
    
    19
    +  , doesDirectoryExist
    
    20
    +  , doesFileExist
    
    21
    +  , getDirectoryContents
    
    22
    +  , createDirectoryIfMissing
    
    14 23
       )
    
    15 24
       where
    
    16 25
     
    
    ... ... @@ -20,6 +29,8 @@ import GHC.Utils.Misc (HasCallStack)
    20 29
     import GHC.Utils.Panic (panic)
    
    21 30
     
    
    22 31
     import System.OsPath
    
    32
    +import System.OsString (isSuffixOf)
    
    33
    +import System.Directory.OsPath (doesDirectoryExist, doesFileExist, getDirectoryContents, createDirectoryIfMissing)
    
    23 34
     import System.Directory.Internal (os)
    
    24 35
     
    
    25 36
     -- | Decode an 'OsPath' to 'FilePath', throwing an 'error' if decoding failed.
    

  • compiler/GHC/Driver/Backpack.hs
    ... ... @@ -441,7 +441,7 @@ addUnit u = do
    441 441
             Nothing  -> panic "addUnit: called too early"
    
    442 442
             Just dbs ->
    
    443 443
              let newdb = UnitDatabase
    
    444
    -               { unitDatabasePath  = "(in memory " ++ showSDoc dflags0 (ppr (unitId u)) ++ ")"
    
    444
    +               { unitDatabasePath  = unsafeEncodeUtf $ "(in memory " ++ showSDoc dflags0 (ppr (unitId u)) ++ ")"
    
    445 445
                    , unitDatabaseUnits = [u]
    
    446 446
                    }
    
    447 447
              in return (dbs ++ [newdb]) -- added at the end because ordering matters
    

  • compiler/GHC/Driver/CodeOutput.hs
    ... ... @@ -38,7 +38,7 @@ import GHC.Driver.LlvmConfigCache (LlvmConfigCache)
    38 38
     import GHC.Driver.Ppr
    
    39 39
     import GHC.Driver.Backend
    
    40 40
     
    
    41
    -import GHC.Data.OsPath
    
    41
    +import GHC.Data.OsPath qualified as OsPath
    
    42 42
     import qualified GHC.Data.ShortText as ST
    
    43 43
     import GHC.Data.Stream           ( liftIO )
    
    44 44
     import qualified GHC.Data.Stream as Stream
    
    ... ... @@ -61,8 +61,6 @@ import GHC.Types.ForeignStubs
    61 61
     import GHC.Types.Unique.DSM
    
    62 62
     import GHC.Types.Unique.Supply ( UniqueTag(..) )
    
    63 63
     
    
    64
    -import System.Directory
    
    65
    -import System.FilePath
    
    66 64
     import System.IO
    
    67 65
     import Data.Set (Set)
    
    68 66
     import qualified Data.Set as Set
    
    ... ... @@ -321,10 +319,9 @@ outputForeignStubs logger tmpfs dflags unit_state mod location stubs
    321 319
             stub_h_file_exists <-
    
    322 320
               case mkStubPaths (initFinderOpts dflags) (moduleName mod) location of
    
    323 321
                 Nothing -> pure False
    
    324
    -            Just path -> do
    
    325
    -              let stub_h = unsafeDecodeUtf path
    
    326
    -              createDirectoryIfMissing True (takeDirectory stub_h)
    
    327
    -              outputForeignStubs_help stub_h stub_h_output_w
    
    322
    +            Just stub_h -> do
    
    323
    +              OsPath.createDirectoryIfMissing True (OsPath.takeDirectory stub_h)
    
    324
    +              outputForeignStubs_help (OsPath.unsafeDecodeUtf stub_h) stub_h_output_w
    
    328 325
                         ("#include <HsFFI.h>\n" ++ cplusplus_hdr) cplusplus_ftr
    
    329 326
     
    
    330 327
             putDumpFileMaybe logger Opt_D_dump_foreign
    

  • compiler/GHC/Driver/DynFlags.hs
    ... ... @@ -101,6 +101,7 @@ import GHC.Core.Unfold
    101 101
     import GHC.Data.Bool
    
    102 102
     import GHC.Data.EnumSet (EnumSet)
    
    103 103
     import GHC.Data.Maybe
    
    104
    +import GHC.Data.OsPath ( OsPath )
    
    104 105
     import GHC.Builtin.Names ( mAIN_NAME )
    
    105 106
     import GHC.Driver.Backend
    
    106 107
     import GHC.Driver.Flags
    
    ... ... @@ -953,7 +954,7 @@ setDynamicNow dflags0 =
    953 954
     data PkgDbRef
    
    954 955
       = GlobalPkgDb
    
    955 956
       | UserPkgDb
    
    956
    -  | PkgDbPath FilePath
    
    957
    +  | PkgDbPath OsPath
    
    957 958
       deriving Eq
    
    958 959
     
    
    959 960
     
    

  • compiler/GHC/Driver/Session.hs
    ... ... @@ -300,6 +300,8 @@ import qualified Data.Set as Set
    300 300
     import GHC.Types.Unique.Set
    
    301 301
     import Data.Word
    
    302 302
     import System.FilePath
    
    303
    +import qualified GHC.Data.OsPath as OsPath
    
    304
    +
    
    303 305
     import Text.ParserCombinators.ReadP hiding (char)
    
    304 306
     import Text.ParserCombinators.ReadP as R
    
    305 307
     
    
    ... ... @@ -2071,7 +2073,7 @@ package_flags_deps :: [(Deprecation, Flag (CmdLineP DynFlags))]
    2071 2073
     package_flags_deps = [
    
    2072 2074
             ------- Packages ----------------------------------------------------
    
    2073 2075
         make_ord_flag defFlag "package-db"
    
    2074
    -      (HasArg (addPkgDbRef . PkgDbPath))
    
    2076
    +      (HasArg (addPkgDbRef . PkgDbPath . OsPath.unsafeEncodeUtf))
    
    2075 2077
       , make_ord_flag defFlag "clear-package-db"      (NoArg clearPkgDb)
    
    2076 2078
       , make_ord_flag defFlag "no-global-package-db"  (NoArg removeGlobalPkgDb)
    
    2077 2079
       , make_ord_flag defFlag "no-user-package-db"    (NoArg removeUserPkgDb)
    
    ... ... @@ -2081,7 +2083,7 @@ package_flags_deps = [
    2081 2083
           (NoArg (addPkgDbRef UserPkgDb))
    
    2082 2084
         -- backwards compat with GHC<=7.4 :
    
    2083 2085
       , make_dep_flag defFlag "package-conf"
    
    2084
    -      (HasArg $ addPkgDbRef . PkgDbPath) "Use -package-db instead"
    
    2086
    +      (HasArg $ addPkgDbRef . PkgDbPath . OsPath.unsafeEncodeUtf) "Use -package-db instead"
    
    2085 2087
       , make_dep_flag defFlag "no-user-package-conf"
    
    2086 2088
           (NoArg removeUserPkgDb)              "Use -no-user-package-db instead"
    
    2087 2089
       , make_ord_flag defGhcFlag "package-name"       (HasArg $ \name ->
    
    ... ... @@ -3307,7 +3309,7 @@ parseEnvFile :: FilePath -> String -> DynP ()
    3307 3309
     parseEnvFile envfile = mapM_ parseEntry . lines
    
    3308 3310
       where
    
    3309 3311
         parseEntry str = case words str of
    
    3310
    -      ("package-db": _)     -> addPkgDbRef (PkgDbPath (envdir </> db))
    
    3312
    +      ("package-db": _)     -> addPkgDbRef (PkgDbPath (OsPath.unsafeEncodeUtf (envdir </> db)))
    
    3311 3313
             -- relative package dbs are interpreted relative to the env file
    
    3312 3314
             where envdir = takeDirectory envfile
    
    3313 3315
                   db     = drop 11 str
    

  • compiler/GHC/Unit/Finder.hs
    ... ... @@ -63,7 +63,6 @@ import GHC.Types.SourceFile
    63 63
     
    
    64 64
     import GHC.Fingerprint
    
    65 65
     import Data.IORef
    
    66
    -import System.Directory.OsPath
    
    67 66
     import Control.Applicative ((<|>))
    
    68 67
     import Control.Monad
    
    69 68
     import Data.Time
    

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

  • compiler/GHC/Utils/Outputable.hs
    ... ... @@ -149,6 +149,7 @@ import Data.String
    149 149
     import Data.Word
    
    150 150
     import System.IO        ( Handle )
    
    151 151
     import System.FilePath
    
    152
    +import System.OsPath (OsPath, decodeUtf)
    
    152 153
     import Text.Printf
    
    153 154
     import Numeric (showFFloat)
    
    154 155
     import Numeric.Natural (Natural)
    
    ... ... @@ -1101,6 +1102,8 @@ instance Outputable Extension where
    1101 1102
     instance Outputable ModuleName where
    
    1102 1103
       ppr = pprModuleName
    
    1103 1104
     
    
    1105
    +instance Outputable OsPath where
    
    1106
    +  ppr p = text $ either show id (decodeUtf p)
    
    1104 1107
     
    
    1105 1108
     pprModuleName :: IsLine doc => ModuleName -> doc
    
    1106 1109
     pprModuleName (ModuleName nm) =