Skip to content

Commit

Permalink
Add --cabal-ghc/-pkg flags to 'configure'
Browse files Browse the repository at this point in the history
Add 'SetupWrapperFlags' with flags to configure a path to GHC and GHC-PKG to
build 'Setup.hs'.

This is an initial draft implementation done primarily for code review of the
basic design decision, so only the configure and the install commands respect
these flags.
  • Loading branch information
Sven Heyll committed Nov 2, 2014
1 parent 1f41dbf commit 06c2501
Show file tree
Hide file tree
Showing 7 changed files with 213 additions and 83 deletions.
13 changes: 13 additions & 0 deletions cabal-install/Distribution/Client/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import Distribution.Client.BuildReports.Types
( ReportLevel(..) )
import Distribution.Client.Setup
( GlobalFlags(..), globalCommand, defaultGlobalFlags
, SetupWrapperFlags(..), setupWrapperOptions
, ConfigExFlags(..), configureExOptions, defaultConfigExFlags
, InstallFlags(..), installOptions, defaultInstallFlags
, UploadFlags(..), uploadCommand
Expand Down Expand Up @@ -127,6 +128,7 @@ import qualified Data.Map as M

data SavedConfig = SavedConfig {
savedGlobalFlags :: GlobalFlags,
savedSetupWrapperFlags :: SetupWrapperFlags,
savedInstallFlags :: InstallFlags,
savedConfigureFlags :: ConfigFlags,
savedConfigureExFlags :: ConfigExFlags,
Expand All @@ -140,6 +142,7 @@ data SavedConfig = SavedConfig {
instance Monoid SavedConfig where
mempty = SavedConfig {
savedGlobalFlags = mempty,
savedSetupWrapperFlags = mempty,
savedInstallFlags = mempty,
savedConfigureFlags = mempty,
savedConfigureExFlags = mempty,
Expand All @@ -151,6 +154,7 @@ instance Monoid SavedConfig where
}
mappend a b = SavedConfig {
savedGlobalFlags = combine savedGlobalFlags,
savedSetupWrapperFlags = combine savedSetupWrapperFlags,
savedInstallFlags = combine savedInstallFlags,
savedConfigureFlags = combine savedConfigureFlags,
savedConfigureExFlags = combine savedConfigureExFlags,
Expand Down Expand Up @@ -367,6 +371,7 @@ commentSavedConfig = do
globalInstallDirs <- defaultInstallDirs defaultCompiler False True
return SavedConfig {
savedGlobalFlags = defaultGlobalFlags,
savedSetupWrapperFlags = mempty,
savedInstallFlags = defaultInstallFlags,
savedConfigureExFlags = defaultConfigExFlags,
savedConfigureFlags = (defaultConfigFlags defaultProgramConfiguration) {
Expand All @@ -388,6 +393,10 @@ configFieldDescriptions =
(commandOptions globalCommand ParseArgs)
["version", "numeric-version", "config-file", "sandbox-config-file"] []

++ toSavedConfig liftSetupWrapperFlag
(setupWrapperOptions ParseArgs)
[] []

++ toSavedConfig liftConfigFlag
(configureOptions ParseArgs)
(["builddir", "constraint", "dependency"]
Expand Down Expand Up @@ -501,6 +510,10 @@ liftGlobalFlag :: FieldDescr GlobalFlags -> FieldDescr SavedConfig
liftGlobalFlag = liftField
savedGlobalFlags (\flags conf -> conf { savedGlobalFlags = flags })

liftSetupWrapperFlag :: FieldDescr SetupWrapperFlags -> FieldDescr SavedConfig
liftSetupWrapperFlag = liftField
savedSetupWrapperFlags (\flags conf -> conf { savedSetupWrapperFlags = flags })

liftConfigFlag :: FieldDescr ConfigFlags -> FieldDescr SavedConfig
liftConfigFlag = liftField
savedConfigureFlags (\flags conf -> conf { savedConfigureFlags = flags })
Expand Down
12 changes: 8 additions & 4 deletions cabal-install/Distribution/Client/Configure.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ import Distribution.Client.InstallPlan (InstallPlan)
import Distribution.Client.IndexUtils as IndexUtils
( getSourcePackages, getInstalledPackages )
import Distribution.Client.Setup
( ConfigExFlags(..), configureCommand, filterConfigureFlags )
( ConfigExFlags(..), configureCommand, filterConfigureFlags
, SetupWrapperFlags(..) )
import Distribution.Client.Types as Source
import Distribution.Client.SetupWrapper
( setupWrapper, SetupScriptOptions(..), defaultSetupScriptOptions )
( setupWrapper, SetupScriptOptions(..), defaultSetupScriptOptions
, updateSetupScriptOptions )
import Distribution.Client.Targets
( userToPackageConstraint )

Expand Down Expand Up @@ -80,12 +82,13 @@ configure :: Verbosity
-> Compiler
-> Platform
-> ProgramConfiguration
-> SetupWrapperFlags
-> ConfigFlags
-> ConfigExFlags
-> [String]
-> IO ()
configure verbosity packageDBs repos comp platform conf
configFlags configExFlags extraArgs = do
setupWrapperFlags configFlags configExFlags extraArgs = do

installedPkgIndex <- getInstalledPackages verbosity comp packageDBs conf
sourcePkgDb <- getSourcePackages verbosity repos
Expand Down Expand Up @@ -114,7 +117,8 @@ configure verbosity packageDBs repos comp platform conf
++ "one local ready package."

where
setupScriptOptions index = SetupScriptOptions {
setupScriptOptions index =
updateSetupScriptOptions setupWrapperFlags $ defaultSetupScriptOptions {
useCabalVersion = chooseCabalVersion configExFlags
(flagToMaybe (configCabalVersion configExFlags)),
useCompiler = Just comp,
Expand Down
32 changes: 19 additions & 13 deletions cabal-install/Distribution/Client/Install.hs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ import qualified Distribution.Client.InstallPlan as InstallPlan
import Distribution.Client.InstallPlan (InstallPlan)
import Distribution.Client.Setup
( GlobalFlags(..)
, SetupWrapperFlags(..)
, ConfigFlags(..), configureCommand, filterConfigureFlags
, ConfigExFlags(..), InstallFlags(..) )
import Distribution.Client.Config
Expand All @@ -86,7 +87,8 @@ import Distribution.Client.Types as Source
import Distribution.Client.BuildReports.Types
( ReportLevel(..) )
import Distribution.Client.SetupWrapper
( setupWrapper, SetupScriptOptions(..), defaultSetupScriptOptions )
( setupWrapper, SetupScriptOptions(..), defaultSetupScriptOptions
, updateSetupScriptOptions )
import qualified Distribution.Client.BuildReports.Anonymous as BuildReports
import qualified Distribution.Client.BuildReports.Storage as BuildReports
( storeAnonymous, storeLocal, fromInstallPlan, fromPlanningFailure )
Expand Down Expand Up @@ -179,15 +181,16 @@ install
-> UseSandbox
-> Maybe SandboxPackageInfo
-> GlobalFlags
-> SetupWrapperFlags
-> ConfigFlags
-> ConfigExFlags
-> InstallFlags
-> HaddockFlags
-> [UserTarget]
-> IO ()
install verbosity packageDBs repos comp platform conf useSandbox mSandboxPkgInfo
globalFlags configFlags configExFlags installFlags haddockFlags
userTargets0 = do
globalFlags setupWrapperFlags configFlags configExFlags installFlags
haddockFlags userTargets0 = do

installContext <- makeInstallContext verbosity args (Just userTargets0)
planResult <- foldProgress logMsg (return . Left) (return . Right) =<<
Expand All @@ -201,9 +204,9 @@ install verbosity packageDBs repos comp platform conf useSandbox mSandboxPkgInfo
processInstallPlan verbosity args installContext installPlan
where
args :: InstallArgs
args = (packageDBs, repos, comp, platform, conf, useSandbox, mSandboxPkgInfo,
globalFlags, configFlags, configExFlags, installFlags,
haddockFlags)
args = (packageDBs, repos, comp, platform, conf, useSandbox,
mSandboxPkgInfo, globalFlags, setupWrapperFlags, configFlags,
configExFlags, installFlags, haddockFlags)

die' message = die (message ++ if isUseSandbox useSandbox
then installFailedInSandbox else [])
Expand Down Expand Up @@ -231,6 +234,7 @@ type InstallArgs = ( PackageDBStack
, UseSandbox
, Maybe SandboxPackageInfo
, GlobalFlags
, SetupWrapperFlags
, ConfigFlags
, ConfigExFlags
, InstallFlags
Expand All @@ -241,7 +245,7 @@ makeInstallContext :: Verbosity -> InstallArgs -> Maybe [UserTarget]
-> IO InstallContext
makeInstallContext verbosity
(packageDBs, repos, comp, _, conf,_,_,
globalFlags, _, _, _, _) mUserTargets = do
globalFlags, _, _, _, _, _) mUserTargets = do

installedPkgIndex <- getInstalledPackages verbosity comp packageDBs conf
sourcePkgDb <- getSourcePackages verbosity repos
Expand Down Expand Up @@ -271,7 +275,7 @@ makeInstallPlan :: Verbosity -> InstallArgs -> InstallContext
-> IO (Progress String String InstallPlan)
makeInstallPlan verbosity
(_, _, comp, platform, _, _, mSandboxPkgInfo,
_, configFlags, configExFlags, installFlags,
_, _, configFlags, configExFlags, installFlags,
_)
(installedPkgIndex, sourcePkgDb,
_, pkgSpecifiers) = do
Expand All @@ -288,7 +292,7 @@ processInstallPlan :: Verbosity -> InstallArgs -> InstallContext
-> InstallPlan
-> IO ()
processInstallPlan verbosity
args@(_,_, comp, _, _, _, _, _, _, _, installFlags, _)
args@(_,_, comp, _, _, _, _, _, _, _, _, installFlags, _)
(installedPkgIndex, sourcePkgDb,
userTargets, pkgSpecifiers) installPlan = do
checkPrintPlan verbosity comp installedPkgIndex installPlan sourcePkgDb
Expand Down Expand Up @@ -654,7 +658,7 @@ printPlan dryRun verbosity plan sourcePkgDb = case plan of
-- 'postInstallActions', as (by definition) we don't have an install plan.
reportPlanningFailure :: Verbosity -> InstallArgs -> InstallContext -> String -> IO ()
reportPlanningFailure verbosity
(_, _, comp, platform, _, _, _
(_, _, comp, platform, _, _, _, _
,_, configFlags, _, installFlags, _)
(_, sourcePkgDb, _, pkgSpecifiers)
message = do
Expand Down Expand Up @@ -730,7 +734,7 @@ postInstallActions :: Verbosity
-> IO ()
postInstallActions verbosity
(packageDBs, _, comp, platform, conf, useSandbox, mSandboxPkgInfo
,globalFlags, configFlags, _, installFlags, _)
,globalFlags, _, configFlags, _, installFlags, _)
targets installPlan = do

unless oneShot $
Expand Down Expand Up @@ -966,7 +970,8 @@ performInstallations :: Verbosity
-> IO InstallPlan
performInstallations verbosity
(packageDBs, _, comp, _, conf, useSandbox, _,
globalFlags, configFlags, configExFlags, installFlags, haddockFlags)
globalFlags, setupWrapperFlags, configFlags, configExFlags, installFlags,
haddockFlags)
installedPkgIndex installPlan = do

-- With 'install -j' it can be a bit hard to tell whether a sandbox is used.
Expand Down Expand Up @@ -1006,7 +1011,8 @@ performInstallations verbosity
distPref = fromFlagOrDefault (useDistPref defaultSetupScriptOptions)
(configDistPref configFlags)

setupScriptOptions index lock = SetupScriptOptions {
setupScriptOptions index lock =
updateSetupScriptOptions setupWrapperFlags $ defaultSetupScriptOptions {
useCabalVersion = chooseCabalVersion configExFlags
(libVersion miscOptions),
useCompiler = Just comp,
Expand Down
51 changes: 30 additions & 21 deletions cabal-install/Distribution/Client/Sandbox.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ module Distribution.Client.Sandbox (

import Distribution.Client.Setup
( SandboxFlags(..), ConfigFlags(..), ConfigExFlags(..), InstallFlags(..)
, GlobalFlags(..), defaultConfigExFlags, defaultInstallFlags
, defaultSandboxLocation, globalRepos )
, GlobalFlags(..), SetupWrapperFlags(..)
, defaultConfigExFlags, defaultInstallFlags, defaultSandboxLocation
, globalRepos )
import Distribution.Client.Sandbox.Timestamp ( listModifiedDeps
, maybeAddCompilerTimestampRecord
, withAddTimestamps
Expand Down Expand Up @@ -549,12 +550,13 @@ data WereDepsReinstalled = ReinstalledSomeDeps | NoDepsReinstalled
-- | Reinstall those add-source dependencies that have been modified since
-- we've last installed them. Assumes that we're working inside a sandbox.
reinstallAddSourceDeps :: Verbosity
-> ConfigFlags -> ConfigExFlags
-> InstallFlags -> GlobalFlags
-> ConfigFlags -> ConfigExFlags -> InstallFlags
-> GlobalFlags -> SetupWrapperFlags
-> FilePath
-> IO WereDepsReinstalled
reinstallAddSourceDeps verbosity configFlags' configExFlags
installFlags globalFlags sandboxDir = topHandler' $ do
reinstallAddSourceDeps verbosity configFlags' configExFlags installFlags
globalFlags setupWrapperFlags
sandboxDir = topHandler' $ do
let sandboxDistPref = sandboxBuildDir sandboxDir
configFlags = configFlags'
{ configDistPref = Flag sandboxDistPref }
Expand All @@ -572,7 +574,8 @@ reinstallAddSourceDeps verbosity configFlags' configExFlags
,(globalRepos globalFlags)
,comp, platform, conf
,UseSandbox sandboxDir, Just sandboxPkgInfo
,globalFlags, configFlags, configExFlags, installFlags
,globalFlags, setupWrapperFlags
,configFlags, configExFlags, installFlags
,haddockFlags)

-- This can actually be replaced by a call to 'install', but we use a
Expand Down Expand Up @@ -682,34 +685,40 @@ maybeReinstallAddSourceDeps :: Verbosity
-> ConfigFlags -- ^ Saved configure flags
-- (from dist/setup-config)
-> GlobalFlags
-> SetupWrapperFlags
-> IO (UseSandbox, SavedConfig
,WereDepsReinstalled)
maybeReinstallAddSourceDeps verbosity numJobsFlag configFlags' globalFlags' = do
maybeReinstallAddSourceDeps verbosity
numJobsFlag
configFlags'
globalFlags'
setupWrapperFlags' = do
(useSandbox, config) <- loadConfigOrSandboxConfig verbosity globalFlags'
(configUserInstall configFlags')
case useSandbox of
NoSandbox -> return (NoSandbox, config, NoDepsReinstalled)
UseSandbox sandboxDir -> do
-- Reinstall the modified add-source deps.
let configFlags = savedConfigureFlags config
`mappendSomeSavedFlags`
configFlags'
configExFlags = defaultConfigExFlags
`mappend` savedConfigureExFlags config
installFlags' = defaultInstallFlags
`mappend` savedInstallFlags config
installFlags = installFlags' {
installNumJobs = installNumJobs installFlags'
`mappend` numJobsFlag
let configFlags = savedConfigureFlags config
`mappendSomeSavedFlags` configFlags'
configExFlags = defaultConfigExFlags
`mappend` savedConfigureExFlags config
installFlags' = defaultInstallFlags
`mappend` savedInstallFlags config
installFlags = installFlags' {
installNumJobs = installNumJobs installFlags'
`mappend` numJobsFlag
}
globalFlags = savedGlobalFlags config
-- This makes it possible to override things like 'remote-repo-cache'
-- from the command line. These options are hidden, and are only
-- useful for debugging, so this should be fine.
`mappend` globalFlags'
globalFlags = savedGlobalFlags config
`mappend` globalFlags'
setupWrapperFlags = savedSetupWrapperFlags config
`mappend` setupWrapperFlags'
depsReinstalled <- reinstallAddSourceDeps verbosity
configFlags configExFlags installFlags globalFlags
sandboxDir
setupWrapperFlags sandboxDir
return (UseSandbox sandboxDir, config, depsReinstalled)

where
Expand Down
Loading

4 comments on commit 06c2501

@23Skidoo
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need a special SetupWrapperFlags record - information about the build compiler is not specific to setup scripts and could be potentially used for other things.

The logical place to put this stuff is ConfigFlags and LocalBuildInfo. Add a configBuildHcPath flag to ConfigFlags, and a buildCompiler field to LocalBuildInfo. This will be consistent with already-existing configHcPath and compiler.

Then you can just pass LocalBuildInfo.buildCompiler to setupWrapper via the SetupScriptOptions.useCompiler field.

@sheyll
Copy link
Owner

@sheyll sheyll commented on 06c2501 Nov 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok thanks alot! I will exactly that.

@sheyll
Copy link
Owner

@sheyll sheyll commented on 06c2501 Nov 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any hints on testing?

@23Skidoo
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compile a build-type: Custom package with -v3 and check that the right compiler is used.

Please sign in to comment.