From fbbb3862f4dfc4bfa9ddb17baa3fb5906539da87 Mon Sep 17 00:00:00 2001 From: Oleg Grenrus Date: Mon, 20 Apr 2020 13:56:13 +0300 Subject: [PATCH] Refactor cabalInstallVersions, add make doctest-cli --- Makefile | 4 ++++ .../Distribution/Client/BuildReports/Anonymous.hs | 8 ++------ cabal-install/Distribution/Client/Config.hs | 8 +++----- cabal-install/Distribution/Client/GZipUtils.hs | 4 ++++ cabal-install/Distribution/Client/HttpUtils.hs | 6 ++---- .../Distribution/Client/ProjectPlanOutput.hs | 4 ++-- cabal-install/Distribution/Client/Utils.hs | 15 ++++++++++++++- cabal-install/Distribution/Client/VCS.hs | 2 +- 8 files changed, 32 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index e6548e2e65a..4c2bafc336f 100644 --- a/Makefile +++ b/Makefile @@ -107,6 +107,10 @@ ghcid-cli : doctest : doctest --fast Cabal/Distribution Cabal/Language +# This is not run as part of validate.sh (we need hackage-security, which is tricky to get). +doctest-cli : + doctest -D__DOCTEST__ --fast cabal-install/Distribution + # tests check-tests : diff --git a/cabal-install/Distribution/Client/BuildReports/Anonymous.hs b/cabal-install/Distribution/Client/BuildReports/Anonymous.hs index 9c7c0f3d302..0b07f01339c 100644 --- a/cabal-install/Distribution/Client/BuildReports/Anonymous.hs +++ b/cabal-install/Distribution/Client/BuildReports/Anonymous.hs @@ -33,16 +33,13 @@ import qualified Distribution.Client.Types as BR ( BuildOutcome, BuildFailure(..), BuildResult(..) , DocsResult(..), TestsResult(..) ) import Distribution.Client.Utils - ( mergeBy, MergeResult(..) ) -import qualified Paths_cabal_install (version) + ( mergeBy, MergeResult(..), cabalInstallVersion ) import Distribution.Package ( PackageIdentifier(..), mkPackageName ) import Distribution.PackageDescription ( FlagName, mkFlagName, unFlagName , FlagAssignment, mkFlagAssignment, unFlagAssignment ) -import Distribution.Version - ( mkVersion' ) import Distribution.System ( OS, Arch ) import Distribution.Compiler @@ -159,8 +156,7 @@ new os' arch' comp pkgid flags deps result = cabalInstallID :: PackageIdentifier cabalInstallID = - PackageIdentifier (mkPackageName "cabal-install") - (mkVersion' Paths_cabal_install.version) + PackageIdentifier (mkPackageName "cabal-install") cabalInstallVersion -- ------------------------------------------------------------ -- * External format diff --git a/cabal-install/Distribution/Client/Config.hs b/cabal-install/Distribution/Client/Config.hs index b17c3584ec2..3ca2678fea3 100644 --- a/cabal-install/Distribution/Client/Config.hs +++ b/cabal-install/Distribution/Client/Config.hs @@ -109,6 +109,8 @@ import Distribution.Simple.Program ( defaultProgramDb ) import Distribution.Simple.Utils ( die', notice, warn, lowercase, cabalVersion ) +import Distribution.Client.Utils + ( cabalInstallVersion ) import Distribution.Compiler ( CompilerFlavor(..), defaultCompilerFlavor ) import Distribution.Verbosity @@ -145,10 +147,6 @@ import Distribution.Compat.Environment ( getEnvironment, lookupEnv ) import Distribution.Compat.Exception ( catchIO ) -import qualified Paths_cabal_install - ( version ) -import Data.Version - ( showVersion ) import Data.Char ( isSpace ) import qualified Data.Map as M @@ -829,7 +827,7 @@ writeConfigFile file comments vals = do ,"-- This config file was generated using the following versions" ,"-- of Cabal and cabal-install:" ,"-- Cabal library version: " ++ Text.display cabalVersion - ,"-- cabal-install version: " ++ showVersion Paths_cabal_install.version + ,"-- cabal-install version: " ++ Text.display cabalInstallVersion ,"","" ] diff --git a/cabal-install/Distribution/Client/GZipUtils.hs b/cabal-install/Distribution/Client/GZipUtils.hs index 3f467555266..003ba0e99c7 100644 --- a/cabal-install/Distribution/Client/GZipUtils.hs +++ b/cabal-install/Distribution/Client/GZipUtils.hs @@ -24,6 +24,10 @@ import Distribution.Client.Compat.Prelude import Codec.Compression.Zlib.Internal import Data.ByteString.Lazy.Internal as BS (ByteString(Empty, Chunk)) +#ifndef MIN_VERSION_zlib +#define MIN_VERSION_zlib(x,y,z) 1 +#endif + #if MIN_VERSION_zlib(0,6,0) import Control.Exception (throw) import Control.Monad.ST.Lazy (ST, runST) diff --git a/cabal-install/Distribution/Client/HttpUtils.hs b/cabal-install/Distribution/Client/HttpUtils.hs index 96e98cec69a..79b36f2fcd2 100644 --- a/cabal-install/Distribution/Client/HttpUtils.hs +++ b/cabal-install/Distribution/Client/HttpUtils.hs @@ -34,14 +34,13 @@ import Control.DeepSeq ( force ) import Control.Monad ( guard ) -import qualified Paths_cabal_install (version) import Distribution.Verbosity (Verbosity) import Distribution.Pretty (prettyShow) import Distribution.Simple.Utils ( die', info, warn, debug, notice , copyFileVerbose, withTempFile, IOData (..) ) import Distribution.Client.Utils - ( withTempFileName ) + ( withTempFileName, cabalInstallVersion ) import Distribution.Client.Types ( unRepoName, RemoteRepo(..) ) import Distribution.System @@ -72,7 +71,6 @@ import Distribution.Simple.Program.Run import Numeric (showHex) import System.Random (randomRIO) import System.Exit (ExitCode(..)) -import Data.Version (showVersion) import qualified Crypto.Hash.SHA256 as SHA256 import qualified Data.ByteString.Base16 as Base16 @@ -872,7 +870,7 @@ plainHttpTransport = -- userAgent :: String -userAgent = concat [ "cabal-install/", showVersion Paths_cabal_install.version +userAgent = concat [ "cabal-install/", prettyShow cabalInstallVersion , " (", prettyShow buildOS, "; ", prettyShow buildArch, ")" ] diff --git a/cabal-install/Distribution/Client/ProjectPlanOutput.hs b/cabal-install/Distribution/Client/ProjectPlanOutput.hs index 38311b25e5c..c623a4d6104 100644 --- a/cabal-install/Distribution/Client/ProjectPlanOutput.hs +++ b/cabal-install/Distribution/Client/ProjectPlanOutput.hs @@ -23,6 +23,7 @@ import Distribution.Client.Types.PackageLocation (PackageLocation(..)) import Distribution.Client.Types.ConfiguredId (confInstId) import Distribution.Client.Types.SourceRepo (SourceRepoMaybe, SourceRepositoryPackage (..)) import Distribution.Client.HashValue (showHashValue, hashValue) +import Distribution.Client.Utils (cabalInstallVersion) import qualified Distribution.Client.InstallPlan as InstallPlan import qualified Distribution.Client.Utils.Json as J @@ -49,7 +50,6 @@ import Distribution.Compat.Graph (Graph, Node) import qualified Distribution.Compat.Binary as Binary import Distribution.Simple.Utils import Distribution.Verbosity -import qualified Paths_cabal_install as Our (version) import Prelude () import Distribution.Client.Compat.Prelude @@ -90,7 +90,7 @@ encodePlanAsJson :: DistDirLayout -> ElaboratedInstallPlan -> ElaboratedSharedCo encodePlanAsJson distDirLayout elaboratedInstallPlan elaboratedSharedConfig = --TODO: [nice to have] include all of the sharedPackageConfig and all of -- the parts of the elaboratedInstallPlan - J.object [ "cabal-version" J..= jdisplay Our.version + J.object [ "cabal-version" J..= jdisplay cabalInstallVersion , "cabal-lib-version" J..= jdisplay cabalVersion , "compiler-id" J..= (J.String . showCompilerId . pkgConfigCompiler) elaboratedSharedConfig diff --git a/cabal-install/Distribution/Client/Utils.hs b/cabal-install/Distribution/Client/Utils.hs index b37825adc7e..bc7bde50ef5 100644 --- a/cabal-install/Distribution/Client/Utils.hs +++ b/cabal-install/Distribution/Client/Utils.hs @@ -19,7 +19,8 @@ module Distribution.Client.Utils ( MergeResult(..) , tryFindPackageDesc , relaxEncodingErrors , ProgressPhase (..) - , progressMessage) + , progressMessage + , cabalInstallVersion) where import Prelude () @@ -29,6 +30,7 @@ import Distribution.Compat.Environment import Distribution.Compat.Exception ( catchIO ) import Distribution.Compat.Time ( getModTime ) import Distribution.Simple.Setup ( Flag(..) ) +import Distribution.Version import Distribution.Verbosity import Distribution.Simple.Utils ( die', findPackageDesc, noticeNoWrap ) import qualified Data.ByteString.Lazy as BS @@ -61,6 +63,10 @@ import qualified System.Directory as Dir import qualified System.IO.Error as IOError #endif +#ifndef __DOCTEST__ +import qualified Paths_cabal_install (version) +#endif + -- | Generic merging utility. For sorted input lists this is a full outer join. -- mergeBy :: (a -> b -> Ordering) -> [a] -> [b] -> [MergeResult a b] @@ -356,3 +362,10 @@ progressMessage verbosity phase subject = do ProgressHaddock -> "Haddock " ProgressInstalling -> "Installing " ProgressCompleted -> "Completed " + +cabalInstallVersion :: Version +#ifdef __DOCTEST__ +cabalInstallVersion = mkVersion [3,3] +#else +cabalInstallVersion = mkVersion' Paths_cabal_install.version +#endif diff --git a/cabal-install/Distribution/Client/VCS.hs b/cabal-install/Distribution/Client/VCS.hs index 784c22ecc28..f5f96ea1292 100644 --- a/cabal-install/Distribution/Client/VCS.hs +++ b/cabal-install/Distribution/Client/VCS.hs @@ -545,7 +545,7 @@ svnProgram = (simpleProgram "svn") { -- -- % cat foo -- first line --- >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> +-- >> >>>>>>>>>>>>>>>>>>>>>>>>>>>>> -- branch BBB -- ================================ -- branch AAA