From 3601819865a2eb3d9eccc2508980459984f7bce7 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Sat, 16 Apr 2016 22:38:48 -0700 Subject: [PATCH] Fix #3345 by having Install manually register packages Unfortunately, it was too difficult to factor out the common code between ProjectBuilding and Install. Signed-off-by: Edward Z. Yang --- cabal-install/Distribution/Client/Install.hs | 48 ++++++++++++------- cabal-install/cabal-install.cabal | 7 +++ .../IntegrationTests/custom/custom_dep.sh | 13 +++++ .../custom/custom_dep/client/B.hs | 2 + .../custom/custom_dep/client/Setup.hs | 2 + .../custom/custom_dep/client/client.cabal | 12 +++++ .../custom/custom_dep/custom/A.hs | 1 + .../custom/custom_dep/custom/Setup.hs | 2 + .../custom/custom_dep/custom/custom.cabal | 12 +++++ 9 files changed, 83 insertions(+), 16 deletions(-) create mode 100644 cabal-install/tests/IntegrationTests/custom/custom_dep.sh create mode 100644 cabal-install/tests/IntegrationTests/custom/custom_dep/client/B.hs create mode 100644 cabal-install/tests/IntegrationTests/custom/custom_dep/client/Setup.hs create mode 100644 cabal-install/tests/IntegrationTests/custom/custom_dep/client/client.cabal create mode 100644 cabal-install/tests/IntegrationTests/custom/custom_dep/custom/A.hs create mode 100644 cabal-install/tests/IntegrationTests/custom/custom_dep/custom/Setup.hs create mode 100644 cabal-install/tests/IntegrationTests/custom/custom_dep/custom/custom.cabal diff --git a/cabal-install/Distribution/Client/Install.hs b/cabal-install/Distribution/Client/Install.hs index 254fc04fae3..403c5c9757b 100644 --- a/cabal-install/Distribution/Client/Install.hs +++ b/cabal-install/Distribution/Client/Install.hs @@ -54,6 +54,7 @@ import Control.Applicative import Data.Traversable ( traverse ) #endif +import Control.Exception ( assert ) import Control.Monad ( filterM, forM_, when, unless ) import System.Directory @@ -122,8 +123,7 @@ import Distribution.Utils.NubList import Distribution.Simple.Compiler ( CompilerId(..), Compiler(compilerId), compilerFlavor , CompilerInfo(..), compilerInfo, PackageDB(..), PackageDBStack ) -import Distribution.Simple.Program (ProgramConfiguration, - defaultProgramConfiguration) +import Distribution.Simple.Program (ProgramConfiguration) import qualified Distribution.Simple.InstallDirs as InstallDirs import qualified Distribution.Simple.PackageIndex as PackageIndex import Distribution.Simple.PackageIndex (InstalledPackageIndex) @@ -143,6 +143,9 @@ import Distribution.Simple.Utils import Distribution.Simple.InstallDirs as InstallDirs ( PathTemplate, fromPathTemplate, toPathTemplate, substPathTemplate , initialPathTemplateEnv, installDirsTemplateEnv ) +import Distribution.Simple.Configure (interpretPackageDbFlags) +import Distribution.Simple.Register (registerPackage) +import Distribution.Simple.Program.HcPkg (MultiInstance(..)) import Distribution.Package ( PackageIdentifier(..), PackageId, packageName, packageVersion , Package(..) @@ -1094,8 +1097,8 @@ performInstallations verbosity (setupScriptOptions installedPkgIndex cacheLock rpkg) configFlags' - installFlags haddockFlags - cinfo platform pkg rpkg pkgoverride mpath useLogFile + installFlags haddockFlags comp conf + platform pkg rpkg pkgoverride mpath useLogFile where cinfo = compilerInfo comp @@ -1390,7 +1393,8 @@ installUnpackedPackage -> ConfigFlags -> InstallFlags -> HaddockFlags - -> CompilerInfo + -> Compiler + -> ProgramConfiguration -> Platform -> PackageDescription -> ReadyPackage @@ -1400,9 +1404,8 @@ installUnpackedPackage -> IO BuildResult installUnpackedPackage verbosity buildLimit installLock numJobs scriptOptions - configFlags installFlags haddockFlags - cinfo platform pkg rpkg pkgoverride workingDir useLogFile = do - + configFlags installFlags haddockFlags comp conf + platform pkg rpkg pkgoverride workingDir useLogFile = do -- Override the .cabal file if necessary case pkgoverride of Nothing -> return () @@ -1461,19 +1464,32 @@ installUnpackedPackage verbosity buildLimit installLock numJobs withWin32SelfUpgrade verbosity ipid configFlags cinfo platform pkg $ do setup Cabal.copyCommand copyFlags mLogPath - when shouldRegister $ do - setup Cabal.registerCommand registerFlags mLogPath -- Capture installed package configuration file, so that -- it can be incorporated into the final InstallPlan - maybePkgConfs <- maybeGenPkgConfs mLogPath - - return (Right (BuildOk docsResult testsResult maybePkgConfs)) + -- TODO: This is duplicated with + -- Distribution/Client/ProjectBuilding.hs, search for + -- the Note [Updating installedUnitId]. + ipkgs <- genPkgConfs mLogPath + let ipkgs' = case ipkgs of + [ipkg] -> [ipkg { Installed.installedUnitId = ipid }] + _ -> assert (any ((== ipid) . Installed.installedUnitId) + ipkgs) ipkgs + let packageDBs = interpretPackageDbFlags + (fromFlag (configUserInstall configFlags)) + (configPackageDBs configFlags) + forM_ ipkgs' $ \ipkg' -> + registerPackage verbosity comp conf + NoMultiInstance + packageDBs ipkg' + + return (Right (BuildOk docsResult testsResult ipkgs')) where pkgid = packageId pkg ipid = installedUnitId rpkg - buildCommand' = buildCommand defaultProgramConfiguration + cinfo = compilerInfo comp + buildCommand' = buildCommand conf buildFlags _ = emptyBuildFlags { buildDistPref = configDistPref configFlags, buildVerbosity = toFlag verbosity' @@ -1516,9 +1532,9 @@ installUnpackedPackage verbosity buildLimit installLock numJobs userInstall = fromFlagOrDefault defaultUserInstall (configUserInstall configFlags') - maybeGenPkgConfs :: Maybe FilePath + genPkgConfs :: Maybe FilePath -> IO [Installed.InstalledPackageInfo] - maybeGenPkgConfs mLogPath = + genPkgConfs mLogPath = if shouldRegister then do tmp <- getTemporaryDirectory withTempDirectory verbosity tmp (tempTemplate "pkgConf") $ \dir -> do diff --git a/cabal-install/cabal-install.cabal b/cabal-install/cabal-install.cabal index 2780db4a199..8aa77fbdeb4 100644 --- a/cabal-install/cabal-install.cabal +++ b/cabal-install/cabal-install.cabal @@ -31,6 +31,13 @@ Extra-Source-Files: -- Do NOT edit this section manually; instead, run the script. -- BEGIN gen-extra-source-files tests/IntegrationTests/common.sh + tests/IntegrationTests/custom/custom_dep.sh + tests/IntegrationTests/custom/custom_dep/client/B.hs + tests/IntegrationTests/custom/custom_dep/client/Setup.hs + tests/IntegrationTests/custom/custom_dep/client/client.cabal + tests/IntegrationTests/custom/custom_dep/custom/A.hs + tests/IntegrationTests/custom/custom_dep/custom/Setup.hs + tests/IntegrationTests/custom/custom_dep/custom/custom.cabal tests/IntegrationTests/custom/plain.err tests/IntegrationTests/custom/plain.sh tests/IntegrationTests/custom/plain/A.hs diff --git a/cabal-install/tests/IntegrationTests/custom/custom_dep.sh b/cabal-install/tests/IntegrationTests/custom/custom_dep.sh new file mode 100644 index 00000000000..dce72a1f993 --- /dev/null +++ b/cabal-install/tests/IntegrationTests/custom/custom_dep.sh @@ -0,0 +1,13 @@ +. ./common.sh +cd custom_dep +cabal sandbox init +cabal sandbox add-source custom +cabal sandbox add-source client +# Some care must be taken here: we want the Setup script +# to build against GHC's bundled Cabal, but passing +# --package-db=clear --package-db=global to cabal is +# insufficient, as these flags are NOT respected when +# building Setup scripts. Changing HOME to a location +# which definitely does not have a local .cabal +# directory works, the environment variable propagates to GHC. +HOME=`pwd` cabal install client diff --git a/cabal-install/tests/IntegrationTests/custom/custom_dep/client/B.hs b/cabal-install/tests/IntegrationTests/custom/custom_dep/client/B.hs new file mode 100644 index 00000000000..af119169669 --- /dev/null +++ b/cabal-install/tests/IntegrationTests/custom/custom_dep/client/B.hs @@ -0,0 +1,2 @@ +module B where +import A diff --git a/cabal-install/tests/IntegrationTests/custom/custom_dep/client/Setup.hs b/cabal-install/tests/IntegrationTests/custom/custom_dep/client/Setup.hs new file mode 100644 index 00000000000..9a994af677b --- /dev/null +++ b/cabal-install/tests/IntegrationTests/custom/custom_dep/client/Setup.hs @@ -0,0 +1,2 @@ +import Distribution.Simple +main = defaultMain diff --git a/cabal-install/tests/IntegrationTests/custom/custom_dep/client/client.cabal b/cabal-install/tests/IntegrationTests/custom/custom_dep/client/client.cabal new file mode 100644 index 00000000000..2bb74b34594 --- /dev/null +++ b/cabal-install/tests/IntegrationTests/custom/custom_dep/client/client.cabal @@ -0,0 +1,12 @@ +name: client +version: 0.1.0.0 +license: BSD3 +author: Edward Z. Yang +maintainer: ezyang@cs.stanford.edu +build-type: Simple +cabal-version: >=1.10 + +library + exposed-modules: B + build-depends: base, custom + default-language: Haskell2010 diff --git a/cabal-install/tests/IntegrationTests/custom/custom_dep/custom/A.hs b/cabal-install/tests/IntegrationTests/custom/custom_dep/custom/A.hs new file mode 100644 index 00000000000..d843c00b782 --- /dev/null +++ b/cabal-install/tests/IntegrationTests/custom/custom_dep/custom/A.hs @@ -0,0 +1 @@ +module A where diff --git a/cabal-install/tests/IntegrationTests/custom/custom_dep/custom/Setup.hs b/cabal-install/tests/IntegrationTests/custom/custom_dep/custom/Setup.hs new file mode 100644 index 00000000000..9a994af677b --- /dev/null +++ b/cabal-install/tests/IntegrationTests/custom/custom_dep/custom/Setup.hs @@ -0,0 +1,2 @@ +import Distribution.Simple +main = defaultMain diff --git a/cabal-install/tests/IntegrationTests/custom/custom_dep/custom/custom.cabal b/cabal-install/tests/IntegrationTests/custom/custom_dep/custom/custom.cabal new file mode 100644 index 00000000000..a8de1daa59f --- /dev/null +++ b/cabal-install/tests/IntegrationTests/custom/custom_dep/custom/custom.cabal @@ -0,0 +1,12 @@ +name: custom +version: 0.1.0.0 +license: BSD3 +author: Edward Z. Yang +maintainer: ezyang@cs.stanford.edu +build-type: Custom +cabal-version: >=1.10 + +library + exposed-modules: A + build-depends: base + default-language: Haskell2010