Skip to content

Commit

Permalink
Capture installed package information.
Browse files Browse the repository at this point in the history
The goal is to learn the installed package id of the package we just
installed, as necessary for #1860. We achieve this by inserting an
additional call to "setup register" that produces the installed package
information in a file. We read and parse that file and could now return
the installed package id, but it is not clear what interface would be
appropriate.
  • Loading branch information
Toxaris committed Sep 8, 2013
1 parent 5373be5 commit 142f420
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions cabal-install/Distribution/Client/Install.hs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ import qualified Distribution.Simple.Setup as Cabal
, registerCommand, RegisterFlags(..), emptyRegisterFlags
, testCommand, TestFlags(..), emptyTestFlags )
import Distribution.Simple.Utils
( rawSystemExit, comparing, writeFileAtomic )
( rawSystemExit, comparing, writeFileAtomic
, withTempFile , withFileContents )
import Distribution.Simple.InstallDirs as InstallDirs
( PathTemplate, fromPathTemplate, toPathTemplate, substPathTemplate
, initialPathTemplateEnv, installDirsTemplateEnv )
Expand Down Expand Up @@ -1209,15 +1210,32 @@ installUnpackedPackage verbosity buildLimit installLock numJobs
| otherwise = TestsNotTried

-- Install phase
onFailure InstallFailed $ criticalSection installLock $
onFailure InstallFailed $ criticalSection installLock $ do
-- Capture installed package configuration file
maybePkgConf <-
if shouldRegister then do
tmp <- getTemporaryDirectory
withTempFile tmp (tempTemplate "pkgConf") $ \pkgConfFile handle -> do
hClose handle
let registerFlags' version = (registerFlags version) {
Cabal.regGenPkgConf = toFlag (Just pkgConfFile)
}
setup Cabal.registerCommand registerFlags'
withFileContents pkgConfFile $ \pkgConfText ->
case Installed.parseInstalledPackageInfo pkgConfText of
Installed.ParseFailed perror -> error (show perror)
Installed.ParseOk warnings pkgConf -> return (Just pkgConf)
else return Nothing

-- Actual installation
withWin32SelfUpgrade verbosity configFlags compid platform pkg $ do
case rootCmd miscOptions of
(Just cmd) -> reexec cmd
Nothing -> do
setup Cabal.copyCommand copyFlags
when shouldRegister $ do
setup Cabal.registerCommand registerFlags
return (Right (BuildOk docsResult testsResult))
return (Right (BuildOk docsResult testsResult))

where
pkgid = packageId pkg
Expand Down Expand Up @@ -1246,6 +1264,7 @@ installUnpackedPackage verbosity buildLimit installLock numJobs
Cabal.regVerbosity = toFlag verbosity'
}
verbosity' = maybe verbosity snd useLogFile
tempTemplate name = name ++ "-" ++ display pkgid

addDefaultInstallDirs :: ConfigFlags -> IO ConfigFlags
addDefaultInstallDirs configFlags' = do
Expand Down

0 comments on commit 142f420

Please sign in to comment.