Commit 57024727 authored by Duncan Coutts's avatar Duncan Coutts
Browse files

Add install --log-builds flag

Eg can use cabal install foo --log-builds='$pkgid-$compiler.log'
and the build log for each package will written to a separate
file. If an existing file is given then the log is appended.
This or something like it should help in future with build
reporting of the non-anonymous kind.
parent 5cb6ea3b
...@@ -23,7 +23,10 @@ import Control.Monad ...@@ -23,7 +23,10 @@ import Control.Monad
( when, unless ) ( when, unless )
import System.Directory import System.Directory
( getTemporaryDirectory, doesFileExist ) ( getTemporaryDirectory, doesFileExist )
import System.FilePath ((</>),(<.>)) import System.FilePath
( (</>), (<.>) )
import System.IO
( openFile, IOMode(AppendMode) )
import Distribution.Client.Dependency import Distribution.Client.Dependency
( resolveDependenciesWithProgress, PackagesVersionPreference(..) ( resolveDependenciesWithProgress, PackagesVersionPreference(..)
...@@ -61,6 +64,9 @@ import Distribution.Simple.Setup ...@@ -61,6 +64,9 @@ import Distribution.Simple.Setup
( flagToMaybe ) ( flagToMaybe )
import Distribution.Simple.Utils import Distribution.Simple.Utils
( defaultPackageDesc, inDir, rawSystemExit, withTempDirectory ) ( defaultPackageDesc, inDir, rawSystemExit, withTempDirectory )
import Distribution.Simple.InstallDirs
( fromPathTemplate, toPathTemplate
, initialPathTemplateEnv, substPathTemplate )
import Distribution.Package import Distribution.Package
( PackageIdentifier(..), Package(..), thisPackageVersion ) ( PackageIdentifier(..), Package(..), thisPackageVersion )
import Distribution.PackageDescription as PackageDescription import Distribution.PackageDescription as PackageDescription
...@@ -144,9 +150,10 @@ installWithPlanner planner verbosity packageDB repos comp conf configFlags insta ...@@ -144,9 +150,10 @@ installWithPlanner planner verbosity packageDB repos comp conf configFlags insta
installPlan' <- installPlan' <-
executeInstallPlan installPlan $ \cpkg -> executeInstallPlan installPlan $ \cpkg ->
installConfiguredPackage configFlags cpkg $ \configFlags' apkg -> installConfiguredPackage configFlags cpkg $ \configFlags' apkg ->
installAvailablePackage verbosity apkg $ installAvailablePackage verbosity apkg $ \pkg mpath ->
installUnpackedPackage verbosity (setupScriptOptions installed) installUnpackedPackage verbosity (setupScriptOptions installed)
miscOptions configFlags' miscOptions configFlags'
pkg mpath useLogFile
writeInstallPlanBuildReports installPlan' writeInstallPlanBuildReports installPlan'
writeInstallPlanBuildLog installPlan' writeInstallPlanBuildLog installPlan'
printBuildFailures installPlan' printBuildFailures installPlan'
...@@ -163,6 +170,14 @@ installWithPlanner planner verbosity packageDB repos comp conf configFlags insta ...@@ -163,6 +170,14 @@ installWithPlanner planner verbosity packageDB repos comp conf configFlags insta
useLoggingHandle = Nothing, useLoggingHandle = Nothing,
useWorkingDir = Nothing useWorkingDir = Nothing
} }
useLogFile :: Maybe (PackageIdentifier -> FilePath)
useLogFile = fmap substLogFileName
(Cabal.flagToMaybe (installLogFile installFlags))
substLogFileName path pkg = fromPathTemplate
. substPathTemplate env
. toPathTemplate
$ path
where env = initialPathTemplateEnv (packageId pkg) (compilerId comp)
dryRun = Cabal.fromFlag (installDryRun installFlags) dryRun = Cabal.fromFlag (installDryRun installFlags)
miscOptions = InstallMisc { miscOptions = InstallMisc {
rootCmd = if Cabal.fromFlag (Cabal.configUserInstall configFlags) rootCmd = if Cabal.fromFlag (Cabal.configUserInstall configFlags)
...@@ -315,8 +330,10 @@ installUnpackedPackage :: Verbosity ...@@ -315,8 +330,10 @@ installUnpackedPackage :: Verbosity
-> Cabal.ConfigFlags -> Cabal.ConfigFlags
-> GenericPackageDescription -> GenericPackageDescription
-> Maybe FilePath -- ^ Directory to change to before starting the installation. -> Maybe FilePath -- ^ Directory to change to before starting the installation.
-> Maybe (PackageIdentifier -> FilePath) -- ^ File to log output to (if any)
-> IO BuildResult -> IO BuildResult
installUnpackedPackage verbosity scriptOptions miscOptions configFlags pkg mpath installUnpackedPackage verbosity scriptOptions miscOptions configFlags
pkg workingDir useLogFile
= onFailure ConfigureFailed $ do = onFailure ConfigureFailed $ do
setup configureCommand (filterConfigureFlags configFlags) setup configureCommand (filterConfigureFlags configFlags)
onFailure BuildFailed $ do onFailure BuildFailed $ do
...@@ -329,9 +346,14 @@ installUnpackedPackage verbosity scriptOptions miscOptions configFlags pkg mpath ...@@ -329,9 +346,14 @@ installUnpackedPackage verbosity scriptOptions miscOptions configFlags pkg mpath
return BuildOk return BuildOk
where where
buildCommand = Cabal.buildCommand defaultProgramConfiguration buildCommand = Cabal.buildCommand defaultProgramConfiguration
setup cmd flags = setup cmd flags = do
logFileHandle <- case useLogFile of
Nothing -> return Nothing
Just logFileName -> fmap Just $
openFile (logFileName (packageId pkg)) AppendMode
setupWrapper verbosity setupWrapper verbosity
scriptOptions { useWorkingDir = mpath } scriptOptions { useLoggingHandle = logFileHandle
, useWorkingDir = workingDir }
(Just $ PackageDescription.packageDescription pkg) (Just $ PackageDescription.packageDescription pkg)
cmd flags [] cmd flags []
reexec cmd = do reexec cmd = do
...@@ -341,7 +363,7 @@ installUnpackedPackage verbosity scriptOptions miscOptions configFlags pkg mpath ...@@ -341,7 +363,7 @@ installUnpackedPackage verbosity scriptOptions miscOptions configFlags pkg mpath
let self = bindir </> "cabal" <.> exeExtension let self = bindir </> "cabal" <.> exeExtension
weExist <- doesFileExist self weExist <- doesFileExist self
if weExist if weExist
then inDir mpath $ then inDir workingDir $
rawSystemExit verbosity cmd rawSystemExit verbosity cmd
[self, "install", "--only" [self, "install", "--only"
,"--verbose=" ++ showForCabal verbosity] ,"--verbose=" ++ showForCabal verbosity]
......
...@@ -204,7 +204,8 @@ data InstallFlags = InstallFlags { ...@@ -204,7 +204,8 @@ data InstallFlags = InstallFlags {
installDryRun :: Flag Bool, installDryRun :: Flag Bool,
installOnly :: Flag Bool, installOnly :: Flag Bool,
installRootCmd :: Flag String, installRootCmd :: Flag String,
installCabalVersion :: Flag Version installCabalVersion :: Flag Version,
installLogFile :: Flag FilePath
} }
defaultInstallFlags :: InstallFlags defaultInstallFlags :: InstallFlags
...@@ -212,7 +213,8 @@ defaultInstallFlags = InstallFlags { ...@@ -212,7 +213,8 @@ defaultInstallFlags = InstallFlags {
installDryRun = Flag False, installDryRun = Flag False,
installOnly = Flag False, installOnly = Flag False,
installRootCmd = mempty, installRootCmd = mempty,
installCabalVersion = mempty installCabalVersion = mempty,
installLogFile = mempty
} }
installCommand :: CommandUI (Cabal.ConfigFlags, InstallFlags) installCommand :: CommandUI (Cabal.ConfigFlags, InstallFlags)
...@@ -241,6 +243,12 @@ installCommand = configureCommand { ...@@ -241,6 +243,12 @@ installCommand = configureCommand {
(reqArg "VERSION" (readP_to_E ("Cannot parse cabal lib version: "++) (reqArg "VERSION" (readP_to_E ("Cannot parse cabal lib version: "++)
(fmap toFlag parse)) (fmap toFlag parse))
(map display . flagToList)) (map display . flagToList))
, option [] ["log-builds"]
"Log all builds to file (name template can use $pkgid, $compiler, $os, $arch)"
installLogFile (\v flags -> flags { installLogFile = v })
(reqArg' "FILE" toFlag flagToList)
] ++ case showOrParseArgs of -- TODO: remove when "cabal install" avoids ] ++ case showOrParseArgs of -- TODO: remove when "cabal install" avoids
ParseArgs -> ParseArgs ->
option [] ["only"] option [] ["only"]
...@@ -257,7 +265,8 @@ instance Monoid InstallFlags where ...@@ -257,7 +265,8 @@ instance Monoid InstallFlags where
installDryRun = combine installDryRun, installDryRun = combine installDryRun,
installOnly = combine installOnly, installOnly = combine installOnly,
installRootCmd = combine installRootCmd, installRootCmd = combine installRootCmd,
installCabalVersion = combine installCabalVersion installCabalVersion = combine installCabalVersion,
installLogFile = combine installLogFile
} }
where combine field = field a `mappend` field b where combine field = field a `mappend` field b
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment