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

Add Legacy Comparison Flag #1

Open
wants to merge 1 commit into
base: parse-cabal-project-parsec
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions cabal-install/cabal-install.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ flag git-rev
default: False
manual: True

flag legacy-comparison
description: Enable comparison between the new and legacy cabal.project parser
default: False
manual: True

common warnings
ghc-options:
-Wall
Expand Down Expand Up @@ -282,6 +287,9 @@ library
build-depends: githash ^>= 0.1.7.0
cpp-options: -DGIT_REV

if flag(legacy-comparison)
cpp-options: -DLEGACY_COMPARISON

executable cabal
import: warnings, base-dep
main-is: Main.hs
Expand Down
49 changes: 34 additions & 15 deletions cabal-install/src/Distribution/Client/ProjectConfig.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TypeApplications #-}
{-# OPTIONS_GHC -Wno-unused-matches #-}

-- | Handling project configuration.
module Distribution.Client.ProjectConfig
Expand Down Expand Up @@ -117,7 +118,9 @@ import Distribution.Client.HttpUtils
)
import Distribution.Client.Types
import Distribution.Client.Utils.Parsec (renderParseError)
#ifdef LEGACY_COMPARISON
import GHC.Stack (HasCallStack, callStack)
#endif

import Distribution.Simple.Errors
import Distribution.Simple.PackageDescription (flattenDups)
Expand Down Expand Up @@ -830,30 +833,46 @@ readProjectLocalFreezeConfig verbosity httpTransport distDirLayout =
"freeze"
"project freeze file"

{- HLINT ignore "Defined but not used" -}

-- | Reads a named extended (with imports and conditionals) config file in the given project root dir, or returns empty.
#ifdef LEGACY_COMPARISON
readProjectFileSkeleton :: HasCallStack => Verbosity -> HttpTransport -> DistDirLayout -> String -> String -> Rebuild ProjectConfigSkeleton
#else
readProjectFileSkeleton :: Verbosity -> HttpTransport -> DistDirLayout -> String -> String -> Rebuild ProjectConfigSkeleton
#endif
readProjectFileSkeleton
verbosity
httpTransport
dir@DistDirLayout{distProjectFile, distDownloadSrcDirectory}
dir
extensionName
extensionDescription = do
legacyPcs <- readProjectFileSkeletonLegacy verbosity httpTransport dir extensionName extensionDescription
exists <- liftIO $ doesFileExist extensionFile
if exists
then do
monitorFiles [monitorFileHashed extensionFile]
extensionDescription =
do
exists <- liftIO $ doesFileExist extensionFile
if exists
then do
monitorFiles [monitorFileHashed extensionFile]
parseConfig
else do
monitorFiles [monitorNonExistentFile extensionFile]
return mempty
where
extensionFile = (distProjectFile dir) extensionName
readExtensionFile :: Verbosity -> FilePath -> IO ProjectConfigSkeleton
readExtensionFile verbosity' file = readAndParseFile (Parsec.parseProject extensionFile (distDownloadSrcDirectory dir) httpTransport verbosity' . ProjectConfigToParse) verbosity' file
#ifdef LEGACY_COMPARISON
parseConfig = do
legacyPcs <- readProjectFileSkeletonLegacy verbosity httpTransport dir extensionName extensionDescription
pcs <- liftIO $ readExtensionFile verbosity extensionFile
monitorFiles $ map monitorFileHashed (projectConfigPathRoot <$> projectSkeletonImports pcs)
unless (legacyPcs == pcs) (error (show callStack ++ "\nParsec: " ++ show pcs ++ "\nLegacy: " ++ show legacyPcs))
pure pcs
else do
monitorFiles [monitorNonExistentFile extensionFile]
return mempty
where
extensionFile = distProjectFile extensionName
readExtensionFile :: Verbosity -> FilePath -> IO ProjectConfigSkeleton
readExtensionFile verbosity' file = readAndParseFile (Parsec.parseProject extensionFile distDownloadSrcDirectory httpTransport verbosity' . ProjectConfigToParse) verbosity' file
return pcs
#else
parseConfig = do
pcs <- liftIO $ readExtensionFile verbosity extensionFile
monitorFiles $ map monitorFileHashed (projectConfigPathRoot <$> projectSkeletonImports pcs)
return pcs
#endif

readAndParseFile
:: (BS.ByteString -> IO (Parsec.ParseResult a))
Expand Down
Loading