Skip to content
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

Cabal Error Refactor #9018

Merged
merged 33 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
4a438ba
I have added a function "dieWithException" which will replace the die…
SuganyaAK Jun 12, 2023
fe970bc
Codebase is formatted with fourmolu and compiled without warnings.
SuganyaAK Jun 13, 2023
722d778
Enabled fourmolu action
SuganyaAK Jun 13, 2023
574bf67
Running fourmolu through github action as the previous ones failed.
SuganyaAK Jun 14, 2023
5663f3b
Function `exceptionWithMetadata` and constructors for each exception …
SuganyaAK Jun 23, 2023
7bdb74d
I have added a function "dieWithException" which will replace the die…
SuganyaAK Jun 12, 2023
570d1e5
Codebase is formatted with fourmolu and compiled without warnings.
SuganyaAK Jun 13, 2023
6842366
Enabled fourmolu action
SuganyaAK Jun 13, 2023
3f11d92
Running fourmolu through github action as the previous ones failed.
SuganyaAK Jun 14, 2023
9e6a92c
Function `exceptionWithMetadata` and constructors for each exception …
SuganyaAK Jun 23, 2023
efac6a4
Updated changelog
SuganyaAK Jun 23, 2023
56a58ac
Merge branch 'Cabal-Error-Refactor' of https://github.com/SuganyaAK/c…
SuganyaAK Jun 23, 2023
9c90d0b
PatternMatching cases of diewithexception and displayexception reduced
SuganyaAK Jun 23, 2023
56e4473
Delete fourmolu.yaml
SuganyaAK Jun 23, 2023
b47370b
Delete settings.json
SuganyaAK Jun 23, 2023
0e7f15a
Replaced die' calls for modules srcDist.hs and HcPkg.hs
SuganyaAK Jun 26, 2023
a1365df
Merge branch 'Cabal-Error-Refactor' of https://github.com/SuganyaAK/c…
SuganyaAK Jun 26, 2023
7e017ba
Replaced die' calls in modules `build.hs`,`Haddock.hs` and `Program.hs`
SuganyaAK Jun 29, 2023
fb3275a
Replaced die' calls in modules `Build.hs`, `Haddock.hs` and `Program.hs`
SuganyaAK Jun 29, 2023
6a4a886
Replaced die' calls in modules `GHCJS.hs`, `HaskellSuite.hs` and `Bui…
SuganyaAK Jul 4, 2023
1e0bbef
Merge branch 'master' into Cabal-Error-Refactor
SuganyaAK Jul 4, 2023
fe51fb1
Formatted the codebase with Fourmolu
SuganyaAK Jul 7, 2023
d47b8ae
Accepted the new output with error codes and adding the file relevant…
SuganyaAK Jul 7, 2023
2fe47db
Changes in `Utils.hs` and `Errors.hs` to reflect the new error codes
SuganyaAK Jul 7, 2023
2ad952d
Keeping rip intact
SuganyaAK Jul 8, 2023
bbc63bc
test changes
gbaz Jul 12, 2023
cf5a38f
CallStack unmarked from the error output
SuganyaAK Jul 14, 2023
972eb33
callstack unmarked from output
SuganyaAK Jul 14, 2023
12a5846
unmarked callstack in test output
gbaz Jul 14, 2023
2fd3503
Format the codebase with fourmolu
SuganyaAK Jul 15, 2023
9aa458c
Changed to Error identifier to "Cabal-"
SuganyaAK Jul 16, 2023
2dc8828
Updated Constructors as per review comments
SuganyaAK Jul 16, 2023
4fd1225
Rectifying Hlint warning
SuganyaAK Jul 17, 2023
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
1 change: 1 addition & 0 deletions Cabal/Cabal.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ library
Distribution.Simple.Command
Distribution.Simple.Compiler
Distribution.Simple.Configure
Distribution.Simple.Errors
Distribution.Simple.Flag
Distribution.Simple.GHC
Distribution.Simple.GHCJS
Expand Down
19 changes: 7 additions & 12 deletions Cabal/src/Distribution/Simple/Bench.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ import qualified Distribution.Simple.LocalBuildInfo as LBI
import Distribution.Simple.Setup.Benchmark
import Distribution.Simple.UserHooks
import Distribution.Simple.Utils

import Distribution.Types.UnqualComponentName

import Distribution.Simple.Errors
import System.Directory (doesFileExist)
import System.FilePath ((<.>), (</>))

Expand Down Expand Up @@ -65,10 +67,8 @@ bench args pkg_descr lbi flags = do
-- Check that the benchmark executable exists.
exists <- doesFileExist cmd
unless exists $
die' verbosity $
"Could not find benchmark program \""
++ cmd
++ "\". Did you build the package first?"
dieWithException verbosity $
NoBenchMarkProgram cmd

notice verbosity $ startMessage name
-- This will redirect the child process
Expand All @@ -92,9 +92,7 @@ bench args pkg_descr lbi flags = do
exitSuccess

when (PD.hasBenchmarks pkg_descr && null enabledBenchmarks) $
die' verbosity $
"No benchmarks enabled. Did you remember to configure with "
++ "\'--enable-benchmarks\'?"
dieWithException verbosity EnableBenchMark

bmsToRun <- case benchmarkNames of
[] -> return enabledBenchmarks
Expand All @@ -106,11 +104,8 @@ bench args pkg_descr lbi flags = do
Just t -> return t
_
| mkUnqualComponentName bmName `elem` allNames ->
die' verbosity $
"Package configured with benchmark "
++ bmName
++ " disabled."
| otherwise -> die' verbosity $ "no such benchmark: " ++ bmName
dieWithException verbosity $ BenchMarkNameDisabled bmName
| otherwise -> dieWithException verbosity $ NoBenchMark bmName

let totalBenchmarks = length bmsToRun
notice verbosity $ "Running " ++ show totalBenchmarks ++ " benchmarks..."
Expand Down
31 changes: 15 additions & 16 deletions Cabal/src/Distribution/Simple/Build.hs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ import Distribution.Compat.Graph (IsNode (..))

import Control.Monad
import qualified Data.ByteString.Lazy as LBS
import Distribution.Simple.Errors
import System.Directory (doesFileExist, getCurrentDirectory, removeFile)
import System.FilePath (takeDirectory, (<.>), (</>))

Expand Down Expand Up @@ -198,9 +199,7 @@ dumpBuildInfo verbosity distPref dumpBuildInfoFlag pkg_descr lbi flags = do

(compilerProg, _) <- case flavorToProgram (compilerFlavor (compiler lbi)) of
Nothing ->
die' verbosity $
"dumpBuildInfo: Unknown compiler flavor: "
++ show (compilerFlavor (compiler lbi))
dieWithException verbosity $ UnknownCompilerFlavor (compilerFlavor (compiler lbi))
Just program -> requireProgram verbosity program (withPrograms lbi)

let (warns, json) = mkBuildInfo pwd pkg_descr lbi flags (compilerProg, compiler lbi) activeTargets
Expand Down Expand Up @@ -248,9 +247,9 @@ repl pkg_descr lbi flags suffixes args = do
-- This seems DEEPLY questionable.
[] -> case allTargetsInBuildOrder' pkg_descr lbi of
(target : _) -> return target
[] -> die' verbosity $ "Failed to determine target."
[] -> dieWithException verbosity $ FailedToDetermineTarget
[target] -> return target
_ -> die' verbosity $ "The 'repl' command does not support multiple targets at once."
_ -> dieWithException verbosity $ NoMultipleTargets
let componentsToBuild = neededTargetsInBuildOrder' pkg_descr lbi [nodeKey target]
debug verbosity $
"Component build order: "
Expand Down Expand Up @@ -313,7 +312,7 @@ startInterpreter verbosity programDb comp platform packageDBs =
case compilerFlavor comp of
GHC -> GHC.startInterpreter verbosity programDb comp platform packageDBs
GHCJS -> GHCJS.startInterpreter verbosity programDb comp platform packageDBs
_ -> die' verbosity "A REPL is not supported with this compiler."
_ -> dieWithException verbosity REPLNotSupported

buildComponent
:: Verbosity
Expand Down Expand Up @@ -512,7 +511,7 @@ buildComponent
(CTest TestSuite{testInterface = TestSuiteUnsupported tt})
_
_ =
die' verbosity $ "No support for building test suite type " ++ prettyShow tt
dieWithException verbosity $ NoSupportBuildingTestSuite tt
buildComponent
verbosity
numJobs
Expand Down Expand Up @@ -544,7 +543,7 @@ buildComponent
(CBench Benchmark{benchmarkInterface = BenchmarkUnsupported tt})
_
_ =
die' verbosity $ "No support for building benchmark type " ++ prettyShow tt
dieWithException verbosity $ NoSupportBuildingBenchMark tt

generateCode
:: [String]
Expand Down Expand Up @@ -717,7 +716,7 @@ replComponent
(CTest TestSuite{testInterface = TestSuiteUnsupported tt})
_
_ =
die' verbosity $ "No support for building test suite type " ++ prettyShow tt
dieWithException verbosity $ NoSupportBuildingTestSuite tt
replComponent
replFlags
verbosity
Expand All @@ -742,7 +741,7 @@ replComponent
(CBench Benchmark{benchmarkInterface = BenchmarkUnsupported tt})
_
_ =
die' verbosity $ "No support for building benchmark type " ++ prettyShow tt
dieWithException verbosity $ NoSupportBuildingBenchMark tt

----------------------------------------------------
-- Shared code for buildComponent and replComponent
Expand Down Expand Up @@ -938,7 +937,7 @@ buildLib verbosity numJobs pkg_descr lbi lib clbi =
GHCJS -> GHCJS.buildLib verbosity numJobs pkg_descr lbi lib clbi
UHC -> UHC.buildLib verbosity pkg_descr lbi lib clbi
HaskellSuite{} -> HaskellSuite.buildLib verbosity pkg_descr lbi lib clbi
_ -> die' verbosity "Building is not supported with this compiler."
_ -> dieWithException verbosity BuildingNotSupportedWithCompiler

-- | Build a foreign library
--
Expand All @@ -955,7 +954,7 @@ buildFLib
buildFLib verbosity numJobs pkg_descr lbi flib clbi =
case compilerFlavor (compiler lbi) of
GHC -> GHC.buildFLib verbosity numJobs pkg_descr lbi flib clbi
_ -> die' verbosity "Building is not supported with this compiler."
_ -> dieWithException verbosity BuildingNotSupportedWithCompiler

buildExe
:: Verbosity
Expand All @@ -970,7 +969,7 @@ buildExe verbosity numJobs pkg_descr lbi exe clbi =
GHC -> GHC.buildExe verbosity numJobs pkg_descr lbi exe clbi
GHCJS -> GHCJS.buildExe verbosity numJobs pkg_descr lbi exe clbi
UHC -> UHC.buildExe verbosity pkg_descr lbi exe clbi
_ -> die' verbosity "Building is not supported with this compiler."
_ -> dieWithException verbosity BuildingNotSupportedWithCompiler

replLib
:: ReplOptions
Expand All @@ -986,7 +985,7 @@ replLib replFlags verbosity pkg_descr lbi lib clbi =
-- NoFlag as the numJobs parameter.
GHC -> GHC.replLib replFlags verbosity NoFlag pkg_descr lbi lib clbi
GHCJS -> GHCJS.replLib (replOptionsFlags replFlags) verbosity NoFlag pkg_descr lbi lib clbi
_ -> die' verbosity "A REPL is not supported for this compiler."
_ -> dieWithException verbosity REPLNotSupported

replExe
:: ReplOptions
Expand All @@ -1000,7 +999,7 @@ replExe replFlags verbosity pkg_descr lbi exe clbi =
case compilerFlavor (compiler lbi) of
GHC -> GHC.replExe replFlags verbosity NoFlag pkg_descr lbi exe clbi
GHCJS -> GHCJS.replExe (replOptionsFlags replFlags) verbosity NoFlag pkg_descr lbi exe clbi
_ -> die' verbosity "A REPL is not supported for this compiler."
_ -> dieWithException verbosity REPLNotSupported

replFLib
:: ReplOptions
Expand All @@ -1013,7 +1012,7 @@ replFLib
replFLib replFlags verbosity pkg_descr lbi exe clbi =
case compilerFlavor (compiler lbi) of
GHC -> GHC.replFLib replFlags verbosity NoFlag pkg_descr lbi exe clbi
_ -> die' verbosity "A REPL is not supported for this compiler."
_ -> dieWithException verbosity REPLNotSupported

-- | Runs 'componentInitialBuildSteps' on every configured component.
initialBuildSteps
Expand Down
7 changes: 4 additions & 3 deletions Cabal/src/Distribution/Simple/BuildPaths.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,20 @@ module Distribution.Simple.BuildPaths
import Distribution.Compat.Prelude
import Prelude ()

import Data.List (stripPrefix)
import Distribution.Compiler
import Distribution.ModuleName as ModuleName
import Distribution.Package
import Distribution.PackageDescription
import Distribution.Pretty
import Distribution.Simple.Errors
import Distribution.Simple.LocalBuildInfo
import Distribution.Simple.Setup.Common (defaultDistPref)
import Distribution.Simple.Setup.Haddock (HaddockTarget (..))
import Distribution.Simple.Utils
import Distribution.System
import Distribution.Utils.Path
import Distribution.Verbosity

import Data.List (stripPrefix)
import System.FilePath (normalise, (<.>), (</>))

-- ---------------------------------------------------------------------------
Expand Down Expand Up @@ -192,7 +192,8 @@ getSourceFiles verbosity dirs modules = flip traverse modules $ \m ->
findFileWithExtension ["hs", "lhs", "hsig", "lhsig"] dirs (ModuleName.toFilePath m)
>>= maybe (notFound m) (return . normalise)
where
notFound module_ = die' verbosity $ "can't find source for module " ++ prettyShow module_
notFound module_ =
dieWithException verbosity $ CantFindSourceModule module_

-- | The directory where we put build results for an executable
exeBuildDir :: LocalBuildInfo -> Executable -> FilePath
Expand Down
Loading
Loading