Skip to content

Commit

Permalink
Stop logging to file when build inplace
Browse files Browse the repository at this point in the history
In f70fc98, while refactoring
buildInplaceUnpackedPackage and buildAndInstallUnpackedPackage, we
started logging into a file on both cases, instead of logging to a file
only for buildAndInstallUnpackedPackage.

When building a package inplace, it is much more useful to be able to
see the GHC invocation directly outside of a log file.

This is especially relevant for Cabal developers working inplace.

Fixes haskell#9606
  • Loading branch information
alt-romes committed Jan 10, 2024
1 parent df5e188 commit 83d10da
Showing 1 changed file with 33 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,28 +151,27 @@ buildAndRegisterUnpackedPackage
-> ElaboratedReadyPackage
-> FilePath
-> FilePath
-> Maybe (FilePath)
-- ^ The path to an /initialized/ log file
-> (PackageBuildingPhase -> IO ())
-> IO (Maybe FilePath)
-- ^ Returns the path to the /initialized/ log file configured in
-- t'BuildTimeSettings' ('buildSettingLogFile'), if one exists.
-> IO ()
buildAndRegisterUnpackedPackage
verbosity
distDirLayout@DistDirLayout{distTempDirectory}
maybe_semaphore
BuildTimeSettings{buildSettingNumJobs, buildSettingLogFile}
BuildTimeSettings{buildSettingNumJobs}
registerLock
cacheLock
pkgshared@ElaboratedSharedConfig
{ pkgConfigCompiler = compiler
, pkgConfigCompilerProgs = progdb
, pkgConfigPlatform = platform
}
plan
rpkg@(ReadyPackage pkg)
srcdir
builddir
mlogFile
delegate = do
initLogFile

-- Configure phase
delegate $
Expand Down Expand Up @@ -238,10 +237,9 @@ buildAndRegisterUnpackedPackage
annotateFailure mlogFile ReplFailed $
setupInteractive replCommand replFlags replArgs

return mlogFile
return ()
where
uid = installedUnitId rpkg
pkgid = packageId rpkg

comp_par_strat = case maybe_semaphore of
Just sem_name -> Cabal.toFlag (getSemaphoreName sem_name)
Expand Down Expand Up @@ -386,21 +384,6 @@ buildAndRegisterUnpackedPackage
pkgConfDest
setup Cabal.registerCommand registerFlags (const [])

mlogFile :: Maybe FilePath
mlogFile =
case buildSettingLogFile of
Nothing -> Nothing
Just mkLogFile -> Just (mkLogFile compiler platform pkgid uid)

initLogFile :: IO ()
initLogFile =
case mlogFile of
Nothing -> return ()
Just logFile -> do
createDirectoryIfMissing True (takeDirectory logFile)
exists <- doesFileExist logFile
when exists $ removeFile logFile

withLogging :: (Maybe Handle -> IO r) -> IO r
withLogging action =
case mlogFile of
Expand Down Expand Up @@ -459,7 +442,7 @@ buildInplaceUnpackedPackage
buildResult :: BuildResultMisc
buildResult = (docsResult, testsResult)

mlogFile <- buildAndRegisterUnpackedPackage
buildAndRegisterUnpackedPackage
verbosity
distDirLayout
maybe_semaphore
Expand All @@ -471,6 +454,7 @@ buildInplaceUnpackedPackage
rpkg
srcdir
builddir
Nothing -- no log file for inplace builds!
$ \case
PBConfigurePhase{runConfigure} -> do
whenReConfigure $ do
Expand Down Expand Up @@ -572,7 +556,7 @@ buildInplaceUnpackedPackage
BuildResult
{ buildResultDocs = docsResult
, buildResultTests = testsResult
, buildResultLogFile = mlogFile
, buildResultLogFile = Nothing
}
where
dparams = elabDistDirParams pkgshared pkg
Expand Down Expand Up @@ -632,10 +616,13 @@ buildAndInstallUnpackedPackage
{ storePackageDBStack
}
maybe_semaphore
buildSettings@BuildTimeSettings{buildSettingNumJobs}
buildSettings@BuildTimeSettings{buildSettingNumJobs, buildSettingLogFile}
registerLock
cacheLock
pkgshared@ElaboratedSharedConfig{pkgConfigCompiler = compiler}
pkgshared@ElaboratedSharedConfig
{ pkgConfigCompiler = compiler
, pkgConfigPlatform = platform
}
plan
rpkg@(ReadyPackage pkg)
srcdir
Expand All @@ -653,7 +640,9 @@ buildAndInstallUnpackedPackage
-- TODO: [required feature] docs and tests
-- TODO: [required feature] sudo re-exec

mlogFile <- buildAndRegisterUnpackedPackage
initLogFile

buildAndRegisterUnpackedPackage
verbosity
distDirLayout
maybe_semaphore
Expand All @@ -665,6 +654,7 @@ buildAndInstallUnpackedPackage
rpkg
srcdir
builddir
mlogFile
$ \case
PBConfigurePhase{runConfigure} -> do
noticeProgress ProgressStarting
Expand Down Expand Up @@ -758,6 +748,21 @@ buildAndInstallUnpackedPackage
when (isParallelBuild buildSettingNumJobs) $
progressMessage verbosity phase dispname

mlogFile :: Maybe FilePath
mlogFile =
case buildSettingLogFile of
Nothing -> Nothing
Just mkLogFile -> Just (mkLogFile compiler platform pkgid uid)

initLogFile :: IO ()
initLogFile =
case mlogFile of
Nothing -> return ()
Just logFile -> do
createDirectoryIfMissing True (takeDirectory logFile)
exists <- doesFileExist logFile
when exists $ removeFile logFile

-- | The copy part of the installation phase when doing build-and-install
copyPkgFiles
:: Verbosity
Expand Down

0 comments on commit 83d10da

Please sign in to comment.