Skip to content

WIP: Adapt to simplifed subsumption proposal #6545

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions Cabal/Distribution/Compat/ResponseFile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,15 @@ expandResponse = go recursionLimit "."
recursionLimit = 100

go :: Int -> FilePath -> [String] -> IO [String]
go n dir
| n >= 0 = fmap concat . mapM (expand n dir)
| otherwise = const $ hPutStrLn stderr "Error: response file recursion limit exceeded." >> exitFailure
go n dir xs
| n >= 0 = fmap concat $ mapM (\x -> expand n dir x) xs
| otherwise = hPutStrLn stderr "Error: response file recursion limit exceeded." >> exitFailure

expand :: Int -> FilePath -> String -> IO [String]
expand n dir arg@('@':f) = readRecursively n (dir </> f) `catchIOError` (const $ print "?" >> return [arg])
expand _n _dir x = return [x]

readRecursively :: Int -> FilePath -> IO [String]
readRecursively n f = go (n - 1) (takeDirectory f) =<< unescapeArgs <$> readFile f
readRecursively n f = do
xs <- unescapeArgs <$> readFile f
go (n - 1) (takeDirectory f) xs
2 changes: 1 addition & 1 deletion Cabal/Distribution/FieldGrammar/FieldDescrs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fieldDescrPretty (F m) fn = pPretty <$> Map.lookup fn m

-- | Lookup a field value parser.
fieldDescrParse :: P.CabalParsing m => FieldDescrs s a -> P.FieldName -> Maybe (s -> m s)
fieldDescrParse (F m) fn = pParse <$> Map.lookup fn m
fieldDescrParse (F m) fn = (\f -> pParse f) <$> Map.lookup fn m

fieldDescrsToList
:: P.CabalParsing m
Expand Down
4 changes: 2 additions & 2 deletions Cabal/Distribution/Fields/ParseResult.hs
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ parseString
-> IO a
parseString parser verbosity name bs = do
let (warnings, result) = runParseResult (parser bs)
traverse_ (warn verbosity . showPWarning name) warnings
traverse_ (\warning -> warn verbosity $ showPWarning name warning) warnings
case result of
Right x -> return x
Left (_, errors) -> do
traverse_ (warn verbosity . showPError name) errors
traverse_ (\warning -> warn verbosity $ showPError name warning) errors
die' verbosity $ "Failed parsing \"" ++ name ++ "\"."
27 changes: 17 additions & 10 deletions Cabal/Distribution/Make.hs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@ import Distribution.Pretty
import System.Environment (getArgs, getProgName)
import System.Exit

import qualified Prelude (IO)

defaultMain :: IO ()
defaultMain = getArgs >>= defaultMainArgs
defaultMain = getArgs >>= \args -> defaultMainArgs args

defaultMainArgs :: [String] -> IO ()
defaultMainArgs = defaultMainHelper
Expand Down Expand Up @@ -114,6 +116,9 @@ defaultMainHelper args =
++ prettyShow cabalVersion

progs = defaultProgramDb
-- N.B. Use (Prelude.IO ()) instead of (HasCallStack => IO ()) to avoid
-- impredicativity.
commands :: [Command (Prelude.IO ())]
commands =
[configureCommand progs `commandAddAction` configureAction
,buildCommand progs `commandAddAction` buildAction
Expand All @@ -126,7 +131,9 @@ defaultMainHelper args =
,unregisterCommand `commandAddAction` unregisterAction
]

configureAction :: ConfigFlags -> [String] -> IO ()
type Action flags = flags -> [String] -> Prelude.IO ()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes (WithCallStack)IO to Prelude.IO, and I guess this is the place where we'd like the CallStacks to propagate.


configureAction :: Action ConfigFlags
configureAction flags args = do
noExtraFlags args
let verbosity = fromFlag (configVerbosity flags)
Expand All @@ -135,7 +142,7 @@ configureAction flags args = do
: configureArgs backwardsCompatHack flags
where backwardsCompatHack = True

copyAction :: CopyFlags -> [String] -> IO ()
copyAction :: Action CopyFlags
copyAction flags args = do
noExtraFlags args
let destArgs = case fromFlag $ copyDest flags of
Expand All @@ -145,40 +152,40 @@ copyAction flags args = do

rawSystemExit (fromFlag $ copyVerbosity flags) "make" destArgs

installAction :: InstallFlags -> [String] -> IO ()
installAction :: Action InstallFlags
installAction flags args = do
noExtraFlags args
rawSystemExit (fromFlag $ installVerbosity flags) "make" ["install"]
rawSystemExit (fromFlag $ installVerbosity flags) "make" ["register"]

haddockAction :: HaddockFlags -> [String] -> IO ()
haddockAction :: Action HaddockFlags
haddockAction flags args = do
noExtraFlags args
rawSystemExit (fromFlag $ haddockVerbosity flags) "make" ["docs"]
`catchIO` \_ ->
rawSystemExit (fromFlag $ haddockVerbosity flags) "make" ["doc"]

buildAction :: BuildFlags -> [String] -> IO ()
buildAction :: Action BuildFlags
buildAction flags args = do
noExtraFlags args
rawSystemExit (fromFlag $ buildVerbosity flags) "make" []

cleanAction :: CleanFlags -> [String] -> IO ()
cleanAction :: Action CleanFlags
cleanAction flags args = do
noExtraFlags args
rawSystemExit (fromFlag $ cleanVerbosity flags) "make" ["clean"]

sdistAction :: SDistFlags -> [String] -> IO ()
sdistAction :: Action SDistFlags
sdistAction flags args = do
noExtraFlags args
rawSystemExit (fromFlag $ sDistVerbosity flags) "make" ["dist"]

registerAction :: RegisterFlags -> [String] -> IO ()
registerAction :: Action RegisterFlags
registerAction flags args = do
noExtraFlags args
rawSystemExit (fromFlag $ regVerbosity flags) "make" ["register"]

unregisterAction :: RegisterFlags -> [String] -> IO ()
unregisterAction :: Action RegisterFlags
unregisterAction flags args = do
noExtraFlags args
rawSystemExit (fromFlag $ regVerbosity flags) "make" ["unregister"]
6 changes: 3 additions & 3 deletions Cabal/Distribution/Simple.hs
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ autoconfUserHooks
preUnreg = readHook regVerbosity regDistPref
}
where defaultPostConf :: Args -> ConfigFlags -> PackageDescription
-> LocalBuildInfo -> IO ()
-> LocalBuildInfo -> Prelude.IO ()
defaultPostConf args flags pkg_descr lbi
= do let verbosity = fromFlag (configVerbosity flags)
baseDir lbi' = fromMaybe ""
Expand All @@ -692,7 +692,7 @@ autoconfUserHooks
readHookWithArgs :: (a -> Flag Verbosity)
-> (a -> Flag FilePath)
-> Args -> a
-> IO HookedBuildInfo
-> Prelude.IO HookedBuildInfo
readHookWithArgs get_verbosity get_dist_pref _ flags = do
dist_dir <- findDistPrefOrDefault (get_dist_pref flags)
getHookedBuildInfo verbosity (dist_dir </> "build")
Expand All @@ -701,7 +701,7 @@ autoconfUserHooks

readHook :: (a -> Flag Verbosity)
-> (a -> Flag FilePath)
-> Args -> a -> IO HookedBuildInfo
-> Args -> a -> Prelude.IO HookedBuildInfo
readHook get_verbosity get_dist_pref a flags = do
noExtraFlags a
dist_dir <- findDistPrefOrDefault (get_dist_pref flags)
Expand Down
3 changes: 2 additions & 1 deletion Cabal/Distribution/Simple/Bench.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import Distribution.Pretty
import System.Exit ( ExitCode(..), exitFailure, exitSuccess )
import System.Directory ( doesFileExist )
import System.FilePath ( (</>), (<.>) )
import qualified Prelude (IO)

-- | Perform the \"@.\/setup bench@\" action.
bench :: Args -- ^positional command-line arguments
Expand All @@ -49,7 +50,7 @@ bench args pkg_descr lbi flags = do
enabledBenchmarks = map fst (LBI.enabledBenchLBIs pkg_descr lbi)

-- Run the benchmark
doBench :: PD.Benchmark -> IO ExitCode
doBench :: PD.Benchmark -> Prelude.IO ExitCode
doBench bm =
case PD.benchmarkInterface bm of
PD.BenchmarkExeV10 _ _ -> do
Expand Down
30 changes: 16 additions & 14 deletions Cabal/Distribution/Simple/Configure.hs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ import Distribution.Compat.Environment ( lookupEnv )
import Distribution.Compat.Exception ( catchExit, catchIO )

import qualified Data.Set as Set
import qualified Prelude (IO)
Copy link
Collaborator

@phadej phadej Feb 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have

type NoCallStackIO a = OrigPrelude.IO a

defined in Distribution.Compat.Prelude, please don't import Prelude (IO).



type UseExternalInternalDeps = Bool
Expand Down Expand Up @@ -229,25 +230,25 @@ getConfigStateFile filename = do
-- info.
tryGetConfigStateFile :: FilePath -- ^ The file path of the @setup-config@ file.
-> IO (Either ConfigStateFileError LocalBuildInfo)
tryGetConfigStateFile = try . getConfigStateFile
tryGetConfigStateFile path = try $ getConfigStateFile path

-- | Try to read the 'localBuildInfoFile'.
tryGetPersistBuildConfig :: FilePath -- ^ The @dist@ directory path.
-> IO (Either ConfigStateFileError LocalBuildInfo)
tryGetPersistBuildConfig = try . getPersistBuildConfig
tryGetPersistBuildConfig path = try $ getPersistBuildConfig path

-- | Read the 'localBuildInfoFile'. Throw an exception if the file is
-- missing, if the file cannot be read, or if the file was created by an older
-- version of Cabal.
getPersistBuildConfig :: FilePath -- ^ The @dist@ directory path.
-> IO LocalBuildInfo
getPersistBuildConfig = getConfigStateFile . localBuildInfoFile
getPersistBuildConfig path = getConfigStateFile $ localBuildInfoFile path

-- | Try to read the 'localBuildInfoFile'.
maybeGetPersistBuildConfig :: FilePath -- ^ The @dist@ directory path.
-> IO (Maybe LocalBuildInfo)
maybeGetPersistBuildConfig =
liftM (either (const Nothing) Just) . tryGetPersistBuildConfig
maybeGetPersistBuildConfig path =
liftM (either (const Nothing) Just) $ tryGetPersistBuildConfig path

-- | After running configure, output the 'LocalBuildInfo' to the
-- 'localBuildInfoFile'.
Expand Down Expand Up @@ -452,10 +453,11 @@ configure (pkg_descr0, pbi) cfg = do
-- version of a dependency, and the executable to use another.
(allConstraints :: [Dependency],
requiredDepsMap :: Map (PackageName, ComponentName) InstalledPackageInfo)
<- either (die' verbosity) return $
combinedConstraints (configConstraints cfg)
(configDependencies cfg)
installedPackageSet
<- case combinedConstraints (configConstraints cfg)
(configDependencies cfg)
installedPackageSet of
Left err -> die' verbosity err
Right r -> return r

-- pkg_descr: The resolved package description, that does not contain any
-- conditionals, because we have have an assignment for
Expand Down Expand Up @@ -590,9 +592,9 @@ configure (pkg_descr0, pbi) cfg = do
, Nothing == desugarBuildTool pkg_descr buildTool ]
externBuildToolDeps ++ unknownBuildTools

programDb' <-
configureAllKnownPrograms (lessVerbose verbosity) programDb
>>= configureRequiredPrograms verbosity requiredBuildTools
programDb' <- do
progs <- configureAllKnownPrograms (lessVerbose verbosity) programDb
configureRequiredPrograms verbosity requiredBuildTools progs

(pkg_descr', programDb'') <-
configurePkgconfigPackages verbosity pkg_descr programDb' enabled
Expand Down Expand Up @@ -1532,7 +1534,7 @@ configureRequiredPrograms verbosity deps progdb =
-- program matches the required version; otherwise we will accept
-- any version of the program and assume that it is a simpleProgram.
configureRequiredProgram :: Verbosity -> ProgramDb -> LegacyExeDependency
-> IO ProgramDb
-> Prelude.IO ProgramDb
configureRequiredProgram verbosity progdb
(LegacyExeDependency progName verRange) =
case lookupKnownProgram progName progdb of
Expand Down Expand Up @@ -1952,7 +1954,7 @@ checkPackageProblems verbosity dir gpkg pkg = do
errors = [ e | PackageBuildImpossible e <- pureChecks ++ ioChecks ]
warnings = [ w | PackageBuildWarning w <- pureChecks ++ ioChecks ]
if null errors
then traverse_ (warn verbosity) warnings
then traverse_ (\w -> warn verbosity w) warnings
else die' verbosity (intercalate "\n\n" errors)

-- | Preform checks if a relocatable build is allowed
Expand Down
14 changes: 8 additions & 6 deletions Cabal/Distribution/Simple/GHC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ import qualified System.Info
#ifndef mingw32_HOST_OS
import System.Posix (createSymbolicLink)
#endif /* mingw32_HOST_OS */
import qualified Prelude (IO)

-- -----------------------------------------------------------------------------
-- Configuring
Expand Down Expand Up @@ -454,10 +455,10 @@ getInstalledPackagesMonitorFiles :: Verbosity -> Platform
-> ProgramDb
-> [PackageDB]
-> IO [FilePath]
getInstalledPackagesMonitorFiles verbosity platform progdb =
traverse getPackageDBPath
getInstalledPackagesMonitorFiles verbosity platform progdb pkgdbs =
traverse getPackageDBPath pkgdbs
where
getPackageDBPath :: PackageDB -> IO FilePath
getPackageDBPath :: PackageDB -> Prelude.IO FilePath
getPackageDBPath GlobalPackageDB =
selectMonitorFile =<< getGlobalPackageDB verbosity ghcProg

Expand Down Expand Up @@ -1993,9 +1994,9 @@ installLib verbosity lbi targetDir dynlibTargetDir _builtDir pkg lib clbi = do
installOrdinary = install False
installShared = install True

copyModuleFiles ext =
findModuleFilesEx verbosity [builtDir] [ext] (allLibModules lib clbi)
>>= installOrdinaryFiles verbosity targetDir
copyModuleFiles ext = do
files <- findModuleFilesEx verbosity [builtDir] [ext] (allLibModules lib clbi)
installOrdinaryFiles verbosity targetDir files

compiler_id = compilerId (compiler lbi)
platform = hostPlatform lbi
Expand Down Expand Up @@ -2050,6 +2051,7 @@ registerPackage verbosity progdb packageDbs installedPkgInfo registerOptions =
pkgRoot :: Verbosity -> LocalBuildInfo -> PackageDB -> IO FilePath
pkgRoot verbosity lbi = pkgRoot'
where
pkgRoot' :: PackageDB -> IO FilePath
pkgRoot' GlobalPackageDB =
let ghcProg = fromMaybe (error "GHC.pkgRoot: no ghc program") $ lookupProgram ghcProgram (withPrograms lbi)
in fmap takeDirectory (getGlobalPackageDB verbosity ghcProg)
Expand Down
4 changes: 2 additions & 2 deletions Cabal/Distribution/Simple/GHC/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ configureToolchain :: GhcImplInfo
configureToolchain _implInfo ghcProg ghcInfo =
addKnownProgram gccProgram {
programFindLocation = findProg gccProgramName extraGccPath,
programPostConf = configureGcc
programPostConf = \v cpgm -> configureGcc v cpgm
}
. addKnownProgram ldProgram {
programFindLocation = findProg ldProgramName extraLdPath,
programPostConf = configureLd
programPostConf = \v cpgm -> configureLd v cpgm
}
. addKnownProgram arProgram {
programFindLocation = findProg arProgramName extraArPath
Expand Down
14 changes: 8 additions & 6 deletions Cabal/Distribution/Simple/GHCJS.hs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ import System.FilePath ( (</>), (<.>), takeExtension
, takeDirectory, replaceExtension
,isRelative )
import qualified System.Info
import qualified Prelude (IO)

-- -----------------------------------------------------------------------------
-- Configuring
Expand Down Expand Up @@ -339,10 +340,10 @@ getInstalledPackagesMonitorFiles :: Verbosity -> Platform
-> ProgramDb
-> [PackageDB]
-> IO [FilePath]
getInstalledPackagesMonitorFiles verbosity platform progdb =
traverse getPackageDBPath
getInstalledPackagesMonitorFiles verbosity platform progdb pkgdb =
traverse getPackageDBPath pkgdb
where
getPackageDBPath :: PackageDB -> IO FilePath
getPackageDBPath :: PackageDB -> Prelude.IO FilePath
getPackageDBPath GlobalPackageDB =
selectMonitorFile =<< getGlobalPackageDB verbosity ghcjsProg

Expand Down Expand Up @@ -1719,9 +1720,9 @@ installLib verbosity lbi targetDir dynlibTargetDir _builtDir _pkg lib clbi = do
installOrdinary = install False True
installShared = install True True

copyModuleFiles ext =
findModuleFilesEx verbosity [builtDir'] [ext] (allLibModules lib clbi)
>>= installOrdinaryFiles verbosity targetDir
copyModuleFiles ext = do
files <- findModuleFilesEx verbosity [builtDir'] [ext] (allLibModules lib clbi)
installOrdinaryFiles verbosity targetDir files

compiler_id = compilerId (compiler lbi)
platform = hostPlatform lbi
Expand Down Expand Up @@ -1799,6 +1800,7 @@ registerPackage verbosity progdb packageDbs installedPkgInfo registerOptions =
pkgRoot :: Verbosity -> LocalBuildInfo -> PackageDB -> IO FilePath
pkgRoot verbosity lbi = pkgRoot'
where
pkgRoot' :: PackageDB -> IO FilePath
pkgRoot' GlobalPackageDB =
let ghcjsProg = fromMaybe (error "GHCJS.pkgRoot: no ghcjs program") $ lookupProgram ghcjsProgram (withPrograms lbi)
in fmap takeDirectory (getGlobalPackageDB verbosity ghcjsProg)
Expand Down
13 changes: 8 additions & 5 deletions Cabal/Distribution/Simple/Haddock.hs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ haddock pkg_descr lbi suffixes flags' = do

for_ (extraDocFiles pkg_descr) $ \ fpath -> do
files <- matchDirFileGlob verbosity (specVersion pkg_descr) "." fpath
for_ files $ copyFileTo verbosity (unDir $ argOutputDir commonArgs)
for_ files $ \f -> copyFileTo verbosity (unDir $ argOutputDir commonArgs) f

-- ------------------------------------------------------------------------------
-- Contributions to HaddockArgs (see also Doctest.hs for very similar code).
Expand Down Expand Up @@ -501,7 +501,7 @@ getInterfaces :: Verbosity
-> IO HaddockArgs
getInterfaces verbosity lbi clbi htmlTemplate = do
(packageFlags, warnings) <- haddockPackageFlags verbosity lbi clbi htmlTemplate
traverse_ (warn (verboseUnmarkOutput verbosity)) warnings
traverse_ (\w -> warn (verboseUnmarkOutput verbosity) w) warnings
return $ mempty {
argInterfaces = packageFlags
}
Expand Down Expand Up @@ -833,10 +833,13 @@ hscolour' :: (String -> IO ()) -- ^ Called when the 'hscolour' exe is not found.
-> [PPSuffixHandler]
-> HscolourFlags
-> IO ()
hscolour' onNoHsColour haddockTarget pkg_descr lbi suffixes flags =
either onNoHsColour (\(hscolourProg, _, _) -> go hscolourProg) =<<
lookupProgramVersion verbosity hscolourProgram
hscolour' onNoHsColour haddockTarget pkg_descr lbi suffixes flags = do
result <- lookupProgramVersion verbosity hscolourProgram
(orLaterVersion (mkVersion [1,8])) (withPrograms lbi)
case result of
Left err -> onNoHsColour err
Right (hscolourProg, _, _) -> go hscolourProg

where
go :: ConfiguredProgram -> IO ()
go hscolourProg = do
Expand Down
Loading